types

package
v0.0.0-...-77b6ffe Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MaxTxSize = 32 * 1024 // Maximum transaction size
)

Variables

View Source
var (
	ErrSignNotFound    = errors.New("signature not found")
	ErrPubkeyNotFound  = errors.New("public key not found")
	ErrAddressNotMatch = errors.New("address not match")
)

Functions

func NewTxData

func NewTxData(nonce, gasPrice, gasLimit uint64, value *big.Int, payload []byte, from, to common.Address) txData

Types

type BNonce

type BNonce [8]byte

BNonce is a 64-bit hash which proves that a sufficient amount of computation has been carried out on a block

func EncodeNonce

func EncodeNonce(i uint64) BNonce

func (BNonce) DecodeHex

func (n BNonce) DecodeHex(b []byte) error

func (BNonce) Hex

func (n BNonce) Hex() []byte

func (BNonce) SetBytes

func (n BNonce) SetBytes(b []byte)

func (BNonce) Uint64

func (n BNonce) Uint64() uint64

type Block

type Block struct {
	Header       *Header      `json:"header"`
	Transactions Transactions `json:"transactions"`
	PubKey       []byte       `json:"pub_key"`
	Signature    []byte       `json:"signature"`
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(header *Header, txs Transactions) *Block

func (*Block) Clone

func (bl *Block) Clone() *Block

func (*Block) Coinbase

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

func (*Block) ConsensusInfo

func (bl *Block) ConsensusInfo() []byte

func (*Block) Deserialize

func (bl *Block) Deserialize(d []byte) error

func (*Block) Extra

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

func (*Block) GasLimit

func (bl *Block) GasLimit() uint64

func (*Block) GasUsed

func (bl *Block) GasUsed() uint64

func (*Block) Hash

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

Calculate hash of block Combine header hash and transactions hash, and sha256 it

func (*Block) Height

func (bl *Block) Height() uint64

func (*Block) ParentHash

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

func (*Block) ReceiptsHash

func (bl *Block) ReceiptsHash() common.Hash

func (*Block) Serialize

func (bl *Block) Serialize() ([]byte, error)

func (*Block) Sign

func (bl *Block) Sign(priv crypto.PrivateKey) ([]byte, error)

func (*Block) Size

func (bl *Block) Size() uint64

func (*Block) StateRoot

func (bl *Block) StateRoot() common.Hash

func (*Block) Time

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

func (*Block) TxRoot

func (bl *Block) TxRoot() common.Hash

type Blocks

type Blocks []*Block

func (Blocks) Len

func (blks Blocks) Len() int

func (Blocks) Less

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

func (Blocks) Swap

func (blks Blocks) Swap(i, j int)
type Header struct {
	ParentHash    common.Hash    `json:"parent_hash"`              // Hash of parent block
	Height        uint64         `json:"height"`                   // Block height
	StateRoot     common.Hash    `json:"state_root"`               // State root
	TxRoot        common.Hash    `json:"tx_root"`                  // Transaction tree root
	ReceiptsHash  common.Hash    `json:"receipt_hash"`             // Receipts hash
	Coinbase      common.Address `json:"miner"`                    // Miner address who receives reward of this block
	Time          *big.Int       `json:"time"`                     // Timestamp
	GasUsed       uint64         `json:"gas"`                      // Total gas used
	GasLimit      uint64         `json:"gas_limit"`                // Gas limit of this block
	Extra         []byte         `json:"extra,omitempty"`          // Extra data
	ConsensusInfo []byte         `json:"consensus_info,omitempty"` // Extra consensus information
}

func (*Header) Desrialize

func (hd *Header) Desrialize(d []byte) error

func (*Header) Hash

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

func (*Header) HashNoConsensus

func (hd *Header) HashNoConsensus() common.Hash

func (*Header) Serialize

func (hd *Header) Serialize() ([]byte, error)

type Log

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

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	BlockHeight uint64 `json:"blockHeight"`
	// hash of the transaction
	TxHash common.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex" gencodec:"required"`
	// hash of the block in which the transaction was included
	BlockHash common.Hash `json:"blockHash"`
	// index of the log in the receipt
	Index uint `json:"logIndex" gencodec:"required"`

	// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool `json:"removed"`
}

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

func (*Log) Deserialize

func (log *Log) Deserialize(d []byte) error

func (*Log) Serialize

func (log *Log) Serialize() ([]byte, error)

type Logs

type Logs []*Log

func (Logs) Deserialize

func (logs Logs) Deserialize(d []byte) error

func (Logs) Serialize

func (logs Logs) Serialize() ([]byte, error)

type NonceSortedList

type NonceSortedList Transactions

func (NonceSortedList) Len

func (txs NonceSortedList) Len() int

func (NonceSortedList) Less

func (txs NonceSortedList) Less(i, j int) bool

func (NonceSortedList) Swap

func (txs NonceSortedList) Swap(i, j int)

type Receipt

type Receipt struct {
	// Consensus fields
	PostState       common.Hash    `json:"root"`             // post state root
	Status          bool           `json:"status"`           // Transaction executing success or failed
	TxHash          common.Hash    `json:"tx_hash"`          // Transaction hash
	ContractAddress common.Address `json:"contract_address"` // Contract address
	GasUsed         uint64         `json:"gas_used"`         // gas used of transaction
	Logs            []*Log         `json:"logs"`             // contract log events
}

Receipt represents the results of a transaction

func (*Receipt) Deserialize

func (re *Receipt) Deserialize(d []byte) error

func (*Receipt) Serialize

func (re *Receipt) Serialize() ([]byte, error)

func (*Receipt) SetContractAddress

func (re *Receipt) SetContractAddress(addr common.Address)

type Receipts

type Receipts []*Receipt

func (Receipts) Deserialize

func (rps Receipts) Deserialize(d []byte) error

func (Receipts) Hash

func (rps Receipts) Hash() common.Hash

func (Receipts) Serialize

func (rps Receipts) Serialize() ([]byte, error)

type SortedList

type SortedList Transactions

Nonce-asec-sorted and price-desec-sorted list

func (SortedList) Len

func (txs SortedList) Len() int

func (SortedList) Less

func (txs SortedList) Less(i, j int) bool

func (SortedList) Swap

func (txs SortedList) Swap(i, j int)

type Transaction

type Transaction struct {
	PubKey    []byte `json:"pub_key"`   // Public key
	Signature []byte `json:"signature"` // Signature of tx
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(nonce, gasPrice, gasLimit uint64, value *big.Int, payload []byte, from, to common.Address) *Transaction

func (*Transaction) Cost

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

func (*Transaction) Deserialize

func (tx *Transaction) Deserialize(d []byte) error

func (*Transaction) Hash

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

func (*Transaction) Serialize

func (tx *Transaction) Serialize() ([]byte, error)

func (*Transaction) Sign

func (tx *Transaction) Sign(privKey crypto.PrivKey) ([]byte, error)

Sign the transaction with private key

func (*Transaction) Size

func (tx *Transaction) Size() uint32

func (*Transaction) Verify

func (tx *Transaction) Verify() (bool, error)

Verify transaction signature by specific public key

type Transactions

type Transactions []*Transaction

func (Transactions) Commit

func (txs Transactions) Commit(db *db.LDBDatabase) error

func (Transactions) Deserialize

func (txs Transactions) Deserialize(d []byte) error

func (Transactions) Hash

func (txs Transactions) Hash() common.Hash

func (Transactions) Serialize

func (txs Transactions) Serialize() ([]byte, error)

type TxMeta

type TxMeta struct {
	Hash    common.Hash `json:"block_hash"`
	Height  uint64      `json:"height"`
	TxIndex uint64      `json:"tx_index"`
}

TxMeta represents the meta data of a transaction, contains the index of transacitons in a certain block

func (*TxMeta) Deserialize

func (tm *TxMeta) Deserialize(d []byte) error

func (*TxMeta) Serialize

func (tm *TxMeta) Serialize() ([]byte, error)

Jump to

Keyboard shortcuts

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