Documentation ¶
Index ¶
- Variables
- func DeriveSha(list DerivableList) types.Hash
- func Number(b1, b2 *Block) bool
- func SignHeaderInner(h *Header, s Signer, prv *ecdsa.PrivateKey) error
- type Block
- func (b *Block) Bloom() types.Bloom
- func (b *Block) Body() *Body
- func (z *Block) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Block) EncodeMsg(en *msgp.Writer) (err error)
- func (b *Block) Hash() types.Hash
- func (b *Block) HashNoSig() types.Hash
- func (b *Block) Header() *Header
- func (z *Block) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Block) Msgsize() (s int)
- func (b *Block) Number() *big.Int
- func (b *Block) NumberU64() uint64
- func (b *Block) ParentHash() types.Hash
- func (b *Block) Producer() types.Address
- func (b *Block) ReceiptHash() types.Hash
- func (b *Block) Root() types.Hash
- func (b *Block) Size() common.StorageSize
- func (b *Block) String() string
- func (b *Block) Time() *big.Int
- func (b *Block) Transaction(hash types.Hash) *transaction.Transaction
- func (b *Block) Transactions() transaction.Transactions
- func (b *Block) TxHash() types.Hash
- func (z *Block) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (b *Block) WithBody(body *Body) *Block
- func (b *Block) WithSeal(header *Header) *Block
- type BlockBy
- type BlockSigner
- func (s BlockSigner) Equal(signer Signer) bool
- func (s BlockSigner) Hash(h *Header) types.Hash
- func (s BlockSigner) Sender(h *Header) (types.Address, error)
- func (s BlockSigner) SignatureValues(h *Header, sig []byte) (R, S, V *big.Int, err error)
- func (s BlockSigner) VerifySignature(h *Header) (bool, error)
- type Blocks
- type Body
- type ConsensusData
- func (z *ConsensusData) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *ConsensusData) EncodeMsg(en *msgp.Writer) (err error)
- func (c ConsensusData) MarshalJSON() ([]byte, error)
- func (z *ConsensusData) MarshalMsg(b []byte) (o []byte, err error)
- func (z *ConsensusData) Msgsize() (s int)
- func (cd ConsensusData) String() string
- func (c *ConsensusData) UnmarshalJSON(input []byte) error
- func (z *ConsensusData) UnmarshalMsg(bts []byte) (o []byte, err error)
- type DerivableList
- type Header
- func (h *Header) AddSignature(signer Signer, sig []byte) error
- func (z *Header) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Header) EncodeMsg(en *msgp.Writer) (err error)
- func (h *Header) Hash() types.Hash
- func (header *Header) HashNoSig() types.Hash
- func (h Header) MarshalJSON() ([]byte, error)
- func (z *Header) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Header) Msgsize() (s int)
- func (h *Header) String() string
- func (h *Header) UnmarshalJSON(input []byte) error
- func (z *Header) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (h *Header) WithSignature(signer Signer, sig []byte) (*Header, error)
- type HeaderNoSig
- func (z *HeaderNoSig) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *HeaderNoSig) EncodeMsg(en *msgp.Writer) (err error)
- func (h *HeaderNoSig) Hash() types.Hash
- func (z *HeaderNoSig) MarshalMsg(b []byte) (o []byte, err error)
- func (z *HeaderNoSig) Msgsize() (s int)
- func (z *HeaderNoSig) UnmarshalMsg(bts []byte) (o []byte, err error)
- type Headers
- type Signer
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidSig = errors.New("invalid block v, r, s values") ErrInvalidChainId = errors.New("invalid chain id for block signer") )
var (
EmptyRootHash = DeriveSha(transaction.Transactions{})
)
Functions ¶
func DeriveSha ¶
func DeriveSha(list DerivableList) types.Hash
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 (*Block) Hash ¶
Hash returns the keccak256 hash of b's header. The hash is computed on the first call and cached thereafter.
func (*Block) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Block) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Block) ParentHash ¶
func (*Block) ReceiptHash ¶
func (*Block) Size ¶
func (b *Block) Size() common.StorageSize
func (*Block) Transaction ¶
func (b *Block) Transaction(hash types.Hash) *transaction.Transaction
func (*Block) Transactions ¶
func (b *Block) Transactions() transaction.Transactions
func (*Block) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
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) SignatureValues ¶
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 Body ¶
type Body struct {
Transactions []*transaction.Transaction
}
func (*Body) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
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 Header ¶
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 ¶
CopyHeader creates a deep copy of a block header to prevent side effects from modifying a header variable.
func SignHeader ¶
SignHeader signs the header using the given signer and private key
func (*Header) AddSignature ¶
AddSignature returns modify the header( R, S, V) with the given signature.
func (Header) MarshalJSON ¶
func (*Header) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Header) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Header) UnmarshalJSON ¶
func (*Header) UnmarshalMsg ¶
UnmarshalMsg implements msgp.Unmarshaler
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) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
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.