Documentation
¶
Index ¶
- Constants
- Variables
- func SerializeTxs(r io.Writer, txs Transactions)
- type Block
- type BlockHeader
- type ContractSpec
- type IInventory
- type Transaction
- func (tx *Transaction) Amount() *big.Int
- func (tx *Transaction) Compare(v interface{}) int
- func (tx *Transaction) CreateTime() uint32
- func (tx *Transaction) Deserialize(data []byte) error
- func (tx *Transaction) Fee() *big.Int
- func (tx *Transaction) FromChain() string
- func (tx *Transaction) GetType() uint32
- func (tx *Transaction) Hash() crypto.Hash
- func (tx *Transaction) IsLocalChain() bool
- func (tx *Transaction) Nonce() uint32
- func (tx *Transaction) Recipient() accounts.Address
- func (tx *Transaction) Sender() accounts.Address
- func (tx *Transaction) Serialize() []byte
- func (tx *Transaction) SignHash() crypto.Hash
- func (tx *Transaction) ToChain() string
- func (tx *Transaction) Verfiy() (accounts.Address, error)
- func (tx *Transaction) WithPayload(data []byte)
- func (tx *Transaction) WithSignature(sig *crypto.Signature)
- type Transactions
Constants ¶
const ( TypeAtomic uint32 = iota // 链内交易 TypeAcrossChain // 跨链交易 TypeMerged // 跨链合并交易 TypeBackfront // 资金回笼交易 TypeDistribut // 下发交易 TypeIssue // 发行交易 TypeJSContractInit // js contract_Init TypeLuaContractInit // lua contract_Init TypeContractInvoke // contract_Invoke TypeContractQuery // contract_Query )
Transaction type
Variables ¶
var ( // ErrEmptySignature represents no signature ErrEmptySignature = errors.New("Signature Empty Error") )
Functions ¶
func SerializeTxs ¶
func SerializeTxs(r io.Writer, txs Transactions)
SerializeTxs serializes transactions
Types ¶
type Block ¶
type Block struct {
Header *BlockHeader `json:"header"`
Transactions Transactions `json:"transactions"`
// contains filtered or unexported fields
}
Block represents an block in blockchain
func NewBlock ¶
func NewBlock(prvHash crypto.Hash, timeStamp, height, nonce uint32, txsHash crypto.Hash, Txs Transactions) *Block
NewBlock returns an new block
func (*Block) Deserialize ¶
Deserialize deserializes bytes to Block
func (*Block) GetTransactions ¶
func (b *Block) GetTransactions(transactionType uint32) (Transactions, error)
GetTransactions get Transactions by Type
func (*Block) PreviousHash ¶
PreviousHash returns the previous hash of the block
type BlockHeader ¶
type BlockHeader struct {
PreviousHash crypto.Hash `json:"previousHash" `
TimeStamp uint32 `json:"timeStamp"`
Nonce uint32 `json:"nonce" `
TxsMerkleHash crypto.Hash `json:"transactionsMerkleHash" `
Height uint32 `json:"height" `
}
BlockHeader represents the header in block
func NewBlockHeader ¶
func NewBlockHeader(prvHash crypto.Hash, timeStamp, height, nonce uint32, txsHash crypto.Hash) *BlockHeader
NewBlockHeader returns a blockheader
func (*BlockHeader) Deserialize ¶
func (h *BlockHeader) Deserialize(data []byte) error
Deserialize deserialize the input data to header
func (*BlockHeader) Hash ¶
func (h *BlockHeader) Hash() crypto.Hash
Hash returns the hash of the blockheader
func (BlockHeader) Serialize ¶
func (h BlockHeader) Serialize() []byte
Serialize returns the serialized bytes of a blockheader
type ContractSpec ¶
type IInventory ¶
IInventory defines interface that broadcast data should implements
type Transaction ¶
type Transaction struct {
Data txdata `json:"data"`
Payload []byte `json:"payload"`
// contains filtered or unexported fields
}
Transaction represents the basic transaction that contained in blocks
func NewTransaction ¶
func NewTransaction( fromChain coordinate.ChainCoordinate, toChain coordinate.ChainCoordinate, txType uint32, nonce uint32, sender, reciepent accounts.Address, amount, fee *big.Int, CreateTime uint32) *Transaction
NewTransaction creates an new transaction with the parameters
func (*Transaction) Amount ¶
func (tx *Transaction) Amount() *big.Int
Amount returns the transfer �amount of the transaction
func (*Transaction) Compare ¶
func (tx *Transaction) Compare(v interface{}) int
Compare implements interface consensus need
func (*Transaction) CreateTime ¶
func (tx *Transaction) CreateTime() uint32
CreateTime returns the create time of the transaction
func (*Transaction) Deserialize ¶
func (tx *Transaction) Deserialize(data []byte) error
Deserialize deserializes bytes to a transaction
func (*Transaction) Fee ¶
func (tx *Transaction) Fee() *big.Int
Fee returns the nonce of the transaction
func (*Transaction) FromChain ¶
func (tx *Transaction) FromChain() string
FromChain returns the chain coordinate of the sender
func (*Transaction) GetType ¶
func (tx *Transaction) GetType() uint32
GetType returns transaction type
func (*Transaction) Hash ¶
func (tx *Transaction) Hash() crypto.Hash
Hash returns the hash of a transaction
func (*Transaction) IsLocalChain ¶
func (tx *Transaction) IsLocalChain() bool
IsLocalChain returns whether or not local chain
func (*Transaction) Nonce ¶
func (tx *Transaction) Nonce() uint32
Nonce returns the nonce of the transaction
func (*Transaction) Recipient ¶
func (tx *Transaction) Recipient() accounts.Address
Recipient returns the address of the recipient
func (*Transaction) Sender ¶
func (tx *Transaction) Sender() accounts.Address
Sender returns the address of the sender.
func (*Transaction) Serialize ¶
func (tx *Transaction) Serialize() []byte
Serialize returns the serialized bytes of a transaction
func (*Transaction) SignHash ¶
func (tx *Transaction) SignHash() crypto.Hash
SignHash returns the hash of a raw transaction before sign
func (*Transaction) ToChain ¶
func (tx *Transaction) ToChain() string
ToChain returns the chain coordinate of the recipient
func (*Transaction) Verfiy ¶
func (tx *Transaction) Verfiy() (accounts.Address, error)
Verfiy Also can use this method verify signature
func (*Transaction) WithPayload ¶
func (tx *Transaction) WithPayload(data []byte)
WithPayload returns a new transaction with the given data
func (*Transaction) WithSignature ¶
func (tx *Transaction) WithSignature(sig *crypto.Signature)
WithSignature returns a new transaction with the given signature.
type Transactions ¶
type Transactions []*Transaction
Transactions represents transaction slice type for basic sorting.
func DeserializeTxs ¶
func DeserializeTxs(r io.Reader) Transactions
DeserializeTxs deserializes transactions
func (Transactions) Less ¶
func (s Transactions) Less(i, j int) bool
Less compares nonce of the i'th and the j'th element in s
func (Transactions) Swap ¶
func (s Transactions) Swap(i, j int)
Swap swaps the i'th and the j'th element in s