chainutil

package
v0.0.0-...-9bc7f68 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindBlockNonce

func FindBlockNonce(h *types.BlockHeader, target types.BlockID)

FindBlockNonce finds a block nonce meeting the target.

func JustChainIndexes

func JustChainIndexes(blocks []types.Block) []types.ChainIndex

JustChainIndexes returns only the chain index of each block.

func JustHeaders

func JustHeaders(blocks []types.Block) []types.BlockHeader

JustHeaders renters only the headers of each block.

func JustTransactionIDs

func JustTransactionIDs(blocks []types.Block) [][]types.TransactionID

JustTransactionIDs returns only the transaction ids included in each block.

func JustTransactions

func JustTransactions(blocks []types.Block) [][]types.Transaction

JustTransactions returns only the transactions of each block.

Types

type ChainSim

type ChainSim struct {
	Genesis consensus.Checkpoint
	Chain   []types.Block
	State   consensus.State
	// contains filtered or unexported fields
}

ChainSim represents a simulation of a blockchain.

func NewChainSim

func NewChainSim() *ChainSim

NewChainSim returns a new ChainSim useful for simulating forks.

func (*ChainSim) Fork

func (cs *ChainSim) Fork() *ChainSim

Fork forks the current chain.

func (*ChainSim) MineBlock

func (cs *ChainSim) MineBlock() types.Block

MineBlock mine an empty block.

func (*ChainSim) MineBlockWithSiacoinOutputs

func (cs *ChainSim) MineBlockWithSiacoinOutputs(scos ...types.SiacoinOutput) types.Block

MineBlockWithSiacoinOutputs mines a block with a transaction containing the specified siacoin outputs. The ChainSim must have funds equal to or exceeding the sum of the outputs.

func (*ChainSim) MineBlockWithTxns

func (cs *ChainSim) MineBlockWithTxns(txns ...types.Transaction) types.Block

MineBlockWithTxns mine a block with the given transaction.

func (*ChainSim) MineBlocks

func (cs *ChainSim) MineBlocks(n int) []types.Block

MineBlocks mine a number of blocks.

func (*ChainSim) TxnWithSiacoinOutputs

func (cs *ChainSim) TxnWithSiacoinOutputs(scos ...types.SiacoinOutput) types.Transaction

TxnWithSiacoinOutputs returns a transaction containing the specified outputs. The ChainSim must have funds equal to or exceeding the sum of the outputs.

type EphemeralStore

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

EphemeralStore implements chain.ManagerStore in memory.

func NewEphemeralStore

func NewEphemeralStore(c consensus.Checkpoint) *EphemeralStore

NewEphemeralStore returns an in-memory chain.ManagerStore.

func (*EphemeralStore) AddCheckpoint

func (es *EphemeralStore) AddCheckpoint(c consensus.Checkpoint) error

AddCheckpoint implements chain.ManagerStore.

func (*EphemeralStore) BestIndex

func (es *EphemeralStore) BestIndex(height uint64) (types.ChainIndex, error)

BestIndex implements chain.ManagerStore.

func (*EphemeralStore) Checkpoint

func (es *EphemeralStore) Checkpoint(index types.ChainIndex) (consensus.Checkpoint, error)

Checkpoint implements chain.ManagerStore.

func (*EphemeralStore) Close

func (es *EphemeralStore) Close() error

Close implements chain.ManagerStore.

func (*EphemeralStore) ExtendBest

func (es *EphemeralStore) ExtendBest(index types.ChainIndex) error

ExtendBest implements chain.ManagerStore.

func (*EphemeralStore) Flush

func (es *EphemeralStore) Flush() error

Flush implements chain.ManagerStore.

func (*EphemeralStore) Header

func (es *EphemeralStore) Header(index types.ChainIndex) (types.BlockHeader, error)

Header implements chain.ManagerStore.

func (*EphemeralStore) RewindBest

func (es *EphemeralStore) RewindBest() error

RewindBest implements chain.ManagerStore.

type FlatStore

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

FlatStore implements chain.ManagerStore with persistent files.

func NewFlatStore

func NewFlatStore(dir string, c consensus.Checkpoint) (*FlatStore, consensus.Checkpoint, error)

NewFlatStore returns a FlatStore that stores data in the specified dir.

func (*FlatStore) AddCheckpoint

func (fs *FlatStore) AddCheckpoint(c consensus.Checkpoint) error

AddCheckpoint implements chain.ManagerStore.

func (*FlatStore) BestIndex

func (fs *FlatStore) BestIndex(height uint64) (index types.ChainIndex, err error)

BestIndex implements chain.ManagerStore.

func (*FlatStore) Checkpoint

func (fs *FlatStore) Checkpoint(index types.ChainIndex) (c consensus.Checkpoint, err error)

Checkpoint implements chain.ManagerStore.

func (*FlatStore) Close

func (fs *FlatStore) Close() (err error)

Close closes the store.

func (*FlatStore) ExtendBest

func (fs *FlatStore) ExtendBest(index types.ChainIndex) error

ExtendBest implements chain.ManagerStore.

func (*FlatStore) Flush

func (fs *FlatStore) Flush() error

Flush implements chain.ManagerStore.

func (*FlatStore) Header

func (fs *FlatStore) Header(index types.ChainIndex) (types.BlockHeader, error)

Header implements chain.ManagerStore.

func (*FlatStore) RewindBest

func (fs *FlatStore) RewindBest() error

RewindBest implements chain.ManagerStore.

Jump to

Keyboard shortcuts

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