database

package
v0.0.0-...-86708c2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const BlockReward = 100
View Source
const TxFee = uint(50)

Variables

This section is empty.

Functions

func ApplyTx

func ApplyTx(tx SignedTx, s *State) error

func InitDataDirIfNotExists

func InitDataDirIfNotExists(dataDir string, genesis []byte) error

func IsBlockHashValid

func IsBlockHashValid(hash Hash) bool

func NewAccount

func NewAccount(value string) common.Address

func ValidateTx

func ValidateTx(tx SignedTx, s *State) error

Types

type Block

type Block struct {
	Header BlockHeader `json:"header"`
	TXs    []SignedTx  `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 common.Address, txs []SignedTx) 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  common.Address `json:"miner"`
}

type Genesis

type Genesis struct {
	Balances map[common.Address]uint `json:"balances"`
}

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 SignedTx

type SignedTx struct {
	Tx
	Sig []byte `json:"signature"`
}

func NewSignedTx

func NewSignedTx(tx Tx, sig []byte) SignedTx

func (SignedTx) Hash

func (t SignedTx) Hash() (Hash, error)

func (SignedTx) IsAuthentic

func (t SignedTx) IsAuthentic() (bool, error)

type State

type State struct {
	Balances      map[common.Address]uint
	Account2Nonce map[common.Address]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) Copy

func (s *State) Copy() State

func (*State) GetNextAccountNonce

func (s *State) GetNextAccountNonce(account common.Address) uint

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  common.Address `json:"from"`
	To    common.Address `json:"to"`
	Value uint           `json:"value"`
	Nonce uint           `json:"nonce"`
	Data  string         `json:"data"`
	Time  uint64         `json:"time"`
}

func NewTx

func NewTx(from, to common.Address, value, nonce uint, data string) Tx

func (Tx) Cost

func (t Tx) Cost() uint

func (Tx) Encode

func (t Tx) Encode() ([]byte, error)

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