types

package
v0.0.0-...-91a82d4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: LGPL-3.0 Imports: 18 Imported by: 25

README

types

  1. define transaction
  2. define block
  3. define receipt
  4. define some methods for general structure

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ReceiptStatusFailed is the status code of a transaction if execution failed.
	ReceiptStatusFailed = uint64(0)
	// ReceiptStatusFailedRLP is rlp bytes of a transaction if execution failed.
	ReceiptStatusFailedRLP = []byte{}

	// ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
	ReceiptStatusSuccessful = uint64(1)
	// ReceiptStatusSuccessfulRLP is rlp bytes of a transaction if execution succeeded.
	ReceiptStatusSuccessfulRLP = []byte{0x01}
)
View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")

	ErrInvalidType    = errors.New("invalid transaction type")
	ErrInvalidAddress = errors.New("invalid transaction payload address")
	ErrInvalidAction  = errors.New("invalid transaction payload action")
	ErrNotFound       = errors.New("not found")
)

Functions

func CalcGasLimit

func CalcGasLimit(parent *Block) uint64

CalcGasLimit computes the gas limit of the next block after parent.

func CreateBloom

func CreateBloom(receipts Receipts) bloom.Bloom

func DeriveRootHash

func DeriveRootHash(list DerivableList) utils.Hash

DeriveRootHash root hash

func LogsBloom

func LogsBloom(logs []*Log) *big.Int

func NewCandidateTrie

func NewCandidateTrie(root utils.Hash, db *mtp.Database) (*mtp.Trie, error)

func NewDelegateTrie

func NewDelegateTrie(root utils.Hash, db *mtp.Database) (*mtp.Trie, error)

func NewEpochTrie

func NewEpochTrie(root utils.Hash, db *mtp.Database) (*mtp.Trie, error)

func NewMintCntTrie

func NewMintCntTrie(root utils.Hash, db *mtp.Database) (*mtp.Trie, error)

func NewVoteTrie

func NewVoteTrie(root utils.Hash, db *mtp.Database) (*mtp.Trie, error)

Types

type Action

type Action struct {
	TxHash       utils.Hash    `json:"txHash"`
	Sender       utils.Address `json:"sender"`
	GenTimeStamp *big.Int      `json:"generateTime"`
	DelayDur     *big.Int      `json:"delayDuration"`
	// contains filtered or unexported fields
}

Action represents the Redeem transaction deferred Action.

func NewAction

func NewAction(txHash utils.Hash, sender utils.Address, gen, delay *big.Int) *Action

NewAction new action.

func (*Action) Hash

func (a *Action) Hash() utils.Hash

Hash returns the action hash of the action.

type Actions

type Actions []*Action

Actions .

func (Actions) GetRlp

func (a Actions) GetRlp(i int) []byte

GetRlp returns the RLP encoding of one action from the list.

func (Actions) Len

func (a Actions) Len() int

Len returns the number of actions in this list.

type Block

type Block struct {

	// These fields are used to track inter-peer block relay.
	ReceivedAt   time.Time
	ReceivedFrom interface{}
	DposContext  *DposContext
	// contains filtered or unexported fields
}

Block represents an entire block in the blockchain.

func NewBlock

func NewBlock(header *BlockHeader, txs []*Transaction, actions []*Action, receipts []*Receipt) *Block

NewBlock creates a new block.

func NewBlockWithBlockHeader

func NewBlockWithBlockHeader(header *BlockHeader) *Block

NewBlockWithBlockHeader creates a block with the given header data.

func (*Block) Action

func (b *Block) Action(hash utils.Hash) *Action

func (*Block) ActionRoot

func (b *Block) ActionRoot() utils.Hash

func (*Block) Actions

func (b *Block) Actions() Actions

func (*Block) BlockHeader

func (b *Block) BlockHeader() *BlockHeader

func (*Block) Bloom

func (b *Block) Bloom() bloom.Bloom

func (*Block) DecodeRLP

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

DecodeRLP implements rlp.Decoder

func (*Block) Difficulty

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

func (*Block) DposCtx

func (b *Block) DposCtx() *DposContext

func (*Block) EncodeRLP

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

EncodeRLP implements rlp.Encoder

func (*Block) ExtraData

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

func (*Block) GasLimit

func (b *Block) GasLimit() uint64

func (*Block) GasUsed

func (b *Block) GasUsed() uint64

func (*Block) Hash

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

Hash returns the keccak256 hash of b's header.

func (*Block) HashNoNonce

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

HashNoNonce hash without nonce

func (*Block) Height

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

func (*Block) Miner

func (b *Block) Miner() utils.Address

func (*Block) Nonce

func (b *Block) Nonce() uint64

func (*Block) PreviousHash

func (b *Block) PreviousHash() utils.Hash

func (*Block) ReceiptsRoot

func (b *Block) ReceiptsRoot() utils.Hash

func (*Block) Size

func (b *Block) Size() utils.StorageSize

Size returns the true RLP encoded storage size of the block

func (*Block) StateRoot

func (b *Block) StateRoot() utils.Hash

func (*Block) Time

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

func (*Block) Transaction

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

func (*Block) Transactions

func (b *Block) Transactions() Transactions

func (*Block) TransactionsRoot

func (b *Block) TransactionsRoot() utils.Hash

func (*Block) WithActions

func (b *Block) WithActions(actions []*Action) *Block

WithActions a block with the given actions data.

func (*Block) WithSeal

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

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

func (*Block) WithStateRoot

func (b *Block) WithStateRoot(root utils.Hash) *Block

WithStateRoot a block with the given state root.

func (*Block) WithTxs

func (b *Block) WithTxs(txs []*Transaction) *Block

WithTxs a block with the given txs data.

type BlockHeader

type BlockHeader struct {
	PreviousHash     utils.Hash        `json:"previousHash"`
	Miner            utils.Address     `json:"miner"`
	StateRoot        utils.Hash        `json:"stateRoot"`
	ActionsRoot      utils.Hash        `json:"actonsroot"`
	TransactionsRoot utils.Hash        `json:"transactionsRoot"`
	ReceiptsRoot     utils.Hash        `json:"receiptsRoot"`
	DposContext      *DposContextProto `json:"dposContext" rlp:"nil"`
	LogsBloom        bloom.Bloom       `json:"logsBloom"`
	Difficulty       *big.Int          `json:"difficulty"`
	Height           *big.Int          `json:"height"`
	GasLimit         uint64            `json:"gasLimit"`
	GasUsed          uint64            `json:"gasUsed" `
	TimeStamp        *big.Int          `json:"timestamp"`
	ExtraData        []byte            `json:"extraData"`
	Nonce            MinerNonce        `json:"nonce"`
}

BlockHeader represents a block header in blockchain.

func CopyBlockHeader

func CopyBlockHeader(h *BlockHeader) *BlockHeader

CopyBlockHeader creates a deep copy of a block header

func (*BlockHeader) Hash

func (h *BlockHeader) Hash() utils.Hash

Hash returns the block hash of the header

func (*BlockHeader) HashNoNonce

func (h *BlockHeader) HashNoNonce() utils.Hash

HashNoNonce returns the hash which is used as input for the proof-of-work search.

func (*BlockHeader) Size

func (h *BlockHeader) Size() utils.StorageSize

Size returns the approximate memory used by all internal contents.

type Blocks

type Blocks []*Block

Blocks sort by height

func (Blocks) Len

func (s Blocks) Len() int

func (Blocks) Less

func (s Blocks) Less(i, j int) bool

func (Blocks) Swap

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

type CandidateInfo

type CandidateInfo struct {
	Addr        utils.Address
	Weight      uint64 // 100
	DegradeTime uint64
}

type Confirmed

type Confirmed struct {
	BlockHeight uint64        // confirmed
	BlockHash   utils.Hash    // confirmed
	Address     utils.Address // producer
	Signature   []byte        // signature
}

func (*Confirmed) Hash

func (c *Confirmed) Hash() utils.Hash

Hash returns the hash to be signed by the sender.

func (*Confirmed) IsValidate

func (c *Confirmed) IsValidate() bool

IsValidate returns the validate

type DerivableList

type DerivableList interface {
	Len() int
	GetRlp(i int) []byte
}

DerivableList array

type DposContext

type DposContext struct {
	// contains filtered or unexported fields
}

func NewDposContext

func NewDposContext(db *mtp.Database) (*DposContext, error)

func NewDposContextFromProto

func NewDposContextFromProto(db *mtp.Database, ctxProto *DposContextProto) (*DposContext, error)

func (*DposContext) BecomeCandidate

func (d *DposContext) BecomeCandidate(candidateAddr utils.Address) error

func (*DposContext) CandidateTrie

func (d *DposContext) CandidateTrie() *mtp.Trie

func (*DposContext) CommitTo

func (d *DposContext) CommitTo(dbw *mtp.Database) (*DposContextProto, error)

func (*DposContext) Copy

func (d *DposContext) Copy() *DposContext

func (*DposContext) DB

func (d *DposContext) DB() *mtp.Database

func (*DposContext) Delegate

func (d *DposContext) Delegate(delegatorAddr utils.Address, candidateAddrs []*utils.Address) error

func (*DposContext) DelegateTrie

func (d *DposContext) DelegateTrie() *mtp.Trie

func (*DposContext) EpochTrie

func (d *DposContext) EpochTrie() *mtp.Trie

func (*DposContext) FromProto

func (d *DposContext) FromProto(dcp *DposContextProto) error

func (*DposContext) GetCandidateAddrs

func (dc *DposContext) GetCandidateAddrs(delegator utils.Address) ([]utils.Address, error)

func (*DposContext) GetCandidates

func (dc *DposContext) GetCandidates() ([]*CandidateInfo, error)

func (*DposContext) GetDelegators

func (dc *DposContext) GetDelegators(candidate utils.Address) ([]utils.Address, error)

func (*DposContext) GetValidators

func (dc *DposContext) GetValidators() ([]utils.Address, error)

func (*DposContext) IsDpos

func (dc *DposContext) IsDpos() bool

func (*DposContext) KickoutCandidate

func (d *DposContext) KickoutCandidate(candidateAddr utils.Address) error

func (*DposContext) MintCntTrie

func (d *DposContext) MintCntTrie() *mtp.Trie

func (*DposContext) RevertToSnapShot

func (d *DposContext) RevertToSnapShot(snapshot *DposContext)

func (*DposContext) Root

func (d *DposContext) Root() (h utils.Hash)

func (*DposContext) SetCandidate

func (dc *DposContext) SetCandidate(candidate *mtp.Trie)

func (*DposContext) SetDelegate

func (dc *DposContext) SetDelegate(delegate *mtp.Trie)

func (*DposContext) SetEpoch

func (dc *DposContext) SetEpoch(epoch *mtp.Trie)

func (*DposContext) SetMintCnt

func (dc *DposContext) SetMintCnt(mintCnt *mtp.Trie)

func (*DposContext) SetValidators

func (dc *DposContext) SetValidators(validators []utils.Address) error

func (*DposContext) SetVote

func (dc *DposContext) SetVote(vote *mtp.Trie)

func (*DposContext) Snapshot

func (d *DposContext) Snapshot() *DposContext

func (*DposContext) ToProto

func (d *DposContext) ToProto() *DposContextProto

func (*DposContext) UnDelegate

func (d *DposContext) UnDelegate(delegatorAddr utils.Address) error

func (*DposContext) VoteTrie

func (d *DposContext) VoteTrie() *mtp.Trie

type DposContextProto

type DposContextProto struct {
	EpochHash     utils.Hash `json:"epochRoot"        gencodec:"required"`
	DelegateHash  utils.Hash `json:"delegateRoot"     gencodec:"required"`
	CandidateHash utils.Hash `json:"candidateRoot"    gencodec:"required"`
	VoteHash      utils.Hash `json:"voteRoot"         gencodec:"required"`
	MintCntHash   utils.Hash `json:"mintCntRoot"      gencodec:"required"`
}

func (*DposContextProto) Root

func (p *DposContextProto) Root() (h utils.Hash)

type Log

type Log struct {
	// Consensus fields:
	Address utils.Address `json:"address" gencodec:"required"` // address of the contract that generated the event
	Topics  []utils.Hash  `json:"topics" gencodec:"required"`  // list of topics provided by the contract.
	Data    []byte        `json:"data" gencodec:"required"`    // supplied by the contract, usually ABI-encoded

	// Derived fields. These fields are filled in by the node but not secured by consensus.
	BlockHeight      uint64     `json:"blockHeight"`                          // block in which the transaction was included
	BlockHash        utils.Hash `json:"blockHash"`                            // hash of the block in which the transaction was included
	TransactionHash  utils.Hash `json:"transactionHash" gencodec:"required"`  // hash of the transaction
	TransactionIndex uint       `json:"transactionIndex" gencodec:"required"` // index of the transaction in the block
	LogIndex         uint       `json:"logIndex" gencodec:"required"`         // index of the log in the receipt
	Removed          bool       `json:"removed"`                              // The Removed field is true if this log was reverted due to a chain reorganisation.
}

Log represents a contract log event. These events are generated by the log opcode and stored/indexed by the node.

func (*Log) DecodeRLP

func (l *Log) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Log) EncodeRLP

func (l *Log) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

type LogForStorage

type LogForStorage Log

LogForStorage is a wrapper around a Log that flattens and parses the entire content of a log including non-consensus fields.

func (*LogForStorage) DecodeRLP

func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder. The entire content of a log including non-consensus fields.

func (*LogForStorage) EncodeRLP

func (l *LogForStorage) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder. The entire content of a log including non-consensus fields.

type Logs

type Logs []*Log

Logs is a wrapper around a Log array to implement DerivableList.

func (Logs) GetRlp

func (l Logs) GetRlp(i int) []byte

GetRlp returns the RLP encoding of one log from the list.

func (Logs) Len

func (l Logs) Len() int

Len returns the number of logs in this list.

type MinerNonce

type MinerNonce [8]byte

A MinerNonce 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) MinerNonce

EncodeNonce converts the given integer to a block nonce.

func (MinerNonce) MarshalText

func (n MinerNonce) MarshalText() ([]byte, error)

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

func (MinerNonce) Uint64

func (n MinerNonce) Uint64() uint64

Uint64 returns the integer value of a block nonce.

func (*MinerNonce) UnmarshalText

func (n *MinerNonce) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Receipt

type Receipt struct {
	// Consensus fields
	State             []byte      `json:"root"`
	Status            uint64      `json:"status"`
	CumulativeGasUsed uint64      `json:"cumulativeGasUsed" gencodec:"required"`
	LogsBloom         bloom.Bloom `json:"logsBloom"         gencodec:"required"`
	Logs              []*Log      `json:"logs"              gencodec:"required"`

	// Derived fields. (don't reorder!)
	TransactionHash utils.Hash    `json:"transactionHash" gencodec:"required"`
	ContractAddress utils.Address `json:"contractAddress"`
	GasUsed         uint64        `json:"gasUsed" gencodec:"required"`
}

Receipt represents the results of a transaction.

func NewReceipt

func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt

NewReceipt creates a transaction receipt.

func (*Receipt) DecodeRLP

func (r *Receipt) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*Receipt) EncodeRLP

func (r *Receipt) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*Receipt) Size

func (r *Receipt) Size() utils.StorageSize

Size returns the approximate memory used by all internal contents.

type ReceiptForStorage

type ReceiptForStorage Receipt

ReceiptForStorage is a wrapper around a Receipt that flattens and parses the entire content of a log including non-consensus fields.

func (*ReceiptForStorage) DecodeRLP

func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error

func (*ReceiptForStorage) EncodeRLP

func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt into an RLP stream.

type Receipts

type Receipts []*Receipt

Receipts is a wrapper around a Receipt array to implement DerivableList.

func (Receipts) GetRlp

func (r Receipts) GetRlp(i int) []byte

GetRlp returns the RLP encoding of one receipt from the list.

func (Receipts) Len

func (r Receipts) Len() int

Len returns the number of receipts in this list.

type Signer

type Signer struct{}

Signer encapsulates transaction signature handling.

func (Signer) Hash

func (s Signer) Hash(tx *Transaction) utils.Hash

Hash returns the hash to be signed by the sender.

func (Signer) SignatureValues

func (s Signer) SignatureValues(signature []byte) (r, sb, 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 StorageTx

type StorageTx struct {
	BlockHash   utils.Hash
	BlockHeight uint64
	TxIndex     uint64
	Tx          *Transaction
}

func NewStorageTx

func NewStorageTx(blockHash utils.Hash, blockHeight, txIndex uint64, tx *Transaction) *StorageTx

type StorageTxs

type StorageTxs []*StorageTx

func (StorageTxs) ToTransactions

func (s StorageTxs) ToTransactions() Transactions

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction transaction

func NewTransaction

func NewTransaction(txType TxType, nonce uint64, value *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, tos ...*utils.Address) *Transaction

NewTransaction new transaction

func (*Transaction) ChainID

func (tx *Transaction) ChainID(signer Signer) (*big.Int, error)

ChainID returns which chain id this transaction was signed for (if at all)

func (*Transaction) Cost

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

Cost returns value + gasprice * gaslimit.

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

func (tx *Transaction) Gas() uint64

func (*Transaction) GasPrice

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

func (*Transaction) Hash

func (tx *Transaction) Hash() utils.Hash

Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

func (*Transaction) Payload

func (tx *Transaction) Payload() []byte

func (*Transaction) Protected

func (tx *Transaction) Protected(signer Signer) (bool, error)

Protected returns whether the transaction is protected from replay protection.

func (*Transaction) Sender

func (tx *Transaction) Sender(signer Signer) (utils.Address, error)

Sender sender address of the transaction using the given signer

func (*Transaction) SignTx

func (tx *Transaction) SignTx(s Signer, prv *ecdsa.PrivateKey) error

SignTx signs the transaction using the given signer and private key

func (*Transaction) Signature

func (tx *Transaction) Signature() []byte

func (*Transaction) Size

func (tx *Transaction) Size() utils.StorageSize

Size returns the true RLP encoded storage size of the transaction

func (*Transaction) Tos

func (tx *Transaction) Tos() []*utils.Address

func (*Transaction) Type

func (tx *Transaction) Type() TxType

func (*Transaction) Validate

func (tx *Transaction) Validate(cfg *params.ChainConfig) error

Validate Valid the transaction when the type isn't the binary

func (*Transaction) Value

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

func (*Transaction) WithSignature

func (tx *Transaction) WithSignature(signature []byte)

WithSignature returns a new transaction with the given signature.

type Transactions

type Transactions []*Transaction

Transactions is is a wrapper around a Transaction array to implement DerivableList.

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.

type TransactionsByPriceAndNonce

type TransactionsByPriceAndNonce struct {
	// contains filtered or unexported fields
}

TransactionsByPriceAndNonce represents a set of transactions

func NewTransactionsByPriceAndNonce

func NewTransactionsByPriceAndNonce(signer Signer, txs map[utils.Address]Transactions) *TransactionsByPriceAndNonce

NewTransactionsByPriceAndNonce creates a transaction set that can retrieve price sorted transactions in a nonce-honouring way.

func (*TransactionsByPriceAndNonce) Peek

Peek returns the next transaction by price.

func (*TransactionsByPriceAndNonce) Pop

func (t *TransactionsByPriceAndNonce) Pop()

Pop removes the best transactiont.

func (*TransactionsByPriceAndNonce) Shift

func (t *TransactionsByPriceAndNonce) Shift()

Shift replaces the current best head with the next one from the same account.

type TxType

type TxType uint64

TxType transaction type

const (
	Binary TxType = iota
	LoginCandidate
	LogoutCandidate
	Delegate
	UnDelegate
	Redeem
)

type TxsByNonce

type TxsByNonce Transactions

TxsByNonce transactions sort by nonce

func (TxsByNonce) Len

func (s TxsByNonce) Len() int

func (TxsByNonce) Less

func (s TxsByNonce) Less(i, j int) bool

func (TxsByNonce) Swap

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

type TxsByPriceToHigh

type TxsByPriceToHigh []*Transaction

TxsByPriceToHigh Price from low to high

func (TxsByPriceToHigh) Len

func (t TxsByPriceToHigh) Len() int

func (TxsByPriceToHigh) Less

func (t TxsByPriceToHigh) Less(i, j int) bool

func (TxsByPriceToHigh) Swap

func (t TxsByPriceToHigh) Swap(i, j int)

type TxsByPriceToLow

type TxsByPriceToLow Transactions

TxsByPriceToLow transactions sort by price and implements the heap interface Price from high to low

func (TxsByPriceToLow) Len

func (s TxsByPriceToLow) Len() int

func (TxsByPriceToLow) Less

func (s TxsByPriceToLow) Less(i, j int) bool

func (*TxsByPriceToLow) Pop

func (s *TxsByPriceToLow) Pop() interface{}

func (*TxsByPriceToLow) Push

func (s *TxsByPriceToLow) Push(x interface{})

func (TxsByPriceToLow) Swap

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

Jump to

Keyboard shortcuts

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