core

package
v0.0.0-...-a6ba2ba Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound     = errors.New("account not found")
	ErrInsufficientBalance = errors.New("insufficient account balance")
)
View Source
var ErrBlockKnown = errors.New("block already known")

Functions

func CalculateDataHash

func CalculateDataHash(txx []*Transaction) (hash types.Hash, err error)

Types

type Account

type Account struct {
	Address types.Address
	Balance uint64
}

func (*Account) String

func (a *Account) String() string

type AccountState

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

func NewAccountState

func NewAccountState() *AccountState

func (*AccountState) CreateAccount

func (s *AccountState) CreateAccount(address types.Address) *Account

func (*AccountState) GetAccount

func (s *AccountState) GetAccount(address types.Address) (*Account, error)

func (*AccountState) GetBalance

func (s *AccountState) GetBalance(address types.Address) (uint64, error)

func (*AccountState) Transfer

func (s *AccountState) Transfer(from, to types.Address, amount uint64) error

type Block

type Block struct {
	*Header

	Transactions []*Transaction
	Validator    crypto.PublicKey
	Signature    *crypto.Signature
	// contains filtered or unexported fields
}

func NewBlock

func NewBlock(h *Header, txx []*Transaction) (*Block, error)

func NewBlockFromPrevHeader

func NewBlockFromPrevHeader(prevHeader *Header, txx []*Transaction) (*Block, error)

func (*Block) AddTransaction

func (b *Block) AddTransaction(tx *Transaction)

func (*Block) Decode

func (b *Block) Decode(dec Decoder[*Block]) error

func (*Block) Encode

func (b *Block) Encode(enc Encoder[*Block]) error

func (*Block) Hash

func (b *Block) Hash(hasher Hasher[*Header]) types.Hash

func (*Block) Sign

func (b *Block) Sign(privKey crypto.PrivateKey) error

func (*Block) Verify

func (b *Block) Verify() error

type BlockHasher

type BlockHasher struct{}

func (BlockHasher) Hash

func (BlockHasher) Hash(b *Header) types.Hash

type BlockValidator

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

func NewBlockValidator

func NewBlockValidator(bc *Blockchain) *BlockValidator

func (*BlockValidator) ValidateBlock

func (v *BlockValidator) ValidateBlock(b *Block) error

type Blockchain

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

func NewBlockchain

func NewBlockchain(l log.Logger, genesis *Block) (*Blockchain, error)

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(b *Block) error

func (*Blockchain) GetBlock

func (bc *Blockchain) GetBlock(height uint32) (*Block, error)

func (*Blockchain) GetBlockByHash

func (bc *Blockchain) GetBlockByHash(hash types.Hash) (*Block, error)

func (*Blockchain) GetHeader

func (bc *Blockchain) GetHeader(height uint32) (*Header, error)

func (*Blockchain) GetTxByHash

func (bc *Blockchain) GetTxByHash(hash types.Hash) (*Transaction, error)

func (*Blockchain) HasBlock

func (bc *Blockchain) HasBlock(height uint32) bool

func (*Blockchain) Height

func (bc *Blockchain) Height() uint32

[0, 1, 2 ,3] => 4 len [0, 1, 2 ,3] => 3 height

func (*Blockchain) SetValidator

func (bc *Blockchain) SetValidator(v Validator)

type CollectionTx

type CollectionTx struct {
	Fee      int64
	MetaData []byte
}

type Decoder

type Decoder[T any] interface {
	Decode(T) error
}

type Encoder

type Encoder[T any] interface {
	Encode(T) error
}

type GobBlockDecoder

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

func NewGobBlockDecoder

func NewGobBlockDecoder(r io.Reader) *GobBlockDecoder

func (*GobBlockDecoder) Decode

func (dec *GobBlockDecoder) Decode(b *Block) error

type GobBlockEncoder

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

func NewGobBlockEncoder

func NewGobBlockEncoder(w io.Writer) *GobBlockEncoder

func (*GobBlockEncoder) Encode

func (enc *GobBlockEncoder) Encode(b *Block) error

type GobTxDecoder

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

func NewGobTxDecoder

func NewGobTxDecoder(r io.Reader) *GobTxDecoder

func (*GobTxDecoder) Decode

func (e *GobTxDecoder) Decode(tx *Transaction) error

type GobTxEncoder

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

func NewGobTxEncoder

func NewGobTxEncoder(w io.Writer) *GobTxEncoder

func (*GobTxEncoder) Encode

func (e *GobTxEncoder) Encode(tx *Transaction) error

type Hasher

type Hasher[T any] interface {
	Hash(T) types.Hash
}
type Header struct {
	Version       uint32
	DataHash      types.Hash
	PrevBlockHash types.Hash
	Height        uint32
	Timestamp     int64
}

func (*Header) Bytes

func (h *Header) Bytes() []byte

type Instruction

type Instruction byte
const (
	InstrPushInt  Instruction = 0x0a // 10
	InstrAdd      Instruction = 0x0b // 11
	InstrPushByte Instruction = 0x0c
	InstrPack     Instruction = 0x0d
	InstrSub      Instruction = 0x0e
	InstrStore    Instruction = 0x0f
)

type MemoryStore

type MemoryStore struct {
}

func NewMemorystore

func NewMemorystore() *MemoryStore

func (*MemoryStore) Put

func (s *MemoryStore) Put(b *Block) error

type MintTx

type MintTx struct {
	Fee             int64
	NFT             types.Hash
	Collection      types.Hash
	MetaData        []byte
	CollectionOwner crypto.PublicKey
	Signature       crypto.Signature
}

type Stack

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

func NewStack

func NewStack(size int) *Stack

func (*Stack) Pop

func (s *Stack) Pop() any

func (*Stack) Push

func (s *Stack) Push(v any)

type State

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

func NewState

func NewState() *State

func (*State) Delete

func (s *State) Delete(k []byte) error

func (*State) Get

func (s *State) Get(k []byte) ([]byte, error)

func (*State) Put

func (s *State) Put(k, v []byte) error

type Storage

type Storage interface {
	Put(*Block) error
}

type Transaction

type Transaction struct {
	// Only used for native NFT logic
	TxInner any
	// Any arbitrary data for the VM
	Data      []byte
	To        crypto.PublicKey
	Value     uint64
	From      crypto.PublicKey
	Signature *crypto.Signature
	Nonce     int64
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(data []byte) *Transaction

func (*Transaction) Decode

func (tx *Transaction) Decode(dec Decoder[*Transaction]) error

func (*Transaction) Encode

func (tx *Transaction) Encode(enc Encoder[*Transaction]) error

func (*Transaction) Hash

func (tx *Transaction) Hash(hasher Hasher[*Transaction]) types.Hash

func (*Transaction) Sign

func (tx *Transaction) Sign(privKey crypto.PrivateKey) error

func (*Transaction) Verify

func (tx *Transaction) Verify() error

type TxHasher

type TxHasher struct{}

func (TxHasher) Hash

func (TxHasher) Hash(tx *Transaction) types.Hash

Hash will hash the whole bytes of the TX no exception.

type TxType

type TxType byte
const (
	TxTypeCollection TxType = iota // 0x0
	TxTypeMint                     // 0x01
)

type VM

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

func NewVM

func NewVM(data []byte, contractState *State) *VM

func (*VM) Exec

func (vm *VM) Exec(instr Instruction) error

func (*VM) Run

func (vm *VM) Run() error

type Validator

type Validator interface {
	ValidateBlock(*Block) error
}

Jump to

Keyboard shortcuts

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