types

package
v0.0.0-...-77960fc Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var Bloom9 = bloom9
View Source
var (
	EmptyRootHash = DeriveSha(Transactions{})
)
View Source
var (
	ErrInvalidChainId = errors.New("invalid chain id for signer")
)
View Source
var (
	// ErrInvalidSig returns when the signature is not valid
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)

Functions

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

func DeriveSha

func DeriveSha(list DerivableList) common.Hash

func IsNullUTXO

func IsNullUTXO(utxo *UTXO) bool

func Number

func Number(b1, b2 *Block) bool

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

func SignatureValues(sig []byte) (r, s, v *big.Int)

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

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

func (b *Block) DecodeRLP(s *rlp.Stream) error

DecodeRLP decodes the Ethereum

func (*Block) DeprecatedTd

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

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

func (b *Block) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP block format.

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

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

func (*Block) Header

func (b *Block) Header() *Header

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 and uncle contents.

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 Bloom

type Bloom [BloomByteLength]byte

Bloom represents a 2048 bit bloom filter.

func BytesToBloom

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func (*Bloom) Add

func (b *Bloom) Add(d *big.Int)

Add adds d to the filter. Future calls of Test(d) will return true.

func (Bloom) Big

func (b Bloom) Big() *big.Int

Big converts b to a big integer.

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

func (Bloom) MarshalText

func (b Bloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (Bloom) Test

func (b Bloom) Test(test *big.Int) bool

func (Bloom) TestBytes

func (b Bloom) TestBytes(test []byte) bool

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

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

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

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 Sig

type Sig struct {
	V *big.Int `json:"v"`
	R *big.Int `json:"r"`
	S *big.Int `json:"s"`
}

Sig represents the signature values

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

func (tx *Transaction) Fee() *big.Int

Fee returns a copy of the tx fee

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

func (s Transactions) Len() int

Len returns the length of s.

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.

type TxOut

type TxOut struct {
	Owner  common.Address `json:"owner"`
	Amount *big.Int       `json:"amount"`
}

TxOut is the tx output

func NewNullTxOut

func NewNullTxOut() *TxOut

NewNullTxOut

type UTXO

type UTXO struct {
	UTXOID
	TxOut
}

UTXO is the unspent tx output

func NewNullUTXO

func NewNullUTXO() *UTXO

NewNullUTXO

func (UTXO) Equals

func (u UTXO) Equals(other UTXO) bool

Equals check if two UTXO objs are identical

func (UTXO) ID

func (u UTXO) ID() UTXOID

ID returns the identity of a UTXO obj

type UTXOID

type UTXOID struct {
	BlockNum uint64 `json:"blockNum"`
	TxIndex  uint32 `json:"txIndex"`
	OutIndex byte   `json:"outIndex"`
}

UTXOID is the identity of a UTXO obj

func (UTXOID) Equals

func (id UTXOID) Equals(other UTXOID) bool

Equals check if two UTXOID objs are identical

Jump to

Keyboard shortcuts

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