money

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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

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

Types

type BackendAPI

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) (*wallet.RoundNumber, error)
	GetFeeCreditBill(ctx context.Context, unitID types.UnitID) (*wallet.Bill, 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

type DustCollectionResult struct {
	AccountIndex         uint64
	DustCollectionResult *dc.DustCollectionResult // NB! can be nil
}

type GetBalanceCmd

type GetBalanceCmd struct {
	AccountIndex uint64
	CountDCBills bool
}

type ReceiverData

type ReceiverData struct {
	PubKey []byte
	Amount uint64
}

type SendCmd

type SendCmd struct {
	Receivers           []ReceiverData
	WaitForConfirmation bool
	AccountIndex        uint64
}

type TxPublisher

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

func NewTxPublisher

func NewTxPublisher(backend BackendAPI, log *slog.Logger) *TxPublisher

func (*TxPublisher) Close

func (w *TxPublisher) Close()

func (*TxPublisher) SendTx

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

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, feeManagerDB fees.FeeManagerDB, backend BackendAPI, log *slog.Logger) (*Wallet, error)

func (*Wallet) AddFeeCredit

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

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

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

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

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

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

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

GetRoundNumber returns the latest round number in node and backend.

func (*Wallet) ReclaimFeeCredit

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

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

func (w *Wallet) SystemID() types.SystemID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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