blockchain

package
v0.0.0-...-1abd620 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Description: This file use ethereum's trie to store the state of the blockchain

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTxTreeRoot

func GetTxTreeRoot(txs []structs.Transaction) []byte

To check the Txs integrity of the block

Types

type BlockChain

type BlockChain struct {
	CurrentBlock *structs.Block // the current block

	ChainConfig  *config.ChainConfig // the chain configuration
	Storage      *storage.Storage    // Storage is the bolt-db to store the blocks
	StateManager *StateManager       // the state manager to manage the states of the blockchain
}

func NewBlockChain

func NewBlockChain(cc *config.ChainConfig) (*BlockChain, error)

func (*BlockChain) AddGenesisBlock

func (bc *BlockChain) AddGenesisBlock(b *structs.Block)

add the genisis block in a blockchain

func (*BlockChain) CommitBlock

func (bc *BlockChain) CommitBlock(b *structs.Block)

Consensus done, add the block to storage and commit the states

func (*BlockChain) NewBlock

func (bc *BlockChain) NewBlock(txs []structs.Transaction) *structs.Block

func (*BlockChain) NewGenisisBlock

func (bc *BlockChain) NewGenisisBlock(db ethdb.Database) *structs.Block

type StateManager

type StateManager struct {
	ChainConfig *config.ChainConfig // the chain configuration

	// Used to store the Bitcoin-like UTXO set
	UTXOSet *UTXOSet // the UTXO set of the blockchain

	DirtyState map[string]structs.State // the state which has been updated but not committed
	// contains filtered or unexported fields
}

func NewStateManager

func NewStateManager(cc *config.ChainConfig, db ethdb.Database) (*StateManager, error)

func (*StateManager) CommitStates

func (stm *StateManager) CommitStates(stateRoot []byte) []byte

Consensus Passed, Commit the states

func (*StateManager) UpdateAccountState

func (stm *StateManager) UpdateAccountState(addr string, amount *big.Int, st *trie.Trie, deposit bool)

func (*StateManager) UpdateStates

func (stm *StateManager) UpdateStates(txs []structs.Transaction, stateRoot []byte) bool

Check the txs and update the states to the DirtyState

type UTXOSet

type UTXOSet struct {
}

Jump to

Keyboard shortcuts

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