database

package
v0.0.0-...-ff0fddd Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 9 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

func NewAccount

func NewAccount(value string) Account

type Block

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

func NewBlock

func NewBlock(parent Hash, time uint64, 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"`
	Time   uint64 `json:"time"`
}

type Hash

type Hash [32]byte

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
}

State used to control the state of the chain

func NewStateFromDisk

func NewStateFromDisk() (*State, error)

NewStateFromDisk -> load all state information

func (*State) AddBlock

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

AddBlock add transaction to the block

func (*State) AddTx

func (s *State) AddTx(tx Tx) error

Add -> add new tx to mempool

func (*State) Close

func (s *State) Close()

Close -> close file overwrite for State

func (*State) LatestBlockHash

func (s *State) LatestBlockHash() Hash

LatestBlockHash -> get the last snapshot of tx.db transactions

func (*State) Persist

func (s *State) Persist() (Hash, error)

Persist -> persist transactions into tx file

type Tx

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

func NewTx

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

NewTx -> return a new Tx

func (Tx) IsReward

func (t Tx) IsReward() bool

IsReward -> check if Data field is eq to reward

Jump to

Keyboard shortcuts

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