spdagvm

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutputPaymentID uint32 = iota
	OutputTakeOrLeaveID
)

Output types

View Source
const (
	InputID uint32 = iota
)

Input types

View Source
const MaxSize = 1 << 18

MaxSize is the maximum allowed tx size. It is necessary to deter DoS.

Variables

View Source
var (
	ID = ids.NewID([32]byte{'s', 'p', 'd', 'a', 'g', 'v', 'm'})
)

ID this VM should be referenced with

Functions

func SortIns

func SortIns(ins []Input, signers []*InputSigner)

SortIns sorts the tx input list by inputID | inputIndex

func SortOuts

func SortOuts(outs []Output)

SortOuts sorts the tx output list by byte representation

func SortTxSig

func SortTxSig(sigs []*Sig)

SortTxSig sorts the tx signature list by index

Types

type APIOutput

type APIOutput struct {
	Amount     json.Uint64   `json:"amount"`
	Locktime   json.Uint64   `json:"locktime"`
	Threshold  json.Uint32   `json:"threshold"`
	Addresses  []ids.ShortID `json:"addresses"`
	Locktime2  json.Uint64   `json:"locktime2"`
	Threshold2 json.Uint32   `json:"threshold2"`
	Addresses2 []ids.ShortID `json:"addresses2"`
}

APIOutput ...

type BuildGenesisArgs

type BuildGenesisArgs struct {
	Outputs []APIOutput `json:"outputs"`
}

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) NewInputPayment

func (b Builder) NewInputPayment(sourceID ids.ID, sourceIndex uint32, amount uint64, sigs []*Sig) Input

NewInputPayment returns a new input that consumes a UTXO.

func (Builder) NewOutputPayment

func (b Builder) NewOutputPayment(
	amount,
	locktime uint64,
	threshold uint32,
	addresses []ids.ShortID,
) Output

NewOutputPayment returns a new output that generates a standard UTXO.

func (Builder) NewOutputTakeOrLeave

func (b Builder) NewOutputTakeOrLeave(
	amount,
	locktime1 uint64,
	threshold1 uint32,
	addresses1 []ids.ShortID,
	locktime2 uint64,
	threshold2 uint32,
	addresses2 []ids.ShortID,
) Output

NewOutputTakeOrLeave returns a new output that generates a UTXO with all the features of the standard UTXO, plus the ability to have a different set of addresses spend the asset after the specified time.

func (Builder) NewSig

func (b Builder) NewSig(index uint32) *Sig

NewSig returns a new signature object. This object will specify the address in the UTXO that will be used to authorize the wrapping input.

func (Builder) NewTx

func (b Builder) NewTx(ins []Input, outs []Output, signers []*InputSigner) (*Tx, error)

NewTx returns a new transaction where:

  • The inputs to the Tx are [ins], sorted.
  • The outputs of the Tx are [outs], sorted
  • The ith signer will be used to sign the ith input. This means that len([inputs]) must be == len([signers]).

TODO: Should the signer be part of the input

func (Builder) NewTxFromUTXOs

func (b Builder) NewTxFromUTXOs(keychain *Keychain, utxos []*UTXO, amount, txFee, locktime uint64,
	threshold uint32, toAddrs []ids.ShortID, changeAddr ids.ShortID, currentTime uint64) (*Tx, error)

NewTxFromUTXOs returns a new transaction where:

  • One of the outputs is an Output with [amount] avax that is controlled by [toAddr].
  • This output can't be spent until at least [locktime].
  • If there is any "change" there is another output controlled by [changeAddr] with the change.
  • The UTXOs consumed to make this transaction are a subset of [utxos].
  • The keys controlling [utxos] are in [keychain]

type Codec

type Codec struct{}

Codec is used to serialize and de-serialize transaction objects

func (*Codec) MarshalOutput

func (c *Codec) MarshalOutput(out Output) ([]byte, error)

MarshalOutput returns the byte representation of the output

func (*Codec) MarshalTx

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

MarshalTx returns the byte representation of the tx

func (*Codec) MarshalUTXO

func (c *Codec) MarshalUTXO(utxo *UTXO) ([]byte, error)

MarshalUTXO returns the byte representation of the utxo

func (*Codec) MarshalUTXOs

func (c *Codec) MarshalUTXOs(utxos []*UTXO) ([]byte, error)

MarshalUTXOs returns the byte representation of the utxos

func (*Codec) MarshalUnsignedTx

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

MarshalUnsignedTx returns the byte representation of the unsigned tx

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

func (*Codec) UnmarshalUTXO

func (c *Codec) UnmarshalUTXO(b []byte) (*UTXO, error)

UnmarshalUTXO attempts to convert the stream of bytes into a representation of an utxo

func (*Codec) UnmarshalUTXOs

func (c *Codec) UnmarshalUTXOs(b []byte) ([]*UTXO, error)

UnmarshalUTXOs attempts to convert the stream of bytes into a representation of a slice of utxos

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{ TxFee uint64 }

Factory ...

func (*Factory) New

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

New ...

type GetTxStatusArgs

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

GetTxStatusArgs are arguments for GetTxStatus

type GetTxStatusReply

type GetTxStatusReply struct {
	// Status of the returned transaction
	Status choices.Status `json:"status"`
}

GetTxStatusReply is the reply from GetTxStatus

type GetUTXOsArgs

type GetUTXOsArgs struct {
	Addresses []ids.ShortID `json:"addresses"`
}

GetUTXOsArgs are arguments for GetUTXOs

type GetUTXOsReply

type GetUTXOsReply struct {
	// Each element is the string repr. of an unspent UTXO that
	// references an address in the arguments
	UTXOs []formatting.CB58 `json:"utxos"`
}

GetUTXOsReply is the reply from GetUTXOs

type Input

type Input interface {
	formatting.PrefixedStringer

	InputSource() (ids.ID, uint32)
	InputID() ids.ID

	Verify() error
}

Input describes the interface all inputs must implement

type InputPayment

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

InputPayment is an input that consumes an output InputPayment implements Input

func (*InputPayment) Amount

func (in *InputPayment) Amount() uint64

Amount this input will produce for the tx

func (*InputPayment) InputID

func (in *InputPayment) InputID() ids.ID

InputID returns the ID of the UTXO this input consumes

func (*InputPayment) InputSource

func (in *InputPayment) InputSource() (ids.ID, uint32)

InputSource returns: 1) The ID of the transaction that produced the UTXO this input consumes 2) The index within that transaction of the UTXO this input consumes

func (*InputPayment) PrefixedString

func (in *InputPayment) PrefixedString(prefix string) string

PrefixedString converts this input to a string representation with a prefix for each newline

func (*InputPayment) String

func (in *InputPayment) String() string

func (*InputPayment) Verify

func (in *InputPayment) Verify() error

Verify this input is syntactically valid

type InputSigner

type InputSigner struct {
	Keys []*crypto.PrivateKeySECP256K1R
}

InputSigner stores the keys used to sign an input

type IssueTxArgs

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

IssueTxArgs are arguments for passing into IssueTx requests

type IssueTxReply

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

IssueTxReply defines the IssueTx replies returned from the API

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. If [key] is already in the keychain, does nothing.

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 second return value is false.

func (*Keychain) GetSigsAndKeys

func (kc *Keychain) GetSigsAndKeys(addresses []ids.ShortID, threshold int) ([]*Sig, []*crypto.PrivateKeySECP256K1R, bool)

GetSigsAndKeys returns:

  1. A list of *Sig where Sig.Index is the index of an address in [addresses] such that a key in this keychain that controls the address
  2. A list of private keys such that each key controls an address in [addresses]
  3. true iff this keychain contains at least [threshold] keys that control an address in [addresses]

func (*Keychain) New

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

New returns a newly generated private key. The key and the address it controls are added to [kc.Keys] and [kc.Addrs], respectively

func (*Keychain) PrefixedString

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

PrefixedString returns the key chain as a string representation with [prefix] added before every line.

func (*Keychain) Spend

func (kc *Keychain) Spend(utxo *UTXO, time uint64) (Input, *InputSigner, error)

Spend attempts to create an input

func (*Keychain) String

func (kc *Keychain) String() string

type Output

type Output interface {
	formatting.PrefixedStringer

	Unlock(Input, uint64) error
	Verify() error
}

Output describes what functions every output must implement

type OutputPayment

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

OutputPayment represents an output that transfers value OutputPayment implements Output

func (*OutputPayment) Addresses

func (op *OutputPayment) Addresses() []ids.ShortID

Addresses are the representations of keys that can produce signatures to spend this output

func (*OutputPayment) Amount

func (op *OutputPayment) Amount() uint64

Amount of value this output creates

func (*OutputPayment) Locktime

func (op *OutputPayment) Locktime() uint64

Locktime is the time that this output should be able to be spent

func (*OutputPayment) PrefixedString

func (op *OutputPayment) PrefixedString(prefix string) string

PrefixedString converts this input to a string representation with a prefix for each newline

func (*OutputPayment) String

func (op *OutputPayment) String() string

func (*OutputPayment) Threshold

func (op *OutputPayment) Threshold() uint32

Threshold is the number of signatures this output will require to be spent

func (*OutputPayment) Unlock

func (op *OutputPayment) Unlock(in Input, time uint64) error

Unlock returns true if the input has the correct signatures to spend this output

func (*OutputPayment) Verify

func (op *OutputPayment) Verify() error

Verify that this output is syntactically correct

type OutputTakeOrLeave

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

OutputTakeOrLeave is a take-or-leave transaction. It implements Output. After time [locktime1], it can be spent using [threshold1] signatures, where each signature is from [addresses1] After time [locktime2], it can also be spent using [threshold2] signatures, where each signature is from [addresses2]

func (*OutputTakeOrLeave) Addresses1

func (otol *OutputTakeOrLeave) Addresses1() []ids.ShortID

Addresses1 are the addresses controlled by keys that can produce signatures to spend this output

func (*OutputTakeOrLeave) Addresses2

func (otol *OutputTakeOrLeave) Addresses2() []ids.ShortID

Addresses2 are the addresses controlled by keys that can produce signatures to spend this output

func (*OutputTakeOrLeave) Amount

func (otol *OutputTakeOrLeave) Amount() uint64

Amount returns the value this output produces

func (*OutputTakeOrLeave) Locktime1

func (otol *OutputTakeOrLeave) Locktime1() uint64

Locktime1 returns the time after which the first set of addresses may spend this output are unlocked

func (*OutputTakeOrLeave) Locktime2

func (otol *OutputTakeOrLeave) Locktime2() uint64

Locktime2 returns when the second set of addresses are unlocked

func (*OutputTakeOrLeave) PrefixedString

func (otol *OutputTakeOrLeave) PrefixedString(prefix string) string

PrefixedString converts this input to a string representation with a prefix for each newline

func (*OutputTakeOrLeave) String

func (otol *OutputTakeOrLeave) String() string

func (*OutputTakeOrLeave) Threshold1

func (otol *OutputTakeOrLeave) Threshold1() uint32

Threshold1 returns the number of signatures the first set of addresses need to produce to be able to spend this output

func (*OutputTakeOrLeave) Threshold2

func (otol *OutputTakeOrLeave) Threshold2() uint32

Threshold2 returns the number of signatures the second set of addresses need to produce to be able to spend this output

func (*OutputTakeOrLeave) Unlock

func (otol *OutputTakeOrLeave) Unlock(in Input, time uint64) error

Unlock returns true if the input has the correct signatures to spend this output at time time

func (*OutputTakeOrLeave) Verify

func (otol *OutputTakeOrLeave) Verify() error

Verify that this output is syntactically correct

type Service

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

Service defines the API services exposed by the spdag vm

func (*Service) GetTxStatus

func (service *Service) GetTxStatus(r *http.Request, args *GetTxStatusArgs, reply *GetTxStatusReply) error

GetTxStatus returns the status of the transaction whose ID is [args.TxID]

func (*Service) GetUTXOs

func (service *Service) GetUTXOs(r *http.Request, args *GetUTXOsArgs, reply *GetUTXOsReply) error

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

func (*Service) IssueTx

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

IssueTx attempts to issue a transaction into consensus

type Sig

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

Sig is a signature on a transaction

type StaticService

type StaticService struct{}

StaticService defines the static API exposed by the spdag 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 the core operation that can be performed. The tx uses the UTXO model. That is, a tx's inputs will consume previous tx's outputs. A tx will be valid if the inputs have the authority to consume the outputs they are attempting to consume and the inputs consume sufficient state to produce the outputs.

func (*Tx) Bytes

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

Bytes of this transaction

func (*Tx) ID

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

ID of this transaction

func (*Tx) Ins

func (t *Tx) Ins() []Input

Ins returns the ins of this tx

func (*Tx) Outs

func (t *Tx) Outs() []Output

Outs returns the outs of this tx

func (*Tx) PrefixedString

func (t *Tx) PrefixedString(prefix string) string

PrefixedString converts this tx to a string representation with a prefix for each newline

func (*Tx) String

func (t *Tx) String() string

func (*Tx) UTXOs

func (t *Tx) UTXOs() []*UTXO

UTXOs returns the UTXOs that this transaction will produce if accepted.

func (*Tx) Verify

func (t *Tx) Verify(ctx *snow.Context, txFee uint64) error

Verify that this transaction is well formed

type UTXO

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

UTXO represents an unspent transaction output

func (*UTXO) Bytes

func (u *UTXO) Bytes() []byte

Bytes returns a binary representation of this utxo

func (*UTXO) ID

func (u *UTXO) ID() ids.ID

ID returns a unique identifier for this utxo

func (*UTXO) Out

func (u *UTXO) Out() Output

Out returns the output this utxo wraps

func (*UTXO) PrefixedString

func (u *UTXO) PrefixedString(prefix string) string

PrefixedString converts this utxo to a string representation with a prefix for each newline

func (*UTXO) Source

func (u *UTXO) Source() (ids.ID, uint32)

Source returns the origin of this utxo. Specifically the txID and the outputIndex this utxo represents

func (*UTXO) String

func (u *UTXO) String() string

type UniqueTx

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

UniqueTx provides a de-duplication service for txs. This only provides a performance boost

func (*UniqueTx) Accept

func (tx *UniqueTx) Accept() error

Accept is called when the transaction was finalized as accepted by consensus

func (*UniqueTx) Bytes

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

Bytes returns the binary representation of this transaction

func (*UniqueTx) Dependencies

func (tx *UniqueTx) Dependencies() []snowstorm.Tx

Dependencies returns the set of transactions this transaction builds on

func (*UniqueTx) Evict

func (tx *UniqueTx) Evict()

Evict is called when this UniqueTx will no longer be returned from a cache lookup

func (*UniqueTx) ID

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

ID returns the wrapped txID

func (*UniqueTx) InputIDs

func (tx *UniqueTx) InputIDs() ids.Set

InputIDs returns the set of utxoIDs this transaction consumes

func (*UniqueTx) Reject

func (tx *UniqueTx) Reject() error

Reject is called when the transaction was finalized as rejected by consensus

func (*UniqueTx) Status

func (tx *UniqueTx) Status() choices.Status

Status returns the current status of this transaction

func (*UniqueTx) Verify

func (tx *UniqueTx) Verify() error

Verify the validity of this transaction

func (*UniqueTx) VerifyState

func (tx *UniqueTx) VerifyState() error

VerifyState the validity of this transaction

func (*UniqueTx) VerifyTx

func (tx *UniqueTx) VerifyTx() error

VerifyTx the validity of this transaction

type VM

type VM struct {

	// The transaction fee, which the sender pays. The fee is burned.
	TxFee uint64
	// contains filtered or unexported fields
}

VM implements the avalanche.DAGVM interface

func (*VM) Bootstrapped added in v0.5.3

func (vm *VM) Bootstrapped() error

Bootstrapped marks this VM as bootstrapped

func (*VM) Bootstrapping added in v0.5.3

func (vm *VM) Bootstrapping() error

Bootstrapping marks this VM as bootstrapping

func (*VM) CreateHandlers

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

CreateHandlers makes new service objects with references to the vm

func (*VM) CreateKey

func (vm *VM) CreateKey() (string, error)

CreateKey returns a new base58-encoded private key

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) GetAddress

func (vm *VM) GetAddress(privKeyStr string) (string, error)

GetAddress returns the string repr. of the address controlled by a base58-encoded private key

func (*VM) GetBalance

func (vm *VM) GetBalance(address, assetID string) (uint64, error)

GetBalance returns [address]'s balance of the asset whose ID is [assetID]

func (*VM) GetTx

func (vm *VM) GetTx(txID ids.ID) (snowstorm.Tx, error)

GetTx returns the transaction whose ID is [txID]

func (*VM) GetTxHistory

func (vm *VM) GetTxHistory(address string) (string, []string, map[string]string, []map[string]string, error)

GetTxHistory takes an address and returns an ordered list of known records containing key-value pairs of data.

func (*VM) GetUTXOs

func (vm *VM) GetUTXOs(addrs ids.ShortSet) ([]*UTXO, error)

GetUTXOs returns the UTXOs such that at least one address in [addrs] is referenced in the UTXO.

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 avalanche.DAGVM interface

func (*VM) IssueTx

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

IssueTx implements the avalanche.DAGVM interface

func (*VM) ListAssets

func (vm *VM) ListAssets(address string) ([]string, error)

ListAssets returns the IDs of assets such that [address] has a non-zero balance of that asset

func (*VM) ParseTx

func (vm *VM) ParseTx(b []byte) (snowstorm.Tx, error)

ParseTx parses bytes to a *UniqueTx

func (*VM) PendingTxs

func (vm *VM) PendingTxs() []snowstorm.Tx

PendingTxs returns the transactions that have not yet been added to consensus

func (*VM) Send

func (vm *VM) Send(amount uint64, assetID, toAddrStr string, fromPKs []string) (string, error)

Send issues a transaction that sends [amount] from the addresses controlled by [fromPKs] to [toAddrStr]. Send returns the transaction's ID. Any "change" will be sent to the address controlled by the first element of [fromPKs].

func (*VM) Shutdown

func (vm *VM) Shutdown() error

Shutdown implements the avalanche.DAGVM interface

Jump to

Keyboard shortcuts

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