types

package
v0.0.0-...-dee6c83 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: GPL-3.0, LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package types contains data types related to Shx consensus.

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
)
View Source
const (
	// ReceiptStatusFailed is the status code of a transaction if execution failed.
	ReceiptStatusFailed = uint(0)

	// ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
	ReceiptStatusSuccessful = uint(1)
)

Variables

View Source
var (
	ErrInvalidChainId    = errors.New("invalid chain id for signer")
	ErrInvalidAsynsinger = errors.New("invalid chain id  Asyn Send OK for signer")
)
View Source
var Bloom9 = bloom9
View Source
var (
	EmptyRootHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)
View Source
var (
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
View Source
var (
	ErrSignCheckFailed = errors.New("recover pubkey failed")
)

Functions

func ASynrecoverPlain

func ASynrecoverPlain(tx *Transaction, sighash common.Hash, R, S, Vb *big.Int) (common.Address, error)

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

func DeriveSha

func DeriveSha(list DerivableList) common.Hash

func DeriveShaWithTree

func DeriveShaWithTree(list DerivableList) common.Hash

func LogsBloom

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

func Number

func Number(b1, b2 *Block) bool

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 Shx blockchain.

func BuildBlock

func BuildBlock(header *Header, txs []*Transaction, td *big.Int) *Block

func NewBlock

func NewBlock(header *Header, txs []*Transaction, proofs []*ProofState, receipts []*Receipt) *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 Shx

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

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

func (*Block) EncodeRLP

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

EncodeRLP serializes b into the Shx 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) ProofHash

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

func (*Block) ProofRoot

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

func (*Block) Proofs

func (b *Block) Proofs() ProofStates

func (*Block) ReceiptHash

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

func (*Block) Root

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

func (*Block) Size

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

func (*Block) String

func (b *Block) String() string

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, proofs []*ProofState) *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
	Proofs       []*ProofState
}

Body is a simple (mutable, non-safe) data container for storing and moving a block's data contents (transactions and uncles) together.

type ConfirmMsg

type ConfirmMsg struct {
	Confirm ProofConfirm
	Sign    []byte
}

func (ConfirmMsg) Hash

func (cfm ConfirmMsg) Hash() common.Hash

type DerivableList

type DerivableList interface {
	Len() int
	GetRlp(i int) []byte
	GetMerkleContent(i int) merkletree.Content
}
type Header struct {
	ParentHash  common.Hash    `json:"parentHash"       gencodec:"required"`
	Coinbase    common.Address `json:"miner"            gencodec:"required"`
	ProofHash   common.Hash    `json:"proofHash"        gencodec:"required"` // latest proofHash of current node.
	Root        common.Hash    `json:"stateRoot"        gencodec:"required"`
	TxHash      common.Hash    `json:"transactionsRoot" gencodec:"required"`
	ReceiptHash common.Hash    `json:"receiptsRoot"     gencodec:"required"`
	ProofRoot   common.Hash    `json:"proofRoot"		gencodec:"required"` // merkle-root of peer's proofState in block body.
	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"`
}

Header represents a block header in the Shx 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) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

func (*Header) String

func (h *Header) String() string

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(input []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
	BlockNumber uint64 `json:"blockNumber"`
	// 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) 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.

func (*Log) String

func (l *Log) String() string

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.

func (*LogForStorage) EncodeRLP

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

EncodeRLP implements rlp.Encoder.

type ProofConfirm

type ProofConfirm struct {
	Signature ProofSignature
	Confirm   bool
}

func (ProofConfirm) Data

func (pc ProofConfirm) Data() []byte

type ProofSignature

type ProofSignature []byte

func (ProofSignature) Hash

func (p ProofSignature) Hash() common.Hash

type ProofState

type ProofState struct {
	Addr common.Address
	Root common.Hash
	Num  uint64
}

func (ProofState) CalculateHash

func (p ProofState) CalculateHash() ([]byte, error)

func (ProofState) Equals

func (p ProofState) Equals(other merkletree.Content) (bool, error)

type ProofStates

type ProofStates []*ProofState

func (ProofStates) GetMerkleContent

func (s ProofStates) GetMerkleContent(i int) merkletree.Content

func (ProofStates) GetRlp

func (s ProofStates) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp

func (ProofStates) Len

func (s ProofStates) Len() int

Len returns the length of s

func (ProofStates) Swap

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

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

type QSHandle

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

func QSGetInstance

func QSGetInstance() *QSHandle

func (*QSHandle) ASyncValidateSign

func (qs *QSHandle) ASyncValidateSign(tx *Transaction, hash []byte, r []byte, s []byte, v byte) error

func (*QSHandle) Init

func (qs *QSHandle) Init() error

func (*QSHandle) Release

func (qs *QSHandle) Release() error

func (*QSHandle) ValidateSign

func (qs *QSHandle) ValidateSign(hash []byte, r []byte, s []byte, v byte) ([]byte, error)

type QSSigner

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

EIP155Transaction implements Signer using the EIP155 rules.

func NewQSSigner

func NewQSSigner(chainId *big.Int) QSSigner

func (QSSigner) Equal

func (s QSSigner) Equal(s2 Signer) bool

func (QSSigner) Hash

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

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (QSSigner) SignatureValues

func (s QSSigner) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error)

WithSignature returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type QueryState

type QueryState struct {
	Miner  common.Address
	Number big.Int
}

func (QueryState) Data

func (qs QueryState) Data() []byte

type QueryStateMsg

type QueryStateMsg struct {
	Qs   QueryState
	Sign []byte
}

func (QueryStateMsg) Hash

func (qsm QueryStateMsg) Hash() common.Hash

type Receipt

type Receipt struct {
	// Consensus fields
	Status uint `json:"status"`
	// Not consensus fields
	//Confirm count by miner node.
	ConfirmCount uint64 `json:"confirmed" gencodec:"required"`

	// Implementation fields (don't reorder!)
	TxHash common.Hash `json:"transactionHash" gencodec:"required"`
}

Receipt represents the results of a transaction.

func NewReceipt

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

NewReceipt creates a barebone transaction receipt, copying the init fields.

func (*Receipt) CalculateHash

func (r *Receipt) CalculateHash() ([]byte, error)

func (*Receipt) DecodeRLP

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

DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt from an RLP stream.

func (*Receipt) EncodeRLP

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

EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt into an RLP stream. If no post state is present, byzantium fork is assumed.

func (*Receipt) Equals

func (r *Receipt) Equals(other merkletree.Content) (bool, error)

func (Receipt) MarshalJSON

func (r Receipt) MarshalJSON() ([]byte, error)

func (*Receipt) String

func (r *Receipt) String() string

String implements the Stringer interface.

func (*Receipt) UnmarshalJSON

func (r *Receipt) UnmarshalJSON(input []byte) error

type ReceiptForStorage

type ReceiptForStorage Receipt

ReceiptForStorage is a wrapper around a Receipt that flattens and parses the entire content of a receipt, as opposed to only the consensus fields originally.

func (*ReceiptForStorage) DecodeRLP

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

DecodeRLP implements rlp.Decoder, and loads both consensus and implementation fields of a receipt from an RLP stream.

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

func (r Receipts) GetMerkleContent(i int) merkletree.Content

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 RecoverPubkey

type RecoverPubkey struct {
	Tx   *Transaction // recover tx's hash
	Hash []byte
	Sig  []byte // signature
}

result for recover pubkey

type ResponseState

type ResponseState struct {
	Number  big.Int
	Root    common.Hash
	Querier common.Address
}

func (ResponseState) Data

func (rs ResponseState) Data() []byte

type ResponseStateMsg

type ResponseStateMsg struct {
	Rs   ResponseState
	Sign []byte
}

func (ResponseStateMsg) Hash

func (rsm ResponseStateMsg) Hash() common.Hash

type Signer

type Signer interface {
	// 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(config *config.ChainConfig) Signer

MakeSigner returns a Signer based on the given chain config and block number.

type StorageBlock

type StorageBlock Block

[deprecated by eth/63] StorageBlock defines the RLP encoding of a Block stored in the state database. The StorageBlock encoding contains fields that would otherwise need to be recomputed.

func (*StorageBlock) DecodeRLP

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

[deprecated by eth/63]

type TaskTh

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

type Transaction

type Transaction struct {

	// caches
	Forward bool
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(data []byte) *Transaction

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

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

func (*Transaction) CheckNonce

func (tx *Transaction) CheckNonce() bool

func (*Transaction) Data

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

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

DecodeRLP implements rlp.Encoder

func (*Transaction) Equals

func (tx *Transaction) Equals(other merkletree.Content) (bool, error)

func (*Transaction) Hash

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

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

func (*Transaction) IsForward

func (tx *Transaction) IsForward() bool

func (*Transaction) MarshalJSON

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

func (*Transaction) SetForward

func (tx *Transaction) SetForward(forward bool)

func (*Transaction) Size

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

func (*Transaction) String

func (tx *Transaction) String() string

func (*Transaction) UnmarshalJSON

func (tx *Transaction) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes the web3 RPC transaction format.

type Transactions

type Transactions []*Transaction

Transaction slice type for basic sorting.

func TxDifference

func TxDifference(a, b Transactions) (keep Transactions)

Returns a new set t which is the difference between a to b

func (Transactions) GetMerkleContent

func (s Transactions) GetMerkleContent(i int) merkletree.Content

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

type TransactionsByPayload

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

func NewTransactionsByPayload

func NewTransactionsByPayload(txs Transactions) *TransactionsByPayload

NewTransactionsByPayload creates a transaction set that can retrieve payload length sorted transactions.

Note, the input map is reowned so the caller should not interact any more with if after providing it to the constructor.

func (*TransactionsByPayload) Peek

Peek returns the next transaction by price.

func (*TransactionsByPayload) Pop

func (t *TransactionsByPayload) Pop()

Pop removes the best transaction, *not* replacing it with the next one from the same account. This should be used when a transaction cannot be executed and hence all subsequent ones should be discarded from the same account.

func (*TransactionsByPayload) Shift

func (t *TransactionsByPayload) Shift()

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

type TxByPayload

type TxByPayload Transactions

func (TxByPayload) Len

func (s TxByPayload) Len() int

func (TxByPayload) Less

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

func (*TxByPayload) Pop

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

func (*TxByPayload) Push

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

func (TxByPayload) Swap

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

type WorkProof

type WorkProof struct {
	Number big.Int
	Sign   ProofSignature
	Txs    Transactions
	States ProofStates
}

func (WorkProof) Data

func (wp WorkProof) Data() []byte

return data to sign a signature.

type WorkProofMsg

type WorkProofMsg struct {
	Proof WorkProof
	Sign  []byte
}

func (WorkProofMsg) Hash

func (wpm WorkProofMsg) Hash() common.Hash

Jump to

Keyboard shortcuts

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