Documentation ¶
Index ¶
- Constants
- Variables
- func IsEncrypted(config WalletConfig) (bool, error)
- func OpenDb(config WalletConfig) (*wdb, error)
- type Bill
- type BlockProof
- type Db
- type GetBalanceCmd
- type SendCmd
- type TxContext
- type TxConverter
- type Wallet
- func (w *Wallet) AddAccount() (uint64, []byte, error)
- func (w *Wallet) AddBill(accountIndex uint64, bill *Bill) error
- func (w *Wallet) CollectDust(ctx context.Context) error
- func (w *Wallet) DeleteDb()
- func (w *Wallet) GetAccountKey(accountIndex uint64) (*wallet.AccountKey, error)
- func (w *Wallet) GetAccountKeys() ([]*wallet.AccountKey, error)
- func (w *Wallet) GetAllBills() ([][]*Bill, error)
- func (w *Wallet) GetBalance(cmd GetBalanceCmd) (uint64, error)
- func (w *Wallet) GetBalances(cmd GetBalanceCmd) ([]uint64, error)
- func (w *Wallet) GetBill(accountIndex uint64, billId []byte) (*Bill, error)
- func (w *Wallet) GetBills(accountIndex uint64) ([]*Bill, error)
- func (w *Wallet) GetConfig() WalletConfig
- func (w *Wallet) GetMnemonic() (string, error)
- func (w *Wallet) GetPublicKey(accountIndex uint64) ([]byte, error)
- func (w *Wallet) GetPublicKeys() ([][]byte, error)
- func (w *Wallet) ProcessBlock(b *block.Block) error
- func (w *Wallet) Send(ctx context.Context, cmd SendCmd) ([]*Bill, error)
- func (w *Wallet) Shutdown()
- func (w *Wallet) StartDustCollectorJob() error
- func (w *Wallet) Sync(ctx context.Context) error
- func (w *Wallet) SyncToMaxBlockNumber(ctx context.Context) error
- type WalletConfig
Constants ¶
const WalletFileName = "wallet.db"
Variables ¶
var ( ErrSwapInProgress = errors.New("swap is in progress, synchronize your wallet to complete the process") ErrInsufficientBalance = errors.New("insufficient balance for transaction") ErrInvalidPubKey = errors.New("invalid public key, public key must be in compressed secp256k1 format") ErrInvalidAmount = errors.New("invalid amount") ErrInvalidAccountIndex = errors.New("invalid account index") ErrInvalidPassword = errors.New("invalid password") ErrInvalidBlockSystemID = errors.New("invalid system identifier") ErrTxFailedToConfirm = errors.New("transaction(s) failed to confirm") )
Functions ¶
func IsEncrypted ¶
func IsEncrypted(config WalletConfig) (bool, error)
IsEncrypted returns true if wallet exists and is encrypted and or false if wallet exists and is not encrypted, returns error if wallet does not exist.
func OpenDb ¶
func OpenDb(config WalletConfig) (*wdb, error)
Types ¶
type Bill ¶ added in v0.1.1
type Bill struct { Id *uint256.Int `json:"id"` Value uint64 `json:"value"` TxHash []byte `json:"txHash"` BlockProof *BlockProof `json:"blockProof"` // dc bill specific fields IsDcBill bool `json:"dcBill"` DcTimeout uint64 `json:"dcTimeout"` DcNonce []byte `json:"dcNonce"` // DcExpirationTimeout blockHeight when dc bill gets removed from state tree DcExpirationTimeout uint64 `json:"dcExpirationTimeout"` }
type BlockProof ¶ added in v0.1.1
type BlockProof struct { Tx *txsystem.Transaction `json:"tx"` Proof *block.BlockProof `json:"proof"` BlockNumber uint64 `json:"blockNumber"` }
func NewBlockProof ¶ added in v0.1.1
func NewBlockProof(tx *txsystem.Transaction, proof *block.BlockProof, blockNumber uint64) (*BlockProof, error)
func (*BlockProof) ToSchema ¶ added in v0.1.1
func (b *BlockProof) ToSchema() *block.TxProof
type GetBalanceCmd ¶ added in v0.1.1
type TxContext ¶
type TxContext interface { AddAccount(accountIndex uint64, key *wallet.AccountKey) error GetAccountKey(accountIndex uint64) (*wallet.AccountKey, error) GetAccountKeys() ([]*wallet.AccountKey, error) GetMaxAccountIndex() (uint64, error) SetMaxAccountIndex(accountIndex uint64) error GetMasterKey() (string, error) SetMasterKey(masterKey string) error GetMnemonic() (string, error) SetMnemonic(mnemonic string) error IsEncrypted() (bool, error) SetEncrypted(encrypted bool) error VerifyPassword() (bool, error) GetBlockNumber() (uint64, error) SetBlockNumber(blockNumber uint64) error GetBill(accountIndex uint64, id []byte) (*Bill, error) SetBill(accountIndex uint64, bill *Bill) error ContainsBill(accountIndex uint64, id *uint256.Int) (bool, error) RemoveBill(accountIndex uint64, id *uint256.Int) error GetBills(accountIndex uint64) ([]*Bill, error) GetAllBills() ([][]*Bill, error) GetBalance(cmd GetBalanceCmd) (uint64, error) GetBalances(cmd GetBalanceCmd) ([]uint64, error) GetDcMetadataMap(accountIndex uint64) (map[uint256.Int]*dcMetadata, error) GetDcMetadata(accountIndex uint64, nonce []byte) (*dcMetadata, error) SetDcMetadata(accountIndex uint64, nonce []byte, dcMetadata *dcMetadata) error }
type TxConverter ¶ added in v0.1.1
type TxConverter struct { }
func (*TxConverter) ConvertTx ¶ added in v0.1.1
func (t *TxConverter) ConvertTx(tx *txsystem.Transaction) (txsystem.GenericTransaction, error)
type Wallet ¶
func CreateNewWallet ¶
func CreateNewWallet(mnemonic string, config WalletConfig) (*Wallet, 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 LoadExistingWallet ¶
func LoadExistingWallet(config WalletConfig) (*Wallet, error)
func (*Wallet) AddAccount ¶ added in v0.1.1
AddAccount adds the next account in account key series to the wallet. New accounts are indexed only from the time of creation and not backwards in time. Returns new account's index and public key.
func (*Wallet) AddBill ¶ added in v0.1.1
AddBill adds bill to wallet. Given bill must have a valid transaction with P2PKH predicate for given account. Block proof is not verified, but transaction is required. Overwrites existing bill with the same ID, if one exists.
func (*Wallet) CollectDust ¶
CollectDust starts the dust collector process for all accounts in the wallet. Wallet needs to be synchronizing using Sync or SyncToMaxBlockNumber in order to receive transactions and finish the process. The function blocks until dust collector process is finished or timed out. Skips account if the account already has only one or no bills.
func (*Wallet) GetAccountKey ¶ added in v0.1.1
func (w *Wallet) GetAccountKey(accountIndex uint64) (*wallet.AccountKey, error)
func (*Wallet) GetAccountKeys ¶ added in v0.1.1
func (w *Wallet) GetAccountKeys() ([]*wallet.AccountKey, error)
func (*Wallet) GetAllBills ¶ added in v0.1.1
GetAllBills returns all bills owned by the wallet for all accounts.
func (*Wallet) GetBalance ¶
func (w *Wallet) GetBalance(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(cmd GetBalanceCmd) ([]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) GetBill ¶ added in v0.1.1
GetBill returns bill for the given bill id. If bill does not exist returns error "bill does not exist".
func (*Wallet) GetBills ¶ added in v0.1.1
GetBills returns all bills owned by the wallet for the given account.
func (*Wallet) GetConfig ¶ added in v0.1.1
func (w *Wallet) GetConfig() WalletConfig
func (*Wallet) GetMnemonic ¶
GetMnemonic returns mnemonic seed of the wallet
func (*Wallet) GetPublicKey ¶
GetPublicKey returns public key of the wallet (compressed secp256k1 key 33 bytes)
func (*Wallet) GetPublicKeys ¶ added in v0.1.1
GetPublicKeys returns public keys of the wallet, indexed by account indexes
func (*Wallet) Send ¶
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, prioritzing larger bills. Returns list of bills including transaction and proof data, if waitForConfirmation=true, otherwise nil.
func (*Wallet) Shutdown ¶
func (w *Wallet) Shutdown()
Shutdown terminates connection to alphabill node, closes wallet db, cancels dust collector job and any background goroutines.
func (*Wallet) StartDustCollectorJob ¶
StartDustCollectorJob starts the dust collector background process that runs every hour until wallet is shut down. Wallet needs to be synchronizing using Sync or SyncToMaxBlockNumber in order to receive transactions and finish the process. Returns error if the job failed to start.
func (*Wallet) Sync ¶
Sync synchronises wallet from the last known block number with the given alphabill node. The function blocks forever or until alphabill connection is terminated. Returns immediately if already synchronizing.
func (*Wallet) SyncToMaxBlockNumber ¶
SyncToMaxBlockNumber synchronises wallet from the last known block number with the given alphabill node. The function blocks until maximum block height, calculated at the start of the process, is reached. Returns immediately with ErrWalletAlreadySynchronizing if already synchronizing.
type WalletConfig ¶
type WalletConfig struct { // Directory where default boltdb wallet database is created, only used when Db is not set, // if empty then 'home/.alphabill/wallet' directory is used. DbPath string // Custom database implementation, if set then DbPath is not used, // if not set then boltdb is created at DbPath. Db Db // WalletPass used to encrypt/decrypt sensitive information. If empty then wallet will not be encrypted. WalletPass string // Configuration options for connecting to alphabill nodes. AlphabillClientConfig client.AlphabillClientConfig }
func (*WalletConfig) GetWalletDir ¶
func (c *WalletConfig) GetWalletDir() (string, error)
GetWalletDir returns wallet directory, if DbPath is set then returns DbPath, if DbPath is not set then returns 'home/.alphabill/wallet'.