Documentation ¶
Index ¶
- Variables
- type Account
- type AccountState
- type Block
- type BlockHeader
- type Transaction
- type TransactionPool
- func (txpool *TransactionPool) AddTransactionToPool(tx *Transaction)
- func (txpool *TransactionPool) AddTransactionsToPool(txs []*Transaction)
- func (txpool *TransactionPool) ClearQueue()
- func (txpool *TransactionPool) Locked()
- func (txpool *TransactionPool) PackTransactions(maxTxs uint64) []*Transaction
- func (txpool *TransactionPool) Size() int
- func (txpool *TransactionPool) Unlocked()
Constants ¶
This section is empty.
Variables ¶
View Source
var NodeLog *log.Logger
Functions ¶
This section is empty.
Types ¶
type AccountState ¶
AccountState 账户状态详情
func DecodeToAccountState ¶
func DecodeToAccountState(b []byte) *AccountState
DecodeToAccountState 对AccountState进行解码
func (*AccountState) Deduct ¶
func (as *AccountState) Deduct(val *big.Int) bool
Deduct 扣款, 减少一个账户的余额
func (*AccountState) Deposit ¶
func (as *AccountState) Deposit(value *big.Int)
Deposit 存款, 增加一个账户的余额
type Block ¶
type Block struct { Header *BlockHeader Body []*Transaction Hash []byte }
Block 区块
func NewBlock ¶
func NewBlock(header *BlockHeader, body []*Transaction) *Block
NewBlock 创建区块 调用前需要保证区块头中的信息完善且正确 创建后不应进行修改操作, 否则哈希结果出错
type BlockHeader ¶
type BlockHeader struct { ParentBlockHash []byte // 父区块哈希 StateRoot []byte // 状态树根哈希 TxRoot []byte // 交易的哈希 Number uint64 // 表明该区块是区块链中的第几个区块 Time time.Time // 区块创建时间 Miner uint64 // 区块创建节点 }
BlockHeader 区块头
func DecodeBlockHeader ¶
func DecodeBlockHeader(b []byte) *BlockHeader
DecodeBlockHeader 对BlockHeader进行解码
type Transaction ¶
type Transaction struct { Sender string Recipient string Nonce uint64 Value *big.Int Hash []byte // 一些额外信息 Time time.Time // 添加到交易池的时间 }
Transaction 交易
func DecodeTransaction ¶
func DecodeTransaction(b []byte) *Transaction
DecodeTransaction 对Transaction进行解码
func NewTransaction ¶
func NewTransaction(sender, recipient string, value *big.Int, nonce uint64) *Transaction
NewTransaction 创建交易 创建后不应进行修改操作, 否则哈希结果出错
type TransactionPool ¶
type TransactionPool struct { Queue []*Transaction // 交易队列 // contains filtered or unexported fields }
TransactionPool 交易池
func (*TransactionPool) AddTransactionToPool ¶
func (txpool *TransactionPool) AddTransactionToPool(tx *Transaction)
AddTransactionToPool 添加交易
func (*TransactionPool) AddTransactionsToPool ¶
func (txpool *TransactionPool) AddTransactionsToPool(txs []*Transaction)
AddTransactionsToPool 批量添加交易
func (*TransactionPool) PackTransactions ¶
func (txpool *TransactionPool) PackTransactions(maxTxs uint64) []*Transaction
PackTransactions 获取交易 maxTxs: 能获取到的最大交易数目, 当前交易池中交易数目小于maxTxs时, 返回全部交易, 否则返回maxTxs个交易
Click to show internal directories.
Click to hide internal directories.