Documentation
¶
Index ¶
- Constants
- func NewTxOut(value uint64) *corepb.TxOut
- type Address
- type AddressHash
- type AddressPubKeyHash
- type Block
- type BlockHeader
- type Consensus
- type OutPoint
- type SignUpContent
- type SyncManager
- type Transaction
- func (tx *Transaction) CalcTxHash() (*crypto.HashType, error)
- func (tx *Transaction) FromProtoMessage(message proto.Message) error
- func (tx *Transaction) Marshal() (data []byte, err error)
- 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
- type TxIn
- type UtxoWrap
- 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
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 Block ¶
type Block struct {
Hash *crypto.HashType
Header *BlockHeader
Txs []*Transaction
Signature []byte
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) 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(*crypto.HashType) error
VerifySign(*Block) (bool, error)
VerifyMinerEpoch(*Block) error
StopMint()
RecoverMint()
BroadcastEternalMsgToMiners(*Block) error
ValidateMiner() bool
}
Consensus define consensus interface
type OutPoint ¶
OutPoint defines a data type that is used to track previous transaction outputs.
func NewOutPoint ¶
NewOutPoint generates a new OutPoint
func (*OutPoint) FromProtoMessage ¶
FromProtoMessage converts proto message to out point.
func (*OutPoint) ToProtoMessage ¶
ToProtoMessage converts out point to proto message.
type SignUpContent ¶
type SignUpContent struct {
// contains filtered or unexported fields
}
SignUpContent identify the tx of signup type
func (*SignUpContent) Addr ¶
func (sc *SignUpContent) Addr() AddressHash
Addr returns addr in signUpContent.
func (*SignUpContent) Marshal ¶
func (sc *SignUpContent) Marshal() (data []byte, err error)
Marshal marshals the SignUpContent to a binary representation of it.
func (*SignUpContent) Unmarshal ¶
func (sc *SignUpContent) Unmarshal(data []byte) error
Unmarshal unmarshals SignUpContent from binary data.
type SyncManager ¶
SyncManager define sync manager interface
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 NewTransaction ¶
func NewTransaction(prevOutPoint OutPoint, value uint64, lockTime int64) *Transaction
NewTransaction generates a new Transaction
func (*Transaction) CalcTxHash ¶
func (tx *Transaction) CalcTxHash() (*crypto.HashType, error)
CalcTxHash calculates tx hash
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) 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
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 UtxoWrap ¶
type UtxoWrap struct {
Output *corepb.TxOut
BlockHeight uint32
IsCoinBase bool
IsSpent bool
IsModified bool
}
UtxoWrap contains info about utxo
func (*UtxoWrap) FromProtoMessage ¶
FromProtoMessage converts proto message to utxo wrap.
func (*UtxoWrap) ToProtoMessage ¶
ToProtoMessage converts utxo wrap to proto message.
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.