chain

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: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 账户的初始余额
	InitBalance, _ = new(big.Int).SetString("100000000000000000000000000000000000000000000", 10)
)

Functions

func GetTxTreeRoot

func GetTxTreeRoot(txs []*base.Transaction) []byte

GetTxTreeRoot 获取交易根,这个根可以用来检查区块中的交易 新建一个空的 mpt, 插入所有 transactions 并计算 root hash

Types

type BlockChain

type BlockChain struct {
	Config          *Config                   // 区块链配置
	CurrentBlock    *base.Block               // 最新的区块
	BlockStorage    blockStorage.BlockStorage // 区块持久化
	StateStorage    stateStorage.StateStorage // 状态树持久化
	Trie            *mpt.Trie                 // 状态树
	TransactionPool *base.TransactionPool     // 交易池
}

BlockChain 区块链

func NewBlockChain

func NewBlockChain(conf *Config, stateDB stateStorage.StateStorage, blockDB blockStorage.BlockStorage) (*BlockChain, error)

NewBlockChain 创建区块链

func (*BlockChain) AddAccounts

func (bc *BlockChain) AddAccounts(ac []string, as []*base.AccountState)

AddAccounts 新建账户

func (*BlockChain) AddBlock

func (bc *BlockChain) AddBlock(b *base.Block)

AddBlock 添加一个区块

func (*BlockChain) AddGenisisBlock

func (bc *BlockChain) AddGenisisBlock(gb *base.Block)

AddGenisisBlock 将创世区块加入区块链

func (*BlockChain) CloseBlockChain

func (bc *BlockChain) CloseBlockChain()

CloseBlockChain 关闭区块链, 释放资源

func (*BlockChain) FetchAccounts

func (bc *BlockChain) FetchAccounts(addrs []string) []*base.AccountState

FetchAccounts 获取账户信息

func (*BlockChain) GenerateBlock

func (bc *BlockChain) GenerateBlock() *base.Block

GenerateBlock 生成一个区块

func (*BlockChain) GetUpdateStatusTrie

func (bc *BlockChain) GetUpdateStatusTrie(txs []*base.Transaction) []byte

GetUpdateStatusTrie 处理交易并更新状态树, 返回更新后的状态树根

func (*BlockChain) IsValidBlock

func (bc *BlockChain) IsValidBlock(b *base.Block) error

IsValidBlock 验证区块能否合法地上链

func (*BlockChain) NewGenisisBlock

func (bc *BlockChain) NewGenisisBlock() *base.Block

NewGenisisBlock 生成创世区块, 每条区块链只会有一个创世区块

func (*BlockChain) SendTransactionsPool

func (bc *BlockChain) SendTransactionsPool(txs []*base.Transaction)

SendTransactionsPool 将交易批量放入交易池

type Config

type Config struct {
	NodeID    uint64
	BlockSize uint64
	NodesNum  uint64
}

Config 区块链配置

Jump to

Keyboard shortcuts

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