ledger

package
v0.0.0-...-91a82d4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoGenesis = errors.New("Genesis not found in chain")
)

Common errors.

Functions

func SetupGenesis

func SetupGenesis(genesis *Genesis, chain *Chain) (*params.ChainConfig, state.Database, utils.Hash, error)

SetupGenesis The returned chain configuration is never nil.

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

func NewChain

func NewChain(db db.Database) *Chain

NewChain return Chain store schema

func (*Chain) HasHeader

func (c *Chain) HasHeader(blockHash utils.Hash) bool

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config represents cache config

type Genesis

type Genesis struct {
	Config       *params.ChainConfig `json:"config"`
	Nonce        uint64              `json:"nonce"`
	Timestamp    uint64              `json:"timestamp"`
	ExtraData    []byte              `json:"extraData"`
	GasLimit     uint64              `json:"gasLimit"   `
	Difficulty   *big.Int            `json:"difficulty" `
	Mixhash      utils.Hash          `json:"mixHash"`
	Miner        utils.Address       `json:"miner"`
	Height       uint64              `json:"height"`
	GasUsed      uint64              `json:"gasUsed"`
	PreviousHash utils.Hash          `json:"previousHash"`
	Alloc        GenesisAlloc        `json:"alloc"`
}

Genesis specifies the header fields, state of a genesis block.

func DefaultGenesis

func DefaultGenesis() *Genesis

DefaultGenesis returns the nurans main net genesis block.

func (*Genesis) Commit

func (g *Genesis) Commit(chain *Chain) (*types.Block, state.Database, error)

Commit writes the block and state of a genesis specification to the database.

func (Genesis) MarshalJSON

func (g Genesis) MarshalJSON() ([]byte, error)

func (*Genesis) ToBlock

func (g *Genesis) ToBlock(chain *Chain) (*types.Block, state.Database)

ToBlock creates the genesis block and writes state.

func (*Genesis) UnmarshalJSON

func (g *Genesis) UnmarshalJSON(input []byte) error

type GenesisAccount

type GenesisAccount struct {
	Code    []byte                    `json:"code,omitempty"`
	Storage map[utils.Hash]utils.Hash `json:"storage,omitempty"`
	Balance math.HexOrDecimal256      `json:"balance" gencodec:"required"`
	Nonce   uint64                    `json:"nonce,omitempty"`
}

GenesisAccount is an account in the state of the genesis block.

type GenesisAlloc

type GenesisAlloc map[utils.Address]GenesisAccount

GenesisAlloc specifies the initial state that is part of the genesis block.

type Ledger

type Ledger struct {
	// contains filtered or unexported fields
}

Ledger represents the ledger in blockchain

func New

func New(cachecfg *Config, db db.Database, hasState func(hash utils.Hash) bool) *Ledger

New creates a new ledger.

func (*Ledger) CheckLastBlock

func (l *Ledger) CheckLastBlock(genesis *types.Block) *types.Block

CheckLastBlock check the last block is right or reset chain with genesis block.

func (*Ledger) DeleteBlock

func (l *Ledger) DeleteBlock(blockHash utils.Hash)

func (*Ledger) GetBlock

func (l *Ledger) GetBlock(hash utils.Hash) *types.Block

GetBlock retrieves a block from the database by hash,caching it if found.

func (*Ledger) GetBlockByHash

func (l *Ledger) GetBlockByHash(blockHash utils.Hash) *types.Block

GetBlockByHash retrieves a block from the database by hash, caching it if found.

func (*Ledger) GetBlockByHeight

func (l *Ledger) GetBlockByHeight(height uint64) *types.Block

GetBlockByHeight retrieves a block from the database by height.

func (*Ledger) GetDB

func (l *Ledger) GetDB() db.Database

GetDB get db database

func (*Ledger) GetFutureBlock

func (l *Ledger) GetFutureBlock() types.Blocks

GetFutureBlock get all future from ledger cache .

func (*Ledger) GetHeadBlockHash

func (l *Ledger) GetHeadBlockHash() utils.Hash

GetHeadBlockHash get the last block hash

func (*Ledger) GetHeader

func (l *Ledger) GetHeader(hash utils.Hash) *types.BlockHeader

GetHeader retrieves a header from the database by hash,

func (*Ledger) GetReceipt

func (l *Ledger) GetReceipt(txHash utils.Hash) *types.Receipt

GetReceipt return Receipt by transaction hash.

func (*Ledger) GetReceipts

func (l *Ledger) GetReceipts(blockHash utils.Hash) types.Receipts

GetReceipts return Receipts by block hash.

func (*Ledger) GetTd

func (l *Ledger) GetTd(hash utils.Hash) *big.Int

GetTd retrieves a block from the database by hash,caching it if found.

func (*Ledger) GetTransactionByHash

func (l *Ledger) GetTransactionByHash(txHash utils.Hash) *types.StorageTx

GetTransactionByHash retrieves a transaction from the database by hash, caching it if found.

func (*Ledger) HasBlock

func (l *Ledger) HasBlock(hash utils.Hash) bool

HasBlock checks if a block is fully present in the database or not.

func (*Ledger) HasFutureBlock

func (l *Ledger) HasFutureBlock(hash utils.Hash) bool

HasFutureBlock checks if a future block in cache.

func (*Ledger) HasHeader

func (l *Ledger) HasHeader(hash utils.Hash, height uint64) bool

HasHeader checks if a block header is present in the database or not.

func (*Ledger) HasState

func (l *Ledger) HasState(hash utils.Hash) bool

HasState checks if state trie is fully present in the database or not.

func (*Ledger) PutFutureBlock

func (l *Ledger) PutFutureBlock(block *types.Block) error

PutFutureBlock put a block in future cache

func (*Ledger) RemoveFutureBlock

func (l *Ledger) RemoveFutureBlock(hash utils.Hash)

RemoveFutureBlock remove future block by hash

func (*Ledger) ResetChain

func (l *Ledger) ResetChain(genesis *types.Block)

ResetChain reset chain with genesis block

func (*Ledger) RewindChain

func (l *Ledger) RewindChain(height uint64)

RewindChain rewind the chain, deleting all block

func (*Ledger) WriteBlockAndReceipts

func (l *Ledger) WriteBlockAndReceipts(block *types.Block, receipts types.Receipts)

func (*Ledger) WriteBlockAndTd

func (l *Ledger) WriteBlockAndTd(block *types.Block, td *big.Int)

WriteBlockAndTd serializes a block and td into the database, header and txs separately.

func (*Ledger) WriteLegitimateHashAndHeadBlockHash

func (l *Ledger) WriteLegitimateHashAndHeadBlockHash(height uint64, hash utils.Hash)

WriteLegitimateHashAndHeadBlockHash write the Legitimate chain

func (*Ledger) WriteTd

func (l *Ledger) WriteTd(hash utils.Hash, td *big.Int)

WriteTd stores a block's total difficulty into the database, also caching it along the way.

Jump to

Keyboard shortcuts

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