Documentation ¶
Index ¶
- Constants
- Variables
- func SortIns(ins []Input, signers []*InputSigner)
- func SortOuts(outs []Output)
- func SortTxSig(sigs []*Sig)
- type APIOutput
- type BuildGenesisArgs
- type BuildGenesisReply
- type Builder
- func (b Builder) NewInputPayment(sourceID ids.ID, sourceIndex uint32, amount uint64, sigs []*Sig) Input
- func (b Builder) NewOutputPayment(amount, locktime uint64, threshold uint32, addresses []ids.ShortID) Output
- func (b Builder) NewOutputTakeOrLeave(amount, locktime1 uint64, threshold1 uint32, addresses1 []ids.ShortID, ...) Output
- func (b Builder) NewSig(index uint32) *Sig
- func (b Builder) NewTx(ins []Input, outs []Output, signers []*InputSigner) (*Tx, error)
- func (b Builder) NewTxFromUTXOs(keychain *Keychain, utxos []*UTXO, amount, txFee, locktime uint64, ...) (*Tx, error)
- type Codec
- func (c *Codec) MarshalOutput(out Output) ([]byte, error)
- func (c *Codec) MarshalTx(tx *Tx) ([]byte, error)
- func (c *Codec) MarshalUTXO(utxo *UTXO) ([]byte, error)
- func (c *Codec) MarshalUTXOs(utxos []*UTXO) ([]byte, error)
- func (c *Codec) MarshalUnsignedTx(tx *Tx) ([]byte, error)
- func (c *Codec) UnmarshalTx(b []byte) (*Tx, error)
- func (c *Codec) UnmarshalUTXO(b []byte) (*UTXO, error)
- func (c *Codec) UnmarshalUTXOs(b []byte) ([]*UTXO, error)
- type CodecID
- type Factory
- type GetTxStatusArgs
- type GetTxStatusReply
- type GetUTXOsArgs
- type GetUTXOsReply
- type Input
- type InputPayment
- type InputSigner
- type IssueTxArgs
- type IssueTxReply
- type Keychain
- func (kc *Keychain) Add(key *crypto.PrivateKeySECP256K1R)
- func (kc *Keychain) Addresses() ids.ShortSet
- func (kc *Keychain) Get(id ids.ShortID) (*crypto.PrivateKeySECP256K1R, bool)
- func (kc *Keychain) GetSigsAndKeys(addresses []ids.ShortID, threshold int) ([]*Sig, []*crypto.PrivateKeySECP256K1R, bool)
- func (kc *Keychain) New() (*crypto.PrivateKeySECP256K1R, error)
- func (kc *Keychain) PrefixedString(prefix string) string
- func (kc *Keychain) Spend(utxo *UTXO, time uint64) (Input, *InputSigner, error)
- func (kc *Keychain) String() string
- type Output
- type OutputPayment
- func (op *OutputPayment) Addresses() []ids.ShortID
- func (op *OutputPayment) Amount() uint64
- func (op *OutputPayment) Locktime() uint64
- func (op *OutputPayment) PrefixedString(prefix string) string
- func (op *OutputPayment) String() string
- func (op *OutputPayment) Threshold() uint32
- func (op *OutputPayment) Unlock(in Input, time uint64) error
- func (op *OutputPayment) Verify() error
- type OutputTakeOrLeave
- func (otol *OutputTakeOrLeave) Addresses1() []ids.ShortID
- func (otol *OutputTakeOrLeave) Addresses2() []ids.ShortID
- func (otol *OutputTakeOrLeave) Amount() uint64
- func (otol *OutputTakeOrLeave) Locktime1() uint64
- func (otol *OutputTakeOrLeave) Locktime2() uint64
- func (otol *OutputTakeOrLeave) PrefixedString(prefix string) string
- func (otol *OutputTakeOrLeave) String() string
- func (otol *OutputTakeOrLeave) Threshold1() uint32
- func (otol *OutputTakeOrLeave) Threshold2() uint32
- func (otol *OutputTakeOrLeave) Unlock(in Input, time uint64) error
- func (otol *OutputTakeOrLeave) Verify() error
- type Service
- type Sig
- type StaticService
- type Tx
- type UTXO
- type UniqueTx
- func (tx *UniqueTx) Accept()
- func (tx *UniqueTx) Bytes() []byte
- func (tx *UniqueTx) Dependencies() []snowstorm.Tx
- func (tx *UniqueTx) Evict()
- func (tx *UniqueTx) ID() ids.ID
- func (tx *UniqueTx) InputIDs() ids.Set
- func (tx *UniqueTx) Reject()
- func (tx *UniqueTx) Status() choices.Status
- func (tx *UniqueTx) Verify() error
- func (tx *UniqueTx) VerifyState() error
- func (tx *UniqueTx) VerifyTx() error
- type VM
- func (vm *VM) CreateHandlers() map[string]*common.HTTPHandler
- func (vm *VM) CreateKey() (string, error)
- func (vm *VM) CreateStaticHandlers() map[string]*common.HTTPHandler
- func (vm *VM) FlushTxs()
- func (vm *VM) GetAddress(privKeyStr string) (string, error)
- func (vm *VM) GetBalance(address, assetID string) (uint64, error)
- func (vm *VM) GetTx(txID ids.ID) (snowstorm.Tx, error)
- func (vm *VM) GetTxHistory(address string) (string, []string, map[string]string, []map[string]string, error)
- func (vm *VM) GetUTXOs(addrs ids.ShortSet) ([]*UTXO, error)
- func (vm *VM) Initialize(ctx *snow.Context, db database.Database, genesisBytes []byte, ...) error
- func (vm *VM) IssueTx(b []byte, finalized func(choices.Status)) (ids.ID, error)
- func (vm *VM) ListAssets(address string) ([]string, error)
- func (vm *VM) ParseTx(b []byte) (snowstorm.Tx, error)
- func (vm *VM) PendingTxs() []snowstorm.Tx
- func (vm *VM) Send(amount uint64, assetID, toAddrStr string, fromPKs []string) (string, error)
- func (vm *VM) Shutdown()
Constants ¶
const ( OutputPaymentID uint32 = iota OutputTakeOrLeaveID )
Output types
const (
InputID uint32 = iota
)
Input types
const MaxSize = 1 << 18
MaxSize is the maximum allowed tx size. It is necessary to deter DoS.
Variables ¶
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
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 ¶
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 ¶
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 ¶
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] ava 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 ¶
MarshalOutput returns the byte representation of the output
func (*Codec) MarshalUTXO ¶
MarshalUTXO returns the byte representation of the utxo
func (*Codec) MarshalUTXOs ¶
MarshalUTXOs returns the byte representation of the utxos
func (*Codec) MarshalUnsignedTx ¶
MarshalUnsignedTx returns the byte representation of the unsigned tx
func (*Codec) UnmarshalTx ¶
UnmarshalTx attempts to convert the stream of bytes into a representation of a tx
func (*Codec) UnmarshalUTXO ¶
UnmarshalUTXO attempts to convert the stream of bytes into a representation of an utxo
type GetTxStatusArgs ¶
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 ¶
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 ¶
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 ¶
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) 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:
- 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
- A list of private keys such that each key controls an address in [addresses]
- 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 ¶
PrefixedString returns the key chain as a string representation with [prefix] added before every line.
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 ava 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 AVA 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) PrefixedString ¶
PrefixedString converts this tx to a string representation with a prefix for each newline
type UTXO ¶
type UTXO struct {
// contains filtered or unexported fields
}
UTXO represents an unspent transaction output
func (*UTXO) PrefixedString ¶
PrefixedString converts this utxo to a string representation with a prefix for each newline
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()
Accept is called when the transaction was finalized as accepted by consensus
func (*UniqueTx) Dependencies ¶
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) Reject ¶
func (tx *UniqueTx) Reject()
Reject is called when the transaction was finalized as rejected by consensus
func (*UniqueTx) VerifyState ¶
VerifyState 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) 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) GetAddress ¶
GetAddress returns the string repr. of the address controlled by a base58-encoded private key
func (*VM) GetBalance ¶
GetBalance returns [address]'s balance of the asset whose ID is [assetID]
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 ¶
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) ListAssets ¶
ListAssets returns the IDs of assets such that [address] has a non-zero balance of that asset
func (*VM) PendingTxs ¶
PendingTxs returns the transactions that have not yet been added to consensus