Documentation ¶
Index ¶
- Constants
- Variables
- func BloomLookup(bin Bloom, topic bytesBacked) bool
- func DeriveSha(list DerivableList) common.Hash
- func IsNullUTXO(utxo *UTXO) bool
- func Number(b1, b2 *Block) bool
- func Sender(signer Signer, tx *Transaction) ([2]common.Address, error)
- func SignatureValues(sig []byte) (r, s, v *big.Int)
- type Block
- func (b *Block) Body() *Body
- func (b *Block) Coinbase() common.Address
- func (b *Block) DecodeRLP(s *rlp.Stream) error
- func (b *Block) DeprecatedTd() *big.Int
- func (b *Block) EncodeRLP(w io.Writer) error
- func (b *Block) Extra() []byte
- func (b *Block) Hash() common.Hash
- func (b *Block) HashNoNonce() common.Hash
- func (b *Block) Header() *Header
- func (b *Block) Number() *big.Int
- func (b *Block) NumberU64() uint64
- func (b *Block) ParentHash() common.Hash
- func (b *Block) Size() common.StorageSize
- func (b *Block) Time() *big.Int
- func (b *Block) Transaction(hash common.Hash) *Transaction
- func (b *Block) Transactions() Transactions
- func (b *Block) TxHash() common.Hash
- func (b *Block) WithBody(transactions []*Transaction) *Block
- func (b *Block) WithSeal(header *Header) *Block
- type BlockBy
- type BlockNonce
- type Blocks
- type Bloom
- func (b *Bloom) Add(d *big.Int)
- func (b Bloom) Big() *big.Int
- func (b Bloom) Bytes() []byte
- func (b Bloom) MarshalText() ([]byte, error)
- func (b *Bloom) SetBytes(d []byte)
- func (b Bloom) Test(test *big.Int) bool
- func (b Bloom) TestBytes(test []byte) bool
- func (b *Bloom) UnmarshalText(input []byte) error
- type Body
- type DerivableList
- type EIP155Signer
- type Header
- type Sig
- type Signer
- type Transaction
- func (tx *Transaction) DecodeRLP(s *rlp.Stream) error
- func (tx *Transaction) EncodeRLP(w io.Writer) error
- func (tx *Transaction) Fee() *big.Int
- func (tx *Transaction) GetInsCopy() []*UTXO
- func (tx *Transaction) GetOutsCopy() []*TxOut
- func (tx *Transaction) Hash() common.Hash
- func (tx *Transaction) IsDepositTx() bool
- func (tx *Transaction) MarshalJSON() ([]byte, error)
- func (tx *Transaction) Size() common.StorageSize
- func (tx *Transaction) UnmarshalJSON(input []byte) error
- func (tx *Transaction) WithSignature(signer Signer, sig1, sig2 []byte) (*Transaction, error)
- type Transactions
- type TxOut
- type UTXO
- type UTXOID
Constants ¶
const ( // BloomByteLength represents the number of bytes used in a header log bloom. BloomByteLength = 256 // BloomBitLength represents the number of bits used in a header log bloom. BloomBitLength = 8 * BloomByteLength )
Variables ¶
var Bloom9 = bloom9
var (
EmptyRootHash = DeriveSha(Transactions{})
)
var (
ErrInvalidChainId = errors.New("invalid chain id for signer")
)
var ( // ErrInvalidSig returns when the signature is not valid ErrInvalidSig = errors.New("invalid transaction v, r, s values") )
Functions ¶
func BloomLookup ¶
func DeriveSha ¶
func DeriveSha(list DerivableList) common.Hash
func IsNullUTXO ¶
func Sender ¶
func Sender(signer Signer, tx *Transaction) ([2]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.
func SignatureValues ¶
SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.
Types ¶
type Block ¶
type Block struct { // These fields are used by package eth to track // inter-peer block relay. ReceivedAt time.Time ReceivedFrom interface{} // contains filtered or unexported fields }
Block represents an entire block in the Ethereum blockchain.
func NewBlock ¶
func NewBlock(header *Header, txs []*Transaction) *Block
NewBlock creates a new block. The input data is copied, changes to header and to the field values will not affect the block.
The values of TxHash, UncleHash, ReceiptHash and Bloom in header are ignored and set to values derived from the given txs, uncles and receipts.
func NewBlockWithHeader ¶
NewBlockWithHeader creates a block with the given header data. The header data is copied, changes to header and to the field values will not affect the block.
func (*Block) DeprecatedTd ¶
DeprecatedTd is an old relic for extracting the TD of a block. It is in the code solely to facilitate upgrading the database from the old format to the new, after which it should be deleted. Do not use!
func (*Block) Hash ¶
Hash returns the keccak256 hash of b's header. The hash is computed on the first call and cached thereafter.
func (*Block) HashNoNonce ¶
func (*Block) ParentHash ¶
func (*Block) Size ¶
func (b *Block) Size() common.StorageSize
Size returns the true RLP encoded storage size of the block, either by encoding and returning it, or returning a previsouly cached value.
func (*Block) Transaction ¶
func (b *Block) Transaction(hash common.Hash) *Transaction
func (*Block) Transactions ¶
func (b *Block) Transactions() Transactions
func (*Block) WithBody ¶
func (b *Block) WithBody(transactions []*Transaction) *Block
WithBody returns a new block with the given transaction and uncle contents.
type BlockNonce ¶
type BlockNonce [8]byte
A BlockNonce is a 64-bit hash which proves (combined with the mix-hash) that a sufficient amount of computation has been carried out on a block.
func EncodeNonce ¶
func EncodeNonce(i uint64) BlockNonce
EncodeNonce converts the given integer to a block nonce.
func (BlockNonce) MarshalText ¶
func (n BlockNonce) MarshalText() ([]byte, error)
MarshalText encodes n as a hex string with 0x prefix.
func (BlockNonce) Uint64 ¶
func (n BlockNonce) Uint64() uint64
Uint64 returns the integer value of a block nonce.
func (*BlockNonce) UnmarshalText ¶
func (n *BlockNonce) UnmarshalText(input []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type Bloom ¶
type Bloom [BloomByteLength]byte
Bloom represents a 2048 bit bloom filter.
func BytesToBloom ¶
BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.
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 Body ¶
type Body struct {
Transactions []*Transaction
}
Body is a simple (mutable, non-safe) data container for storing and moving a block's data contents (transactions) together.
type DerivableList ¶
type EIP155Signer ¶
type EIP155Signer struct {
// contains filtered or unexported fields
}
EIP155Signer implements Signer using the EIP155 rules.
func NewEIP155Signer ¶
func NewEIP155Signer(chainId *big.Int) 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) (senders [2]common.Address, err error)
func (EIP155Signer) SignatureValues ¶
func (s EIP155Signer) SignatureValues(sig []byte) (R, S, V *big.Int)
SignatureValues returns signature values. This signature
type Header ¶
type Header struct { ParentHash common.Hash `json:"parentHash" gencodec:"required"` Coinbase common.Address `json:"miner" gencodec:"required"` TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` Number *big.Int `json:"number" gencodec:"required"` Time *big.Int `json:"timestamp" gencodec:"required"` Extra []byte `json:"extraData" gencodec:"required"` }
Header represents a block header in the Ethereum blockchain.
func CopyHeader ¶
CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.
func (*Header) Hash ¶
Hash returns the block hash of the header, which is simply the keccak256 hash of its RLP encoding.
func (*Header) HashNoNonce ¶
HashNoNonce returns the hash which is used as input for the proof-of-work search.
func (*Header) Size ¶
func (h *Header) Size() common.StorageSize
Size returns the approximate memory used by all internal contents. It is used to approximate and limit the memory consumption of various caches.
type Signer ¶
type Signer interface { // Sender returns the sender address of the transaction. Sender(tx *Transaction) ([2]common.Address, error) // SignatureValues returns the raw R, S, V values corresponding to the // given signature. SignatureValues(sig []byte) (r, s, v *big.Int) // 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 ¶
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer
MakeSigner returns a Signer based on the given chain config and block number.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is the container of tx data
func NewTransaction ¶
func NewTransaction(in1, in2 *UTXO, out1, out2 *TxOut, fee *big.Int) *Transaction
NewTransaction makes a tx from given inputs and out puts
func SignTx ¶
func SignTx(tx *Transaction, s Signer, prv1 *ecdsa.PrivateKey, prv2 *ecdsa.PrivateKey) (*Transaction, error)
SignTx signs the transaction using the given signer and private key
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) GetInsCopy ¶
func (tx *Transaction) GetInsCopy() []*UTXO
GetInsCopy returns a copy of the tx ins
func (*Transaction) GetOutsCopy ¶
func (tx *Transaction) GetOutsCopy() []*TxOut
GetOutsCopy returns a copy of the tx outs
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() common.Hash
Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.
func (*Transaction) IsDepositTx ¶
func (tx *Transaction) IsDepositTx() bool
func (*Transaction) MarshalJSON ¶
func (tx *Transaction) MarshalJSON() ([]byte, error)
MarshalJSON encodes the web3 RPC transaction format.
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) UnmarshalJSON ¶
func (tx *Transaction) UnmarshalJSON(input []byte) error
UnmarshalJSON decodes the web3 RPC transaction format.
func (*Transaction) WithSignature ¶
func (tx *Transaction) WithSignature(signer Signer, sig1, sig2 []byte) (*Transaction, error)
WithSignature returns a new transaction with the given signature. This signature needs to be formatted as described in the yellow paper (v+27).
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) Remove ¶
func (s *Transactions) Remove(i int)
Remove delete the i'th element from s
func (Transactions) Swap ¶
func (s Transactions) Swap(i, j int)
Swap swaps the i'th and the j'th element in s.