models

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

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

Go to latest
Published: Jul 25, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OTHER       Reason = ""
	SELF_REWARD        = "self-reward"
	BIRTHDAY           = "birthday"
	LOAN               = "loan"
)

Variables

View Source
var (
	ErrInsufficientBalance = errors.New("insufficient balance")
	ErrNextBlockHeight     = errors.New("latest block height doesn't match with next block (height + 1)")
	ErrNextBlockHash       = errors.New("latest block hash doesn't match with next block")
)

Functions

func CompareBlockHash

func CompareBlockHash(h1 Hash, h2 Hash) bool

Types

type Account

type Account string

func NewAccount

func NewAccount(account string) (Account, error)

type Block

type Block struct {
	Header BlockHeader   `json:"header"`
	Txs    []Transaction `json:"transactions"`
}

func NewBlock

func NewBlock(parent Hash, height uint64, nonce uint32, time uint64, txs []Transaction) Block

func (Block) Hash

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

type BlockDB

type BlockDB struct {
	Hash  Hash  `json:"hash"`
	Block Block `json:"block"`
}

type BlockHeader

type BlockHeader struct {
	Parent Hash   `json:"parent"`
	Height uint64 `json:"height"`
	Nonce  uint32 `json:"nonce"`
	Time   uint64 `json:"time"`
}

type FromFileState

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

func NewStateFromFile

func NewStateFromFile(genesisFilePath string, transactionFilePath string) (*FromFileState, error)

func (*FromFileState) Add

func (s *FromFileState) Add(tx Transaction) error

func (*FromFileState) AddBlock

func (s *FromFileState) AddBlock(block Block) error

func (*FromFileState) AddBlocks

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

func (*FromFileState) Balances

func (s *FromFileState) Balances() map[Account]uint

func (*FromFileState) Close

func (s *FromFileState) Close() error

func (*FromFileState) GetLatestBlockHash

func (s *FromFileState) GetLatestBlockHash() Hash

func (*FromFileState) GetLatestBlockHeight

func (s *FromFileState) GetLatestBlockHeight() uint64

func (*FromFileState) Persist

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

func (*FromFileState) Print

func (s *FromFileState) Print()

type GenesisFile

type GenesisFile struct {
	Time     time.Time       `json:"genesis_time"`
	ChainId  string          `json:"chain_id"`
	Balances map[string]uint `json:"balances"`
}

type Hash

type Hash [32]byte

func (Hash) Hex

func (h Hash) Hex() string

func (Hash) MarshalText

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

func (*Hash) UnmarshalText

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

type PendingBlock

type PendingBlock struct {
	Parent       Hash
	Height       uint64
	Time         uint64
	MinerAddress Account
	Txs          []Transaction
}

func NewPendingBlock

func NewPendingBlock(parent Hash, height uint64, minerAddress Account, time uint64, txs []Transaction) PendingBlock

type Reason

type Reason string

Reason transaction reason

func (Reason) IsValid

func (s Reason) IsValid() bool

type State

type State interface {
	// Add adds a transaction
	Add(Transaction) error
	// AddBlock to the state
	AddBlock(Block) error
	// AddBlocks to the state
	AddBlocks([]Block) error
	// Balances return the balances as map
	Balances() map[Account]uint
	Persist() (Hash, error)
	Close() error
	GetLatestBlockHash() Hash
	GetLatestBlockHeight() uint64
	Print()
}

type Transaction

type Transaction struct {
	From   Account `json:"from"`
	To     Account `json:"to"`
	Value  uint    `json:"value"`
	Reason string  `json:"reason"`
	Time   uint64  `json:"time"`
}

func NewTransaction

func NewTransaction(from Account, to Account, value uint, reason string, time uint64) *Transaction

func (Transaction) Hash

func (t Transaction) Hash() (TransactionId, error)

type TransactionId

type TransactionId Hash

Transaction

type User

type User struct {
	Hash string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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