database

package
v0.0.0-...-d801d5e Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account string

Account represents a user address or customer

func NewAccount

func NewAccount(value string) Account

NewAccount takes in a value and returns a new Account type

type Block

type Block struct {
	Header BlockHeader `json:"header"`
	TXs    []Tx        `json:"payload"`
}

Block for a batch of transactions

func GetBlocksAfter

func GetBlocksAfter(blockHash Hash, dataDir string) ([]Block, error)

GetBlocksAfter syncs with all blocks after a specified Hash

func NewBlock

func NewBlock(parent Hash, number uint64, time uint64, txs []Tx) Block

NewBlock creates and returns a Block

func (Block) Hash

func (b Block) Hash() (Hash, error)

Hash creates the Hash for each individual Block

type BlockFS

type BlockFS struct {
	Key   Hash  `json:"hash"`
	Value Block `json:"block"`
}

BlockFS is ...

type BlockHeader

type BlockHeader struct {
	Parent Hash   `json:"parent"`
	Number uint64 `json:"number"`
	Time   uint64 `json:"time"`
}

BlockHeader is meta data for Blocks

type Hash

type Hash [32]byte

Hash replaces the Snapshot type

func (Hash) Hex

func (h Hash) Hex() string

Hex returns the hash encoded as a string

func (Hash) IsEmpty

func (h Hash) IsEmpty() bool

IsEmpty checks weather a has is empty

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText encodes a has into a hex value

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(data []byte) error

UnmarshalText decodes hex into a string

type State

type State struct {
	Balances map[Account]uint
	// contains filtered or unexported fields
}

State encapsulates all the business logic of the chain

func NewStateFromDisk

func NewStateFromDisk(dataDir string) (*State, error)

NewStateFromDisk creates State with a genesis file

func (*State) AddBlock

func (s *State) AddBlock(b Block) (Hash, error)

AddBlock adds a new Block to the db chain

func (*State) AddBlocks

func (s *State) AddBlocks(blocks []Block) error

AddBlocks iterates over a slice of Block types and adds them to state

func (*State) Close

func (s *State) Close() error

Close the dbfile that State uses for mempool

func (*State) LatestBlock

func (s *State) LatestBlock() Block

LatestBlock returns the most recent block created

func (*State) LatestBlockHash

func (s *State) LatestBlockHash() Hash

LatestBlockHash return the most recent block hash

func (*State) NextBlockNumber

func (s *State) NextBlockNumber() uint64

NextBlockNumber return the block number from the state

type Tx

type Tx struct {
	From  Account `json:"from"`
	To    Account `json:"to"`
	Value uint    `json:"value"`
	Data  string  `json:"data"`
}

Tx is a transaction

func NewTx

func NewTx(from Account, to Account, value uint, data string) Tx

NewTx creates a new transaction

func (Tx) IsReward

func (t Tx) IsReward() bool

IsReward checks if the transaction has an awarded bonus

Jump to

Keyboard shortcuts

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