account

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAccountNotRunning = errors.New("the account is not running")

ErrAccountNotRunning is returned when the account isn't running but methods on it are called.

View Source
var ErrEmptyRecipients = errors.New("recipients slice must be of size > 0")

ErrEmptyRecipients is returned when the recipient slice is empty.

View Source
var ErrInvalidAccountSettings = errors.New("invalid account settings")

ErrInvalidAccountSettings is returned when the settings are inconsistent.

View Source
var ErrTargetAddressIsSpent = errors.New("target address is already spent")

ErrTargetAddressIsSpent is returned when an address in the transfer object for a send operation is already spent.

View Source
var ErrTimeoutNotSpecified = errors.New("conditions must define a timeout")

ErrTimeoutNotSpecified is returned when conditions for a deposit address define no timeout.

View Source
var ErrTimeoutTooLow = errors.New("conditions must at least define a timeout of over 2 minutes")

ErrTimeoutTooLow is returned when the defined timeout of the conditions for a deposit address is too low.

Functions

func DefaultInputSelection

func DefaultInputSelection(acc *account, transferValue uint64, balanceCheck bool) (uint64, []api.Input, []uint64, error)

DefaultInputSelection selects fulfilled and timed out deposit addresses as inputs.

Types

type Account

type Account interface {
	// ID returns the account's identifier.
	ID() string
	// Start starts the inner event loop of the account.
	Start() error
	// Shutdown cleanly shutdowns the account and releases its allocated resources.
	Shutdown() error
	// Send sends the specified amounts to the given recipients.
	Send(recipients ...Recipient) (bundle.Bundle, error)
	// AllocateDepositAddress generates a new deposit address with the given conditions.
	AllocateDepositAddress(conds *deposit.Conditions) (*deposit.CDA, error)
	// AvailableBalance gets the current available balance.
	// The balance is computed from all current deposit addresses which are ready
	// for input selection. To get the current total balance, use TotalBalance().
	AvailableBalance() (uint64, error)
	// TotalBalance gets the current total balance.
	// The total balance is computed from all currently allocated deposit addresses.
	// It does not represent the actual available balance for doing transfers.
	// Use AvailableBalance() to get the current available balance.
	TotalBalance() (uint64, error)
	// IsNew checks whether the account is new.
	IsNew() (bool, error)
	// UpdateSettings updates the settings of the account in a safe and synchronized manner.
	UpdateSettings(setts *Settings) error
}

Account is a thread-safe object encapsulating address management, input selection, promotion and reattachments.

func NewAccount

func NewAccount(setts *Settings) (Account, error)

NewAccount creates a new account. If settings are nil, the account is initialized with the default settings provided by DefaultSettings().

type AddrGenFunc

type AddrGenFunc func(index uint64, secLvl consts.SecurityLevel, addChecksum bool) (trinary.Hash, error)

AddrGenFunc defines a function which given the index, security level and addChecksum flag, generates a new address.

func DefaultAddrGen

func DefaultAddrGen(provider SeedProvider, withCache bool) AddrGenFunc

DefaultAddrGen is the default address generation function used by the account, if non is specified. withCache creates a function which caches the computed addresses by the index and security level for subsequent calls.

type InMemorySeedProvider

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

InMemorySeedProvider is a SeedProvider which holds the seed in memory.

func (*InMemorySeedProvider) Seed

func (imsp *InMemorySeedProvider) Seed() (Trytes, error)

type InputSelectionFunc

type InputSelectionFunc func(acc *account, transferValue uint64, balanceCheck bool) (uint64, []api.Input, []uint64, error)

InputSelectionFunc defines a function which given the account, transfer value and the flag balance check, computes the inputs for fulfilling the transfer or the usable balance of the account. The InputSelectionFunc must obey to the rules of conditional deposit addresses to ensure consistency. It returns the computed balance/transfer value, inputs and the key indices to remove from the store.

type Plugin

type Plugin interface {
	// Starts the given plugin and passes in the account object.
	Start(acc Account) error
	// Shutdown instructs the plugin to terminate.
	Shutdown() error
	// Name returns the name of the plugin.
	Name() string
}

Plugin is a component which extends the account's functionality.

type PrepareTransfersFunc

type PrepareTransfersFunc func(transfers bundle.Transfers, options api.PrepareTransfersOptions) ([]trinary.Trytes, error)

PrepareTransfersFunc defines a function which prepares the transaction trytes by generating a bundle, filling in transfers and inputs, adding the remainder address and signing all input transactions.

func DefaultPrepareTransfers

func DefaultPrepareTransfers(a *api.API, provider SeedProvider) PrepareTransfersFunc

DefaultPrepareTransfers is the default prepare transfers function used by the account, if non is specified.

type Recipient

type Recipient = bundle.Transfer

Recipient is a bundle.Transfer but with a nicer name.

type Recipients

type Recipients []Recipient

func (Recipients) AsTransfers

func (recipients Recipients) AsTransfers() bundle.Transfers

AsTransfers converts the recipients to transfers.

func (Recipients) Sum

func (recipients Recipients) Sum() uint64

Sum returns the sum of all amounts.

type SeedProvider

type SeedProvider interface {
	Seed() (Trytes, error)
}

SeedProvider is a provider which provides a seed.

func NewInMemorySeedProvider

func NewInMemorySeedProvider(seed Trytes) SeedProvider

NewInMemorySeedProvider creates a new InMemorySeedProvider providing the given seed.

type Settings

type Settings struct {
	API                 *api.API
	Store               store.Store
	SeedProv            SeedProvider
	MWM                 uint64
	Depth               uint64
	SecurityLevel       consts.SecurityLevel
	TimeSource          timesrc.TimeSource
	InputSelectionStrat InputSelectionFunc
	EventMachine        event.EventMachine
	Plugins             map[string]Plugin
	AddrGen             AddrGenFunc
	PrepareTransfers    PrepareTransfersFunc
}

Settings defines settings used by an account. The settings must not be directly mutated after an account was started.

func DefaultSettings

func DefaultSettings(setts ...Settings) *Settings

DefaultSettings returns Settings initialized with default values: empty seed (81x "9" trytes), mwm: 14, depth: 3, security level: 2, no event machine, system clock as the time source, default input sel. strat, in-memory store, iota-api pointing to localhost, no transfer poller plugin, no promoter-reattacher plugin.

Directories

Path Synopsis
plugins

Jump to

Keyboard shortcuts

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