Documentation
¶
Index ¶
- Variables
- func DeriveSha(list DerivableList) common.Hash
- func Number(b1, b2 *Block) bool
- func Sender(signer Signer, tx *Transaction) (common.Address, error)
- type Block
- func (b *Block) Body() *Body
- func (b *Block) Coinbase() common.Address
- func (b *Block) Difficulty() *big.Int
- func (b *Block) Extra() []byte
- func (b *Block) Hash() common.Hash
- func (b *Block) Header() *Header
- func (b *Block) Nonce() uint64
- 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 Body
- type DerivableList
- type Header
- type MasterSigner
- type Signer
- type Transaction
- type Transactions
Constants ¶
This section is empty.
Variables ¶
var EmptyRootHash = DeriveSha(Transactions{})
var (
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
Functions ¶
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 {
// These fields are used by package eth to track
// inter-peer block relay.
ReceivedAt time.Time
ReceivedFrom interface{}
// contains filtered or unexported fields
}
func NewBlock ¶
func NewBlock(header *Header, txs []*Transaction) *Block
NewBlock creates a new block.
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) Difficulty ¶
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) 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.
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 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 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"`
// Bloom Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
Time *big.Int `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
Nonce BlockNonce `json:"nonce" gencodec:"required"`
}
Header represents a block header in 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 MasterSigner ¶
type MasterSigner struct{}
func NewMasterSigner ¶
func NewMasterSigner() MasterSigner
func (MasterSigner) Equal ¶
func (s MasterSigner) Equal(s2 Signer) bool
func (MasterSigner) Hash ¶
func (fs MasterSigner) Hash(tx *Transaction) common.Hash
Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.
func (MasterSigner) Sender ¶
func (fs MasterSigner) Sender(tx *Transaction) (common.Address, error)
func (MasterSigner) SignatureValues ¶
func (fs MasterSigner) 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 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.
type Transaction ¶
type Transaction struct {
Tx transaction.TxData
// contains filtered or unexported fields
}
func SignTx ¶
func SignTx(tx *Transaction, s Signer, prv *ecdsa.PrivateKey) (*Transaction, error)
SignTx signs the transaction using the given signer and private key
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() common.Hash
Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.
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) WithSignature ¶
func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, error)
WithSignature returns a new transaction with the given signature. This signature needs to be formatted as described (v+27).
type Transactions ¶
type Transactions []*Transaction
Transactions is a Transaction slice type for basic sorting.
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.