wallet

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: Apache-2.0, BSD-2-Clause Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPollingInterval is the polling interval of the wallet when waiting for confirmation (in ms).
	DefaultPollingInterval = 500 * time.Millisecond
	// DefaultConfirmationTimeout is the timeout of waiting for confirmation. (in ms).
	DefaultConfirmationTimeout = 150000 * time.Millisecond
	// DefaultAssetRegistryNetwork is the default asset registry network.
	DefaultAssetRegistryNetwork = "nectar"
)
View Source
const (
	// RegistryHostURL is the host url of the central registry.
	RegistryHostURL = "http://asset-registry.zipp.org"
)

Variables

View Source
var ErrTooManyOutputs = errors.New("number of outputs is more, than supported for a single transaction")

ErrTooManyOutputs is an error returned when the number of outputs/inputs exceeds the protocol wide constant.

Functions

This section is empty.

Types

type AddressManager

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

AddressManager is an manager struct that allows us to keep track of the used and spent addresses.

func NewAddressManager

func NewAddressManager(seed *seed.Seed, lastAddressIndex uint64, spentAddresses []bitmask.BitMask) (addressManager *AddressManager)

NewAddressManager is the constructor for the AddressManager type.

func (*AddressManager) Address

func (addressManager *AddressManager) Address(addressIndex uint64) address.Address

Address returns the address that belongs to the given index.

func (*AddressManager) Addresses

func (addressManager *AddressManager) Addresses() (addresses []address.Address)

Addresses returns a list of all addresses of the wallet.

func (*AddressManager) FirstUnspentAddress

func (addressManager *AddressManager) FirstUnspentAddress() address.Address

FirstUnspentAddress returns the first unspent address that we know.

func (*AddressManager) IsAddressSpent

func (addressManager *AddressManager) IsAddressSpent(addressIndex uint64) bool

IsAddressSpent returns true if the address given by the address index was spent already.

func (*AddressManager) LastUnspentAddress

func (addressManager *AddressManager) LastUnspentAddress() address.Address

LastUnspentAddress returns the last unspent address that we know.

func (*AddressManager) MarkAddressSpent

func (addressManager *AddressManager) MarkAddressSpent(addressIndex uint64)

MarkAddressSpent marks the given address as spent.

func (*AddressManager) NewAddress

func (addressManager *AddressManager) NewAddress() address.Address

NewAddress generates and returns a new unused address.

func (*AddressManager) SpentAddresses

func (addressManager *AddressManager) SpentAddresses() (addresses []address.Address)

SpentAddresses returns a list of all spent addresses of the wallet.

func (*AddressManager) UnspentAddresses

func (addressManager *AddressManager) UnspentAddresses() (addresses []address.Address)

UnspentAddresses returns a list of all unspent addresses of the wallet.

type Asset

type Asset struct {
	// Color contains the identifier of this asset
	Color devnetvm.Color

	// Name of the asset
	Name string `serix:"1,lengthPrefixType=uint32"`

	// currency symbol of the asset (optional)
	Symbol string `serix:"2,lengthPrefixType=uint32"`

	// Precision defines how many decimal places are shown when showing this asset in wallets
	Precision uint32 `serix:"3"`

	// Supply is the amount of tokens that we want to create
	Supply uint64 `serix:"4"`

	// TransactionID that created the asset
	TransactionID utxo.TransactionID `serix:"5"`
}

Asset represents a container for all the information regarding a colored coin.

func AssetFromRegistryEntry

func AssetFromRegistryEntry(regAsset *registry.Asset) (*Asset, error)

AssetFromRegistryEntry creates a wallet asset from a registry asset.

func (*Asset) ToRegistry

func (a *Asset) ToRegistry() *registry.Asset

ToRegistry creates a registry asset from a wallet asset.

type AssetRegistry

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

AssetRegistry represents a registry for colored coins, that stores the relevant metadata in a dictionary.

func NewAssetRegistry

func NewAssetRegistry(network string, registryURL ...string) *AssetRegistry

NewAssetRegistry is the constructor for the AssetRegistry.

func ParseAssetRegistry

func ParseAssetRegistry(marshalUtil *marshalutil.MarshalUtil) (assetRegistry *AssetRegistry, consumedBytes int, err error)

ParseAssetRegistry is a utility function that can be used to parse a marshaled version of the registry.

func (*AssetRegistry) Bytes

func (a *AssetRegistry) Bytes() []byte

Bytes marshal the registry into a sequence of bytes.

func (*AssetRegistry) LoadAsset

func (a *AssetRegistry) LoadAsset(id devnetvm.Color) (*Asset, error)

LoadAsset returns an asset either from local or from central registry.

func (*AssetRegistry) Name

func (a *AssetRegistry) Name(color devnetvm.Color) string

Name returns the name of the given asset.

func (*AssetRegistry) Network

func (a *AssetRegistry) Network() string

Network returns the current network the asset registry connects to.

func (*AssetRegistry) Precision

func (a *AssetRegistry) Precision(color devnetvm.Color) int

Precision returns the amount of decimal places that this token uses.

func (*AssetRegistry) RegisterAsset

func (a *AssetRegistry) RegisterAsset(color devnetvm.Color, asset Asset) error

RegisterAsset registers an asset in the registry, so we can look up names and symbol of colored coins.

func (*AssetRegistry) SetRegistryURL

func (a *AssetRegistry) SetRegistryURL(url string)

SetRegistryURL sets the url of the registry api server.

func (*AssetRegistry) Supply

func (a *AssetRegistry) Supply(color devnetvm.Color) string

Supply returns the initial supply of the token.

func (*AssetRegistry) Symbol

func (a *AssetRegistry) Symbol(color devnetvm.Color) string

Symbol return the symbol of the token.

func (*AssetRegistry) TransactionID

func (a *AssetRegistry) TransactionID(color devnetvm.Color) string

TransactionID returns the ID of the transaction that created the token.

type Connector

type Connector interface {
	UnspentOutputs(addresses ...address.Address) (unspentOutputs OutputsByAddressAndOutputID, err error)
	SendTransaction(transaction *devnetvm.Transaction) (err error)
	RequestFaucetFunds(address address.Address, powTarget int) (err error)
	GetAllowedPledgeIDs() (pledgeIDMap map[mana.Type][]string, err error)
	GetTransactionConfirmationState(txID utxo.TransactionID) (confirmationState confirmation.State, err error)
	GetUnspentAliasOutput(address *devnetvm.AliasAddress) (output *devnetvm.AliasOutput, err error)
}

Connector represents an interface that defines how the wallet interacts with the network. A wallet can either be used locally on a server or it can connect remotely using the web API.

type Option

type Option func(*Wallet)

Option represents an optional parameter .

func AssetRegistryNetwork

func AssetRegistryNetwork(network string) Option

AssetRegistryNetwork defines which network we intend to use for asset lookups.

func ConfirmationPollingInterval

func ConfirmationPollingInterval(interval time.Duration) Option

ConfirmationPollingInterval defines how often the wallet polls the node for confirmation info.

func ConfirmationTimeout

func ConfirmationTimeout(timeout time.Duration) Option

ConfirmationTimeout defines the timeout for waiting for tx confirmation.

func FaucetPowDifficulty

func FaucetPowDifficulty(powTarget int) Option

FaucetPowDifficulty configures the wallet with the faucet's target PoW difficulty.

func GenericConnector

func GenericConnector(connector Connector) Option

GenericConnector allows us to provide a generic connector to the wallet. It can be used to mock the behavior of a real connector in tests or to provide new connection methods for nodes.

func Import

func Import(seed *seed.Seed, lastAddressIndex uint64, spentAddresses []bitmask.BitMask, assetRegistry *AssetRegistry) Option

Import restores a wallet that has previously been created.

func ReusableAddress

func ReusableAddress(enabled bool) Option

ReusableAddress configures the wallet to run in "single address" mode where all the funds are always managed on a single reusable address.

func Stateless

func Stateless(stateless bool) Option

Stateless allows to run the wallet in a stateless mode, meaning outputs will always be refreshed from the connector.

func WebAPI

func WebAPI(baseURL string, setters ...client.Option) Option

WebAPI connects the wallet with the remote API of a node.

type Output

type Output struct {
	Address                  address.Address
	Object                   devnetvm.Output
	Metadata                 OutputMetadata
	ConfirmationStateReached bool
	// Spent is a local wallet-only property that gets set once an output is spent from within the same wallet.
	Spent bool
}

Output is a wallet specific representation of an output in the IOTA network.

type OutputManager

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

OutputManager keeps track of the outputs.

func NewUnspentOutputManager

func NewUnspentOutputManager(addressManager *AddressManager, connector Connector, stateless bool) (outputManager *OutputManager)

NewUnspentOutputManager creates a new UnspentOutputManager.

func (*OutputManager) MarkOutputSpent

func (o *OutputManager) MarkOutputSpent(addy address.Address, outputID utxo.OutputID)

MarkOutputSpent marks the output identified by the given parameters as spent.

func (*OutputManager) Refresh

func (o *OutputManager) Refresh(includeSpentAddresses ...bool) error

Refresh checks for unspent outputs on the addresses provided by address manager and updates the internal state.

func (*OutputManager) UnspentAliasOutputs

func (o *OutputManager) UnspentAliasOutputs(includePending bool, addresses ...address.Address) (unspentOutputs OutputsByAddressAndOutputID)

UnspentAliasOutputs returns the alias type outputs that have not been spent, yet.

func (*OutputManager) UnspentConditionalOutputs

func (o *OutputManager) UnspentConditionalOutputs(includePending bool, addresses ...address.Address) (unspentOutputs OutputsByAddressAndOutputID)

UnspentConditionalOutputs returns the ExtendedLockedoutputs that are conditionally owned by the wallet right now and have not been spent yet. Such outputs can be claimed by the wallet.

func (*OutputManager) UnspentOutputs

func (o *OutputManager) UnspentOutputs(includePending bool, addresses ...address.Address) (unspentOutputs OutputsByAddressAndOutputID)

UnspentOutputs returns the all outputs that have not been spent, yet.

func (*OutputManager) UnspentValueOutputs

func (o *OutputManager) UnspentValueOutputs(includePending bool, addresses ...address.Address) (unspentOutputs OutputsByAddressAndOutputID)

UnspentValueOutputs returns the value type outputs that have not been spent, yet.

type OutputMetadata

type OutputMetadata struct {
	// Timestamp is the timestamp of the tx that created the output.
	Timestamp time.Time
}

OutputMetadata is metadata about the output.

type OutputsByAddressAndOutputID

type OutputsByAddressAndOutputID map[address.Address]map[utxo.OutputID]*Output

func NewAddressToOutputs

func NewAddressToOutputs() OutputsByAddressAndOutputID

NewAddressToOutputs creates an empty container.

func (OutputsByAddressAndOutputID) AliasOutputsOnly

AliasOutputsOnly filters out any non-alias outputs.

func (OutputsByAddressAndOutputID) ConditionalOutputsOnly

func (o OutputsByAddressAndOutputID) ConditionalOutputsOnly() OutputsByAddressAndOutputID

ConditionalOutputsOnly return ExtendedLockedOutputs that are currently conditionally owned by the wallet.

func (OutputsByAddressAndOutputID) OutputCount

func (o OutputsByAddressAndOutputID) OutputCount() int

OutputCount returns the number of outputs in the struct.

func (OutputsByAddressAndOutputID) OutputsByID

func (o OutputsByAddressAndOutputID) OutputsByID() (outputsByID OutputsByID)

OutputsByID returns a collection of Outputs associated with their OutputID.

func (OutputsByAddressAndOutputID) SplitIntoChunksOfMaxInputCount

func (o OutputsByAddressAndOutputID) SplitIntoChunksOfMaxInputCount() []OutputsByAddressAndOutputID

SplitIntoChunksOfMaxInputCount splits the mapping into chunks that contain at most ledgerstate.MaxInputCount outputs.

func (OutputsByAddressAndOutputID) ToLedgerStateOutputs

func (o OutputsByAddressAndOutputID) ToLedgerStateOutputs() devnetvm.Outputs

ToLedgerStateOutputs transforms all outputs in the mapping into a slice of ledgerstate outputs.

func (OutputsByAddressAndOutputID) TotalFundsInOutputs

func (o OutputsByAddressAndOutputID) TotalFundsInOutputs() map[devnetvm.Color]uint64

TotalFundsInOutputs returns the total funds present in the outputs.

func (OutputsByAddressAndOutputID) ValueOutputsOnly

ValueOutputsOnly filters out non-value type outputs (aliases).

type OutputsByID

type OutputsByID map[utxo.OutputID]*Output

OutputsByID is a collection of Outputs associated with their OutputID.

func (OutputsByID) OutputsByAddressAndOutputID

func (o OutputsByID) OutputsByAddressAndOutputID() (outputsByAddressAndOutputID OutputsByAddressAndOutputID)

OutputsByAddressAndOutputID returns a collection of Outputs associated with their Address and OutputID.

type ServerStatus

type ServerStatus struct {
	ID      string
	Synced  bool
	Version string
}

ServerStatus defines the information of connected server

type TimedBalance

type TimedBalance struct {
	Balance map[devnetvm.Color]uint64
	Time    time.Time
}

TimedBalance represents a balance that is time dependent.

type TimedBalanceSlice

type TimedBalanceSlice []*TimedBalance

TimedBalanceSlice is a slice containing TimedBalances.

func (TimedBalanceSlice) Sort

func (t TimedBalanceSlice) Sort()

Sort sorts the balances based on their Time.

type Wallet

type Wallet struct {
	ConfirmationPollInterval time.Duration
	ConfirmationTimeout      time.Duration
	Stateless                bool
	// contains filtered or unexported fields
}

Wallet is a wallet that can handle aliases and extendedlockedoutputs.

func New

func New(options ...Option) (wallet *Wallet)

New is the factory method of the wallet. It either creates a new wallet or restores the wallet backup that is handed in as an optional parameter.

func (*Wallet) AddressManager

func (wallet *Wallet) AddressManager() *AddressManager

AddressManager returns the manager for the addresses of this wallet.

func (*Wallet) AliasBalance

func (wallet *Wallet) AliasBalance(refresh ...bool) (
	confirmedGovernedAliases,
	confirmedStateControlledAliases,
	pendingGovernedAliases,
	pendingStateControlledAliases map[devnetvm.AliasAddress]*devnetvm.AliasOutput,
	err error,
)

AliasBalance returns the aliases held by this wallet.

func (*Wallet) AllowedPledgeNodeIDs added in v0.1.2

func (wallet *Wallet) AllowedPledgeNodeIDs() (res map[mana.Type][]string, err error)

AllowedPledgeNodeIDs retrieves the allowed pledge node IDs.

func (*Wallet) AssetRegistry

func (wallet *Wallet) AssetRegistry() *AssetRegistry

AssetRegistry return the internal AssetRegistry instance of the wallet.

func (*Wallet) AvailableBalance

func (wallet *Wallet) AvailableBalance(refresh ...bool) (confirmedBalance, pendingBalance map[devnetvm.Color]uint64, err error)

AvailableBalance returns the balance that is not held in aliases, and therefore can be used to fund transfers.

func (Wallet) AvailableOutputsOnNFT

func (wallet Wallet) AvailableOutputsOnNFT(nftID string) (owned, governed devnetvm.Outputs, err error)

AvailableOutputsOnNFT returns all outputs that are either owned (SigLocked***, Extended, stateControlled Alias) or governed (governance controlled alias outputs) and are not currently locked.

func (*Wallet) Balance

func (wallet *Wallet) Balance(refresh ...bool) (confirmedBalance, pendingBalance map[devnetvm.Color]uint64, err error)

Balance returns the confirmed and pending balance of the funds managed by this wallet.

func (*Wallet) ClaimConditionalFunds

func (wallet *Wallet) ClaimConditionalFunds(options ...claimconditionaloptions.ClaimConditionalFundsOption) (tx *devnetvm.Transaction, err error)

ClaimConditionalFunds gathers all currently conditionally owned outputs and consolidates them into the output.

func (*Wallet) ConditionalBalances

func (wallet *Wallet) ConditionalBalances(refresh ...bool) (confirmed, pending TimedBalanceSlice, err error)

ConditionalBalances returns all confirmed and pending balances that can be claimed by the wallet up to a certain time.

func (*Wallet) ConsolidateFunds

func (wallet *Wallet) ConsolidateFunds(options ...consolidateoptions.ConsolidateFundsOption) (txs []*devnetvm.Transaction, err error)

ConsolidateFunds consolidates available wallet funds into one output.

func (*Wallet) CreateAsset

func (wallet *Wallet) CreateAsset(asset Asset, waitForConfirmation ...bool) (assetColor devnetvm.Color, err error)

CreateAsset creates a new colored token with the given details.

func (*Wallet) CreateNFT

func (wallet *Wallet) CreateNFT(options ...createnftoptions.CreateNFTOption) (tx *devnetvm.Transaction, nftID *devnetvm.AliasAddress, err error)

CreateNFT spends funds from the wallet to create an NFT.

func (*Wallet) DelegatedAliasBalance

func (wallet *Wallet) DelegatedAliasBalance(refresh ...bool) (
	confirmedDelegatedAliases map[devnetvm.AliasAddress]*devnetvm.AliasOutput,
	pendingDelegatedAliases map[devnetvm.AliasAddress]*devnetvm.AliasOutput,
	err error,
)

DelegatedAliasBalance returns the pending and confirmed aliases that are delegated.

func (*Wallet) DepositFundsToNFT

func (wallet *Wallet) DepositFundsToNFT(options ...deposittonftoptions.DepositFundsToNFTOption) (tx *devnetvm.Transaction, err error)

DepositFundsToNFT deposits funds to the given alias from the wallet funds. If the wallet is not the state controller, an error is returned.

func (*Wallet) DestroyNFT

func (wallet *Wallet) DestroyNFT(options ...destroynftoptions.DestroyNFTOption) (tx *devnetvm.Transaction, err error)

DestroyNFT destroys the given nft (alias).

func (*Wallet) ExportState

func (wallet *Wallet) ExportState() []byte

ExportState exports the current state of the wallet to a marshaled version.

func (*Wallet) NewReceiveAddress

func (wallet *Wallet) NewReceiveAddress() address.Address

NewReceiveAddress generates and returns a new unused receive address.

func (*Wallet) ReceiveAddress

func (wallet *Wallet) ReceiveAddress() address.Address

ReceiveAddress returns the last receive address of the wallet.

func (*Wallet) Refresh

func (wallet *Wallet) Refresh(rescanSpentAddresses ...bool) (err error)

Refresh scans the addresses for incoming transactions. If the optional rescanSpentAddresses parameter is set to true we also scan the spent addresses again (this can take longer).

func (*Wallet) RemainderAddress

func (wallet *Wallet) RemainderAddress() address.Address

RemainderAddress returns the address that is used for the remainder of funds.

func (*Wallet) RequestFaucetFunds

func (wallet *Wallet) RequestFaucetFunds(waitForConfirmation ...bool) (err error)

RequestFaucetFunds requests some funds from the faucet for testing purposes.

func (*Wallet) Seed

func (wallet *Wallet) Seed() *seed.Seed

Seed returns the seed of this wallet that is used to generate all of the wallets addresses and private keys.

func (*Wallet) SendFunds

func (wallet *Wallet) SendFunds(options ...sendoptions.SendFundsOption) (tx *devnetvm.Transaction, err error)

SendFunds sends funds from the wallet.

func (*Wallet) ServerStatus

func (wallet *Wallet) ServerStatus() (status ServerStatus, err error)

ServerStatus retrieves the connected server status.

func (Wallet) SweepNFTOwnedFunds

func (wallet Wallet) SweepNFTOwnedFunds(options ...sweepnftownedoptions.SweepNFTOwnedFundsOption) (tx *devnetvm.Transaction, err error)

SweepNFTOwnedFunds collects all funds from non-alias outputs that are owned by the nft into the wallet.

func (*Wallet) SweepNFTOwnedNFTs

func (wallet *Wallet) SweepNFTOwnedNFTs(options ...sweepnftownednftsoptions.SweepNFTOwnedNFTsOption) (tx *devnetvm.Transaction, sweptNFTs []*devnetvm.AliasAddress, err error)

func (*Wallet) TimelockedBalances

func (wallet *Wallet) TimelockedBalances(refresh ...bool) (confirmed, pending TimedBalanceSlice, err error)

TimelockedBalances returns all confirmed and pending balances that are currently timelocked.

func (*Wallet) TransferNFT

func (wallet *Wallet) TransferNFT(options ...transfernftoptions.TransferNFTOption) (tx *devnetvm.Transaction, err error)

TransferNFT transfers an NFT to a given address.

func (*Wallet) UnspentAliasOutputs

func (wallet *Wallet) UnspentAliasOutputs(includePending bool) map[address.Address]map[utxo.OutputID]*Output

UnspentAliasOutputs returns the unspent alias outputs that are available for spending.

func (*Wallet) UnspentOutputs

func (wallet *Wallet) UnspentOutputs() map[address.Address]map[utxo.OutputID]*Output

UnspentOutputs returns the unspent outputs that are available for spending.

func (*Wallet) UnspentValueOutputs

func (wallet *Wallet) UnspentValueOutputs() map[address.Address]map[utxo.OutputID]*Output

UnspentValueOutputs returns the unspent value type outputs that are available for spending.

func (*Wallet) WaitForTxAcceptance

func (wallet *Wallet) WaitForTxAcceptance(txID utxo.TransactionID, optionalCtx ...context.Context) (err error)

WaitForTxAcceptance waits for the given tx to be accepted.

func (*Wallet) WithdrawFundsFromNFT

func (wallet *Wallet) WithdrawFundsFromNFT(options ...withdrawfromnftoptions.WithdrawFundsFromNFTOption) (tx *devnetvm.Transaction, err error)

WithdrawFundsFromNFT withdraws funds from the given alias. If the wallet is not the state controller, or too much funds are withdrawn, an error is returned.

type WebConnector

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

WebConnector implements a connector that uses the web API to connect to a node to implement the required functions for the wallet.

func NewWebConnector

func NewWebConnector(baseURL string, setters ...client.Option) *WebConnector

NewWebConnector is the constructor for the WebConnector.

func (WebConnector) GetAllowedPledgeIDs added in v0.1.2

func (webConnector WebConnector) GetAllowedPledgeIDs() (pledgeIDMap map[mana.Type][]string, err error)

GetAllowedPledgeIDs gets the list of nodeIDs that the node accepts as pledgeIDs in a transaction.

func (WebConnector) GetTransactionConfirmationState

func (webConnector WebConnector) GetTransactionConfirmationState(txID utxo.TransactionID) (confirmationState confirmation.State, err error)

GetTransactionConfirmationState fetches the ConfirmationState of the transaction.

func (WebConnector) GetUnspentAliasOutput

func (webConnector WebConnector) GetUnspentAliasOutput(addr *devnetvm.AliasAddress) (output *devnetvm.AliasOutput, err error)

GetUnspentAliasOutput returns the current unspent alias output that belongs to a given alias address.

func (*WebConnector) RequestFaucetFunds

func (webConnector *WebConnector) RequestFaucetFunds(addr address.Address, powTarget int) (err error)

RequestFaucetFunds request some funds from the faucet for test purposes.

func (WebConnector) SendTransaction

func (webConnector WebConnector) SendTransaction(tx *devnetvm.Transaction) (err error)

SendTransaction sends a new transaction to the network.

func (*WebConnector) ServerStatus

func (webConnector *WebConnector) ServerStatus() (status ServerStatus, err error)

ServerStatus retrieves the connected server status with Info api.

func (WebConnector) UnspentOutputs

func (webConnector WebConnector) UnspentOutputs(addresses ...address.Address) (unspentOutputs OutputsByAddressAndOutputID, err error)

UnspentOutputs returns the outputs of transactions on the given addresses that have not been spent yet.

Jump to

Keyboard shortcuts

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