Documentation ¶
Index ¶
- func BloomLookup(bin, topic []byte) bool
- func CreateBloom(receipts Receipts) []byte
- func DeriveSha(list DerivableList) []byte
- func IsContractAddr(addr []byte) bool
- func LogsBloom(logs state.Logs) *big.Int
- func Number(b1, b2 *Block) bool
- type Block
- func (block *Block) BlockInfo() BlockInfo
- func (block *Block) CalcGasLimit(parent *Block) *big.Int
- func (block *Block) Diff() *big.Int
- func (self *Block) GetTransaction(hash []byte) *Transaction
- func (block *Block) Hash() ethutil.Bytes
- func (block *Block) HashNoNonce() []byte
- func (self *Block) N() []byte
- func (self *Block) Receipts() []*Receipt
- func (self *Block) RlpData() interface{}
- func (block *Block) RlpDecode(data []byte)
- func (block *Block) RlpEncode() []byte
- func (block *Block) RlpValueDecode(decoder *ethutil.Value)
- func (block *Block) Root() interface{}
- func (self *Block) SetReceipts(receipts Receipts)
- func (self *Block) SetTransactions(txs Transactions)
- func (block *Block) SetUncles(uncles []*Block)
- func (self *Block) Size() ethutil.StorageSize
- func (block *Block) State() *state.StateDB
- func (block *Block) String() string
- func (block *Block) Sync()
- func (block *Block) Transactions() Transactions
- func (block *Block) Trie() *trie.Trie
- func (block *Block) Undo()
- func (block *Block) Value() *ethutil.Value
- type BlockBy
- type BlockInfo
- type BlockProcessor
- type Blocks
- type Broadcaster
- type DerivableList
- type Receipt
- type Receipts
- type Transaction
- func (tx *Transaction) Curve() (v byte, r []byte, s []byte)
- func (self *Transaction) Data() []byte
- func (self *Transaction) From() []byte
- func (self *Transaction) Gas() *big.Int
- func (self *Transaction) GasPrice() *big.Int
- func (tx *Transaction) Hash() []byte
- func (self *Transaction) Nonce() uint64
- func (tx *Transaction) PublicKey() []byte
- func (tx *Transaction) RlpData() interface{}
- func (tx *Transaction) RlpDecode(data []byte)
- func (tx *Transaction) RlpEncode() []byte
- func (tx *Transaction) RlpValue() *ethutil.Value
- func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value)
- func (tx *Transaction) Sender() []byte
- func (self *Transaction) SetNonce(nonce uint64)
- func (tx *Transaction) Sign(privk []byte) error
- func (tx *Transaction) Signature(key []byte) []byte
- func (tx *Transaction) String() string
- func (self *Transaction) To() []byte
- func (self *Transaction) Value() *big.Int
- type Transactions
- type TxByNonce
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BloomLookup ¶
This function is called by the function "bloomFilter" defined in the file core/filter.go
func CreateBloom ¶
Creates the LogsBloom of a block. That is, the union of the LogsBloom of all the receipts in the block. Each block has many receipts. Each receipt has many logs (each log has 3 fields: the address, the topics and the data). The LogsBloom of a receipt will be the lower 11 bits of the modulo operation by 2048 of the kecchak(address and logs of the receipt) modulo 2048.
func DeriveSha ¶
func DeriveSha(list DerivableList) []byte
Takes as an argument a list of DerivableList objects, constructs a trie and returns the root hash of the trie.
func IsContractAddr ¶
Returns true if the provided 'addr' has a length of 0, false otherwise.
Types ¶
type Block ¶
type Block struct { PrevHash ethutil.Bytes Uncles Blocks UncleSha []byte Coinbase []byte Difficulty *big.Int Time int64 Number *big.Int GasLimit *big.Int GasUsed *big.Int Extra string Nonce ethutil.Bytes TxSha, ReceiptSha []byte LogsBloom []byte Reward *big.Int // contains filtered or unexported fields }
PrevHash: The Keccak 256-bit hash of the parent block’s header, in its entirety;
Uncles : The uncles of the Block.
UncleSha: The Keccak 256-bit hash of the uncles of the Block.
CoinBase: The address of the beneficiary.
beneficiary: The 160-bit address to which all fees collected from the successful mining of this block are transferred.
state: The Keccak 256-bit hash of the root node of the state trie, after all transactions are executed
Difficulty : Difficulty of the current block.
Time: Creation time of the Block.
Number: The number of the Block. This is equal to the number of ancestor blocks.
GasLimit: The maximum gas limit all the transactions inside this Block are allowed to consume.
GasUsed: The total gas used by the transactions of the Block.
Extra: An arbitrary byte array containing data relevant to this block. According to the Ethereum yellow paper this should be 32 bytes or less.
Nonce: The Block nonce. This is what miners keep changing to compute a solution to PoW.
transactions: List of transactions and/or contracts to be created included in this Block.
receipts: The receipts of the transactions
TxSha: The Keccak 256-bit hash of the root node of the transactions trie of the block
ReceiptSha: The Keccak 256-bit hash of the root node of the receipts trie of the block.
LogsBloom: The Bloom filter composed from indexable information (logger address and log topics) contained in each log entry from the receipt of each transaction in the transactions list
Reward: The reward of the beneficiary (miner)
func CreateBlock ¶
func CreateBlock(root interface{}, prevHash []byte, base []byte, Difficulty *big.Int, Nonce []byte, extra string) *Block
Creates a Block. See the Block data structure for an explanation of the fields used.
The root parameter is the root of the block's state trie.
The Block created will be created at the current Unix time.
Notice that there are no transactions and receipts passed as arguments to this function.
func NewBlockFromBytes ¶
Creates a new Block from raw bytes. These bytes should be the bytes representation of result of the RLP-encoding of a Block.
func NewBlockFromRlpValue ¶
Creates a new Block from the rlpValue object. Only the block's header, transactions and uncles are derived from the rlpValue object.
func NewUncleBlockFromValue ¶
Creates and sets the uncle of a block based on an ethutil.Value object that contains that information.
'header' parameter: an ethutil.Value object containing the header of the uncle block.
The header of the uncle Block (and any Block) contains those fields: PrevHash, UncleSha, Coinbase, state, TxSha, ReceiptSha, LogsBloom, Difficulty, Number, GasLimit, GasUsed, Time, Extra, Nonce. See also the function Block.HashNoNonce() for details about these fields.
func (*Block) CalcGasLimit ¶
Calculates the gas limit.
If the Block passed as a parameter is the genesis block the gas limit is set to 10^6.
Otherwise the gas limit will be ~= 1023 * parent.GasLimit + parent.GasUsed*6/5
The minimum gas limit is set to 125000.
func (*Block) GetTransaction ¶
func (self *Block) GetTransaction(hash []byte) *Transaction
Searches for a transaction in the current Block based on the transactions hash and the hash parameter and returns it if it exists. Otherwise returns nil.
func (*Block) Hash ¶
Returns the block's hash. To do so, the block's header is first converted to an ethutil.Value object and then the Encode function is called upon the latter.
func (*Block) HashNoNonce ¶
Returns the hash of an object that is almost the same as a Block. The differences are:
1. The object to be hashed contains only the uncles hash.
2. The object to be hashed contains the root of the state and not eh state as a whole.
3. The object to be hashed contains only the TxSha and not the receipts.
4. The object to be hashed contains only the ReceiptSha and not the transactions.
5. The object to be hashed does not contain the Reward of the miner.
Note: The object to be hashed if appended with the Nonce field of the Block will comprise the Block's header.
func (*Block) RlpData ¶
func (self *Block) RlpData() interface{}
Returns an object containing the fields of the caller (Block) that can be rlp-encoded.
func (*Block) RlpDecode ¶
RLP-decodes a Block. To do so, a new ethutil.Value object is created from the 'data' parameter and then the function Block.RlpValueDecode(data) is called on the current Block. The 'data' parameter represents the rlp-encodable fields of a Block and can be obtained by using the function Block.RlpData().
func (*Block) RlpEncode ¶
Calls Block.Value() function on the current Block and then rlp-encodes the Block. The rlp-encodable fields of a Block are it's header, transactions and uncles.
func (*Block) RlpValueDecode ¶
RLP-decodes the rlp-encodable fields of a Block, aka the header, transactions and uncles. parameter decoder: The above fields of the Block after having been cast to an ethutil.Value object.
func (*Block) SetReceipts ¶
Sets the receipts of a Block to the parameter 'receipts'. Also calculates and sets the LogsBloom field which is derived by the receipts.
func (*Block) SetTransactions ¶
func (self *Block) SetTransactions(txs Transactions)
Sets the transactions of a Block to the parameter 'transactions'. Also calculates and sets the TxSha field which is derived by the transactions.
func (*Block) SetUncles ¶
Sets the uncles of a Block to the parameter 'uncles'. This function is also called by Block.CreateBlock. Also sets the UncleSha of the Block based on the provided parameter. To do so, an inner function called rlpUncles() is used.
func (*Block) Size ¶
func (self *Block) Size() ethutil.StorageSize
Returns a float64 object representing the size of storage needed to save this block's rlp-encoding. The rlp-encodable fields of a Block are it's header, transactions and uncles.
func (*Block) Sync ¶
func (block *Block) Sync()
Sync the block's state and contract respectively. For more, see the state package of this go-ethereum version.
func (*Block) Transactions ¶
func (block *Block) Transactions() Transactions
Returns the transactions of the block.
type BlockInfo ¶
An object used to represent a Block's main info.
Number: The number of the block
Hash: The hash of the block
Parent: The parent of the block.
TD: used by the package core to store the total difficulty of the chain up to and including this block.
TD(Block) = TD(Block.parent) + Block.difficulty + sum(u.difficulty for u in Block.uncles)
func (*BlockInfo) RlpDecode ¶
Only a BlockInfo object can call this function.
Param: data: Should be the bytes representation of the RLP-encoding of the caller.
Description: Sets the caller's fields to the RLP-decoded parts of the 'data' parameter. To do so, the parameter `data` is converted to an ethutil.Value object and the RLP-decoding operation happens on the Value object.
More information about the ethutil.Value object can be found in the file ethutil/README.md
type BlockProcessor ¶
Any type that implements this interface must also implement the function Process which calculates and returns in that order: the total difficulty of the block as a bigInt, the messages of the block (aka the transactions) and/or an error.
In case of an error the values returned by the function Process for the td and messages are nil.
type Broadcaster ¶
A Broadcaster is a type that can broadcast messages of a given type to a list of recipients.
type DerivableList ¶
Any type that implements this interface can then call the function types.DeriveSha(list DerivableList) Len(): returns the number of the elements of the object that implements this interface. GetRlp(i int): returns the RLP-encoding of i-th element of the object that implements this interface.
type Receipt ¶
type Receipt struct { PostState []byte CumulativeGasUsed *big.Int Bloom []byte // contains filtered or unexported fields }
Represents the receipts field of a Transaction. The receipt contains certain information regarding the execution of the transaction. Each receipt is placed on a trie.
PostState: the state after the execution of the transaction
CumulativeGasUsed: The cumulative gas used up to and including the current transaction of a Block.
Bloom: A hash (2048 bits)
logs: A series of log entries. Each entry is a tuple of the logger’s address, a possibly empty series of 32-byte log topics, and some number of bytes of data. See state/log.go for more.
func NewReceipt ¶
Creates a new Receipt object provided the 'root' of the receipts trie and the cumulative gas used.
func NewRecieptFromValue ¶
Creates a new Receipt object from an rlp-encoded ethutil.Value object 'val'.
func (*Receipt) Cmp ¶
Returns true if the caller Receipt is the same as the 'other', false otherwise. Two Receipt objects are the same if their PostState fields are equal.
func (*Receipt) RlpData ¶
func (self *Receipt) RlpData() interface{}
Returns the rlp-encodable fields of the caller. The only difference between what this function returns and the caller's fields is that this function returns the result of the RlpData() function called on the logs field.
func (*Receipt) RlpEncode ¶
Rlp-encoded the rlp-encodable fields of a Receipt object. These fields are obtained through the function Receipt.RlpData().
func (*Receipt) RlpValueDecode ¶
Sets the caller's receipt fields to the rlp-decoded fields of the decoder parameter.
type Receipts ¶
type Receipts []*Receipt
An array of Receipts.
func (Receipts) GetRlp ¶
Returns the rlp-encoding of the i-th Receipt of the caller. This function, along with the Len function are implemented so as that a Receipt object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.
func (Receipts) Len ¶
Returns the number of Receipts that the caller consists of. This function, along with the GetRlp function are implemented so as that a Receipt object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Definition of a transaction object.
Nonce: A value equal to the number of transactions that originated from this address or, in the case of accounts with associated code, the number of contract-creations made by this account.
recipient: The 160-bit address of the transaction's recipient or, for a contract creation transaction, nil.
value: This is equal to the number of Wei to be transferred to the transaction's recipient or, in the case of contract creation, as an endowment to the newly created account.
gas: The gas limit equal to the maximum amount of gas that should be used when executing this transaction.
gasPrice: This is equal to the number of Wei to be paid per unit of gas for all computation costs incurred as a result of the execution of this transaction.
data: An unlimited size byte array specifying the input data of the transaction. The first 4 bytes of this field specify which function to call when the transaction will execute by using the hash of the function's name to be called and it's arguments. The rest of the data field are the arguments passed to the function. If the data field is empty, it means a transaction is for a payment and not an execution of the contract.
v, r, s: Values corresponding to the ECDSA digital signature of the transaction and used to determine the originating Externally Owned Account.
func NewContractCreationTx ¶
func NewContractCreationTx(value, gas, gasPrice *big.Int, script []byte) *Transaction
Creates and returns a new Transaction which represents the creation of a contract. The Transaction's 'recipient' field will be set to nil and the Transaction's 'data' field will be set equal to the 'script' parameter. All other Transaction fields will be set to the corresponing parameters passed to this function ( except of course for the fields nonce,v,r,s which are not set)
func NewTransactionFromBytes ¶
func NewTransactionFromBytes(data []byte) *Transaction
Creates and returns a new Transaction based on the 'data' parameter. The latter should be a valid rlp-encoding of a Transaction object. (The 'data' parameter is converted to an ethutil.Value object first and then gets decoded)
func NewTransactionFromValue ¶
func NewTransactionFromValue(val *ethutil.Value) *Transaction
Creates and returns a new Transaction based on the 'val' parameter. The latter should be a valid rlp-encoding of a Transaction object that has been cast to an ethutil.Value object.
func NewTransactionMessage ¶
func NewTransactionMessage(to []byte, value, gas, gasPrice *big.Int, data []byte) *Transaction
Creates and returns a new Transaction. All Transaction fields will be set to the corresponing parameters passed to this function ( except of course for the fields nonce,v,r,s which are not set)
func (*Transaction) Curve ¶
func (tx *Transaction) Curve() (v byte, r []byte, s []byte)
Returns v, r, s of the Transaction. r and s are left-padded to 32 bytes. For more, see the function ethutil.leftPadBytes
func (*Transaction) Data ¶
func (self *Transaction) Data() []byte
Returns the data field of the caller.
func (*Transaction) From ¶
func (self *Transaction) From() []byte
Returns the sender of the transaction.
func (*Transaction) Gas ¶
func (self *Transaction) Gas() *big.Int
Returns the gas field of the caller.
func (*Transaction) GasPrice ¶
func (self *Transaction) GasPrice() *big.Int
Returns the gasPrice field of the caller.
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() []byte
Returns the hash of the caller. The hash will be the Kecchak-256 hash of these Transaction fields: nonce, gasPrice, gas, recipient, value, data.
func (*Transaction) Nonce ¶
func (self *Transaction) Nonce() uint64
Returns the nonce field of the caller.
func (*Transaction) PublicKey ¶
func (tx *Transaction) PublicKey() []byte
Retrieves and returns the public key of the transaction. The public key used to be obtained through the github.com/obscuren/secp256k1-go package repo but this package no longer exists. One may now use the function RecoverPubKey from https://github.com/ethereum/go-ethereum/blob/master/crypto/secp256k1/secp256.go
func (*Transaction) RlpData ¶
func (tx *Transaction) RlpData() interface{}
Returns the rlp-encodable fields of the caller (all fields of a Transaction object).
func (*Transaction) RlpDecode ¶
func (tx *Transaction) RlpDecode(data []byte)
Sets the caller's fields equal to the rlp-decoding of the 'data' parameter. The 'data' parameter must be a valid bytes representation of a Transaction that has been cast to an ethutil.Value object.
func (*Transaction) RlpEncode ¶
func (tx *Transaction) RlpEncode() []byte
Returns the rlp-encoding of the cast of the caller object to an ethutil.Value object. The cast is done through the Transaction.RlpValue() function)
func (*Transaction) RlpValue ¶
func (tx *Transaction) RlpValue() *ethutil.Value
Casts and returns the caller to an ethutil.Value object.
func (*Transaction) RlpValueDecode ¶
func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value)
Sets the caller's fields equal to the rlp-decoding of the 'decoder'. The 'decoder' must be Transaction cast to an ethutil.Value object.
func (*Transaction) Sender ¶
func (tx *Transaction) Sender() []byte
Returns the sender of the transaction. To do so, the public key of the transaction is retrieved first through the function Transaction.PublicKey(). If the public key passes validation then the last 12 bytes of the public key are returned (aka the sender address)
func (*Transaction) SetNonce ¶
func (self *Transaction) SetNonce(nonce uint64)
Sets the caller's nonce field equal to the 'nonce' parameter.
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(privk []byte) error
Signes the transaction. To do so, the function Transaction.Signature is called, which makes use of a non-existent package. Refer to the Transaction.Signature for more. After the transaction has been signed the r,s,v fields of the Transaction are set to the signatures appropriate fields.
r is set to the first 32 bytes of the signature.
s is set to the 32-th up to and including the 63-th bytes of the signature.
v is set to the sum of the last bit of the transaction and the number 27.
func (*Transaction) Signature ¶
func (tx *Transaction) Signature(key []byte) []byte
Calculates and returns the signature of the hash of a transaction with the param key. The signature used to be obtained through the github.com/obscuren/secp256k1-go package repo but this package no longer exists. One may now use the function Sign from https://github.com/ethereum/go-ethereum/blob/master/crypto/secp256k1/secp256.go
func (*Transaction) String ¶
func (tx *Transaction) String() string
Returns the string representation of the caller.
func (*Transaction) To ¶
func (self *Transaction) To() []byte
Returns the recipient field of the caller.
func (*Transaction) Value ¶
func (self *Transaction) Value() *big.Int
Returns the value field of the caller.
type Transactions ¶
type Transactions []*Transaction
Transaction slice type for basic sorting
func (Transactions) GetRlp ¶
func (s Transactions) GetRlp(i int) []byte
Returns the rlp-encoding of the i-th Transaction of the caller. This function, along with the Len function are implemented so as that a Transaction object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.
func (Transactions) Len ¶
func (s Transactions) Len() int
Returns the number of the Transaction objects that the caller consists of. This function, along with the GetRlp function are implemented so as that a Transaction object can call the function DeriveSha (defined in the file types/derive_sha.go) which constructs a trie and returns the hash root of that trie.
func (Transactions) RlpData ¶
func (self Transactions) RlpData() interface{}
Returns the rlp-encodable fields of all the Transaction objects that the caller consists of.
type TxByNonce ¶
type TxByNonce struct{ Transactions }
Data type used for performing comparison operations on Transaction objects.