wallet

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: Apache-2.0, BSD-2-Clause Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 ledgerstate.Color

	// Name of the asset
	Name string

	// currency symbol of the asset (optional)
	Symbol string

	// Precision defines how many decimal places are shown when showing this asset in wallets
	Precision int

	// Address defines the target address where the asset is supposed to be created
	Address ledgerstate.Address

	// the amount of tokens that we want to create
	Amount uint64
}

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

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() *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 (assetRegistry *AssetRegistry) Bytes() []byte

Bytes marshal the registry into a sequence of bytes.

func (*AssetRegistry) Name

func (assetRegistry *AssetRegistry) Name(color ledgerstate.Color) string

Name returns the name of the given asset.

func (*AssetRegistry) Precision

func (assetRegistry *AssetRegistry) Precision(color ledgerstate.Color) int

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

func (*AssetRegistry) RegisterAsset

func (assetRegistry *AssetRegistry) RegisterAsset(color ledgerstate.Color, asset Asset)

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

func (*AssetRegistry) Symbol

func (assetRegistry *AssetRegistry) Symbol(color ledgerstate.Color) string

Symbol return the symbol of the token.

type Connector

type Connector interface {
	UnspentOutputs(addresses ...address.Address) (unspentOutputs map[address.Address]map[ledgerstate.OutputID]*Output, err error)
	SendTransaction(transaction *ledgerstate.Transaction) (err error)
	RequestFaucetFunds(address address.Address) (err error)
	GetAllowedPledgeIDs() (pledgeIDMap map[mana.Type][]string, 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 InclusionState

type InclusionState struct {
	Liked       bool
	Confirmed   bool
	Rejected    bool
	Conflicting bool
	Spent       bool
}

InclusionState is a container for the different flags of an output that define if it was accepted in the network.

func (InclusionState) String added in v0.4.0

func (i InclusionState) String() string

String returns a human-readable representation of the InclusionState.

type Option

type Option func(*Wallet)

Option represents an optional parameter .

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 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
	OutputID       ledgerstate.OutputID
	Balances       *ledgerstate.ColoredBalances
	InclusionState InclusionState
	Metadata       OutputMetadata
}

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

func (*Output) String added in v0.4.0

func (o *Output) String() string

String returns a human-readable representation of the Output.

type OutputMetadata added in v0.5.0

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 added in v0.4.0

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

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

func (OutputsByAddressAndOutputID) OutputsByID added in v0.4.0

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

OutputsByID returns a collection of Outputs associated with their OutputID.

type OutputsByID added in v0.4.0

type OutputsByID map[ledgerstate.OutputID]*Output

OutputsByID is a collection of Outputs associated with their OutputID.

func (OutputsByID) OutputsByAddressAndOutputID added in v0.4.0

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

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

type SendFundsOption

type SendFundsOption func(*sendFundsOptions) error

SendFundsOption is the type for the optional parameters for the SendFunds call.

func AccessManaPledgeID added in v0.5.0

func AccessManaPledgeID(nodeID string) SendFundsOption

AccessManaPledgeID is an option for SendFunds call that defines the nodeID to pledge access mana to.

func ConsensusManaPledgeID added in v0.5.0

func ConsensusManaPledgeID(nodeID string) SendFundsOption

ConsensusManaPledgeID is an option for SendFunds call that defines the nodeID to pledge consensus mana to.

func Destination

func Destination(addr address.Address, amount uint64, optionalColor ...ledgerstate.Color) SendFundsOption

Destination is an option for the SendFunds call that defines a destination for funds that are supposed to be moved.

func Remainder

func Remainder(addr address.Address) SendFundsOption

Remainder is an option for the SendsFunds call that allows us to specify the remainder address that is supposed to be used in the corresponding transaction.

type ServerStatus

type ServerStatus struct {
	ID        string
	Synced    bool
	Version   string
	ManaDecay float64
}

ServerStatus defines the information of connected server

type UnspentOutputManager

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

UnspentOutputManager is a manager for the unspent outputs of the addresses of a wallet. It allows us to keep track of the spent state of outputs using our local knowledge about outputs that have already been spent and allows us to cache results that would otherwise have to be requested by the server over and over again.

func NewUnspentOutputManager

func NewUnspentOutputManager(addressManager *AddressManager, connector Connector) (outputManager *UnspentOutputManager)

NewUnspentOutputManager creates a new UnspentOutputManager.

func (*UnspentOutputManager) MarkOutputSpent

func (unspentOutputManager *UnspentOutputManager) MarkOutputSpent(address address.Address, outputID ledgerstate.OutputID)

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

func (*UnspentOutputManager) Refresh

func (unspentOutputManager *UnspentOutputManager) Refresh(includeSpentAddresses ...bool) (err error)

Refresh retrieves the unspent outputs from the node. If includeSpentAddresses is set to true, then it also scans the addresses from which we previously spent already.

func (*UnspentOutputManager) UnspentOutputs

func (unspentOutputManager *UnspentOutputManager) UnspentOutputs(addresses ...address.Address) (unspentOutputs map[address.Address]map[ledgerstate.OutputID]*Output)

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

type Wallet

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

Wallet represents a simple cryptocurrency wallet for the IOTA tangle. It contains the logic to manage the movement of funds.

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) AllowedPledgeNodeIDs added in v0.5.0

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

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

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

func (*Wallet) CreateAsset

func (wallet *Wallet) CreateAsset(asset Asset) (assetColor ledgerstate.Color, err error)

CreateAsset creates a new colored token with the given details.

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 ...SendFundsOption) (tx *ledgerstate.Transaction, err error)

SendFunds issues a payment of the given amount to the given address.

func (*Wallet) ServerStatus

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

ServerStatus retrieves the connected server status.

func (*Wallet) UnspentOutputs

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

UnspentOutputs returns the unspent outputs that are available for spending.

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.5.0

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

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

RequestFaucetFunds request some funds from the faucet for test purposes.

func (WebConnector) SendTransaction

func (webConnector WebConnector) SendTransaction(tx *ledgerstate.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 map[address.Address]map[ledgerstate.OutputID]*Output, err error)

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

Directories

Path Synopsis
packages

Jump to

Keyboard shortcuts

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