money

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsufficientBalance = errors.New("insufficient balance for transaction")
	ErrInvalidPubKey       = errors.New("invalid public key, public key must be in compressed secp256k1 format")

	ErrNoFeeCredit           = errors.New("no fee credit in money wallet")
	ErrInsufficientFeeCredit = errors.New("insufficient fee credit balance for transaction(s)")
)

Functions

func CreateNewWallet

func CreateNewWallet(am account.Manager, mnemonic string) error

CreateNewWallet creates a new wallet. To synchronize wallet with a node call Sync. Shutdown needs to be called to release resources used by wallet. If mnemonic seed is empty then new mnemonic will ge generated, otherwise wallet is restored using given mnemonic.

func FeeCreditRecordIDFormPublicKey added in v0.2.0

func FeeCreditRecordIDFormPublicKey(shardPart, pubKey []byte) types.UnitID

func NewTxLog added in v0.1.3

func NewTxLog(pendingTxs []*types.TransactionOrder) *txLog

Types

type BackendAPI added in v0.1.4

type BackendAPI interface {
	GetBalance(ctx context.Context, pubKey []byte, includeDCBills bool) (uint64, error)
	ListBills(ctx context.Context, pubKey []byte, includeDCBills bool, offsetKey string, limit int) (*backend.ListBillsResponse, error)
	GetBills(ctx context.Context, pubKey []byte) ([]*wallet.Bill, error)
	GetRoundNumber(ctx context.Context) (uint64, error)
	GetFeeCreditBill(ctx context.Context, unitID types.UnitID) (*wallet.Bill, error)
	GetLockedFeeCredit(ctx context.Context, systemID []byte, unitID []byte) (*types.TransactionRecord, error)
	GetClosedFeeCredit(ctx context.Context, fcbID []byte) (*types.TransactionRecord, error)
	PostTransactions(ctx context.Context, pubKey wallet.PubKey, txs *wallet.Transactions) error
	GetTxProof(ctx context.Context, unitID types.UnitID, txHash wallet.TxHash) (*wallet.Proof, error)
}

type DustCollectionResult added in v0.2.0

type DustCollectionResult struct {
	AccountIndex uint64
	FeeSum       uint64
	SwapProof    *wallet.Proof
}

type DustCollector added in v0.2.0

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

func NewDustCollector added in v0.2.0

func NewDustCollector(systemID []byte, maxBillsPerDC int, backend BackendAPI, unitLocker UnitLocker) *DustCollector

func (*DustCollector) CollectDust added in v0.2.0

func (w *DustCollector) CollectDust(ctx context.Context, accountKey *account.AccountKey) (*DustCollectionResult, error)

CollectDust joins up to N units into existing target unit, prioritizing small units first. The largest unit is selected as the target unit. Returns swap transaction proof or error or nil if there's not enough bills to swap.

type GetBalanceCmd added in v0.1.1

type GetBalanceCmd struct {
	AccountIndex uint64
	CountDCBills bool
}

type SendCmd added in v0.1.1

type SendCmd struct {
	ReceiverPubKey      []byte
	Amount              uint64
	WaitForConfirmation bool
	AccountIndex        uint64
}

type TxPublisher added in v0.2.0

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

func NewTxPublisher added in v0.2.0

func NewTxPublisher(backend BackendAPI) *TxPublisher

func (*TxPublisher) Close added in v0.2.0

func (w *TxPublisher) Close()

func (*TxPublisher) SendTx added in v0.2.0

func (w *TxPublisher) SendTx(ctx context.Context, tx *types.TransactionOrder, senderPubKey []byte) (*wallet.Proof, error)

SendTx sends tx and waits for confirmation, returns tx proof

type UnitLocker added in v0.2.0

type UnitLocker interface {
	LockUnit(lockedBill *unitlock.LockedUnit) error
	UnlockUnit(accountID, unitID []byte) error
	GetUnit(accountID, unitID []byte) (*unitlock.LockedUnit, error)
	GetUnits(accountID []byte) ([]*unitlock.LockedUnit, error)
	Close() error
}

type Wallet

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

func LoadExistingWallet

func LoadExistingWallet(am account.Manager, unitLocker UnitLocker, backend BackendAPI) (*Wallet, error)

func (*Wallet) AddFeeCredit added in v0.2.0

func (w *Wallet) AddFeeCredit(ctx context.Context, cmd fees.AddFeeCmd) (*fees.AddFeeCmdResponse, error)

AddFeeCredit creates fee credit for the given amount. Wallet must have a bill large enough for the required amount plus fees. Returns transferFC and addFC transaction proofs.

func (*Wallet) Close added in v0.2.0

func (w *Wallet) Close()

Close terminates connection to alphabill node, closes account manager and cancels any background goroutines.

func (*Wallet) CollectDust

func (w *Wallet) CollectDust(ctx context.Context, accountNumber uint64) ([]*DustCollectionResult, error)

CollectDust starts the dust collector process for the requested accounts in the wallet. Dust collection process joins up to N units into existing target unit, prioritizing small units first. The largest unit in wallet is selected as the target unit. If accountNumber is equal to 0 then dust collection is run for all accounts, returns list of swap tx proofs together with account numbers, the proof can be nil if swap tx was not sent e.g. if there's not enough bills to swap. If accountNumber is greater than 0 then dust collection is run only for the specific account, returns single swap tx proof, the proof can be nil e.g. if there's not enough bills to swap.

func (*Wallet) GetAccountManager added in v0.1.3

func (w *Wallet) GetAccountManager() account.Manager

func (*Wallet) GetBalance

func (w *Wallet) GetBalance(ctx context.Context, cmd GetBalanceCmd) (uint64, error)

GetBalance returns sum value of all bills currently owned by the wallet, for given account. The value returned is the smallest denomination of alphabills.

func (*Wallet) GetBalances added in v0.1.1

func (w *Wallet) GetBalances(ctx context.Context, cmd GetBalanceCmd) ([]uint64, uint64, error)

GetBalances returns sum value of all bills currently owned by the wallet, for all accounts. The value returned is the smallest denomination of alphabills.

func (*Wallet) GetFeeCredit added in v0.2.0

func (w *Wallet) GetFeeCredit(ctx context.Context, cmd fees.GetFeeCreditCmd) (*wallet.Bill, error)

GetFeeCredit returns fee credit bill for given account, can return nil if fee credit bill has not been created yet.

func (*Wallet) GetFeeCreditBill added in v0.2.0

func (w *Wallet) GetFeeCreditBill(ctx context.Context, unitID types.UnitID) (*wallet.Bill, error)

GetFeeCreditBill returns fee credit bill for given unitID can return nil if fee credit bill has not been created yet.

func (*Wallet) GetRoundNumber added in v0.2.0

func (w *Wallet) GetRoundNumber(ctx context.Context) (uint64, error)

GetRoundNumber returns latest round number known to the wallet, including empty rounds.

func (*Wallet) ReclaimFeeCredit added in v0.2.0

func (w *Wallet) ReclaimFeeCredit(ctx context.Context, cmd fees.ReclaimFeeCmd) (*fees.ReclaimFeeCmdResponse, error)

ReclaimFeeCredit reclaims fee credit. Reclaimed fee credit is added to the largest bill in wallet. Returns closeFC and reclaimFC transaction proofs.

func (*Wallet) Send

func (w *Wallet) Send(ctx context.Context, cmd SendCmd) ([]*wallet.Proof, error)

Send creates, signs and broadcasts transactions, in total for the given amount, to the given public key, the public key must be in compressed secp256k1 format. Sends one transaction per bill, prioritizing larger bills. Waits for initial response from the node, returns error if any transaction was not accepted to the mempool. Returns list of tx proofs, if waitForConfirmation=true, otherwise nil.

func (*Wallet) SendTx added in v0.2.0

func (w *Wallet) SendTx(ctx context.Context, tx *types.TransactionOrder, senderPubKey []byte) (*wallet.Proof, error)

SendTx sends tx and waits for confirmation, returns tx proof

func (*Wallet) SystemID added in v0.2.0

func (w *Wallet) SystemID() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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