database

package
v0.0.0-...-2c02b6f Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const BlockReward = 100

Variables

This section is empty.

Functions

func IsBlockHashValid

func IsBlockHashValid(hash Hash) bool

Types

type Account

type Account string

func NewAccount

func NewAccount(value string) Account

type Block

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

func GetBlocksAfter

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

func NewBlock

func NewBlock(parent Hash, number uint64, nonce uint32, time uint64, miner Account, txs []Tx) Block

func (Block) Hash

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

type BlockFS

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

type BlockHeader

type BlockHeader struct {
	Parent Hash    `json:"parent"`
	Number uint64  `json:"number"`
	Nonce  uint32  `json:"nonce"`
	Time   uint64  `json:"time"`
	Miner  Account `json:"miner"`
}

type Hash

type Hash [32]byte

func (Hash) Hex

func (h Hash) Hex() string

func (Hash) IsEmpty

func (h Hash) IsEmpty() bool

func (Hash) MarshalText

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

func (*Hash) UnmarshalText

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

type State

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

func NewStateFromDisk

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

func (*State) AddBlock

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

func (*State) AddBlocks

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

func (*State) Close

func (s *State) Close() error

func (*State) LatestBlock

func (s *State) LatestBlock() Block

func (*State) LatestBlockHash

func (s *State) LatestBlockHash() Hash

func (*State) NextBlockNumber

func (s *State) NextBlockNumber() uint64

type Tx

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

func NewTx

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

func (Tx) Hash

func (t Tx) Hash() (Hash, error)

func (Tx) IsReward

func (t Tx) IsReward() bool

Jump to

Keyboard shortcuts

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