wallet

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: Apache-2.0, BSD-2-Clause Imports: 15 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 *walletseed.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) walletaddr.Address

Address returns the address that belongs to the given index.

func (*AddressManager) Addresses

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

Addresses returns a list of all addresses of the wallet.

func (*AddressManager) FirstUnspentAddress

func (addressManager *AddressManager) FirstUnspentAddress() walletaddr.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() walletaddr.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() walletaddr.Address

NewAddress generates and returns a new unused address.

func (*AddressManager) SpentAddresses

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

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

func (*AddressManager) UnspentAddresses

func (addressManager *AddressManager) UnspentAddresses() (addresses []walletaddr.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 balance.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 address.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 balance.Color) string

Name returns the name of the given asset.

func (*AssetRegistry) Precision

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

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

func (*AssetRegistry) RegisterAsset

func (assetRegistry *AssetRegistry) RegisterAsset(color balance.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 balance.Color) string

Symbol return the symbol of the token.

type Connector

type Connector interface {
	UnspentOutputs(addresses ...walletaddr.Address) (unspentOutputs map[walletaddr.Address]map[transaction.ID]*Output, err error)
	SendTransaction(tx *transaction.Transaction) (err error)
	RequestFaucetFunds(addr walletaddr.Address) (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.

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 *walletseed.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
	TransactionID  transaction.ID
	Balances       map[balance.Color]uint64
	InclusionState InclusionState
}

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

type SendFundsOption

type SendFundsOption func(*sendFundsOptions) error

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

func Destination

func Destination(addr address.Address, amount uint64, optionalColor ...balance.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 walletaddr.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
}

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(addr walletaddr.Address, transactionID transaction.ID)

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 ...walletaddr.Address) (unspentOutputs map[walletaddr.Address]map[transaction.ID]*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) AssetRegistry

func (wallet *Wallet) AssetRegistry() *AssetRegistry

AssetRegistry return the internal AssetRegistry instance of the wallet.

func (*Wallet) Balance

func (wallet *Wallet) Balance() (confirmedBalance map[balance.Color]uint64, pendingBalance map[balance.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 balance.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() walletaddr.Address

NewReceiveAddress generates and returns a new unused receive address.

func (*Wallet) ReceiveAddress

func (wallet *Wallet) ReceiveAddress() walletaddr.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() walletaddr.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() *walletseed.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 *transaction.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[walletaddr.Address]map[transaction.ID]*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) RequestFaucetFunds

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

RequestFaucetFunds request some funds from the faucet for test purposes.

func (WebConnector) SendTransaction

func (webConnector WebConnector) SendTransaction(tx *transaction.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 ...walletaddr.Address) (unspentOutputs map[walletaddr.Address]map[transaction.ID]*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