avm

package
v1.7.13 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: BSD-3-Clause Imports: 58 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCodecs

func NewCodecs(fxs []fxs.Fx) (codec.Manager, codec.Manager, error)

NewCodecs returns the genesis codec and the normal codec for the provided feature extensions.

func NewPubSubFilterer

func NewPubSubFilterer(tx *txs.Tx) pubsub.Filterer

func SortOperations

func SortOperations(ops []*Operation, c codec.Manager)

Types

type AssetDefinition

type AssetDefinition struct {
	Name         string                   `json:"name"`
	Symbol       string                   `json:"symbol"`
	Denomination json.Uint8               `json:"denomination"`
	InitialState map[string][]interface{} `json:"initialState"`
	Memo         string                   `json:"memo"`
}

type AssetIDChangeAddr

type AssetIDChangeAddr struct {
	FormattedAssetID
	api.JSONChangeAddr
}

AssetIDChangeAddr is an asset ID and a change address

type Balance

type Balance struct {
	AssetID string      `json:"asset"`
	Balance json.Uint64 `json:"balance"`
}

type BaseTx

type BaseTx struct {
	djtx.BaseTx `serialize:"true"`
}

BaseTx is the basis of all transactions.

func (*BaseTx) ExecuteWithSideEffects

func (t *BaseTx) ExecuteWithSideEffects(_ *VM, batch database.Batch) error

ExecuteWithSideEffects writes the batch with any additional side effects

func (*BaseTx) Init

func (t *BaseTx) Init(vm *VM) error

Init sets the FxID fields in the inputs and outputs of this BaseTx Also sets the [ctx] in the OutputOwners to the given [vm.ctx] so that the addresses can be json marshalled into human readable format

func (*BaseTx) SemanticVerify

func (t *BaseTx) SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiable) error

SemanticVerify that this transaction is valid to be spent.

func (*BaseTx) SyntacticVerify

func (t *BaseTx) SyntacticVerify(
	ctx *snow.Context,
	c codec.Manager,
	txFeeAssetID ids.ID,
	txFee uint64,
	_ uint64,
	_ int,
) error

SyntacticVerify that this transaction is well-formed.

type BuildGenesisArgs

type BuildGenesisArgs struct {
	NetworkID   json.Uint32                `json:"networkID"`
	GenesisData map[string]AssetDefinition `json:"genesisData"`
	Encoding    formatting.Encoding        `json:"encoding"`
}

BuildGenesisArgs are arguments for BuildGenesis

type BuildGenesisReply

type BuildGenesisReply struct {
	Bytes    string              `json:"bytes"`
	Encoding formatting.Encoding `json:"encoding"`
}

BuildGenesisReply is the reply from BuildGenesis

type Client

type Client interface {
	WalletClient
	// GetTxStatus returns the status of [txID]
	GetTxStatus(ctx context.Context, txID ids.ID, options ...rpc.Option) (choices.Status, error)
	// ConfirmTx attempts to confirm [txID] by repeatedly checking its status.
	// Note: ConfirmTx will block until either the context is done or the client
	//       returns a decided status.
	ConfirmTx(ctx context.Context, txID ids.ID, freq time.Duration, options ...rpc.Option) (choices.Status, error)
	// GetTx returns the byte representation of [txID]
	GetTx(ctx context.Context, txID ids.ID, options ...rpc.Option) ([]byte, error)
	// IssueStopVertex issues a stop vertex.
	IssueStopVertex(ctx context.Context, options ...rpc.Option) error
	// GetUTXOs returns the byte representation of the UTXOs controlled by [addrs]
	GetUTXOs(
		ctx context.Context,
		addrs []ids.ShortID,
		limit uint32,
		startAddress ids.ShortID,
		startUTXOID ids.ID,
		options ...rpc.Option,
	) ([][]byte, ids.ShortID, ids.ID, error)
	// GetAtomicUTXOs returns the byte representation of the atomic UTXOs controlled by [addrs]
	// from [sourceChain]
	GetAtomicUTXOs(
		ctx context.Context,
		addrs []ids.ShortID,
		sourceChain string,
		limit uint32,
		startAddress ids.ShortID,
		startUTXOID ids.ID,
		options ...rpc.Option,
	) ([][]byte, ids.ShortID, ids.ID, error)
	// GetAssetDescription returns a description of [assetID]
	GetAssetDescription(ctx context.Context, assetID string, options ...rpc.Option) (*GetAssetDescriptionReply, error)
	// GetBalance returns the balance of [assetID] held by [addr].
	// If [includePartial], balance includes partial owned (i.e. in a multisig) funds.
	GetBalance(ctx context.Context, addr ids.ShortID, assetID string, includePartial bool, options ...rpc.Option) (*GetBalanceReply, error)
	// GetAllBalances returns all asset balances for [addr]
	GetAllBalances(ctx context.Context, addr ids.ShortID, includePartial bool, options ...rpc.Option) ([]Balance, error)
	// CreateAsset creates a new asset and returns its assetID
	CreateAsset(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		name string,
		symbol string,
		denomination byte,
		holders []*ClientHolder,
		minters []ClientOwners,
		options ...rpc.Option,
	) (ids.ID, error)
	// CreateFixedCapAsset creates a new fixed cap asset and returns its assetID
	CreateFixedCapAsset(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		name string,
		symbol string,
		denomination byte,
		holders []*ClientHolder,
		options ...rpc.Option,
	) (ids.ID, error)
	// CreateVariableCapAsset creates a new variable cap asset and returns its assetID
	CreateVariableCapAsset(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		name string,
		symbol string,
		denomination byte,
		minters []ClientOwners,
		options ...rpc.Option,
	) (ids.ID, error)
	// CreateNFTAsset creates a new NFT asset and returns its assetID
	CreateNFTAsset(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		name string,
		symbol string,
		minters []ClientOwners,
		options ...rpc.Option,
	) (ids.ID, error)
	// CreateAddress creates a new address controlled by [user]
	CreateAddress(ctx context.Context, user api.UserPass, options ...rpc.Option) (ids.ShortID, error)
	// ListAddresses returns all addresses on this chain controlled by [user]
	ListAddresses(ctx context.Context, user api.UserPass, options ...rpc.Option) ([]ids.ShortID, error)
	// ExportKey returns the private key corresponding to [addr] controlled by [user]
	ExportKey(ctx context.Context, user api.UserPass, addr ids.ShortID, options ...rpc.Option) (*crypto.PrivateKeySECP256K1R, error)
	// ImportKey imports [privateKey] to [user]
	ImportKey(ctx context.Context, user api.UserPass, privateKey *crypto.PrivateKeySECP256K1R, options ...rpc.Option) (ids.ShortID, error)
	// Mint [amount] of [assetID] to be owned by [to]
	Mint(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		amount uint64,
		assetID string,
		to ids.ShortID,
		options ...rpc.Option,
	) (ids.ID, error)
	// SendNFT sends an NFT and returns the ID of the newly created transaction
	SendNFT(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		assetID string,
		groupID uint32,
		to ids.ShortID,
		options ...rpc.Option,
	) (ids.ID, error)
	// MintNFT issues a MintNFT transaction and returns the ID of the newly created transaction
	MintNFT(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		assetID string,
		payload []byte,
		to ids.ShortID,
		options ...rpc.Option,
	) (ids.ID, error)
	// Import sends an import transaction to import funds from [sourceChain] and
	// returns the ID of the newly created transaction
	Import(ctx context.Context, user api.UserPass, to ids.ShortID, sourceChain string, options ...rpc.Option) (ids.ID, error) // Export sends an asset from this chain to the P/C-Chain.
	// After this tx is accepted, the DJTX must be imported to the P/C-chain with an importTx.
	// Returns the ID of the newly created atomic transaction
	Export(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		amount uint64,
		to ids.ShortID,
		toChainIDAlias string,
		assetID string,
		options ...rpc.Option,
	) (ids.ID, error)
}

Client for interacting with an AVM (X-Chain) instance

func NewClient

func NewClient(uri, chain string) Client

NewClient returns an AVM client for interacting with avm [chain]

type ClientHolder added in v1.7.11

type ClientHolder struct {
	Amount  uint64
	Address ids.ShortID
}

ClientHolder describes how much an address owns of an asset

type ClientOwners added in v1.7.11

type ClientOwners struct {
	Threshold uint32
	Minters   []ids.ShortID
}

ClientOwners describes who can perform an action

type ClientSendOutput added in v1.7.11

type ClientSendOutput struct {
	// The amount of funds to send
	Amount uint64

	// ID of the asset being sent
	AssetID string

	// Address of the recipient
	To ids.ShortID
}

ClientSendOutput specifies that [Amount] of asset [AssetID] be sent to [To]

type Config

type Config struct {
	IndexTransactions    bool `json:"index-transactions"`
	IndexAllowIncomplete bool `json:"index-allow-incomplete"`
}

type CreateAssetArgs

type CreateAssetArgs struct {
	api.JSONSpendHeader           // User, password, from addrs, change addr
	Name                string    `json:"name"`
	Symbol              string    `json:"symbol"`
	Denomination        byte      `json:"denomination"`
	InitialHolders      []*Holder `json:"initialHolders"`
	MinterSets          []Owners  `json:"minterSets"`
}

CreateAssetArgs are arguments for passing into CreateAsset

type CreateAssetTx

type CreateAssetTx struct {
	BaseTx       `serialize:"true"`
	Name         string          `serialize:"true" json:"name"`
	Symbol       string          `serialize:"true" json:"symbol"`
	Denomination byte            `serialize:"true" json:"denomination"`
	States       []*InitialState `serialize:"true" json:"initialStates"`
}

CreateAssetTx is a transaction that creates a new asset.

func (*CreateAssetTx) Init

func (t *CreateAssetTx) Init(vm *VM) error

func (*CreateAssetTx) InitialStates

func (t *CreateAssetTx) InitialStates() []*InitialState

InitialStates track which virtual machines, and the initial state of these machines, this asset uses. The returned array should not be modified.

func (*CreateAssetTx) Sort

func (t *CreateAssetTx) Sort()

func (*CreateAssetTx) SyntacticVerify

func (t *CreateAssetTx) SyntacticVerify(
	ctx *snow.Context,
	c codec.Manager,
	txFeeAssetID ids.ID,
	_ uint64,
	txFee uint64,
	numFxs int,
) error

SyntacticVerify that this transaction is well-formed.

func (*CreateAssetTx) UTXOs

func (t *CreateAssetTx) UTXOs() []*djtx.UTXO

UTXOs returns the UTXOs transaction is producing.

type CreateNFTAssetArgs

type CreateNFTAssetArgs struct {
	api.JSONSpendHeader          // User, password, from addrs, change addr
	Name                string   `json:"name"`
	Symbol              string   `json:"symbol"`
	MinterSets          []Owners `json:"minterSets"`
}

CreateNFTAssetArgs are arguments for passing into CreateNFTAsset requests

type ExportArgs

type ExportArgs struct {
	// User, password, from addrs, change addr
	api.JSONSpendHeader
	// Amount of nDJTX to send
	Amount json.Uint64 `json:"amount"`

	// Chain the funds are going to. Optional. Used if To address does not include the chainID.
	TargetChain string `json:"targetChain"`

	// ID of the address that will receive the DJTX. This address may include the
	// chainID, which is used to determine what the destination chain is.
	To string `json:"to"`

	AssetID string `json:"assetID"`
}

ExportArgs are arguments for passing into ExportAVA requests

type ExportKeyArgs

type ExportKeyArgs struct {
	api.UserPass
	Address string `json:"address"`
}

ExportKeyArgs are arguments for ExportKey

type ExportKeyReply

type ExportKeyReply struct {
	// The decrypted PrivateKey for the Address provided in the arguments
	PrivateKey *crypto.PrivateKeySECP256K1R `json:"privateKey"`
}

ExportKeyReply is the response for ExportKey

type ExportTx

type ExportTx struct {
	BaseTx `serialize:"true"`

	// Which chain to send the funds to
	DestinationChain ids.ID `serialize:"true" json:"destinationChain"`

	// The outputs this transaction is sending to the other chain
	ExportedOuts []*djtx.TransferableOutput `serialize:"true" json:"exportedOutputs"`
}

ExportTx is a transaction that exports an asset to another blockchain.

func (*ExportTx) ExecuteWithSideEffects

func (t *ExportTx) ExecuteWithSideEffects(vm *VM, batch database.Batch) error

ExecuteWithSideEffects writes the batch with any additional side effects

func (*ExportTx) Init

func (t *ExportTx) Init(vm *VM) error

func (*ExportTx) SemanticVerify

func (t *ExportTx) SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiable) error

SemanticVerify that this transaction is valid to be spent.

func (*ExportTx) SyntacticVerify

func (t *ExportTx) SyntacticVerify(
	ctx *snow.Context,
	c codec.Manager,
	txFeeAssetID ids.ID,
	txFee uint64,
	_ uint64,
	_ int,
) error

SyntacticVerify that this transaction is well-formed.

type Factory

type Factory struct {
	TxFee            uint64
	CreateAssetTxFee uint64
}

func (*Factory) New

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

type FormattedAssetID

type FormattedAssetID struct {
	AssetID ids.ID `json:"assetID"`
}

FormattedAssetID defines a JSON formatted struct containing an assetID as a string

type Fx

type Fx interface {
	// Initialize this feature extension to be running under this VM. Should
	// return an error if the VM is incompatible.
	Initialize(vm interface{}) error

	// Notify this Fx that the VM is in bootstrapping
	Bootstrapping() error

	// Notify this Fx that the VM is bootstrapped
	Bootstrapped() error

	// VerifyTransfer verifies that the specified transaction can spend the
	// provided utxo with no restrictions on the destination. If the transaction
	// can't spend the output based on the input and credential, a non-nil error
	// should be returned.
	VerifyTransfer(tx, in, cred, utxo interface{}) error

	// VerifyOperation verifies that the specified transaction can spend the
	// provided utxos conditioned on the result being restricted to the provided
	// outputs. If the transaction can't spend the output based on the input and
	// credential, a non-nil error  should be returned.
	VerifyOperation(tx, op, cred interface{}, utxos []interface{}) error
}

Fx is the interface a feature extension must implement to support the AVM.

type FxCredential

type FxCredential struct {
	FxID              ids.ID `serialize:"false" json:"fxID"`
	verify.Verifiable `serialize:"true" json:"credential"`
}

type FxOperation

type FxOperation interface {
	verify.Verifiable
	snow.ContextInitializable
	djtx.Coster

	Outs() []verify.State
}

type Genesis

type Genesis struct {
	Txs []*GenesisAsset `serialize:"true"`
}

func (*Genesis) IsSortedAndUnique

func (g *Genesis) IsSortedAndUnique() bool

func (*Genesis) Len

func (g *Genesis) Len() int

func (*Genesis) Less

func (g *Genesis) Less(i, j int) bool

func (*Genesis) Sort

func (g *Genesis) Sort()

func (*Genesis) Swap

func (g *Genesis) Swap(i, j int)

type GenesisAsset

type GenesisAsset struct {
	Alias             string `serialize:"true"`
	txs.CreateAssetTx `serialize:"true"`
}

type GetAddressTxsArgs

type GetAddressTxsArgs struct {
	api.JSONAddress
	// Cursor used as a page index / offset
	Cursor json.Uint64 `json:"cursor"`
	// PageSize num of items per page
	PageSize json.Uint64 `json:"pageSize"`
	// AssetID defaulted to DJTX if omitted or left blank
	AssetID string `json:"assetID"`
}

type GetAddressTxsReply

type GetAddressTxsReply struct {
	TxIDs []ids.ID `json:"txIDs"`
	// Cursor used as a page index / offset
	Cursor json.Uint64 `json:"cursor"`
}

type GetAllBalancesArgs

type GetAllBalancesArgs struct {
	api.JSONAddress
	IncludePartial bool `json:"includePartial"`
}

type GetAllBalancesReply

type GetAllBalancesReply struct {
	Balances []Balance `json:"balances"`
}

GetAllBalancesReply is the response from a call to GetAllBalances

type GetAssetDescriptionArgs

type GetAssetDescriptionArgs struct {
	AssetID string `json:"assetID"`
}

GetAssetDescriptionArgs are arguments for passing into GetAssetDescription requests

type GetAssetDescriptionReply

type GetAssetDescriptionReply struct {
	FormattedAssetID
	Name         string     `json:"name"`
	Symbol       string     `json:"symbol"`
	Denomination json.Uint8 `json:"denomination"`
}

GetAssetDescriptionReply defines the GetAssetDescription replies returned from the API

type GetBalanceArgs

type GetBalanceArgs struct {
	Address        string `json:"address"`
	AssetID        string `json:"assetID"`
	IncludePartial bool   `json:"includePartial"`
}

GetBalanceArgs are arguments for passing into GetBalance requests

type GetBalanceReply

type GetBalanceReply struct {
	Balance json.Uint64   `json:"balance"`
	UTXOIDs []djtx.UTXOID `json:"utxoIDs"`
}

GetBalanceReply defines the GetBalance replies returned from the API

type GetTxStatusReply

type GetTxStatusReply struct {
	Status choices.Status `json:"status"`
}

GetTxStatusReply defines the GetTxStatus replies returned from the API

type Holder

type Holder struct {
	Amount  json.Uint64 `json:"amount"`
	Address string      `json:"address"`
}

Holder describes how much an address owns of an asset

type ImportArgs

type ImportArgs struct {
	// User that controls To
	api.UserPass

	// Chain the funds are coming from
	SourceChain string `json:"sourceChain"`

	// Address receiving the imported DJTX
	To string `json:"to"`
}

ImportArgs are arguments for passing into Import requests

type ImportKeyArgs

type ImportKeyArgs struct {
	api.UserPass
	PrivateKey *crypto.PrivateKeySECP256K1R `json:"privateKey"`
}

ImportKeyArgs are arguments for ImportKey

type ImportKeyReply

type ImportKeyReply struct {
	// The address controlled by the PrivateKey provided in the arguments
	Address string `json:"address"`
}

ImportKeyReply is the response for ImportKey

type ImportTx

type ImportTx struct {
	BaseTx `serialize:"true"`

	// Which chain to consume the funds from
	SourceChain ids.ID `serialize:"true" json:"sourceChain"`

	// The inputs to this transaction
	ImportedIns []*djtx.TransferableInput `serialize:"true" json:"importedInputs"`
}

ImportTx is a transaction that imports an asset from another blockchain.

func (*ImportTx) AssetIDs

func (t *ImportTx) AssetIDs() ids.Set

AssetIDs returns the IDs of the assets this transaction depends on

func (*ImportTx) ConsumedAssetIDs

func (t *ImportTx) ConsumedAssetIDs() ids.Set

ConsumedAssetIDs returns the IDs of the assets this transaction consumes

func (*ImportTx) ExecuteWithSideEffects

func (t *ImportTx) ExecuteWithSideEffects(vm *VM, batch database.Batch) error

ExecuteWithSideEffects writes the batch with any additional side effects

func (*ImportTx) Init

func (t *ImportTx) Init(vm *VM) error

func (*ImportTx) InputUTXOs

func (t *ImportTx) InputUTXOs() []*djtx.UTXOID

InputUTXOs track which UTXOs this transaction is consuming.

func (*ImportTx) NumCredentials

func (t *ImportTx) NumCredentials() int

NumCredentials returns the number of expected credentials

func (*ImportTx) SemanticVerify

func (t *ImportTx) SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiable) error

SemanticVerify that this transaction is well-formed.

func (*ImportTx) SyntacticVerify

func (t *ImportTx) SyntacticVerify(
	ctx *snow.Context,
	c codec.Manager,
	txFeeAssetID ids.ID,
	txFee uint64,
	_ uint64,
	numFxs int,
) error

SyntacticVerify that this transaction is well-formed.

type InitialState

type InitialState struct {
	FxIndex uint32         `serialize:"true" json:"fxIndex"`
	FxID    ids.ID         `serialize:"false" json:"fxID"`
	Outs    []verify.State `serialize:"true" json:"outputs"`
}

func (*InitialState) InitCtx

func (is *InitialState) InitCtx(ctx *snow.Context)

func (*InitialState) Sort

func (is *InitialState) Sort(c codec.Manager)

func (*InitialState) Verify

func (is *InitialState) Verify(c codec.Manager, numFxs int) error

type MintArgs

type MintArgs struct {
	api.JSONSpendHeader             // User, password, from addrs, change addr
	Amount              json.Uint64 `json:"amount"`
	AssetID             string      `json:"assetID"`
	To                  string      `json:"to"`
}

MintArgs are arguments for passing into Mint requests

type MintNFTArgs

type MintNFTArgs struct {
	api.JSONSpendHeader                     // User, password, from addrs, change addr
	AssetID             string              `json:"assetID"`
	Payload             string              `json:"payload"`
	To                  string              `json:"to"`
	Encoding            formatting.Encoding `json:"encoding"`
}

MintNFTArgs are arguments for passing into MintNFT requests

type Operation

type Operation struct {
	djtx.Asset `serialize:"true"`
	UTXOIDs    []*djtx.UTXOID  `serialize:"true" json:"inputIDs"`
	FxID       ids.ID          `serialize:"false" json:"fxID"`
	Op         fxs.FxOperation `serialize:"true" json:"operation"`
}

func (*Operation) Verify

func (op *Operation) Verify(c codec.Manager) error

type OperationTx

type OperationTx struct {
	BaseTx `serialize:"true"`
	Ops    []*Operation `serialize:"true" json:"operations"`
}

OperationTx is a transaction with no credentials.

func (*OperationTx) AssetIDs

func (t *OperationTx) AssetIDs() ids.Set

AssetIDs returns the IDs of the assets this transaction depends on

func (*OperationTx) ConsumedAssetIDs

func (t *OperationTx) ConsumedAssetIDs() ids.Set

ConsumedAssetIDs returns the IDs of the assets this transaction consumes

func (*OperationTx) Init

func (t *OperationTx) Init(vm *VM) error

func (*OperationTx) InputUTXOs

func (t *OperationTx) InputUTXOs() []*djtx.UTXOID

InputUTXOs track which UTXOs this transaction is consuming.

func (*OperationTx) NumCredentials

func (t *OperationTx) NumCredentials() int

NumCredentials returns the number of expected credentials

func (*OperationTx) Operations

func (t *OperationTx) Operations() []*Operation

Operations track which ops this transaction is performing. The returned array should not be modified.

func (*OperationTx) SemanticVerify

func (t *OperationTx) SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiable) error

SemanticVerify that this transaction is well-formed.

func (*OperationTx) SyntacticVerify

func (t *OperationTx) SyntacticVerify(
	ctx *snow.Context,
	c codec.Manager,
	txFeeAssetID ids.ID,
	txFee uint64,
	_ uint64,
	numFxs int,
) error

SyntacticVerify that this transaction is well-formed.

func (*OperationTx) UTXOs

func (t *OperationTx) UTXOs() []*djtx.UTXO

UTXOs returns the UTXOs transaction is producing.

type Owners

type Owners struct {
	Threshold json.Uint32 `json:"threshold"`
	Minters   []string    `json:"minters"`
}

Owners describes who can perform an action

type SendArgs

type SendArgs struct {
	// User, password, from addrs, change addr
	api.JSONSpendHeader

	// The amount, assetID, and destination to send funds to
	SendOutput

	// Memo field
	Memo string `json:"memo"`
}

SendArgs are arguments for passing into Send requests

type SendMultipleArgs

type SendMultipleArgs struct {
	// User, password, from addrs, change addr
	api.JSONSpendHeader

	// The outputs of the transaction
	Outputs []SendOutput `json:"outputs"`

	// Memo field
	Memo string `json:"memo"`
}

SendMultipleArgs are arguments for passing into SendMultiple requests

type SendNFTArgs

type SendNFTArgs struct {
	api.JSONSpendHeader             // User, password, from addrs, change addr
	AssetID             string      `json:"assetID"`
	GroupID             json.Uint32 `json:"groupID"`
	To                  string      `json:"to"`
}

SendNFTArgs are arguments for passing into SendNFT requests

type SendOutput

type SendOutput struct {
	// The amount of funds to send
	Amount json.Uint64 `json:"amount"`

	// ID of the asset being sent
	AssetID string `json:"assetID"`

	// Address of the recipient
	To string `json:"to"`
}

SendOutput specifies that [Amount] of asset [AssetID] be sent to [To]

type Service

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

Service defines the base service for the asset vm

func (*Service) CreateAddress

func (service *Service) CreateAddress(r *http.Request, args *api.UserPass, reply *api.JSONAddress) error

CreateAddress creates an address for the user [args.Username]

func (*Service) CreateAsset

func (service *Service) CreateAsset(r *http.Request, args *CreateAssetArgs, reply *AssetIDChangeAddr) error

CreateAsset returns ID of the newly created asset

func (*Service) CreateFixedCapAsset

func (service *Service) CreateFixedCapAsset(r *http.Request, args *CreateAssetArgs, reply *AssetIDChangeAddr) error

CreateFixedCapAsset returns ID of the newly created asset

func (*Service) CreateNFTAsset

func (service *Service) CreateNFTAsset(r *http.Request, args *CreateNFTAssetArgs, reply *AssetIDChangeAddr) error

CreateNFTAsset returns ID of the newly created asset

func (*Service) CreateVariableCapAsset

func (service *Service) CreateVariableCapAsset(r *http.Request, args *CreateAssetArgs, reply *AssetIDChangeAddr) error

CreateVariableCapAsset returns ID of the newly created asset

func (*Service) Export

func (service *Service) Export(_ *http.Request, args *ExportArgs, reply *api.JSONTxIDChangeAddr) error

Export sends an asset from this chain to the P/C-Chain. After this tx is accepted, the DJTX must be imported to the P/C-chain with an importTx. Returns the ID of the newly created atomic transaction

func (*Service) ExportKey

func (service *Service) ExportKey(r *http.Request, args *ExportKeyArgs, reply *ExportKeyReply) error

ExportKey returns a private key from the provided user

func (*Service) GetAddressTxs

func (service *Service) GetAddressTxs(r *http.Request, args *GetAddressTxsArgs, reply *GetAddressTxsReply) error

GetAddressTxs returns list of transactions for a given address

func (*Service) GetAllBalances

func (service *Service) GetAllBalances(r *http.Request, args *GetAllBalancesArgs, reply *GetAllBalancesReply) error

GetAllBalances returns a map where:

Key: ID of an asset such that [args.Address] has a non-zero balance of the asset
Value: The balance of the asset held by the address

If ![args.IncludePartial], returns only unlocked balance/UTXOs with a 1-out-of-1 multisig. Otherwise, returned balance/UTXOs includes assets held only partially by the address, and includes balances with locktime in the future.

func (*Service) GetAssetDescription

func (service *Service) GetAssetDescription(_ *http.Request, args *GetAssetDescriptionArgs, reply *GetAssetDescriptionReply) error

GetAssetDescription creates an empty account with the name passed in

func (*Service) GetBalance

func (service *Service) GetBalance(r *http.Request, args *GetBalanceArgs, reply *GetBalanceReply) error

GetBalance returns the balance of an asset held by an address. If ![args.IncludePartial], returns only the balance held solely (1 out of 1 multisig) by the address and with a locktime in the past. Otherwise, returned balance includes assets held only partially by the address, and includes balances with locktime in the future.

func (*Service) GetTx

func (service *Service) GetTx(r *http.Request, args *api.GetTxArgs, reply *api.GetTxReply) error

GetTx returns the specified transaction

func (*Service) GetTxStatus

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

GetTxStatus returns the status of the specified transaction

func (*Service) GetUTXOs

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

GetUTXOs gets all utxos for passed in addresses

func (*Service) Import

func (service *Service) Import(_ *http.Request, args *ImportArgs, reply *api.JSONTxID) error

Import imports an asset to this chain from the P/C-Chain. The DJTX must have already been exported from the P/C-Chain. Returns the ID of the newly created atomic transaction

func (*Service) ImportKey

func (service *Service) ImportKey(r *http.Request, args *ImportKeyArgs, reply *api.JSONAddress) error

ImportKey adds a private key to the provided user

func (*Service) IssueStopVertex

func (service *Service) IssueStopVertex(_ *http.Request, _ *struct{}, _ *struct{}) error

func (*Service) IssueTx

func (service *Service) IssueTx(r *http.Request, args *api.FormattedTx, reply *api.JSONTxID) error

IssueTx attempts to issue a transaction into consensus

func (*Service) ListAddresses

func (service *Service) ListAddresses(_ *http.Request, args *api.UserPass, response *api.JSONAddresses) error

ListAddresses returns all of the addresses controlled by user [args.Username]

func (*Service) Mint

func (service *Service) Mint(r *http.Request, args *MintArgs, reply *api.JSONTxIDChangeAddr) error

Mint issues a transaction that mints more of the asset

func (*Service) MintNFT

func (service *Service) MintNFT(r *http.Request, args *MintNFTArgs, reply *api.JSONTxIDChangeAddr) error

MintNFT issues a MintNFT transaction and returns the ID of the newly created transaction

func (*Service) Send

func (service *Service) Send(r *http.Request, args *SendArgs, reply *api.JSONTxIDChangeAddr) error

Send returns the ID of the newly created transaction

func (*Service) SendMultiple

func (service *Service) SendMultiple(r *http.Request, args *SendMultipleArgs, reply *api.JSONTxIDChangeAddr) error

SendMultiple sends a transaction with multiple outputs.

func (*Service) SendNFT

func (service *Service) SendNFT(r *http.Request, args *SendNFTArgs, reply *api.JSONTxIDChangeAddr) error

SendNFT sends an NFT

type State

type State interface {
	djtx.UTXOState
	djtx.StatusState
	djtx.SingletonState
	TxState
	DeduplicateTx(tx *UniqueTx) *UniqueTx
}

State persistently maintains a set of UTXOs, transaction, statuses, and singletons.

func NewState

func NewState(config StateConfig) (State, error)

type StateConfig added in v1.7.11

type StateConfig struct {
	DB                  database.Database
	GenesisCodec, Codec codec.Manager
	Metrics             prometheus.Registerer
}

type StaticClient added in v1.7.11

type StaticClient interface {
	BuildGenesis(ctx context.Context, args *BuildGenesisArgs, options ...rpc.Option) (*BuildGenesisReply, error)
}

StaticClient for interacting with the AVM static api

func NewStaticClient added in v1.7.11

func NewStaticClient(uri string) StaticClient

NewClient returns an AVM client for interacting with the avm static api

type StaticService

type StaticService struct{}

StaticService defines the base service for the asset vm

func CreateStaticService

func CreateStaticService() *StaticService

func (*StaticService) BuildGenesis

func (ss *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 {
	UnsignedTx `serialize:"true" json:"unsignedTx"`

	Creds []*fxs.FxCredential `serialize:"true" json:"credentials"` // The credentials of this transaction
}

Tx is the core operation that can be performed. The tx uses the UTXO model. Specifically, a txs inputs will consume previous txs 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) Credentials

func (t *Tx) Credentials() []verify.Verifiable

Credentials describes the authorization that allows the Inputs to consume the specified UTXOs. The returned array should not be modified.

func (*Tx) Init

func (t *Tx) Init(vm *VM) error

Init initializes FxID where required Used for JSON marshaling of data

func (*Tx) SemanticVerify

func (t *Tx) SemanticVerify(vm *VM, tx UnsignedTx) error

SemanticVerify verifies that this transaction is well-formed.

func (*Tx) SignNFTFx

func (t *Tx) SignNFTFx(c codec.Manager, signers [][]*crypto.PrivateKeySECP256K1R) error

func (*Tx) SignPropertyFx

func (t *Tx) SignPropertyFx(c codec.Manager, signers [][]*crypto.PrivateKeySECP256K1R) error

func (*Tx) SignSECP256K1Fx

func (t *Tx) SignSECP256K1Fx(c codec.Manager, signers [][]*crypto.PrivateKeySECP256K1R) error

func (*Tx) SyntacticVerify

func (t *Tx) SyntacticVerify(
	ctx *snow.Context,
	c codec.Manager,
	txFeeAssetID ids.ID,
	txFee uint64,
	creationTxFee uint64,
	numFxs int,
) error

SyntacticVerify verifies that this transaction is well-formed.

type TxCachedState

type TxCachedState struct {
	*txs.Tx
	// contains filtered or unexported fields
}

type TxState

type TxState interface {
	// Tx attempts to load a transaction from storage.
	GetTx(txID ids.ID) (*Tx, error)

	// PutTx saves the provided transaction to storage.
	PutTx(txID ids.ID, tx *Tx) error

	// DeleteTx removes the provided transaction from storage.
	DeleteTx(txID ids.ID) error
}

TxState is a thin wrapper around a database to provide, caching, serialization, and de-serialization of transactions.

func NewMeteredTxState

func NewMeteredTxState(db database.Database, codec codec.Manager, metrics prometheus.Registerer) (TxState, error)

func NewTxState

func NewTxState(db database.Database, codec codec.Manager) TxState

type UniqueTx

type UniqueTx struct {
	*TxCachedState
	// 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, error)

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

func (tx *UniqueTx) HasWhitelist() bool

Whitelist is not supported by this transaction type, so [false] is returned.

func (*UniqueTx) ID

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

ID returns the wrapped txID

func (*UniqueTx) InputIDs

func (tx *UniqueTx) InputIDs() []ids.ID

InputIDs returns the set of utxoIDs this transaction consumes

func (*UniqueTx) InputUTXOs

func (tx *UniqueTx) InputUTXOs() []*djtx.UTXOID

InputUTXOs returns the utxos that will be consumed on tx acceptance

func (*UniqueTx) Key

func (tx *UniqueTx) Key() interface{}

func (*UniqueTx) Reject

func (tx *UniqueTx) Reject() error

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

func (*UniqueTx) SemanticVerify

func (tx *UniqueTx) SemanticVerify() error

SemanticVerify the validity of this transaction

func (*UniqueTx) Status

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

Status returns the current status of this transaction

func (*UniqueTx) SyntacticVerify

func (tx *UniqueTx) SyntacticVerify() error

SyntacticVerify verifies that this transaction is well formed

func (*UniqueTx) UTXOs

func (tx *UniqueTx) UTXOs() []*djtx.UTXO

UTXOs returns the utxos that will be added to the UTXO set on tx acceptance

func (*UniqueTx) Verify

func (tx *UniqueTx) Verify() error

Verify the validity of this transaction

func (*UniqueTx) Whitelist

func (tx *UniqueTx) Whitelist() (ids.Set, error)

Whitelist is not supported by this transaction type, so [false] is returned.

type UnsignedTx

type UnsignedTx interface {
	Init(*VM) error
	Initialize(unsignedBytes, bytes []byte)
	ID() ids.ID
	UnsignedBytes() []byte
	Bytes() []byte

	ConsumedAssetIDs() ids.Set
	AssetIDs() ids.Set

	NumCredentials() int
	InputUTXOs() []*djtx.UTXOID
	UTXOs() []*djtx.UTXO

	SyntacticVerify(
		ctx *snow.Context,
		c codec.Manager,
		txFeeAssetID ids.ID,
		txFee uint64,
		creationTxFee uint64,
		numFxs int,
	) error
	SemanticVerify(vm *VM, tx UnsignedTx, creds []verify.Verifiable) error
	ExecuteWithSideEffects(vm *VM, batch database.Batch) error
}

type VM

type VM struct {
	Factory

	djtx.AddressManager
	djtx.AtomicUTXOManager
	ids.Aliaser
	// contains filtered or unexported fields
}

func (*VM) AppGossip

func (vm *VM) AppGossip(nodeID ids.NodeID, msg []byte) error

This VM doesn't (currently) have any app-specific messages

func (*VM) AppRequest

func (vm *VM) AppRequest(nodeID ids.NodeID, requestID uint32, deadline time.Time, request []byte) error

This VM doesn't (currently) have any app-specific messages

func (*VM) AppRequestFailed

func (vm *VM) AppRequestFailed(nodeID ids.NodeID, requestID uint32) error

This VM doesn't (currently) have any app-specific messages

func (*VM) AppResponse

func (vm *VM) AppResponse(nodeID ids.NodeID, requestID uint32, response []byte) error

This VM doesn't (currently) have any app-specific messages

func (*VM) Connected

func (vm *VM) Connected(nodeID ids.NodeID, nodeVersion version.Application) error

func (*VM) CreateHandlers

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

func (*VM) CreateStaticHandlers

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

func (*VM) DeduplicateTx added in v1.7.13

func (vm *VM) DeduplicateTx(tx *UniqueTx) *UniqueTx

UniqueTx de-duplicates the transaction.

func (*VM) Disconnected

func (vm *VM) Disconnected(nodeID ids.NodeID) error

func (*VM) FlushTxs

func (vm *VM) FlushTxs()

FlushTxs into consensus

func (*VM) GetTx

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

func (*VM) HealthCheck

func (vm *VM) HealthCheck() (interface{}, error)

TODO: add health checks

func (*VM) Initialize

func (vm *VM) Initialize(
	ctx *snow.Context,
	dbManager manager.Manager,
	genesisBytes []byte,
	upgradeBytes []byte,
	configBytes []byte,
	toEngine chan<- common.Message,
	fxs []*common.Fx,
	_ common.AppSender,
) error

func (*VM) IssueTx

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

IssueTx attempts to send a transaction to consensus. If onDecide is specified, the function will be called when the transaction is either accepted or rejected with the appropriate status. This function will go out of scope when the transaction is removed from memory.

func (*VM) LoadUser

func (vm *VM) LoadUser(
	username string,
	password string,
	addrsToUse ids.ShortSet,
) (
	[]*djtx.UTXO,
	*secp256k1fx.Keychain,
	error,
)

LoadUser returns: 1) The UTXOs that reference one or more addresses controlled by the given user 2) A keychain that contains this user's keys If [addrsToUse] has positive length, returns UTXOs that reference one or more addresses controlled by the given user that are also in [addrsToUse].

func (*VM) Mint

func (vm *VM) Mint(
	utxos []*djtx.UTXO,
	kc *secp256k1fx.Keychain,
	amounts map[ids.ID]uint64,
	to ids.ShortID,
) (
	[]*txs.Operation,
	[][]*crypto.PrivateKeySECP256K1R,
	error,
)

func (*VM) MintNFT

func (vm *VM) MintNFT(
	utxos []*djtx.UTXO,
	kc *secp256k1fx.Keychain,
	assetID ids.ID,
	payload []byte,
	to ids.ShortID,
) (
	[]*txs.Operation,
	[][]*crypto.PrivateKeySECP256K1R,
	error,
)

func (*VM) ParseTx

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

func (*VM) PendingTxs

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

func (*VM) SetState

func (vm *VM) SetState(state snow.State) error

func (*VM) Shutdown

func (vm *VM) Shutdown() error

func (*VM) Spend

func (vm *VM) Spend(
	utxos []*djtx.UTXO,
	kc *secp256k1fx.Keychain,
	amounts map[ids.ID]uint64,
) (
	map[ids.ID]uint64,
	[]*djtx.TransferableInput,
	[][]*crypto.PrivateKeySECP256K1R,
	error,
)

func (*VM) SpendAll

func (vm *VM) SpendAll(
	utxos []*djtx.UTXO,
	kc *secp256k1fx.Keychain,
) (
	map[ids.ID]uint64,
	[]*djtx.TransferableInput,
	[][]*crypto.PrivateKeySECP256K1R,
	error,
)

func (*VM) SpendNFT

func (vm *VM) SpendNFT(
	utxos []*djtx.UTXO,
	kc *secp256k1fx.Keychain,
	assetID ids.ID,
	groupID uint32,
	to ids.ShortID,
) (
	[]*txs.Operation,
	[][]*crypto.PrivateKeySECP256K1R,
	error,
)

func (*VM) Version

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

type WalletClient

type WalletClient interface {
	// IssueTx issues a transaction to a node and returns the TxID
	IssueTx(ctx context.Context, tx []byte, options ...rpc.Option) (ids.ID, error)
	// Send [amount] of [assetID] to address [to]
	Send(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		amount uint64,
		assetID string,
		to ids.ShortID,
		memo string,
		options ...rpc.Option,
	) (ids.ID, error)
	// SendMultiple sends a transaction from [user] funding all [outputs]
	SendMultiple(
		ctx context.Context,
		user api.UserPass,
		from []ids.ShortID,
		changeAddr ids.ShortID,
		outputs []ClientSendOutput,
		memo string,
		options ...rpc.Option,
	) (ids.ID, error)
}

interface of an AVM wallet client for interacting with avm managed wallet on [chain]

func NewWalletClient

func NewWalletClient(uri, chain string) WalletClient

NewWalletClient returns an AVM wallet client for interacting with avm managed wallet on [chain]

type WalletService

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

func (*WalletService) IssueTx

func (w *WalletService) IssueTx(r *http.Request, args *api.FormattedTx, reply *api.JSONTxID) error

IssueTx attempts to issue a transaction into consensus

func (*WalletService) Send

func (w *WalletService) Send(r *http.Request, args *SendArgs, reply *api.JSONTxIDChangeAddr) error

Send returns the ID of the newly created transaction

func (*WalletService) SendMultiple

func (w *WalletService) SendMultiple(r *http.Request, args *SendMultipleArgs, reply *api.JSONTxIDChangeAddr) error

SendMultiple sends a transaction with multiple outputs.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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