types

package
v0.0.0-...-e4b14ae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2018 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyRootHash = DeriveSha(Transactions{})
View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)

Functions

func DeriveSha

func DeriveSha(list DerivableList) common.Hash

func Number

func Number(b1, b2 *Block) bool

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

func NewBlockWithHeader(header *Header) *Block

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) Body

func (b *Block) Body() *Body

Body returns the non-header content of the block.

func (*Block) Coinbase

func (b *Block) Coinbase() common.Address

func (*Block) Difficulty

func (b *Block) Difficulty() *big.Int

func (*Block) Extra

func (b *Block) Extra() []byte

func (*Block) Hash

func (b *Block) Hash() common.Hash

Hash returns the keccak256 hash of b's header. The hash is computed on the first call and cached thereafter.

func (*Block) Header

func (b *Block) Header() *Header

func (*Block) Nonce

func (b *Block) Nonce() uint64

func (*Block) Number

func (b *Block) Number() *big.Int

func (*Block) NumberU64

func (b *Block) NumberU64() uint64

func (*Block) ParentHash

func (b *Block) ParentHash() common.Hash

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) Time

func (b *Block) Time() *big.Int

func (*Block) Transaction

func (b *Block) Transaction(hash common.Hash) *Transaction

func (*Block) Transactions

func (b *Block) Transactions() Transactions

func (*Block) TxHash

func (b *Block) TxHash() common.Hash

func (*Block) WithBody

func (b *Block) WithBody(transactions []*Transaction) *Block

WithBody returns a new block with the given transaction.

func (*Block) WithSeal

func (b *Block) WithSeal(header *Header) *Block

WithSeal returns a new block with the data from b but the header replaced with the sealed one.

type BlockBy

type BlockBy func(b1, b2 *Block) bool

func (BlockBy) Sort

func (self BlockBy) Sort(blocks Blocks)

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 Blocks

type Blocks []*Block

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 DerivableList interface {
	Len() int
	GetRlp(i int) []byte
}
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

func CopyHeader(h *Header) *Header

CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.

func (*Header) Hash

func (h *Header) Hash() common.Hash

Hash returns the block hash of the header, which is simply the keccak256 hash of its RLP encoding.

func (*Header) HashNoNonce

func (h *Header) HashNoNonce() common.Hash

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.

func MakeSigner

func MakeSigner() Signer

MakeSigner returns a Signer.

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) Len

func (s Transactions) Len() int

Len returns the length of s.

func (Transactions) Swap

func (s Transactions) Swap(i, j int)

Swap swaps the i'th and the j'th element in s.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL