Documentation ¶
Index ¶
- Constants
- Variables
- func Decode(dst *Hash, src string) error
- func DoubleHashB(b []byte) []byte
- func Hash2CommonHash(h Hash) common.Hash
- func HashB(b []byte) []byte
- func IsValidFrozenPeriod(height uint64) bool
- func IsValidStakingValue(value int64) bool
- func MoveBytes(bs []byte) []byte
- func NewEmptyBLSPublicKey() *chiapos.G1Element
- func NewEmptyBLSSignature() *chiapos.G2Element
- func NewEmptyBigInt() *big.Int
- func NewEmptyPoCPublicKey() *pocec.PublicKey
- func NewEmptyPoCSignature() *pocec.Signature
- func ReadUint64(r io.Reader, pver uint32) (uint64, int, error)
- func WriteTxOut(w io.Writer, to *TxOut) error
- func WriteUint64(w io.Writer, val uint64) (int, error)
- func WriteVarBytes(w io.Writer, bytes []byte) error
- type BlockBase
- type BlockHeader
- func (h *BlockHeader) BannedPublicKeys() (banned []interfaces.PublicKey)
- func (h *BlockHeader) BlockHash() Hash
- func (h *BlockHeader) Bytes(mode CodecMode) ([]byte, error)
- func (h *BlockHeader) CheckVersionConstraint() error
- func (h *BlockHeader) Decode(r io.Reader, mode CodecMode) (n int, err error)
- func (h *BlockHeader) Encode(w io.Writer, mode CodecMode) (n int, err error)
- func (h *BlockHeader) FromProto(pb *wirepb.BlockHeader) error
- func (h *BlockHeader) GetChainID() (Hash, error)
- func (h *BlockHeader) PlainSize() int
- func (h *BlockHeader) PoCHash() (Hash, error)
- func (h *BlockHeader) PublicKey() interfaces.PublicKey
- func (h *BlockHeader) Quality() *big.Int
- func (h *BlockHeader) SetBanListFromProposals(proposals []*FaultPubKey) error
- func (h *BlockHeader) SetBytes(bs []byte, mode CodecMode) error
- func (h *BlockHeader) ToProto() *wirepb.BlockHeader
- func (h *BlockHeader) VerifySig() (bool, error)
- type CodecMode
- type FaultPubKey
- func (fpk *FaultPubKey) Bytes(mode CodecMode) ([]byte, error)
- func (fpk *FaultPubKey) Decode(r io.Reader, mode CodecMode) (n int, err error)
- func (fpk *FaultPubKey) Encode(w io.Writer, mode CodecMode) (n int, err error)
- func (fpk *FaultPubKey) FromProto(pb *wirepb.Punishment) error
- func (fpk *FaultPubKey) Hash(index int) Hash
- func (fpk *FaultPubKey) IsValid() error
- func (fpk *FaultPubKey) PlainSize() int
- func (fpk *FaultPubKey) SetBytes(bs []byte, mode CodecMode) error
- func (fpk *FaultPubKey) ToProto() *wirepb.Punishment
- func (fpk *FaultPubKey) Type() ProposalType
- func (fpk *FaultPubKey) Version() uint32
- type Hash
- func BuildMerkleTreeStoreForProposal(proposals *ProposalArea) []*Hash
- func BuildMerkleTreeStoreTransactions(transactions []*MsgTx, witness bool) []*Hash
- func CommonHash2Hash(h *common.Hash) *Hash
- func DoubleHashH(b []byte) Hash
- func GetMerkleRootFromCache(baseHash *Hash, cache []*Hash) Hash
- func GetProposalHash(proposal Proposal, index int) Hash
- func HashH(b []byte) Hash
- func HashMerkleBranches(left *Hash, right *Hash) *Hash
- func NewHash(newHash []byte) (*Hash, error)
- func NewHashFromHash(h Hash) *Hash
- func NewHashFromProto(pb *wirepb.Hash) (*Hash, error)
- func NewHashFromStr(hash string) (*Hash, error)
- type Message
- type MsgBlock
- func (msg *MsgBlock) AddTransaction(tx *MsgTx)
- func (msg *MsgBlock) BlockHash() Hash
- func (msg *MsgBlock) Bytes(mode CodecMode) ([]byte, error)
- func (msg *MsgBlock) ClearTransactions()
- func (msg *MsgBlock) Decode(r io.Reader, mode CodecMode) (n int, err error)
- func (msg *MsgBlock) DeserializeTxLoc(r *bytes.Buffer) ([]TxLoc, error)
- func (msg *MsgBlock) Encode(w io.Writer, mode CodecMode) (n int, err error)
- func (msg *MsgBlock) FromProto(pb *wirepb.Block) error
- func (msg *MsgBlock) PlainSize() int
- func (msg *MsgBlock) SetBytes(bs []byte, mode CodecMode) error
- func (msg *MsgBlock) ToProto() (*wirepb.Block, error)
- func (msg *MsgBlock) TxHashes() ([]Hash, error)
- type MsgTx
- func (msg *MsgTx) AddTxIn(ti *TxIn)
- func (msg *MsgTx) AddTxOut(to *TxOut)
- func (msg *MsgTx) Bytes(mode CodecMode) ([]byte, error)
- func (msg *MsgTx) Decode(r io.Reader, mode CodecMode) (n int, err error)
- func (msg *MsgTx) Encode(w io.Writer, mode CodecMode) (n int, err error)
- func (msg *MsgTx) FromProto(pb *wirepb.Tx) error
- func (msg *MsgTx) IsCoinBaseTx() bool
- func (msg *MsgTx) PlainSize() int
- func (msg *MsgTx) RemoveAllTxOut()
- func (msg *MsgTx) RemoveTxOut(index int)
- func (msg *MsgTx) SetBytes(bs []byte, mode CodecMode) error
- func (msg *MsgTx) SetPayload(payload []byte)
- func (msg *MsgTx) ToProto() *wirepb.Tx
- func (msg *MsgTx) TxHash() Hash
- func (msg *MsgTx) WitnessHash() Hash
- type NormalProposal
- func (np *NormalProposal) Bytes(mode CodecMode) ([]byte, error)
- func (np *NormalProposal) Content() []byte
- func (np *NormalProposal) Decode(r io.Reader, mode CodecMode) (n int, err error)
- func (np *NormalProposal) Encode(w io.Writer, mode CodecMode) (n int, err error)
- func (np *NormalProposal) FromProto(pb *wirepb.Proposal) error
- func (np *NormalProposal) Hash(index int) Hash
- func (np *NormalProposal) PlainSize() int
- func (np *NormalProposal) SetBytes(bs []byte, mode CodecMode) error
- func (np *NormalProposal) ToProto() *wirepb.Proposal
- func (np *NormalProposal) Type() ProposalType
- func (np *NormalProposal) Version() uint32
- type OutPoint
- type Proposal
- type ProposalArea
- func (pa *ProposalArea) Bytes(mode CodecMode) ([]byte, error)
- func (pa *ProposalArea) Count() int
- func (pa *ProposalArea) Decode(r io.Reader, mode CodecMode) (n int, err error)
- func (pa *ProposalArea) Encode(w io.Writer, mode CodecMode) (n int, err error)
- func (pa *ProposalArea) FromProto(pb *wirepb.ProposalArea) error
- func (pa *ProposalArea) OtherCount() int
- func (pa *ProposalArea) PlainSize() int
- func (pa *ProposalArea) PunishmentCount() int
- func (pa *ProposalArea) SetBytes(bs []byte, mode CodecMode) error
- func (pa *ProposalArea) ToProto() (*wirepb.ProposalArea, error)
- type ProposalType
- type TxIn
- type TxLoc
- type TxOut
- type TxWitness
- type WitnessRedeemScriptHash
Constants ¶
const ( BlockVersionV1 = 1 BlockVersionV2 = 2 BlockVersion = BlockVersionV2 )
BlockVersion is the current latest supported block version.
const ( // TxVersion is the current latest supported transaction version. TxVersion = 1 // MaxTxInSequenceNum is the maximum sequence number the sequence field // of a transaction input can be. MaxTxInSequenceNum uint64 = math.MaxUint64 // MaxPrevOutIndex is the maximum index the index field of a previous // outpoint can be. MaxPrevOutIndex uint32 = math.MaxUint32 // SequenceLockTimeDisabled is a flag that if set on a transaction // input's sequence number, the sequence number will not be interpreted // as a relative locktime. SequenceLockTimeDisabled uint64 = 1 << 63 // SequenceLockTimeIsSeconds is a flag thabt if set on a transaction // input's sequence number, the relative locktime has units of 32 // seconds(close to block interval). SequenceLockTimeIsSeconds uint64 = 1 << 38 // SequenceLockTimeMask is a mask that extracts the relative locktime // when masked against the transaction input sequence number. SequenceLockTimeMask uint64 = 0x00000000ffffffff // SequenceLockTimeGranularity is the defined time based granularity // for seconds-based relative time locks. When converting from seconds // to a sequence number, the value is right shifted by this amount, // therefore the granularity of relative time locks in 32 or 2^5 // seconds. Enforced relative lock times are multiples of 32 seconds. SequenceLockTimeGranularity = 5 )
const ( ProposalVersion = 1 HeadersPerProposal = 2 HeaderSizePerPlaceHolder = 500 PlaceHolderSize = HeadersPerProposal * HeaderSizePerPlaceHolder )
const HashSize = 32
HashSize is the array size used to store sha hashes. See Hash.
const MaxBlockPayload = 2000000
MaxBlockPayload is the maximum bytes a block message can be in bytes. 2MB.
const MaxHashStringSize = HashSize * 2
MaxHashStringSize is the maximum length of a Hash hash string.
const MaxTxPerBlock = (MaxBlockPayload / minTxPayload) + 1
maxTxPerBlock is the maximum number of transactions that could possibly fit into a block.
const MinBlockHeaderPayload = blockHeaderMinPlainSize
Variables ¶
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.
var (
ErrInvalidCodecMode = errors.New("invalid codec mode for wire")
)
Functions ¶
func Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func DoubleHashB ¶
DoubleHashB calculates sha256(sha256(b)) and returns the resulting bytes.
func Hash2CommonHash ¶
func IsValidFrozenPeriod ¶
func IsValidStakingValue ¶
func NewEmptyBLSPublicKey ¶
func NewEmptyBLSSignature ¶
func NewEmptyBigInt ¶
func NewEmptyPoCPublicKey ¶
func NewEmptyPoCSignature ¶
func ReadUint64 ¶
ReadUint64 reads a variable from r for 8 Bytes and returns it as a uint64.
func WriteTxOut ¶
WriteTxOut encodes to into the mass protocol encoding for a transaction output (TxOut) to w.
func WriteUint64 ¶
WriteUint64 serializes val to 8 Bytes
Types ¶
type BlockBase ¶
type BlockBase struct { Header BlockHeader Proposals ProposalArea }
type BlockHeader ¶
type BlockHeader struct { ChainID Hash Version uint64 Height uint64 Timestamp time.Time Previous Hash TransactionRoot Hash WitnessRoot Hash ProposalRoot Hash Target *big.Int Challenge Hash PubKey interfaces.PublicKey Proof poc.Proof Signature interfaces.Signature BanList []interfaces.PublicKey BindingRoot common.Hash // use this while header.Version >= 2 }
func MockHeader ¶
func MockHeader(version uint64, proofType poc.ProofType) *BlockHeader
func NewBlockHeaderFromBytes ¶
func NewBlockHeaderFromBytes(bhBytes []byte, mode CodecMode) (*BlockHeader, error)
func NewBlockHeaderFromProto ¶
func NewBlockHeaderFromProto(pb *wirepb.BlockHeader) (*BlockHeader, error)
NewBlockHeaderFromProto get wire BlockHeader from proto BlockHeader
func NewEmptyBlockHeader ¶
func NewEmptyBlockHeader() *BlockHeader
func (*BlockHeader) BannedPublicKeys ¶
func (h *BlockHeader) BannedPublicKeys() (banned []interfaces.PublicKey)
Both old and new public keys are allowed packed
func (*BlockHeader) BlockHash ¶
func (h *BlockHeader) BlockHash() Hash
BlockHash computes the block identifier hash for the given block header.
func (*BlockHeader) CheckVersionConstraint ¶
func (h *BlockHeader) CheckVersionConstraint() error
func (*BlockHeader) FromProto ¶
func (h *BlockHeader) FromProto(pb *wirepb.BlockHeader) error
FromProto load proto BlockHeader into wire BlockHeader
func (*BlockHeader) GetChainID ¶
func (h *BlockHeader) GetChainID() (Hash, error)
GetChainID calc chainID, only block with 0 height can be calc
func (*BlockHeader) PlainSize ¶
func (h *BlockHeader) PlainSize() int
func (*BlockHeader) PoCHash ¶
func (h *BlockHeader) PoCHash() (Hash, error)
PoCHash generate hash of all PoC needed elements in block header
func (*BlockHeader) PublicKey ¶
func (h *BlockHeader) PublicKey() interfaces.PublicKey
func (*BlockHeader) SetBanListFromProposals ¶
func (h *BlockHeader) SetBanListFromProposals(proposals []*FaultPubKey) error
func (*BlockHeader) ToProto ¶
func (h *BlockHeader) ToProto() *wirepb.BlockHeader
ToProto get proto BlockHeader from wire BlockHeader
func (*BlockHeader) VerifySig ¶
func (h *BlockHeader) VerifySig() (bool, error)
type FaultPubKey ¶
type FaultPubKey struct { PubKey interfaces.PublicKey Testimony [HeadersPerProposal]*BlockHeader // contains filtered or unexported fields }
FaultPubKey implements Proposal, representing for punishment-double-mining-pubKey
func NewEmptyFaultPubKey ¶
func NewEmptyFaultPubKey() *FaultPubKey
func NewFaultPubKeyFromBytes ¶
func NewFaultPubKeyFromBytes(bs []byte, mode CodecMode) (*FaultPubKey, error)
func (*FaultPubKey) FromProto ¶
func (fpk *FaultPubKey) FromProto(pb *wirepb.Punishment) error
func (*FaultPubKey) Hash ¶
func (fpk *FaultPubKey) Hash(index int) Hash
func (*FaultPubKey) IsValid ¶
func (fpk *FaultPubKey) IsValid() error
func (*FaultPubKey) PlainSize ¶
func (fpk *FaultPubKey) PlainSize() int
PlainSize returns the number of bytes the FaultPubKey contains.
func (*FaultPubKey) ToProto ¶
func (fpk *FaultPubKey) ToProto() *wirepb.Punishment
func (*FaultPubKey) Type ¶
func (fpk *FaultPubKey) Type() ProposalType
func (*FaultPubKey) Version ¶
func (fpk *FaultPubKey) Version() uint32
type Hash ¶
Hash is used in several of the mass messages and common structures. It typically represents the double sha256 of data.
func BuildMerkleTreeStoreForProposal ¶
func BuildMerkleTreeStoreForProposal(proposals *ProposalArea) []*Hash
func CommonHash2Hash ¶
func DoubleHashH ¶
DoubleHashH calculates sha256(sha256(b)) and returns the resulting bytes as a Hash.
func GetMerkleRootFromCache ¶
func GetProposalHash ¶
func HashMerkleBranches ¶
HashMerkleBranches takes two hashes, treated as the left and right tree nodes, and returns the hash of their concatenation. This is a helper function used to aid in the generation of a merkle tree.
func NewHash ¶
NewHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.
func NewHashFromHash ¶
func NewHashFromProto ¶
NewHashFromProto get Hash From proto Hash
func NewHashFromStr ¶
NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.
func (*Hash) Bytes ¶
Bytes returns the bytes which represent the hash as a byte slice.
NOTE: This makes a copy of the bytes and should have probably been named CloneBytes. It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.
func (*Hash) SetBytes ¶
SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.
type MsgBlock ¶
type MsgBlock struct { Header BlockHeader Proposals ProposalArea Transactions []*MsgTx }
MsgBlock implements the Message interface and represents a mass block message. It is used to deliver block and transaction information in response to a getdata message (MsgGetData) for a given block hash.
func NewBlockFromProto ¶
NewBlockFromProto get wire Block from proto Block
func NewEmptyMsgBlock ¶
func NewEmptyMsgBlock() *MsgBlock
func NewMsgBlock ¶
func NewMsgBlock(blockHeader *BlockHeader) *MsgBlock
NewMsgBlock returns a new mass block message that conforms to the Message interface. See MsgBlock for details.
func (*MsgBlock) AddTransaction ¶
AddTransaction adds a transaction to the message.
func (*MsgBlock) ClearTransactions ¶
func (msg *MsgBlock) ClearTransactions()
ClearTransactions removes all transactions from the message.
func (*MsgBlock) DeserializeTxLoc ¶
func (*MsgBlock) FromProto ¶
FromProto load proto Block into wire Block, if error happens, old content is still immutable
type MsgTx ¶
MsgTx implements the Message interface and represents a mass tx message. It is used to deliver transaction information in response to a getdata message (MsgGetData) for a given transaction.
Use the AddTxIn and AddTxOut functions to build up the list of transaction inputs and outputs.
func NewMsgTx ¶
func NewMsgTx() *MsgTx
NewMsgTx returns a new mass tx message that conforms to the Message interface. The return instance has a default version of TxVersion and there are no transaction inputs or outputs. Also, the lock time is set to zero to indicate the transaction is valid immediately as opposed to some time in future.
func NewTxFromProto ¶
NewTxFromProto get wire Tx from proto Tx
func (*MsgTx) IsCoinBaseTx ¶
IsCoinBaseTx determines whether or not a transaction is a coinbase. A coinbase is a special transaction created by miners that has no inputs. This is represented in the block chain by a transaction with a single input that has a previous output transaction index set to the maximum value along with a zero hash.
This function only differs from IsCoinBase in that it works with a raw wire transaction as opposed to a higher level util transaction.
func (*MsgTx) RemoveAllTxOut ¶
func (msg *MsgTx) RemoveAllTxOut()
func (*MsgTx) RemoveTxOut ¶
func (*MsgTx) SetPayload ¶
func (*MsgTx) WitnessHash ¶
WitnessHash generates the hash of the transaction serialized according to the new witness serialization defined in BIP0141 and BIP0144. The final output is used within the Segregated Witness commitment of all the witnesses within a block. If a transaction has no witness data, then the witness hash, is the same as its txid.
type NormalProposal ¶
type NormalProposal struct {
// contains filtered or unexported fields
}
NormalProposal implements Proposal, representing for all proposals with no consensus proposalType.
func NewPlaceHolder ¶
func NewPlaceHolder() *NormalProposal
PlaceHolder prevents miner from eliminating all punishment proposals, because that is more profitable to save block size for transactions.
func (*NormalProposal) Content ¶
func (np *NormalProposal) Content() []byte
func (*NormalProposal) Hash ¶
func (np *NormalProposal) Hash(index int) Hash
func (*NormalProposal) PlainSize ¶
func (np *NormalProposal) PlainSize() int
func (*NormalProposal) SetBytes ¶
func (np *NormalProposal) SetBytes(bs []byte, mode CodecMode) error
func (*NormalProposal) ToProto ¶
func (np *NormalProposal) ToProto() *wirepb.Proposal
func (*NormalProposal) Type ¶
func (np *NormalProposal) Type() ProposalType
func (*NormalProposal) Version ¶
func (np *NormalProposal) Version() uint32
type OutPoint ¶
OutPoint defines a mass data type that is used to track previous transaction outputs.
func NewOutPoint ¶
NewOutPoint returns a new mass transaction outpoint point with the provided hash and index.
type Proposal ¶
type Proposal interface { Bytes(CodecMode) ([]byte, error) SetBytes([]byte, CodecMode) error Hash(int) Hash }
General Proposal Interface
type ProposalArea ¶
type ProposalArea struct { PunishmentArea []*FaultPubKey OtherArea []*NormalProposal }
ProposalArea represents for proposals in blocks.
func NewProposalArea ¶
func NewProposalArea(punishmentArea []*FaultPubKey, otherArea []*NormalProposal) (*ProposalArea, error)
func NewProposalAreaFromProto ¶
func NewProposalAreaFromProto(pb *wirepb.ProposalArea) (*ProposalArea, error)
NewProposalAreaFromProto get wire ProposalArea from proto ProposalArea
func (*ProposalArea) Count ¶
func (pa *ProposalArea) Count() int
func (*ProposalArea) FromProto ¶
func (pa *ProposalArea) FromProto(pb *wirepb.ProposalArea) error
FromProto load proto ProposalArea into wire ProposalArea, if error happens, old content is still immutable
func (*ProposalArea) OtherCount ¶
func (pa *ProposalArea) OtherCount() int
func (*ProposalArea) PlainSize ¶
func (pa *ProposalArea) PlainSize() int
func (*ProposalArea) PunishmentCount ¶
func (pa *ProposalArea) PunishmentCount() int
func (*ProposalArea) ToProto ¶
func (pa *ProposalArea) ToProto() (*wirepb.ProposalArea, error)
ToProto get proto ProposalArea from wire ProposalArea
type ProposalType ¶
type ProposalType uint32
type TxIn ¶
TxIn defines a mass transaction input.
type TxLoc ¶
TxLoc holds locator data for the offset and length of where a transaction is located within a MsgBlock data buffer.
type TxOut ¶
TxOut defines a mass transaction output.
type TxWitness ¶
type TxWitness [][]byte
TxWitness defines the witness for a TxIn. A witness is to be interpreted as a slice of byte slices, or a stack with one or many elements.