Documentation ¶
Index ¶
- Constants
- Variables
- func DeriveChainId(v *big.Int) *big.Int
- func EmptyHash(hash Hash) bool
- func Hex2Bytes(str string) []byte
- func ParseBytes(val *string) ([]byte, error)
- func ParseInt64orHex(val *string) (int64, error)
- func ParseUint256orHex(val *string) (*big.Int, error)
- func ParseUint64orHex(val *string) (uint64, error)
- type Address
- type Big
- func (b Big) ImplementsGraphQLType(name string) bool
- func (b Big) MarshalText() ([]byte, error)
- func (b *Big) String() string
- func (b *Big) ToInt() *big.Int
- func (b *Big) UnmarshalGraphQL(input interface{}) error
- func (b *Big) UnmarshalJSON(input []byte) error
- func (b *Big) UnmarshalText(input []byte) error
- type Block
- func (b *Block) Body() *Body
- func (b *Block) Hash() Hash
- func (b *Block) MarshalWith(ar *fastrlp.Arena) *fastrlp.Value
- func (b *Block) Number() uint64
- func (b *Block) ParentHash() Hash
- func (b *Block) String() string
- func (b *Block) UnmarshalRLP(p *fastrlp.Parser, v *fastrlp.Value) error
- func (b *Block) WithSeal(header *Header) *Block
- type Bloom
- type Body
- type Hash
- type Header
- func (h *Header) CalculateHash() (hash Hash)
- func (h *Header) ComputeHash() *Header
- func (h *Header) Copy() *Header
- func (h *Header) HasBody() bool
- func (h *Header) HasReceipts() bool
- func (h *Header) MarshalWith(arena *fastrlp.Arena) *fastrlp.Value
- func (h *Header) SetNonce(i uint64)
- func (h *Header) UnmarshalRLP(p *fastrlp.Parser, v *fastrlp.Value) error
- type HeaderWithoutHash
- type HexBytes
- type IstanbulExtra
- type Log
- type Nonce
- type Receipt
- type ReceiptStatus
- type Transaction
- func (t *Transaction) ComputeHash() *Transaction
- func (t *Transaction) Copy() *Transaction
- func (t *Transaction) GetGasPrice() []byte
- func (t *Transaction) IsContractCreation() bool
- func (t *Transaction) MarshalWith(arena *fastrlp.Arena) *fastrlp.Value
- func (t *Transaction) UnmarshalRLP(p *fastrlp.Parser, v *fastrlp.Value) error
- type Uint64
Constants ¶
const ( HashLength = 32 AddressLength = 20 )
const BloomByteLength = 256
Variables ¶
var ( Big1 = big.NewInt(1) Big2 = big.NewInt(2) Big3 = big.NewInt(3) Big0 = big.NewInt(0) Big32 = big.NewInt(32) Big256 = big.NewInt(256) Big257 = big.NewInt(257) )
var ( // IstanbulDigest represents a hash of "Istanbul practical byzantine fault tolerance" // to identify whether the block is from Istanbul consensus engine IstanbulDigest = StringToHash("0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365") IstanbulExtraVanity = 32 // Fixed number of extra-data bytes reserved for validator vanity IstanbulExtraSeal = 65 // Fixed number of extra-data bytes reserved for validator seal // ErrInvalidIstanbulHeaderExtra is returned if the length of extra-data is less than 32 bytes ErrInvalidIstanbulHeaderExtra = errors.New("invalid istanbul header extra-data") )
var ( // EmptyRootHash is the root when there are no transactions EmptyRootHash = StringToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") // EmptyUncleHash is the root when there are no uncles EmptyUncleHash = StringToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347") )
Functions ¶
func DeriveChainId ¶
deriveChainId derives the chain id from the given v parameter
func ParseBytes ¶
func ParseInt64orHex ¶
func ParseUint64orHex ¶
Types ¶
type Address ¶
type Address [AddressLength]byte
func BytesToAddress ¶
func StringToAddress ¶
func (Address) MarshalText ¶
func (*Address) UnmarshalText ¶
UnmarshalText parses an address in hex syntax.
type Big ¶
Big marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".
Negative integers are not supported at this time. Attempting to marshal them will return an error. Values larger than 256bits are rejected by Unmarshal but will be marshaled without error.
func (Big) ImplementsGraphQLType ¶
ImplementsGraphQLType returns true if Big implements the provided GraphQL type.
func (Big) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Big) UnmarshalGraphQL ¶
UnmarshalGraphQL unmarshals the provided GraphQL query data.
func (*Big) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Big) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
type Block ¶
type Block struct { Header *Header Transactions []*Transaction Uncles []*Header }
func (*Block) ParentHash ¶
func (*Block) UnmarshalRLP ¶
type Bloom ¶
type Bloom [BloomByteLength]byte
func CreateBloom ¶
CreateBloom creates a new bloom filter from a set of receipts
func (*Bloom) UnmarshalText ¶
type Body ¶
type Body struct { Transactions []*Transaction Uncles []*Header }
type Hash ¶
type Hash [HashLength]byte
func BytesToHash ¶
func CalcUncleHash ¶
func StringToHash ¶
func (Hash) MarshalText ¶
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type Header ¶
type Header struct { ParentHash Hash `json:"parentHash" db:"parent_hash"` Sha3Uncles Hash `json:"sha3Uncles" db:"sha3_uncles"` Miner Address `json:"miner" db:"miner"` StateRoot Hash `json:"stateRoot" db:"state_root"` TxRoot Hash `json:"transactionsRoot" db:"transactions_root"` ReceiptsRoot Hash `json:"receiptsRoot" db:"receipts_root"` LogsBloom Bloom `json:"logsBloom" db:"logs_bloom"` Difficulty uint64 `json:"difficulty" db:"difficulty"` Number uint64 `json:"number" db:"number"` GasLimit uint64 `json:"gasLimit" db:"gas_limit"` GasUsed uint64 `json:"gasUsed" db:"gas_used"` Timestamp uint64 `json:"timestamp" db:"timestamp"` ExtraData HexBytes `json:"extraData" db:"extradata"` MixHash Hash `json:"mixHash" db:"mixhash"` Nonce Nonce `json:"nonce" db:"nonce"` Hash Hash }
Header represents a block header in the Ethereum blockchain.
func (*Header) CalculateHash ¶
func (*Header) ComputeHash ¶
ComputeHash computes the hash of the header
func (*Header) HasReceipts ¶
func (*Header) MarshalWith ¶
MarshalWith marshals the header to RLP with a specific fastrlp.Arena
type HeaderWithoutHash ¶
type HeaderWithoutHash struct { ParentHash Hash `json:"parentHash" db:"parent_hash"` Sha3Uncles Hash `json:"sha3Uncles" db:"sha3_uncles"` Miner Address `json:"miner" db:"miner"` StateRoot Hash `json:"stateRoot" db:"state_root"` TxRoot Hash `json:"transactionsRoot" db:"transactions_root"` ReceiptsRoot Hash `json:"receiptsRoot" db:"receipts_root"` LogsBloom Bloom `json:"logsBloom" db:"logs_bloom"` Difficulty uint64 `json:"difficulty" db:"difficulty"` Number uint64 `json:"number" db:"number"` GasLimit uint64 `json:"gasLimit" db:"gas_limit"` GasUsed uint64 `json:"gasUsed" db:"gas_used"` Timestamp uint64 `json:"timestamp" db:"timestamp"` ExtraData HexBytes `json:"extraData" db:"extradata"` MixHash Hash `json:"mixHash" db:"mixhash"` Nonce Nonce `json:"nonce" db:"nonce"` }
func IstanbulFilteredHeader ¶
func IstanbulFilteredHeader(h *Header, keepSeal bool) *HeaderWithoutHash
IstanbulFilteredHeader returns a filtered header which some information (like seal, committed seals) are clean to fulfill the Istanbul hash rules. It returns nil if the extra-data cannot be decoded/encoded by rlp.
type IstanbulExtra ¶
func ExtractIstanbulExtra ¶
func ExtractIstanbulExtra(h *Header) (*IstanbulExtra, error)
ExtractIstanbulExtra extracts all values of the IstanbulExtra from the header. It returns an error if the length of the given extra-data is less than 32 bytes or the extra-data can not be decoded.
type Log ¶
type Log struct { Address Address `json:"address"` Topics []Hash `json:"topics"` Data HexBytes `json:"data"` BlockNumber uint64 `json:"blockNumber"` TxHash Hash `json:"transactionHash"` TxIndex uint `json:"transactionIndex"` BlockHash Hash `json:"blockHash"` LogIndex uint `json:"logIndex"` Removed bool `json:"removed"` }
type Receipt ¶
type Receipt struct { Root Hash `json:"root" db:"root"` CumulativeGasUsed uint64 `json:"cumulativeGasUsed" db:"cumulative_gas_used"` LogsBloom Bloom `json:"logsBloom" db:"bloom"` Logs []*Log `json:"logs"` Status *ReceiptStatus `json:"status"` TxHash Hash `json:"transactionHash" db:"txhash"` ContractAddress Address `json:"contractAddress" db:"contract_address"` GasUsed uint64 `json:"gasUsed" db:"gas_used"` }
func (*Receipt) MarshalLogsWith ¶
MarshalLogsWith marshals the logs of the receipt to RLP with a specific fastrlp.Arena
func (*Receipt) MarshalWith ¶
MarshalWith marshals a receipt with a specific fastrlp.Arena
func (*Receipt) SetStatus ¶
func (r *Receipt) SetStatus(s ReceiptStatus)
type ReceiptStatus ¶
type ReceiptStatus uint64
const ( ReceiptFailed ReceiptStatus = iota ReceiptSuccess )
type Transaction ¶
type Transaction struct { Nonce uint64 `json:"nonce" db:"nonce"` GasPrice HexBytes `json:"gasPrice" db:"gas_price"` Gas uint64 `json:"gas" db:"gas"` To *Address `json:"to" db:"dst"` Value HexBytes `json:"value" db:"value"` Input HexBytes `json:"input" db:"input"` V byte `json:"v" db:"v"` R HexBytes `json:"r" db:"r"` S HexBytes `json:"s" db:"s"` Hash Hash From Address }
func (*Transaction) ComputeHash ¶
func (t *Transaction) ComputeHash() *Transaction
ComputeHash computes the hash of the transaction
func (*Transaction) Copy ¶
func (t *Transaction) Copy() *Transaction
func (*Transaction) GetGasPrice ¶
func (t *Transaction) GetGasPrice() []byte
func (*Transaction) IsContractCreation ¶
func (t *Transaction) IsContractCreation() bool
func (*Transaction) MarshalWith ¶
func (t *Transaction) MarshalWith(arena *fastrlp.Arena) *fastrlp.Value
MarshalWith marshals the transaction to RLP with a specific fastrlp.Arena
func (*Transaction) UnmarshalRLP ¶
UnmarshalRLP unmarshals a Transaction in RLP format
type Uint64 ¶
type Uint64 uint64
Uint64 marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".
func (Uint64) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Uint64) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Uint64) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler