money

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 20 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 DustCollectionResult

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

type GetBalanceCmd

type GetBalanceCmd struct {
	AccountIndex uint64

	// TODO deprecated: if transferDC is sent then the owner of bill becomes dust collector,
	// wallet needs to locally keep track of unswapped bills
	CountDCBills bool
}

type ReceiverData

type ReceiverData struct {
	PubKey []byte
	Amount uint64
}

type RpcClient added in v0.4.0

type RpcClient interface {
	GetRoundNumber(ctx context.Context) (uint64, error)
	GetBill(ctx context.Context, unitID types.UnitID, includeStateProof bool) (*api.Bill, error)
	GetFeeCreditRecord(ctx context.Context, unitID types.UnitID, includeStateProof bool) (*api.FeeCreditBill, error)
	GetUnitsByOwnerID(ctx context.Context, ownerID types.Bytes) ([]types.UnitID, error)
	SendTransaction(ctx context.Context, tx *types.TransactionOrder) ([]byte, error)
	GetTransactionProof(ctx context.Context, txHash types.Bytes) (*types.TransactionRecord, *types.TxProof, error)
	GetBlock(ctx context.Context, roundNumber uint64) (*types.Block, error)
}

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(rpcClient RpcClient, 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 Wallet

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

func LoadExistingWallet

func LoadExistingWallet(am account.Manager, feeManagerDB fees.FeeManagerDB, rpcClient RpcClient, 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 the total value of all bills currently held in the wallet, for the given account, in Tema denomination. Does not count fee credit bills.

func (*Wallet) GetBalances

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

GetBalances returns the total value of all bills currently held in the wallet, for all accounts, in Tema denomination. Does not count fee credit bills.

func (*Wallet) GetFeeCredit

func (w *Wallet) GetFeeCredit(ctx context.Context, cmd fees.GetFeeCreditCmd) (*api.FeeCreditBill, 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) (*api.FeeCreditBill, error)

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

func (*Wallet) GetRoundNumber

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

GetRoundNumber returns the latest round number in node.

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