spchainvm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ID = ids.NewID([32]byte{'s', 'p', 'c', 'h', 'a', 'i', 'n', 'v', 'm'})
)

ID this VM should be referenced by

Functions

This section is empty.

Types

type APIAccount

type APIAccount struct {
	Address ids.ShortID `json:"address"`
	Balance json.Uint64 `json:"balance"`
}

APIAccount ...

type Account

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

Account represents the balance and nonce of a user's funds

func (Account) Balance

func (a Account) Balance() uint64

Balance contained in this account

func (Account) CreateTx

func (a Account) CreateTx(amount uint64, destination ids.ShortID, ctx *snow.Context, key *crypto.PrivateKeySECP256K1R) (*Tx, Account, error)

CreateTx creates a transaction from this account that sends [amount] to the address [destination]

func (Account) ID

func (a Account) ID() ids.ShortID

ID of this account

func (Account) Nonce

func (a Account) Nonce() uint64

Nonce this account was last spent with

func (Account) Receive

func (a Account) Receive(tx *Tx, ctx *snow.Context) (Account, error)

Receive generates a new account state from receiving the transaction

func (Account) Send

func (a Account) Send(tx *Tx, ctx *snow.Context) (Account, error)

Send generates a new account state from sending the transaction

func (Account) String

func (a Account) String() string

func (Account) Verify

func (a Account) Verify() error

Verify that this account is well formed

func (Account) VerifyReceive

func (a Account) VerifyReceive(tx *Tx, ctx *snow.Context) error

VerifyReceive returns if the provided transaction can receive this transaction

func (Account) VerifySend

func (a Account) VerifySend(tx *Tx, ctx *snow.Context) error

VerifySend returns if the provided transaction can send this transaction

type Block

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

Block is a group of transactions

func (*Block) Bytes

func (b *Block) Bytes() []byte

Bytes of this transaction

func (*Block) ID

func (b *Block) ID() ids.ID

ID of this operation

func (*Block) ParentID

func (b *Block) ParentID() ids.ID

ParentID of this operation

func (*Block) Txs

func (b *Block) Txs() []*Tx

Txs contained in the operation

type BuildGenesisArgs

type BuildGenesisArgs struct {
	Accounts []APIAccount `json:"accounts"`
}

BuildGenesisArgs are arguments for BuildGenesis

type BuildGenesisReply

type BuildGenesisReply struct {
	Bytes formatting.CB58 `json:"bytes"`
}

BuildGenesisReply is the reply from BuildGenesis

type Builder

type Builder struct {
	NetworkID uint32
	ChainID   ids.ID
}

Builder defines the functionality for building payment objects.

func (Builder) NewAccount

func (b Builder) NewAccount(id ids.ShortID, nonce, balance uint64) Account

NewAccount creates a new Account

func (Builder) NewBlock

func (b Builder) NewBlock(parentID ids.ID, txs []*Tx) (*Block, error)

NewBlock creates a new block

func (Builder) NewTx

func (b Builder) NewTx(key *crypto.PrivateKeySECP256K1R, nonce, amount uint64, destination ids.ShortID) (*Tx, error)

NewTx creates a new transaction from [key|nonce] for [amount] to [destination]

type Codec

type Codec struct{}

Codec is used to serialize and de-serialize transaction objects

func (*Codec) MarshalAccount

func (c *Codec) MarshalAccount(account Account) ([]byte, error)

MarshalAccount returns the byte representation of the account

func (*Codec) MarshalAccounts

func (c *Codec) MarshalAccounts(accounts []Account) ([]byte, error)

MarshalAccounts returns the byte representation of a list of accounts

func (*Codec) MarshalBlock

func (c *Codec) MarshalBlock(block *Block) ([]byte, error)

MarshalBlock returns the byte representation of the block

func (*Codec) MarshalGenesis

func (c *Codec) MarshalGenesis(accounts []Account) ([]byte, error)

MarshalGenesis returns the byte representation of the genesis

func (*Codec) MarshalTx

func (c *Codec) MarshalTx(tx *Tx) ([]byte, error)

MarshalTx returns the byte representation of the tx

func (*Codec) MarshalUnsignedTx

func (c *Codec) MarshalUnsignedTx(tx *Tx) ([]byte, error)

MarshalUnsignedTx returns the byte representation of the unsigned tx

func (*Codec) UnmarshalAccount

func (c *Codec) UnmarshalAccount(b []byte) (Account, error)

UnmarshalAccount attempts to parse an account from a byte array

func (*Codec) UnmarshalAccounts

func (c *Codec) UnmarshalAccounts(b []byte) ([]Account, error)

UnmarshalAccounts attempts to parse a list of accounts from a byte array

func (*Codec) UnmarshalBlock

func (c *Codec) UnmarshalBlock(b []byte) (*Block, error)

UnmarshalBlock attempts to parse an block from a byte array

func (*Codec) UnmarshalGenesis

func (c *Codec) UnmarshalGenesis(b []byte) ([]Account, error)

UnmarshalGenesis attempts to parse the genesis

func (*Codec) UnmarshalTx

func (c *Codec) UnmarshalTx(b []byte) (*Tx, error)

UnmarshalTx attempts to convert the stream of bytes into a representation of a tx

type CodecID

type CodecID uint32

CodecID is an identifier for a codec

const (
	NoID CodecID = iota
	GenericID
	CustomID
)

Codec types

func (CodecID) String

func (c CodecID) String() string

func (CodecID) Verify

func (c CodecID) Verify() error

Verify that the codec is a known codec value. Returns nil if the codec is valid.

type Factory

type Factory struct{}

Factory ...

func (*Factory) New

func (f *Factory) New() (interface{}, error)

New ...

type GetAccountArgs

type GetAccountArgs struct {
	Address ids.ShortID `json:"address"`
}

GetAccountArgs is the arguments for calling GetAccount [Address] is the string repr. of the address we want to know the nonce and balance of

type GetAccountReply

type GetAccountReply struct {
	Balance json.Uint64 `json:"balance"`
	Nonce   json.Uint64 `json:"nonce"`
}

GetAccountReply is the reply from calling GetAccount [nonce] is the nonce of the address specified in the arguments. [balance] is the balance of the address specified in the arguments.

type IssueTxArgs

type IssueTxArgs struct {
	Tx formatting.CB58 `json:"tx"`
}

IssueTxArgs are the arguments for IssueTx. Tx is the string representation of the transaction being issued

type IssueTxReply

type IssueTxReply struct {
	TxID ids.ID `json:"txID"`
}

IssueTxReply is the reply from IssueTx [TxID] is the ID of the issued transaction.

type Keychain

type Keychain struct {

	// Each element is an address controlled by a key in [Keys]
	// This can be used to iterate over. It should not be modified externally.
	Addrs ids.ShortSet

	// List of keys this keychain manages
	// This can be used to iterate over. It should not be modified externally.
	Keys []*crypto.PrivateKeySECP256K1R
	// contains filtered or unexported fields
}

Keychain is a collection of keys that can be used to spend utxos

func NewKeychain

func NewKeychain(networkID uint32, chainID ids.ID) *Keychain

NewKeychain creates a new keychain for a chain

func (*Keychain) Add

func (kc *Keychain) Add(key *crypto.PrivateKeySECP256K1R)

Add a new key to the key chain

func (*Keychain) Addresses

func (kc *Keychain) Addresses() ids.ShortSet

Addresses returns a list of addresses this keychain manages

func (*Keychain) Get

Get a key from the keychain. If the key is unknown, the

func (*Keychain) New

func (kc *Keychain) New() (*crypto.PrivateKeySECP256K1R, error)

New returns a newly generated private key

func (*Keychain) PrefixedString

func (kc *Keychain) PrefixedString(prefix string) string

PrefixedString returns a string representation of this keychain with each line prepended with [prefix]

func (*Keychain) Spend

func (kc *Keychain) Spend(account Account, amount uint64, destination ids.ShortID) (*Tx, Account, error)

Spend attempts to create a new transaction

func (*Keychain) String

func (kc *Keychain) String() string

type LiveBlock

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

LiveBlock implements snow/snowman.Block

func (*LiveBlock) Accept

func (lb *LiveBlock) Accept()

Accept is called when this block is finalized as accepted by consensus

func (*LiveBlock) Bytes

func (lb *LiveBlock) Bytes() []byte

Bytes returns the binary representation of this transaction

func (*LiveBlock) ID

func (lb *LiveBlock) ID() ids.ID

ID returns the blkID

func (*LiveBlock) Parent

func (lb *LiveBlock) Parent() snowman.Block

Parent returns the parent of this block

func (*LiveBlock) Reject

func (lb *LiveBlock) Reject()

Reject is called when this block is finalized as rejected by consensus

func (*LiveBlock) Status

func (lb *LiveBlock) Status() choices.Status

Status returns the current status of this block

func (*LiveBlock) Verify

func (lb *LiveBlock) Verify() error

Verify the validity of this block

func (*LiveBlock) VerifyBlock

func (lb *LiveBlock) VerifyBlock() error

VerifyBlock the validity of this block

func (*LiveBlock) VerifyState

func (lb *LiveBlock) VerifyState() error

VerifyState the validity of this block

type Service

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

Service defines the API exposed by the payments vm

func (*Service) GetAccount

func (service *Service) GetAccount(_ *http.Request, args *GetAccountArgs, reply *GetAccountReply) error

GetAccount gets the nonce and balance of the account specified in [args]

func (*Service) IssueTx

func (service *Service) IssueTx(_ *http.Request, args *IssueTxArgs, reply *IssueTxReply) error

IssueTx issues the transaction specified in [args] to this service

type StaticService

type StaticService struct{}

StaticService defines the static API exposed by the payments vm

func (*StaticService) BuildGenesis

func (*StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, reply *BuildGenesisReply) error

BuildGenesis returns the UTXOs such that at least one address in [args.Addresses] is referenced in the UTXO.

type Tx

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

Tx is a monetary transfer

func (*Tx) Amount

func (tx *Tx) Amount() uint64

Amount is the number of units to transfer to the recipient

func (*Tx) Bytes

func (tx *Tx) Bytes() []byte

Bytes is the byte representation of this transaction

func (*Tx) ID

func (tx *Tx) ID() ids.ID

ID of this transaction

func (*Tx) Key

func (tx *Tx) Key(ctx *snow.Context) crypto.PublicKey

Key returns the public key used to authorize this transaction This function also sets [tx]'s public key

func (*Tx) Nonce

func (tx *Tx) Nonce() uint64

Nonce is the new nonce of the account this transaction is being sent from

func (*Tx) To

func (tx *Tx) To() ids.ShortID

To is the address this transaction is sending to

func (*Tx) Verify

func (tx *Tx) Verify(ctx *snow.Context) error

Verify that this transaction is well formed

type VM

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

VM implements the snowman.ChainVM interface

func (*VM) BuildBlock

func (vm *VM) BuildBlock() (snowman.Block, error)

BuildBlock implements the snowman.ChainVM interface

func (*VM) CreateHandlers

func (vm *VM) CreateHandlers() map[string]*common.HTTPHandler

CreateHandlers makes new service objects with references to the vm

func (*VM) CreateStaticHandlers

func (vm *VM) CreateStaticHandlers() map[string]*common.HTTPHandler

CreateStaticHandlers makes new service objects without references to the vm

func (*VM) FlushTxs

func (vm *VM) FlushTxs()

FlushTxs into consensus

func (*VM) GetAccount

func (vm *VM) GetAccount(db database.Database, address ids.ShortID) Account

GetAccount returns the account with the specified address

func (*VM) GetBlock

func (vm *VM) GetBlock(id ids.ID) (snowman.Block, error)

GetBlock implements the snowman.ChainVM interface

func (*VM) Initialize

func (vm *VM) Initialize(
	ctx *snow.Context,
	db database.Database,
	genesisBytes []byte,
	toEngine chan<- common.Message,
	fxs []*common.Fx,
) error

Initialize implements the snowman.ChainVM interface

func (*VM) IssueTx

func (vm *VM) IssueTx(b []byte, onDecide func(choices.Status)) (ids.ID, error)

IssueTx ... TODO: Remove this

func (*VM) LastAccepted

func (vm *VM) LastAccepted() ids.ID

LastAccepted returns the last accepted block ID

func (*VM) ParseBlock

func (vm *VM) ParseBlock(b []byte) (snowman.Block, error)

ParseBlock implements the snowman.ChainVM interface

func (*VM) SetPreference

func (vm *VM) SetPreference(preferred ids.ID)

SetPreference sets what the current tail of the chain is

func (*VM) Shutdown

func (vm *VM) Shutdown()

Shutdown implements the snowman.ChainVM interface

Jump to

Keyboard shortcuts

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