block

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSig     = errors.New("invalid block v, r, s values")
	ErrInvalidChainId = errors.New("invalid chain id for block signer")
)
View Source
var (
	EmptyRootHash = DeriveSha(transaction.Transactions{})
)

Functions

func DeriveSha

func DeriveSha(list DerivableList) types.Hash

func Number

func Number(b1, b2 *Block) bool

func SignHeaderInner

func SignHeaderInner(h *Header, s Signer, prv *ecdsa.PrivateKey) error

SignHeaderInner signs the header(modify R S V) using the given signer and private key

Types

type Block

type Block struct {
	H *Header // block header
	B Body    // all transactions in this block

	// These fields are used by package bchain to track
	// inter-peer block relay.
	ReceivedAt   time.Time   `msg:"-"`
	ReceivedFrom interface{} `msg:"-"`
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(header *Header, txs []*transaction.Transaction, receipts []*transaction.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, ReceiptHash and Bloom in header are ignored and set to values derived from the given txs and receipts.

func NewBlockWithHeader

func NewBlockWithHeader(header *Header) *Block

func (*Block) Bloom

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

func (*Block) Body

func (b *Block) Body() *Body

Body returns the non-header content of the block.

func (*Block) DecodeMsg

func (z *Block) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Block) EncodeMsg

func (z *Block) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Block) Hash

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

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

func (*Block) HashNoSig

func (b *Block) HashNoSig() types.Hash

func (*Block) Header

func (b *Block) Header() *Header

func (*Block) MarshalMsg

func (z *Block) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Block) Msgsize

func (z *Block) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Block) Number

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

func (*Block) NumberU64

func (b *Block) NumberU64() uint64

func (*Block) ParentHash

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

func (*Block) Producer

func (b *Block) Producer() types.Address

func (*Block) ReceiptHash

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

func (*Block) Root

func (b *Block) Root() types.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 types.Hash) *transaction.Transaction

func (*Block) Transactions

func (b *Block) Transactions() transaction.Transactions

func (*Block) TxHash

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

func (*Block) UnmarshalMsg

func (z *Block) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Block) WithBody

func (b *Block) WithBody(body *Body) *Block

WithBody returns a new block with the given transaction 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 BlockSigner

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

func NewBlockSigner

func NewBlockSigner(chainId *big.Int) BlockSigner

NewBlockSigner returns a Signer based on the given chain config

func (BlockSigner) Equal

func (s BlockSigner) Equal(signer Signer) bool

func (BlockSigner) Hash

func (s BlockSigner) Hash(h *Header) types.Hash

func (BlockSigner) Sender

func (s BlockSigner) Sender(h *Header) (types.Address, error)

func (BlockSigner) SignatureValues

func (s BlockSigner) SignatureValues(h *Header, sig []byte) (R, S, V *big.Int, err error)

SignatureValues returns a header's R S V based given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.

func (BlockSigner) VerifySignature

func (s BlockSigner) VerifySignature(h *Header) (bool, error)

type Blocks

type Blocks []*Block

type Body

type Body struct {
	Transactions []*transaction.Transaction
}

func (*Body) DecodeMsg

func (z *Body) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Body) EncodeMsg

func (z *Body) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Body) MarshalMsg

func (z *Body) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Body) Msgsize

func (z *Body) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Body) UnmarshalMsg

func (z *Body) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ConsensusData

type ConsensusData struct {
	Id   string `json:"consensus_id"         gencodec:"required"`
	Para []byte `json:"consensus_param"      gencodec:"required"`
}

func (*ConsensusData) DecodeMsg

func (z *ConsensusData) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*ConsensusData) EncodeMsg

func (z *ConsensusData) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (ConsensusData) MarshalJSON

func (c ConsensusData) MarshalJSON() ([]byte, error)

func (*ConsensusData) MarshalMsg

func (z *ConsensusData) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*ConsensusData) Msgsize

func (z *ConsensusData) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (ConsensusData) String

func (cd ConsensusData) String() string

func (*ConsensusData) UnmarshalJSON

func (c *ConsensusData) UnmarshalJSON(input []byte) error

func (*ConsensusData) UnmarshalMsg

func (z *ConsensusData) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type DerivableList

type DerivableList interface {
	Len() int
	GetMsgp(i int) []byte
}
type Header struct {
	ParentHash      types.Hash    `json:"parentHash"         gencodec:"required"`
	StateRootHash   types.Hash    `json:"stateRoot"          gencodec:"required"`
	TxRootHash      types.Hash    `json:"transactionsRoot"   gencodec:"required"`
	ReceiptRootHash types.Hash    `json:"receiptsRoot"       gencodec:"required"`
	Bloom           types.Bloom   `json:"logsBloom"          gencodec:"required"`
	Number          *types.BigInt `json:"number"             gencodec:"required"`
	Time            *types.BigInt `json:"timestamp"          gencodec:"required"`
	Cdata           ConsensusData `json:"consensusData"      gencodec:"required"`
	Extra           []byte        `json:"extraData"          gencodec:"required"`

	//Signature values
	V *types.BigInt `json:"v"`
	R *types.BigInt `json:"r"`
	S *types.BigInt `json:"s"`

	//BlockProducer is not used in protocol, get from the signature(v,r,s)
	Producer types.Address `json:"blockProducer"      gencodec:"required"   msg:"-"`
}

block header

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 SignHeader

func SignHeader(h *Header, s Signer, prv *ecdsa.PrivateKey) (*Header, error)

SignHeader signs the header using the given signer and private key

func (*Header) AddSignature

func (h *Header) AddSignature(signer Signer, sig []byte) error

AddSignature returns modify the header( R, S, V) with the given signature.

func (*Header) DecodeMsg

func (z *Header) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Header) EncodeMsg

func (z *Header) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Header) Hash

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

func (*Header) HashNoSig

func (header *Header) HashNoSig() types.Hash

func (Header) MarshalJSON

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

func (*Header) MarshalMsg

func (z *Header) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Header) Msgsize

func (z *Header) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Header) String

func (h *Header) String() string

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(input []byte) error

func (*Header) UnmarshalMsg

func (z *Header) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (*Header) WithSignature

func (h *Header) WithSignature(signer Signer, sig []byte) (*Header, error)

WithSignature returns a new header with the given signature.

type HeaderNoSig

type HeaderNoSig struct {
	ParentHash      types.Hash
	StateRootHash   types.Hash
	TxRootHash      types.Hash
	ReceiptRootHash types.Hash
	Bloom           types.Bloom
	Number          *types.BigInt
	Time            *types.BigInt
	Cdata           ConsensusData
	Extra           []byte

	//BlockProducer is not used in protocol.
	Producer types.Address `msg:"-" `
}

header wihtout signature

func (*HeaderNoSig) DecodeMsg

func (z *HeaderNoSig) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*HeaderNoSig) EncodeMsg

func (z *HeaderNoSig) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*HeaderNoSig) Hash

func (h *HeaderNoSig) Hash() types.Hash

func (*HeaderNoSig) MarshalMsg

func (z *HeaderNoSig) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*HeaderNoSig) Msgsize

func (z *HeaderNoSig) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*HeaderNoSig) UnmarshalMsg

func (z *HeaderNoSig) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Headers

type Headers struct {
	Headers []*Header
}

type Headers []*Header

func (*Headers) DecodeMsg

func (z *Headers) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Headers) EncodeMsg

func (z *Headers) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Headers) MarshalMsg

func (z *Headers) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Headers) Msgsize

func (z *Headers) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Headers) UnmarshalMsg

func (z *Headers) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	Sender(h *Header) (types.Address, error)
	// SignatureValues returns the raw R, S, V values corresponding to the
	// given signature.
	SignatureValues(h *Header, sig []byte) (r, s, v *big.Int, err error)

	// Hash returns the hash to be signed.
	Hash(h *Header) types.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.

Jump to

Keyboard shortcuts

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