Documentation
¶
Index ¶
- Constants
- func NewTxOut(value uint64) *corepb.TxOut
- type Address
- type AddressHash
- type AddressPubKeyHash
- type AddressTypeSplit
- type Block
- func (block *Block) AppendTx(txs ...*Transaction) *Block
- func (block *Block) BlockHash() *crypto.HashType
- func (block *Block) Copy() *Block
- func (block *Block) FromProtoMessage(message proto.Message) error
- func (block *Block) Marshal() (data []byte, err error)
- func (block *Block) ToProtoMessage() (proto.Message, error)
- func (block *Block) Unmarshal(data []byte) error
- type BlockHeader
- type Consensus
- type Contract
- type IrreversibleInfo
- type OutPoint
- type RegisterCandidateContent
- type SyncManager
- type Token
- type Transaction
- func (tx *Transaction) AppendVin(in ...*TxIn) *Transaction
- func (tx *Transaction) AppendVout(out ...*corepb.TxOut) *Transaction
- func (tx *Transaction) CalcTxHash() (*crypto.HashType, error)
- func (tx *Transaction) ConvToPbTx() (*corepb.Transaction, error)
- func (tx *Transaction) Copy() *Transaction
- func (tx *Transaction) FromProtoMessage(message proto.Message) error
- func (tx *Transaction) Marshal() (data []byte, err error)
- func (tx *Transaction) OutputAmount() uint64
- func (tx *Transaction) ResetTxHash()
- func (tx *Transaction) SerializeSize() (int, error)
- func (tx *Transaction) ToProtoMessage() (proto.Message, error)
- func (tx *Transaction) TxHash() (*crypto.HashType, error)
- func (tx *Transaction) Unmarshal(data []byte) error
- func (tx *Transaction) WithData(data *corepb.Data) *Transaction
- type TxIn
- type TxWrap
- type UtxoMap
- type UtxoWrap
- func (utxoWrap *UtxoWrap) Height() uint32
- func (utxoWrap *UtxoWrap) IsCoinBase() bool
- func (utxoWrap *UtxoWrap) IsModified() bool
- func (utxoWrap *UtxoWrap) IsSpent() bool
- func (utxoWrap *UtxoWrap) Modified()
- func (utxoWrap *UtxoWrap) Script() []byte
- func (utxoWrap *UtxoWrap) SetCoinBase()
- func (utxoWrap *UtxoWrap) Spend()
- func (utxoWrap *UtxoWrap) UnSpend()
- func (utxoWrap *UtxoWrap) Value() uint64
- type VoteContent
Constants ¶
const ( BoxPrefix = 'b' AddressPrefixLength = 2 FixPrefix = 0x13 AddressLength = 26 EncodeAddressLength = 35 )
const
const ( GeneralTx = iota RegisterCandidateTx VoteTx )
Define const
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Address ¶
type Address interface {
String() string
SetString(string) error
Hash() []byte
Hash160() *AddressHash
}
Address is an interface type for any type of destination a transaction output may spend to.
func NewAddress ¶
NewAddress creates an address from string
func NewSplitAddress ¶ added in v0.3.0
NewSplitAddress creates an address with a string prefixed by "b2"
func NewSplitAddressFromHash ¶ added in v0.3.0
NewSplitAddressFromHash creates an address with byte array of size 20
type AddressPubKeyHash ¶
type AddressPubKeyHash struct {
// contains filtered or unexported fields
}
AddressPubKeyHash is an Address for a pay-to-pubkey-hash (P2PKH) transaction.
func NewAddressFromPubKey ¶
func NewAddressFromPubKey(pubKey *crypto.PublicKey) (*AddressPubKeyHash, error)
NewAddressFromPubKey returns a new AddressPubKeyHash derived from an ecdsa public key
func NewAddressPubKeyHash ¶
func NewAddressPubKeyHash(pkHash []byte) (*AddressPubKeyHash, error)
NewAddressPubKeyHash returns a new AddressPubKeyHash. pkHash mustbe 20 bytes.
func (*AddressPubKeyHash) Hash ¶
func (a *AddressPubKeyHash) Hash() []byte
Hash returns the bytes to be included in a txout script to pay to a pubkey hash.
func (*AddressPubKeyHash) Hash160 ¶
func (a *AddressPubKeyHash) Hash160() *AddressHash
Hash160 returns the underlying array of the pubkey hash.
func (*AddressPubKeyHash) SetString ¶
func (a *AddressPubKeyHash) SetString(in string) error
SetString sets the Address's internal byte array using byte array decoded from input base58 format string, returns error if input string is invalid
func (*AddressPubKeyHash) String ¶
func (a *AddressPubKeyHash) String() string
String returns a human-readable string for the pay-to-pubkey-hash address.
type AddressTypeSplit ¶ added in v0.3.0
type AddressTypeSplit struct {
// contains filtered or unexported fields
}
AddressTypeSplit stands for split address
func (*AddressTypeSplit) Hash ¶ added in v0.3.0
func (a *AddressTypeSplit) Hash() []byte
Hash returns the bytes to be included in a txout script to pay to a split addr.
func (*AddressTypeSplit) Hash160 ¶ added in v0.3.0
func (a *AddressTypeSplit) Hash160() *AddressHash
Hash160 returns the underlying array of the pubkey hash.
func (*AddressTypeSplit) SetString ¶ added in v0.3.0
func (a *AddressTypeSplit) SetString(in string) error
SetString sets the Address's internal byte array using byte array decoded from input base58 format string, returns error if input string is invalid
func (*AddressTypeSplit) String ¶ added in v0.3.0
func (a *AddressTypeSplit) String() string
String returns a human-readable string for the split address.
type Block ¶
type Block struct {
Hash *crypto.HashType
Header *BlockHeader
Txs []*Transaction
Signature []byte
IrreversibleInfo *IrreversibleInfo
Height uint32
}
Block defines a block containing block and height that provides easier and more efficient manipulation of raw blocks. It also memoizes hashes for the block and its transactions on their first access so subsequent accesses don't have to repeat the relatively expensive hashing operations.
func NewBlocks ¶
func NewBlocks(prevBlockHash crypto.HashType, txsRoot crypto.HashType, timestamp int64, prevOutPoint OutPoint, value uint64, lockTime int64, height uint32) *Block
NewBlocks generates a new Block
func (*Block) AppendTx ¶ added in v0.3.0
func (block *Block) AppendTx(txs ...*Transaction) *Block
AppendTx appends tx to block
func (*Block) Copy ¶ added in v0.3.0
Copy returns a deep copy: used only for splitBlockOutputs() Only copy needed fields to save efforts: height & vin & vout
func (*Block) FromProtoMessage ¶
FromProtoMessage converts proto message to block.
func (*Block) ToProtoMessage ¶
ToProtoMessage converts block to proto message.
type BlockHeader ¶
type BlockHeader struct {
// Version of the block. This is not the same as the protocol version.
Version int32
// Hash of the previous block header in the block chain.
PrevBlockHash crypto.HashType
// Merkle tree reference to hash of all transactions for the block.
TxsRoot crypto.HashType
// Time the block was created. This is, unfortunately, encoded as a
// uint32 on the wire and therefore is limited to 2106.
TimeStamp int64
// Distinguish between mainnet and testnet.
Magic uint32
PeriodHash crypto.HashType
CandidatesHash crypto.HashType
}
BlockHeader defines information about a block and is used in the block (Block) and headers (MsgHeaders) messages.
func NewBlockHeader ¶
func NewBlockHeader(prevBlockHash crypto.HashType, txsRoot crypto.HashType, timestamp int64) *BlockHeader
NewBlockHeader generates a new BlockHeader
func (*BlockHeader) FromProtoMessage ¶
func (header *BlockHeader) FromProtoMessage(message proto.Message) error
FromProtoMessage converts proto message to block header.
func (*BlockHeader) Marshal ¶
func (header *BlockHeader) Marshal() (data []byte, err error)
Marshal method marshal BlockHeader object to binary
func (*BlockHeader) ToProtoMessage ¶
func (header *BlockHeader) ToProtoMessage() (proto.Message, error)
ToProtoMessage converts block header to proto message.
func (*BlockHeader) Unmarshal ¶
func (header *BlockHeader) Unmarshal(data []byte) error
Unmarshal method unmarshal binary data to BlockHeader object
type Consensus ¶
type Consensus interface {
Run() error
Stop()
StoreCandidateContext(*Block, storage.Batch) error
VerifySign(*Block) (bool, error)
VerifyMinerEpoch(*Block) error
StopMint()
RecoverMint()
BroadcastEternalMsgToMiners(*Block) error
ValidateMiner() bool
TryToUpdateEternalBlock(*Block)
IsCandidateExist(AddressHash) bool
VerifyCandidates(*Block) error
UpdateCandidateContext(*Block) error
}
Consensus define consensus interface
type IrreversibleInfo ¶ added in v0.3.0
IrreversibleInfo defines information about irreversible blocks
func (*IrreversibleInfo) FromProtoMessage ¶ added in v0.3.0
func (ii *IrreversibleInfo) FromProtoMessage(message proto.Message) error
FromProtoMessage converts proto message to IrreversibleInfo.
func (*IrreversibleInfo) Marshal ¶ added in v0.3.0
func (ii *IrreversibleInfo) Marshal() (data []byte, err error)
Marshal method marshal IrreversibleInfo object to binary
func (*IrreversibleInfo) ToProtoMessage ¶ added in v0.3.0
func (ii *IrreversibleInfo) ToProtoMessage() (proto.Message, error)
ToProtoMessage converts IrreversibleInfo to proto message.
func (*IrreversibleInfo) Unmarshal ¶ added in v0.3.0
func (ii *IrreversibleInfo) Unmarshal(data []byte) error
Unmarshal method unmarshal binary data to IrreversibleInfo object
type OutPoint ¶
OutPoint defines a data type that is used to track previous transaction outputs.
func NewOutPoint ¶
NewOutPoint constructs a OutPoint
func (*OutPoint) FromProtoMessage ¶
FromProtoMessage converts proto message to out point.
func (*OutPoint) ToProtoMessage ¶
ToProtoMessage converts out point to proto message.
type RegisterCandidateContent ¶ added in v0.3.0
type RegisterCandidateContent struct {
// contains filtered or unexported fields
}
RegisterCandidateContent identify the tx of RegisterCandidate type
func (*RegisterCandidateContent) Addr ¶ added in v0.3.0
func (sc *RegisterCandidateContent) Addr() AddressHash
Addr returns addr in registerCandidateContent.
func (*RegisterCandidateContent) Marshal ¶ added in v0.3.0
func (sc *RegisterCandidateContent) Marshal() (data []byte, err error)
Marshal marshals the RegisterCandidateContent to a binary representation of it.
func (*RegisterCandidateContent) Unmarshal ¶ added in v0.3.0
func (sc *RegisterCandidateContent) Unmarshal(data []byte) error
Unmarshal unmarshals RegisterCandidateContent from binary data.
type SyncManager ¶
SyncManager define sync manager interface
type Token ¶ added in v0.3.0
type Token struct {
// contains filtered or unexported fields
}
Token stands for token address
func NewTokenFromOutpoint ¶ added in v0.3.0
NewTokenFromOutpoint creates an token adddress from outpoint
type Transaction ¶
type Transaction struct {
Version int32
Vin []*TxIn
Vout []*corepb.TxOut
Data *corepb.Data
Magic uint32
LockTime int64
// contains filtered or unexported fields
}
Transaction defines a transaction.
func ConvPbTx ¶ added in v0.3.0
func ConvPbTx(orig *corepb.Transaction) (*Transaction, error)
ConvPbTx convert a pb tx to types tx
func NewTransaction ¶
func NewTransaction(prevOutPoint OutPoint, value uint64, lockTime int64) *Transaction
NewTransaction generates a new Transaction
func NewTx ¶ added in v0.3.0
func NewTx(ver int32, magic uint32, lockTime int64) *Transaction
NewTx generates a new Transaction
func (*Transaction) AppendVin ¶ added in v0.3.0
func (tx *Transaction) AppendVin(in ...*TxIn) *Transaction
AppendVin appends a tx in to tx
func (*Transaction) AppendVout ¶ added in v0.3.0
func (tx *Transaction) AppendVout(out ...*corepb.TxOut) *Transaction
AppendVout appends a tx out to tx
func (*Transaction) CalcTxHash ¶
func (tx *Transaction) CalcTxHash() (*crypto.HashType, error)
CalcTxHash calculates tx hash
func (*Transaction) ConvToPbTx ¶ added in v0.3.0
func (tx *Transaction) ConvToPbTx() (*corepb.Transaction, error)
ConvToPbTx convert a types tx to corepb tx
func (*Transaction) Copy ¶ added in v0.3.0
func (tx *Transaction) Copy() *Transaction
Copy returns a deep copy, mostly for parallel script verification Do not copy hash since it will be updated anyway in script verification
func (*Transaction) FromProtoMessage ¶
func (tx *Transaction) FromProtoMessage(message proto.Message) error
FromProtoMessage converts proto message to transaction.
func (*Transaction) Marshal ¶
func (tx *Transaction) Marshal() (data []byte, err error)
Marshal method marshal tx object to binary
func (*Transaction) OutputAmount ¶ added in v0.3.0
func (tx *Transaction) OutputAmount() uint64
OutputAmount returns total amount from tx's outputs
func (*Transaction) ResetTxHash ¶ added in v0.3.0
func (tx *Transaction) ResetTxHash()
ResetTxHash reset txhash
func (*Transaction) SerializeSize ¶
func (tx *Transaction) SerializeSize() (int, error)
SerializeSize return tx size.
func (*Transaction) ToProtoMessage ¶
func (tx *Transaction) ToProtoMessage() (proto.Message, error)
ToProtoMessage converts transaction to proto message.
func (*Transaction) TxHash ¶
func (tx *Transaction) TxHash() (*crypto.HashType, error)
TxHash returns tx hash; return cached hash if it exists
func (*Transaction) Unmarshal ¶
func (tx *Transaction) Unmarshal(data []byte) error
Unmarshal method unmarshal binary data to tx object
func (*Transaction) WithData ¶ added in v0.3.0
func (tx *Transaction) WithData(data *corepb.Data) *Transaction
WithData sets Data to tx
type TxIn ¶
TxIn defines a transaction input.
func (*TxIn) FromProtoMessage ¶
FromProtoMessage converts proto message to txin.
func (*TxIn) ToProtoMessage ¶
ToProtoMessage converts txin to proto message.
type TxWrap ¶ added in v0.3.0
type TxWrap struct {
Tx *Transaction
AddedTimestamp int64
Height uint32
FeePerKB uint64
IsScriptValid bool
}
TxWrap wrap transaction
type UtxoWrap ¶
type UtxoWrap struct {
// contains filtered or unexported fields
}
UtxoWrap contains info about utxo
func NewUtxoWrap ¶ added in v0.3.0
NewUtxoWrap returns new utxoWrap.
func (*UtxoWrap) Height ¶ added in v0.3.0
Height returns the height of the block containing the output.
func (*UtxoWrap) IsCoinBase ¶
IsCoinBase returns whether or not the output was contained in a coinbase transaction.
func (*UtxoWrap) IsModified ¶
IsModified returns whether or not the output ismodified.
func (*UtxoWrap) Modified ¶ added in v0.3.0
func (utxoWrap *UtxoWrap) Modified()
Modified marks the output as modified.
func (*UtxoWrap) SetCoinBase ¶ added in v0.3.0
func (utxoWrap *UtxoWrap) SetCoinBase()
SetCoinBase marks the output as coinBase.
func (*UtxoWrap) Spend ¶ added in v0.3.0
func (utxoWrap *UtxoWrap) Spend()
Spend marks the output as spent.
type VoteContent ¶
type VoteContent struct {
// contains filtered or unexported fields
}
VoteContent identify the tx of vote type
func (*VoteContent) Addr ¶
func (vc *VoteContent) Addr() AddressHash
Addr returns addr in voteContent.
func (*VoteContent) Marshal ¶
func (vc *VoteContent) Marshal() (data []byte, err error)
Marshal marshals the VoteContent to a binary representation of it.
func (*VoteContent) Unmarshal ¶
func (vc *VoteContent) Unmarshal(data []byte) error
Unmarshal unmarshals VoteContent from binary data.
func (*VoteContent) Votes ¶
func (vc *VoteContent) Votes() int64
Votes returns votes in voteContent.