Wallet

abstract class Wallet(val chainSelector: ChainSelector)

This class defines a wallet interface. A wallet is a set of payment destinations that are being tracked on a particular blockchain.

Inheritors

Constructors

Link copied to clipboard
constructor(chainSelector: ChainSelector)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class WalletStatistics(val numUnusedAddrs: Int, val numUsedAddrs: Int, val numUnspentTxos: Int, val totalTxos: Int, val numTransactions: Int, val firstReceiveHeight: Long, val lastReceiveHeight: Long, val firstSendHeight: Long, val lastSendHeight: Long, val txCacheSize: Int, val txoCacheSize: Int)

Provide various wallet statistics

Properties

Link copied to clipboard

Control whether saving the wallet to underlying storage is automatic (true, default), or initiated by API calls Wallet performance could improve if automaticFlush is false and the wallet is saved rarely. However state may be lost!

Link copied to clipboard
abstract val balance: Long
Link copied to clipboard
abstract val balanceConfirmed: Long
Link copied to clipboard
abstract val balanceUnconfirmed: Long
Link copied to clipboard
abstract val blockchain: Blockchain

This wallet finds its coins on this blockchain

Link copied to clipboard
Link copied to clipboard
var historicalPrice: (String, Long) -> BigDecimal?

Give this wallet access to the historical price (epoch seconds) of its token in the provided fiat currency code

Link copied to clipboard
abstract val isDeleted: Boolean

True if this wallet is deleted

Link copied to clipboard
abstract val name: String

Any name you may want to call this wallet

Link copied to clipboard
abstract var pause: Boolean

Pause blockchain processing if true

Link copied to clipboard
var spotPrice: (String) -> BigDecimal?

Give this wallet access to the spot price of its token in the provided fiat currency code

Link copied to clipboard
abstract val syncedDate: Long

Returns the current position of this wallet in the blockchain by block time. Since a fork may have occurred, this information does not unambiguously locate the wallet, but it is valuable for UI.

Link copied to clipboard
abstract val syncedHash: ByteArray

Returns the current position of this wallet in the blockchain by block hash. Since a fork may have occurred, this information does not unambiguously locate the wallet, but it is valuable for UI.

Link copied to clipboard
abstract val syncedHeight: Long

Returns the current position of this wallet in the blockchain by block height. Since a fork may have occurred, this information does not unambiguously locate the wallet, but it is valuable for UI.

Functions

Link copied to clipboard
abstract fun abortTransaction(tx: iTransaction, returnUnusedAddresses: List<PayAddress>? = null)

Abort this transaction, whose inputs were reserved by "prepareSend". Update the wallet to release all inputs reserved by this transaction

Link copied to clipboard

Return all configured identity domains

Link copied to clipboard
fun Wallet.chunkInto(payAddress: PayAddress, numUtxos: Int, amt: Long, delta: Long = 100000): List<iTransaction>

This function will split the wallet's native coin so that there are numUtxos of amt satoshis. If the wallet already has some UTXOs that fit the requirements, they count. So its possible that no transactions will be created

Link copied to clipboard
fun Wallet.chunkTokenInto(gid: GroupId, payAddress: PayAddress, numUtxos: Int, tokenAmt: Long = 1): List<iTransaction>

This function will split the wallet's Tokens so that there are numUtxos of amt satoshis. If the wallet already has some UTXOs that fit the requirements, they count. So its possible that no transactions will be created

Link copied to clipboard
abstract fun deleteTxo(vararg txos: iTxOutpoint)
Link copied to clipboard
abstract fun destinationFor(seed: String): PayDestination

Get a repeatable destination, generally used for identity purposes. Given 2 different seeds, this API should at a minimum be statistically unlikely to produce the same address The seed may be public data (a domain name, for example) so wallet security must not depend on it being a secret.

Link copied to clipboard
abstract fun forEachTx(doit: (TransactionHistory) -> Boolean)
Link copied to clipboard
abstract fun forEachTxByAddress(addr: PayAddress, doit: (TransactionHistory) -> Unit)
Link copied to clipboard
abstract fun forEachTxByDate(doit: (TransactionHistory) -> Boolean)
Link copied to clipboard
abstract fun forEachTxo(doit: (Spendable) -> Boolean)
Link copied to clipboard
abstract fun forEachUtxo(doit: (Spendable) -> Boolean)
Link copied to clipboard

Low level API to generate a new address to receive funds, called by newDestination. Use "newDestination()" in almost all cases. This API does not pre-generate (so may be slow), and does not install the destination into bloom filters, etc, before returning. This means that there may be a race condition between the use of the destination returned here and the wallet's monitoring of that destination which could cause funds to be received but not noticed by this wallet.

Link copied to clipboard
abstract fun getBalanceIn(dest: PayAddress, unspent: Boolean = true): Long
abstract fun getBalanceIn(groupId: GroupId, dest: PayAddress? = null, minConfirms: Int = 0, unspent: Boolean = true): Long
Link copied to clipboard

Get the current address to receive funds. Different wallets may support different payment destination types. This API returns whatever is the "default" type for this wallet. This allows generic algorithms to be created that can be applied to many different wallet types. When this API returns, the destination is ready for use (monitoring is installed in remote nodes, IF any remote nodes exist). This API may pre-generate destinations. This address will be returned until activity is detected on-chain, or until markAddressUsed is called

Link copied to clipboard
Link copied to clipboard

Gets a new address: convenience function that is functionally similar to @newDestination but mirrors the bitcoin-cli command

Link copied to clipboard

Get a new address to receive funds. This will return and "retire" the current address. Different wallets may support different payment destination types. This API returns whatever is the "default" type for this wallet. This allows generic algorithms to be created that can be applied to many different wallet types. When this API returns, the destination is ready for use (monitoring is installed in remote nodes, IF any remote nodes exist). This API may pre-generate destinations.

Link copied to clipboard

Wallet implementations may allow access to addresses generated from specific private keys or nonstandard HD derivation paths. The wallet will never offer these destinations as current payment targets. It will only spend them (and show their balance).

Link copied to clipboard
abstract fun getTx(txIdem: Hash256): TransactionHistory?

wallet history by transaction

Link copied to clipboard
abstract fun getTxo(txo: iTxOutpoint): Spendable?

all UTXOs that this wallet is capable of spending (and how to spend them) READ ONLY

Link copied to clipboard
Link copied to clipboard
abstract fun isWalletAddress(dest: PayAddress): Boolean
Link copied to clipboard

Return identity domain data if this domain has previously been used

Link copied to clipboard
Link copied to clipboard
abstract fun markAddressUsed(addr: PayAddress)

Mark an address as 'used' so it will not be provided any longer. Note that if an address is 'seen' on the blockchain, this happens automatically.

Link copied to clipboard
abstract suspend fun newDestination(): PayDestination

Get a new address to receive funds. Different wallets may support different payment destination types. This API returns whatever is the "default" type for this wallet. This allows generic algorithms to be created that can be applied to many different wallet types. When this API returns, the destination is ready for use (monitoring is installed in remote nodes, IF any remote nodes exist). This API may pre-generate destinations.

Link copied to clipboard
abstract fun numTx(): Int
Link copied to clipboard
abstract fun numTxos(): Int
Link copied to clipboard
abstract fun numUtxos(): Int
Link copied to clipboard
abstract fun prepareDestinations(minAmt: Int = MIN_UNUSED_ADDRESSES, chunk: Int = DEFAULT_GEN_ADDRESS_CHUNK_SIZE)

Tell the wallet that now is a good time to top-up a cache of unused destinations

Link copied to clipboard
abstract fun prepareSend(outputs: MutableList<iTxOutput>, minConfirms: Int = 0, deductFeeFromAmount: Boolean = false): iTransaction

Creates an unsigned transaction that sends to a list of outputs. This function will select input coins from the wallet to fill the passed quantity and sign the transaction, but will not relay the transaction to the network.

Link copied to clipboard
abstract fun pubkeyToSecret(pubkey: ByteArray): Secret?
Link copied to clipboard
abstract fun rediscover(forgetAddresses: Boolean = false, noPrehistory: Boolean = false)

Forget all transaction and blockchain state, and asynchronously redo the search for wallet transactions. This is intended for testing and debug

Link copied to clipboard
abstract fun removeIdentityDomain(name: String)

Remove identity domain data

Link copied to clipboard
abstract fun removeIdentityInfo(id: PayAddress)

Remove identity information

Link copied to clipboard
abstract fun removeOnWalletChange(key: Int)

Remove a callback handler for whenever this wallet changes. You must pass the handler you set to ensure you have the wallet change callback.

Link copied to clipboard
abstract fun save(force: Boolean = false)

Write this wallet's changes to underlying storage. Called internally if @automaticSave is true, and/or explicitly called. Synchronous. An inability to save the wallet is a severe problem so exceptions are thrown.

Link copied to clipboard
abstract fun <T> searchTx(doit: (TransactionHistory) -> T?): T?
Link copied to clipboard
abstract fun send(tx: iTransaction, sync: Boolean = false, note: String? = null)

Post this transaction and update the wallet based on any inputs spent. Typically the provided tx came from calling prepareSend

abstract fun send(addrAmt: List<Pair<PayAddress, Long>>, sync: Boolean = false, note: String? = null, minConfirms: Int = 0): iTransaction

Send funds to multiple destinations. This function will select input coins from the wallet to fill the passed quantity

fun send(vararg outputs: iTxOutput, sync: Boolean = false, flags: Int = TxCompletionFlags.BIND_OUTPUT_PARAMETERS or TxCompletionFlags.FUND_GROUPS or TxCompletionFlags.FUND_NATIVE or TxCompletionFlags.USE_GROUP_AUTHORITIES or TxCompletionFlags.SIGN, note: String? = null, minConfirms: Int = 0): iTransaction

abstract fun send(amountSatoshis: Long, destAddress: String, deductFeeFromAmount: Boolean = false, sync: Boolean = false, note: String? = null, minConfirms: Int = 0): iTransaction
abstract fun send(amountSatoshis: Long, destAddress: PayAddress, deductFeeFromAmount: Boolean = false, sync: Boolean = false, note: String? = null, minConfirms: Int = 0): iTransaction
abstract fun send(amountSatoshis: Long, destScript: SatoshiScript, deductFeeFromAmount: Boolean = false, sync: Boolean = false, note: String? = null, minConfirms: Int = 0): iTransaction

Send funds to this destination. This function will select input coins from the wallet to fill the passed quantity

Link copied to clipboard
fun sendNative(vararg outputs: iTxOutput, sync: Boolean = false, note: String? = null): iTransaction

Send funds to multiple destinations (native coin only). This function will select input coins from the wallet to fill the passed quantity

Link copied to clipboard
abstract fun setOnWalletChange(callback: (Wallet, List<TransactionHistory>?) -> Unit): Int

Install a callback handler for whenever this wallet changes

Link copied to clipboard
abstract fun signMessage(message: ByteArray, addr: PayAddress? = null): ByteArray
fun signMessage(message: String, addr: PayAddress? = null): String
Link copied to clipboard

Report various wallet statistics, see WalletStatistics

Link copied to clipboard
abstract fun suggestFee(tx: iTransaction, pad: Int = 0, priority: Int = 0): Long

Calculate a suggested fee for this transaction

Link copied to clipboard
fun sync(maxWait: Long = 10L*86400L*365L, epochTimeinMsOrBlockHeight: Long = -1L): Boolean

Return whether this wallet is synced with its underlying blockchain. If it is not synced, properties like balance and balanceUnconfirmed express some previous state. In the unsynced case, this API will wait for it to do so, but no more than the provided time in milliseconds. If a height is provided, this API returns true if the wallet is synced up to or beyond this height If a height is not provided (or is -1), this API assumes you mean up to "now". This is special cased with an extra check that the blockchain's tip timestamp is within an hour of now. Of course, since blocks can be discovered at any time, and connected nodes can be slow at processing blocks one cannot ever absolutely know whether the wallet is really synced up to "now", so this function is more accurately described as "nearly synced" for any "now" call.

Link copied to clipboard
abstract fun synced(epochTimeinMsOrBlockHeight: Long = -1L): Boolean

Return whether this wallet is synced with its underlying blockchain. If it is not synced, properties like balance and balanceUnconfirmed express some previous state. In the unsynced case, this API will wait for it to do so, but no more than the provided time in milliseconds. If a height is provided, this API returns true if the wallet is synced up to or beyond this height If a height is not provided (or is -1), this API assumes you mean up to "now". This is special cased with an extra check that the blockchain's tip timestamp is within an hour of now. Of course, since blocks can be discovered at any time, and connected nodes can be slow at processing blocks one cannot ever absolutely know whether the wallet is really synced up to "now", so this function is more accurately described as "nearly synced" for any "now" call.

Link copied to clipboard
abstract fun txCompleter(tx: iTransaction, minConfirms: Int, flags: Int, inputAmount: Long? = null, adjustableOutput: Int? = null, destinationAddress: PayAddress? = null)

Modify the passed transaction to complete it to the extent possible by this wallet, including: Find inputs needed to supply satoshis and/or group tokens for this transaction. If change outputs are required, add them. If mint baton passing outputs are possible then add them if equalizeAuthorities=true If outputs are not fully specified, supply the missing constraints.

Link copied to clipboard

Add or update identity domain data

Link copied to clipboard

Add or update identity data

Link copied to clipboard
fun verifyMessage(message: String, addr: PayAddress, sigS: String): Boolean
Link copied to clipboard