Documentation ¶
Overview ¶
Package types contains data types related to Fractal consensus.
Package types contains data types related to Fractal consensus.
Index ¶
- Constants
- Variables
- func BloomLookup(bin *Bloom, topic bytesBacked) bool
- func CalcGasLimit(parent *Block) uint64
- func DeriveSha(list DerivableList) common.Hash
- func LogsBloom(logs []*Log) *big.Int
- func Sender(signer Signer, tx *Transaction) (common.Address, error)
- type Block
- func (b *Block) Bloom() *Bloom
- func (b *Block) CacheBloom(bloom *Bloom)
- func (b *Block) CompareByHeightAndRoundAndSimpleHash(b2 *Block) int
- func (b *Block) CompareByRoundAndSimpleHash(b2 *Block) int
- func (b *Block) DecodeRLP(s *rlp.Stream) error
- func (b *Block) EncodeRLP(w io.Writer) error
- func (b *Block) FullHash() common.Hash
- func (b *Block) MarshalJSON() ([]byte, error)
- func (b *Block) SignHashByte() []byte
- func (b *Block) SimpleHash() common.Hash
- type BlockBody
- type BlockExecutedEvent
- type BlockHeader
- type BlockReceivePathEnum
- type BlockRoundHash
- type BlockRoundHashes
- type BlockStateCheckedEnum
- type Blocks
- type Bloom
- type ChainUpdateEvent
- type DerivableList
- type EIP155Signer
- type FakeSigner
- type FrontierSigner
- type GasPool
- type Log
- type LogForStorage
- type Message
- type NewMinedBlockEvent
- type NewTxsEvent
- type PackerECPubKey
- type PackerInfo
- type PackerInfoMap
- type PackerInfoMapCache
- type PkgReceivePath
- type PkgSigner
- type Receipt
- type ReceiptForStorage
- type Receipts
- type Signer
- type Transaction
- func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, ...) *Transaction
- func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, ...) *Transaction
- func SignTx(tx *Transaction, s Signer, prv crypto.PrivateKey) (*Transaction, error)
- func (tx *Transaction) AsMessage(s Signer) (Message, error)
- func (tx *Transaction) Broadcast() bool
- func (tx *Transaction) ChainId() *big.Int
- func (tx *Transaction) CheckNonce() bool
- func (tx *Transaction) Cost() *big.Int
- func (tx *Transaction) Data() []byte
- func (tx *Transaction) DecodeRLP(s *rlp.Stream) error
- func (tx *Transaction) EncodeRLP(w io.Writer) error
- func (tx *Transaction) Gas() uint64
- func (tx *Transaction) GasPrice() *big.Int
- func (tx *Transaction) Hash() common.Hash
- func (tx *Transaction) MarshalJSON() ([]byte, error)
- func (tx *Transaction) MatchPacker(packerGroupSize uint64, packerIndex uint32, signer Signer) bool
- func (tx *Transaction) Nonce() uint64
- func (tx *Transaction) PackingHash(signer Signer) common.Hash
- func (tx *Transaction) PackingHashUint64(signer Signer) uint64
- func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int)
- func (tx *Transaction) SetFrom(signer Signer, addr common.Address)
- func (tx *Transaction) Size() common.StorageSize
- func (tx *Transaction) To() *common.Address
- func (tx *Transaction) UnmarshalJSON(input []byte) error
- func (tx *Transaction) Value() *big.Int
- func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, error)
- type Transactions
- type TxByNonce
- type TxByPrice
- type TxPackage
- func (pkg *TxPackage) AddTransactions(txs []*Transaction) []*Transaction
- func (pkg *TxPackage) BlockFullHash() common.Hash
- func (pkg *TxPackage) DecodeRLP(s *rlp.Stream) error
- func (pkg *TxPackage) EncodeRLP(w io.Writer) error
- func (pkg *TxPackage) Fork() *TxPackage
- func (pkg *TxPackage) GasPrice() *big.Int
- func (pkg *TxPackage) GenTime() uint64
- func (pkg *TxPackage) Hash() common.Hash
- func (pkg *TxPackage) HopCount() uint64
- func (pkg *TxPackage) IncreaseHopCount()
- func (pkg *TxPackage) MarshalJSON() ([]byte, error)
- func (pkg *TxPackage) Nonce() uint64
- func (pkg *TxPackage) Packer() common.Address
- func (pkg *TxPackage) SetSignature(R, S, V *big.Int)
- func (pkg *TxPackage) Signature() (r *big.Int, s *big.Int, v *big.Int)
- func (pkg *TxPackage) Transactions() []*Transaction
- func (pkg *TxPackage) UnmarshalJSON(input []byte) error
- type TxPackages
- type TxWithIndex
Constants ¶
const ( // BloomByteLength represents the number of bytes used in a log bloom. BloomByteLength = 4096 // BloomBitLength represents the number of bits used in a log bloom. BloomBitLength = 8 * BloomByteLength )
const ( // ReceiptStatusFailed is the status code of a transaction if execution failed. ReceiptStatusFailed = uint64(0) // ReceiptStatusSuccessful is the status code of a transaction if execution succeeded. ReceiptStatusSuccessful = uint64(1) )
const NotInPackage uint32 = math.MaxUint32
If a transaction not in txPackage, the TxPackageIndex is NotInPackage.
Variables ¶
var ( // ErrGasLimitReached is returned by the gas pool if the amount of gas required // by a transaction is higher than what's left in the block. ErrGasLimitReached = errors.New("gas limit reached") )
var (
ErrInvalidChainId = errors.New("invalid chain id for signer")
)
var (
ErrInvalidPkgSig = errors.New("invalid transaction package v, r, s values")
)
var (
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
var ErrMapNotFoundInCache = errors.New("map not found in cache")
Functions ¶
func BloomLookup ¶
func CalcGasLimit ¶
CalcGasLimit computes the gas limit of the next block after parent. This is miner strategy, not consensus protocol.
func DeriveSha ¶
func DeriveSha(list DerivableList) common.Hash
func Sender ¶
func Sender(signer Signer, tx *Transaction) (common.Address, error)
Sender returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.
Sender may cache the address, allowing it to be used regardless of signing method. The cache is invalidated if the cached signer does not match the signer used in the current call.
Types ¶
type Block ¶
type Block struct { // contents Header BlockHeader Body BlockBody // whether the block state has been checked StateChecked BlockStateCheckedEnum // ReceivedAt time.Time ReceivedFrom interface{} ReceivedPath BlockReceivePathEnum // contains filtered or unexported fields }
Block represents a block in the Fractal blockchain.
func NewBlockWithHeader ¶
func NewBlockWithHeader(header *BlockHeader) *Block
func (*Block) CacheBloom ¶
func (*Block) CompareByHeightAndRoundAndSimpleHash ¶
return 1 if b is better then b2
func (*Block) CompareByRoundAndSimpleHash ¶
return 1 if b2 is behind b
func (*Block) FullHash ¶
Hash returns the keccak256 hash of full block. The hash is computed on the first call and cached thereafter.
func (*Block) MarshalJSON ¶
Serialize block to json format
func (*Block) SignHashByte ¶
func (*Block) SimpleHash ¶
Hash returns the keccak256 hash of block's consensus part. The hash is computed on the first call and cached thereafter.
type BlockBody ¶
type BlockBody struct { Transactions []*Transaction `json:"transactions" gencodec:"required"` TxPackageHashes []common.Hash `json:"txpackages" gencodec:"required"` }
BlockHeader represents the body of a block in the Fractal blockchain
type BlockExecutedEvent ¶
type BlockExecutedEvent struct{ Block *Block }
type BlockHeader ¶
type BlockHeader struct { ParentHash common.Hash `json:"parentHash" gencodec:"required"` Round uint64 `json:"round" gencodec:"required"` Sig []byte `json:"sig" gencodec:"required"` Coinbase common.Address `json:"miner" gencodec:"required"` Difficulty *big.Int `json:"difficulty" gencodec:"required"` Height uint64 `json:"height" gencodec:"required"` Amount uint64 `json:"amount" gencodec:"required"` GasLimit uint64 `json:"gasLimit" gencodec:"required"` GasUsed uint64 `json:"gasUsed" gencodec:"required"` StateHash common.Hash `json:"stateHash" gencodec:"required"` TxHash common.Hash `json:"txHash" gencodec:"required"` ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` ParentFullHash common.Hash `json:"parentFullHash" gencodec:"required"` Confirms []common.Hash `json:"confirms" gencodec:"required"` FullSig []byte `json:"fullSig" gencodec:"required"` MinedTime uint64 `json:"minedTime" gencodec:"required"` HopCount uint64 `json:"hopCount" gencodec:"required"` }
BlockHeader represents the header of a block in the Fractal blockchain
func (*BlockHeader) FullHash ¶
func (bh *BlockHeader) FullHash() common.Hash
Hash returns the keccak256 hash of full block. The hash is computed on the first call and cached thereafter.
func (*BlockHeader) SimpleHash ¶
func (bh *BlockHeader) SimpleHash() common.Hash
type BlockReceivePathEnum ¶
type BlockReceivePathEnum byte
const ( BlockNull BlockReceivePathEnum = iota BlockFastSync BlockMined )
type BlockRoundHash ¶
type for block complex index
type BlockRoundHashes ¶
type BlockRoundHashes []*BlockRoundHash
type for block index list
func (*BlockRoundHashes) SortByRoundHash ¶
func (list *BlockRoundHashes) SortByRoundHash()
sort blocks by round
type BlockStateCheckedEnum ¶
type BlockStateCheckedEnum byte
const ( NoBlockState BlockStateCheckedEnum = iota HasBlockStateButNotChecked BlockStateChecked )
type Bloom ¶
type Bloom [BloomByteLength]byte
Bloom represents a 32768 bit bloom filter.
func BytesToBloom ¶
BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.
func CreateBloom ¶
func (Bloom) MarshalText ¶
MarshalText encodes b as a hex string with 0x prefix.
func (*Bloom) SetBytes ¶
SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.
func (*Bloom) UnmarshalText ¶
UnmarshalText b as a hex string with 0x prefix.
type ChainUpdateEvent ¶
type ChainUpdateEvent struct{ Block *Block }
type DerivableList ¶
type EIP155Signer ¶
type EIP155Signer struct {
// contains filtered or unexported fields
}
EIP155Transaction implements Signer using the EIP155 rules.
func NewEIP155Signer ¶
func NewEIP155Signer(chainId uint64) EIP155Signer
func (EIP155Signer) Equal ¶
func (s EIP155Signer) Equal(s2 Signer) bool
func (EIP155Signer) Hash ¶
func (s EIP155Signer) Hash(tx *Transaction) common.Hash
Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.
func (EIP155Signer) Sender ¶
func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error)
func (EIP155Signer) SignatureValues ¶
func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error)
WithSignature returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.
type FakeSigner ¶
type FakeSigner struct{}
FakeSigner for test
func NewFakeSigner ¶
func NewFakeSigner() FakeSigner
func (FakeSigner) Equal ¶
func (s FakeSigner) Equal(s2 Signer) bool
func (FakeSigner) Hash ¶
func (s FakeSigner) Hash(tx *Transaction) common.Hash
Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.
func (FakeSigner) Sender ¶
func (s FakeSigner) Sender(tx *Transaction) (common.Address, error)
func (FakeSigner) SignatureValues ¶
func (s FakeSigner) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error)
WithSignature returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.
type FrontierSigner ¶
type FrontierSigner struct{}
func (FrontierSigner) Equal ¶
func (s FrontierSigner) Equal(s2 Signer) bool
func (FrontierSigner) Hash ¶
func (fs FrontierSigner) Hash(tx *Transaction) common.Hash
Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.
func (FrontierSigner) Sender ¶
func (fs FrontierSigner) Sender(tx *Transaction) (common.Address, error)
func (FrontierSigner) SignatureValues ¶
func (fs FrontierSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)
SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.
type GasPool ¶
type GasPool uint64
GasPool tracks the amount of gas available during execution of the transactions in a block. The zero value is a pool with zero gas available.
type Log ¶
type Log struct { // Consensus fields: // address of the contract that generated the event Address common.Address `json:"address" gencodec:"required"` // list of topics provided by the contract. Topics []common.Hash `json:"topics" gencodec:"required"` // supplied by the contract, usually ABI-encoded Data []byte `json:"data" gencodec:"required"` // Derived fields. These fields are filled in by the node // but not secured by consensus. // block in which the transaction was included BlockNumber uint64 `json:"blockNumber" gencodec:"required"` // hash of the transaction TxHash common.Hash `json:"transactionHash" gencodec:"required"` // index of the package in the block PkgIndex uint32 `json:"packageIndex" gencodec:"required"` // index of the transaction in the block/package TxIndex uint32 `json:"transactionIndex" gencodec:"required"` // index of the log in the receipt Index uint32 `json:"logIndex" gencodec:"required"` }
Log represents a contract log event. These events are generated by the WASM function and stored/indexed by the node.
func (*Log) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON.
type LogForStorage ¶
type LogForStorage Log
LogForStorage is a wrapper around a Log that flattens and parses the entire content of a log including non-consensus fields.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is a fully derived transaction and implements types.Message
func NewMessage ¶
func (Message) CheckNonce ¶
type NewMinedBlockEvent ¶
type NewMinedBlockEvent struct{ Block *Block }
type NewTxsEvent ¶
type NewTxsEvent struct{ Txs []*Transaction }
NewTxsEvent is posted when a batch of transactions enter the transaction pool.
type PackerECPubKey ¶
type PackerECPubKey [65]byte
type PackerInfo ¶
type PackerInfo struct { PackerPubKey PackerECPubKey Coinbase common.Address RpcAddress string // include ip address and port, }
type PackerInfoMap ¶
type PackerInfoMap struct { IndexPackerMap map[uint32]*PackerInfo PubKeyIndexMap map[PackerECPubKey]uint32 }
func NewPackerInfoMap ¶
func NewPackerInfoMap() *PackerInfoMap
type PackerInfoMapCache ¶
type PackerInfoMapCache struct {
// contains filtered or unexported fields
}
func NewPackerInfoMapCache ¶
func NewPackerInfoMapCache(cacheSize uint8) (*PackerInfoMapCache, error)
func (*PackerInfoMapCache) Get ¶
func (ps *PackerInfoMapCache) Get(blockHash common.Hash) (*PackerInfoMap, error)
func (*PackerInfoMapCache) Put ¶
func (ps *PackerInfoMapCache) Put(blockHash common.Hash, packerInfoMap *PackerInfoMap)
type PkgReceivePath ¶
type PkgReceivePath byte
const ( PkgReceivePathBegin PkgReceivePath = iota PkgReceivePathBroadcast PkgReceivePathSync PkgReceivePathFuture PkgReceivePathEnd )
func (PkgReceivePath) String ¶
func (p PkgReceivePath) String() string
type PkgSigner ¶
type PkgSigner interface { // Sign the txPackage with the given key, and return a new signed package. Sign(pkg *TxPackage, key crypto.PrivateKey) (*TxPackage, error) // VerifySignature verify the given package's signature RecoverPubKey(pkg *TxPackage) ([]byte, error) // Hash return the package hash that should be signed. Hash(pkg *TxPackage) common.Hash // SigToRSV transfer the signature into [r||s||v] format. SigToRSV(sig []byte) (r, s, v *big.Int, err error) // Equals return if the given signer == this one. Equals(signer PkgSigner) bool }
func MakePkgSigner ¶
func NewDefaultSigner ¶
func NewDefaultSigner() PkgSigner
type Receipt ¶
type Receipt struct { // Consensus fields PostState []byte `json:"root"` Status uint64 `json:"status"` CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"` Bloom *Bloom `json:"logsBloom" gencodec:"required"` Logs []*Log `json:"logs" gencodec:"required"` // Implementation fields (don't reorder!) TxHash common.Hash `json:"transactionHash" gencodec:"required"` ContractAddress common.Address `json:"contractAddress"` GasUsed uint64 `json:"gasUsed" gencodec:"required"` }
Receipt represents the results of a transaction.
func NewReceipt ¶
NewReceipt creates a barebone transaction receipt, copying the init fields.
func (*Receipt) DecodeRLP ¶
DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt from an RLP stream.
func (*Receipt) EncodeRLP ¶
EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt into an RLP stream. If no post state is present, byzantium fork is assumed.
func (Receipt) MarshalJSON ¶
MarshalJSON marshals as JSON.
func (*Receipt) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON.
type ReceiptForStorage ¶
type ReceiptForStorage Receipt
ReceiptForStorage is a wrapper around a Receipt that flattens and parses the entire content of a receipt, as opposed to only the consensus fields originally.
type Receipts ¶
type Receipts []*Receipt
Receipts is a wrapper around a Receipt array to implement DerivableList.
type Signer ¶
type Signer interface { // Sender returns the sender address of the transaction. Sender(tx *Transaction) (common.Address, error) // SignatureValues returns the raw R, S, V values corresponding to the // given signature. SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error) // Hash returns the hash to be signed. Hash(tx *Transaction) common.Hash // Equal returns true if the given signer is the same as the receiver. Equal(Signer) bool }
Signer encapsulates transaction signature handling. Note that this interface is not a stable API and may change at any time to accommodate new protocol rules.
func MakeSigner ¶
MakeSigner returns a Signer based on the given chain config and block number.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
func NewContractCreation ¶
func NewTransaction ¶
func SignTx ¶
func SignTx(tx *Transaction, s Signer, prv crypto.PrivateKey) (*Transaction, error)
SignTx signs the transaction using the given signer and private key
func (*Transaction) AsMessage ¶
func (tx *Transaction) AsMessage(s Signer) (Message, error)
AsMessage returns the transaction as a types.Message.
AsMessage requires a signer to derive the sender.
func (*Transaction) Broadcast ¶
func (tx *Transaction) Broadcast() bool
func (*Transaction) ChainId ¶
func (tx *Transaction) ChainId() *big.Int
ChainId returns which chain id this transaction was signed for (if at all)
func (*Transaction) CheckNonce ¶
func (tx *Transaction) CheckNonce() bool
func (*Transaction) Cost ¶
func (tx *Transaction) Cost() *big.Int
Cost returns amount + gasprice * gaslimit.
func (*Transaction) Data ¶
func (tx *Transaction) Data() []byte
func (*Transaction) DecodeRLP ¶
func (tx *Transaction) DecodeRLP(s *rlp.Stream) error
DecodeRLP implements rlp.Decoder
func (*Transaction) EncodeRLP ¶
func (tx *Transaction) EncodeRLP(w io.Writer) error
EncodeRLP implements rlp.Encoder
func (*Transaction) Gas ¶
func (tx *Transaction) Gas() uint64
func (*Transaction) GasPrice ¶
func (tx *Transaction) GasPrice() *big.Int
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() common.Hash
Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.
func (*Transaction) MarshalJSON ¶
func (tx *Transaction) MarshalJSON() ([]byte, error)
MarshalJSON encodes the web3 RPC transaction format.
func (*Transaction) MatchPacker ¶
func (tx *Transaction) MatchPacker(packerGroupSize uint64, packerIndex uint32, signer Signer) bool
func (*Transaction) Nonce ¶
func (tx *Transaction) Nonce() uint64
func (*Transaction) PackingHash ¶
func (tx *Transaction) PackingHash(signer Signer) common.Hash
func (*Transaction) PackingHashUint64 ¶
func (tx *Transaction) PackingHashUint64(signer Signer) uint64
func (*Transaction) RawSignatureValues ¶
func (*Transaction) Size ¶
func (tx *Transaction) Size() common.StorageSize
Size returns the true RLP encoded storage size of the transaction, either by encoding and returning it, or returning a previsouly cached value.
func (*Transaction) To ¶
func (tx *Transaction) To() *common.Address
To returns the recipient address of the transaction. It returns nil if the transaction is a contract creation.
func (*Transaction) UnmarshalJSON ¶
func (tx *Transaction) UnmarshalJSON(input []byte) error
UnmarshalJSON decodes the web3 RPC transaction format.
func (*Transaction) Value ¶
func (tx *Transaction) Value() *big.Int
func (*Transaction) WithSignature ¶
func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, error)
WithSignature returns a new transaction with the given signature. This signature is generated by Sign method in the crypto.PrivateKey interface.
type Transactions ¶
type Transactions []*Transaction
Transactions is a Transaction slice type for basic sorting.
func TxDifference ¶
func TxDifference(a, b Transactions) Transactions
TxDifference returns a new set which is the difference between a and b.
func (Transactions) GetRlp ¶
func (s Transactions) GetRlp(i int) []byte
GetRlp implements Rlpable and returns the i'th element of s in rlp.
func (Transactions) Swap ¶
func (s Transactions) Swap(i, j int)
Swap swaps the i'th and the j'th element in s.
type TxByNonce ¶
type TxByNonce Transactions
TxByNonce implements the sort interface to allow sorting a list of transactions by their nonces. This is usually only useful for sorting transactions from a single account, otherwise a nonce comparison doesn't make much sense.
type TxByPrice ¶
type TxByPrice Transactions
TxByPrice implements both the sort and the heap interface, making it useful for all at once sorting as well as individually adding and removing elements.
type TxPackage ¶
type TxPackage struct { ReceivedAt time.Time ReceivedFrom interface{} ReceivedPath PkgReceivePath // contains filtered or unexported fields }
func NewTxPackage ¶
func (*TxPackage) AddTransactions ¶
func (pkg *TxPackage) AddTransactions(txs []*Transaction) []*Transaction
func (*TxPackage) BlockFullHash ¶
func (*TxPackage) Hash ¶
Hash encode the pkgData with rlp and calc the hash value. This is the unique id of a txPackage.
func (*TxPackage) IncreaseHopCount ¶
func (pkg *TxPackage) IncreaseHopCount()
func (*TxPackage) MarshalJSON ¶
func (*TxPackage) SetSignature ¶
func (*TxPackage) Transactions ¶
func (pkg *TxPackage) Transactions() []*Transaction
func (*TxPackage) UnmarshalJSON ¶
type TxPackages ¶
type TxPackages []*TxPackage
type for txpkg array
func (*TxPackages) Copy ¶
func (pkgs *TxPackages) Copy() TxPackages
func (*TxPackages) Remove ¶
func (pkgs *TxPackages) Remove(hash common.Hash)
remove txpkg from array
type TxWithIndex ¶
type TxWithIndex struct { Tx *Transaction TxPackageIndex uint32 // index in txPackage TxIndex uint32 // index in block }