base

package
v0.0.0-...-5fa8bf8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NodeLog *log.Logger

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountAddress string
	PublicKey      []byte
}

Account 预留结构, 便于以后扩展 平台的交互过程暂不涉及客户端加解密的操作

type AccountState

type AccountState struct {
	AccountAddress string
	Nonce          uint64
	Balance        *big.Int // 账户余额
}

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 存款, 增加一个账户的余额

func (*AccountState) Encode

func (as *AccountState) Encode() []byte

Encode 对AccountState进行编码

func (*AccountState) Hash

func (as *AccountState) Hash() []byte

Hash 对AccountState求哈希

type Block

type Block struct {
	Header *BlockHeader
	Body   []*Transaction
	Hash   []byte
}

Block 区块

func DecodeBlock

func DecodeBlock(b []byte) *Block

DecodeBlock 对Block进行解码

func NewBlock

func NewBlock(header *BlockHeader, body []*Transaction) *Block

NewBlock 创建区块 调用前需要保证区块头中的信息完善且正确 创建后不应进行修改操作, 否则哈希结果出错

func (*Block) Encode

func (b *Block) Encode() []byte

Encode 对Block进行编码

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进行解码

func (*BlockHeader) Encode

func (bh *BlockHeader) Encode() []byte

Encode 对BlockHeader进行编码

func (*BlockHeader) Hash

func (bh *BlockHeader) Hash() []byte

Hash 对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 创建交易 创建后不应进行修改操作, 否则哈希结果出错

func (*Transaction) Encode

func (tx *Transaction) Encode() []byte

Encode 对Transaction进行编码

type TransactionPool

type TransactionPool struct {
	Queue []*Transaction // 交易队列
	// contains filtered or unexported fields
}

TransactionPool 交易池

func NewTransactionPool

func NewTransactionPool() *TransactionPool

NewTransactionPool 创建交易池

func (*TransactionPool) AddTransactionToPool

func (txpool *TransactionPool) AddTransactionToPool(tx *Transaction)

AddTransactionToPool 添加交易

func (*TransactionPool) AddTransactionsToPool

func (txpool *TransactionPool) AddTransactionsToPool(txs []*Transaction)

AddTransactionsToPool 批量添加交易

func (*TransactionPool) ClearQueue

func (txpool *TransactionPool) ClearQueue()

ClearQueue 清空交易池

func (*TransactionPool) Locked

func (txpool *TransactionPool) Locked()

Locked 获取锁

func (*TransactionPool) PackTransactions

func (txpool *TransactionPool) PackTransactions(maxTxs uint64) []*Transaction

PackTransactions 获取交易 maxTxs: 能获取到的最大交易数目, 当前交易池中交易数目小于maxTxs时, 返回全部交易, 否则返回maxTxs个交易

func (*TransactionPool) Size

func (txpool *TransactionPool) Size() int

Size 获取交易池中的交易数目

func (*TransactionPool) Unlocked

func (txpool *TransactionPool) Unlocked()

Unlocked 释放锁

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL