pub struct Wallet {
pub chain: Arc<ChainSource>,
pub exit: RwLock<Exit>,
pub movements: Arc<MovementManager>,
/* private fields */
}Expand description
The central entry point for using this library as an Ark wallet.
Overview
- Wallet encapsulates the complete Ark client implementation:
- address generation (Ark addresses/keys)
- boarding onchain funds into Ark from an onchain wallet (see onchain::OnchainWallet)
- offboarding Ark funds to move them back onchain
- sending and receiving Ark payments (including to BOLT11/BOLT12 invoices)
- tracking, selecting, and refreshing VTXOs
- syncing with the Ark server, unilateral exits and performing general maintenance
- Wallet::maintenance: Syncs everything offchain-related and refreshes VTXOs where necessary,
- Wallet::maintenance_with_onchain: The same as Wallet::maintenance but also syncs the onchain wallet and unilateral exits,
- Wallet::maintenance_refresh: Refreshes VTXOs where necessary without syncing anything,
- Wallet::sync: Syncs network fee-rates, ark rounds and arkoor payments,
- Wallet::sync_exits: Updates the status of unilateral exits,
- Wallet::sync_pending_lightning_send_vtxos: Updates the status of pending lightning payments,
- Wallet::try_claim_all_lightning_receives: Wait for payment receipt of all open invoices, then claim them,
- Wallet::sync_pending_boards: Registers boards which are available for use in offchain payments
Key capabilities
- Address management:
- derive and peek deterministic Ark addresses and their indices
- Funds lifecycle:
- board funds from an external onchain wallet onto the Ark
- send out-of-round Ark payments (arkoor)
- offboard funds to onchain addresses
- manage HTLCs and Lightning receives/sends
- VTXO management:
- query spendable and pending VTXOs
- refresh expiring or risky VTXOs
- compute balance broken down by spendable/pending states
- Synchronization and maintenance:
- sync against the Ark server and the onchain source
- reconcile pending rounds, exits, and offchain state
- periodic maintenance helpers (e.g., auto-register boards, refresh policies)
Construction and persistence
- A Wallet is opened or created using a mnemonic and a backend implementing BarkPersister.
- Creation allows the use of an optional onchain wallet for boarding and Exit functionality. It also initializes any internal state and connects to the chain::ChainSource. See onchain::OnchainWallet for an implementation of an onchain wallet using BDK.
Example
let network = Network::Signet;
let mnemonic = Mnemonic::generate(12)?;
let cfg = Config {
server_address: String::from("https://ark.signet.2nd.dev"),
esplora_address: Some(String::from("https://esplora.signet.2nd.dev")),
..Default::default()
};
// You can either use the included SQLite implementation or create your own.
let persister = SqliteClient::open(db_path).await?;
let db: Arc<dyn BarkPersister> = Arc::new(persister);
// Load or create an onchain wallet if needed
let onchain_wallet = OnchainWallet::load_or_create(network, mnemonic.to_seed(""), db.clone()).await?;
// Create or open the Ark wallet
let mut wallet = Wallet::create_with_onchain(
&mnemonic,
network,
cfg.clone(),
db,
&onchain_wallet,
false,
).await?;
// let mut wallet = Wallet::create(&mnemonic, network, cfg.clone(), db.clone(), false).await?;
// let mut wallet = Wallet::open(&mnemonic, db.clone(), cfg.clone()).await?;
// let mut wallet = Wallet::open_with_onchain(
// &mnemonic, network, cfg.clone(), db.clone(), &onchain_wallet
// ).await?;
// There are two main ways to update the wallet, the primary is to use one of the maintenance
// commands which will sync everything, refresh VTXOs and reconcile pending lightning payments.
wallet.maintenance().await?;
wallet.maintenance_with_onchain(&mut onchain_wallet).await?;
// Alternatively, you can use the fine-grained sync commands to sync individual parts of the
// wallet state and use `maintenance_refresh` where necessary to refresh VTXOs.
wallet.sync().await?;
wallet.sync_pending_lightning_send_vtxos().await?;
wallet.register_all_confirmed_boards(&mut onchain_wallet).await?;
wallet.sync_exits(&mut onchain_wallet).await?;
wallet.maintenance_refresh().await?;
// Generate a new Ark address to receive funds via arkoor
let addr = wallet.new_address().await?;
// Query balance and VTXOs
let balance = wallet.balance()?;
let vtxos = wallet.vtxos()?;
// Progress any unilateral exits, make sure to sync first
wallet.exit.progress_exit(&mut onchain_wallet, None).await?;
Fields§
§chain: Arc<ChainSource>The chain source the wallet is connected to
exit: RwLock<Exit>Exit subsystem handling unilateral exits and on-chain reconciliation outside Ark rounds.
movements: Arc<MovementManager>Allows easy creation of and management of wallet fund movements.
Implementations§
Source§impl Wallet
impl Wallet
Sourcepub async fn join_next_round(
&self,
participation: RoundParticipation,
movement_kind: Option<RoundMovement>,
) -> Result<StoredRoundState>
pub async fn join_next_round( &self, participation: RoundParticipation, movement_kind: Option<RoundMovement>, ) -> Result<StoredRoundState>
Start a new round participation
This function will store the state in the db and mark the VTXOs as locked.
pub async fn join_non_interactive_round( &self, participation: RoundParticipation, movement_kind: Option<RoundMovement>, ) -> Result<StoredRoundState>
Sourcepub async fn pending_round_states(&self) -> Result<Vec<StoredRoundState>>
pub async fn pending_round_states(&self) -> Result<Vec<StoredRoundState>>
Get all pending round states
Sourcepub async fn sync_pending_rounds(&self) -> Result<()>
pub async fn sync_pending_rounds(&self) -> Result<()>
Sync pending rounds that have finished but are waiting for confirmations
Sourcepub async fn progress_pending_rounds(
&self,
last_round_event: Option<&RoundEvent>,
) -> Result<()>
pub async fn progress_pending_rounds( &self, last_round_event: Option<&RoundEvent>, ) -> Result<()>
Try to make incremental progress on all pending round states
If the last_round_event argument is not provided, it will be fetched
from the server.
pub async fn subscribe_round_events( &self, ) -> Result<impl Stream<Item = Result<RoundEvent>> + Unpin>
Sourcepub async fn participate_ongoing_rounds(&self) -> Result<()>
pub async fn participate_ongoing_rounds(&self) -> Result<()>
A blocking call that will try to perform a full round participation for all ongoing rounds
Returns only once a round has happened on the server.
Sourcepub async fn cancel_all_pending_rounds(&self) -> Result<()>
pub async fn cancel_all_pending_rounds(&self) -> Result<()>
Will cancel all pending rounds that can safely be canceled
All rounds that have not started yet can safely be canceled, as well as rounds where we have not yet signed any forfeit txs.
Sourcepub async fn cancel_pending_round(&self, id: RoundStateId) -> Result<()>
pub async fn cancel_pending_round(&self, id: RoundStateId) -> Result<()>
Try to cancel the given round
Source§impl Wallet
impl Wallet
Sourcepub async fn lock_vtxos(
&self,
vtxos: impl IntoIterator<Item = impl VtxoRef>,
movement_id: Option<MovementId>,
) -> Result<()>
pub async fn lock_vtxos( &self, vtxos: impl IntoIterator<Item = impl VtxoRef>, movement_id: Option<MovementId>, ) -> Result<()>
Attempts to lock VTXOs with the given VtxoId values. This will only work if the current VtxoState is contained by VtxoStateKind::UNSPENT_STATES.
§Errors
- If the VTXO is not in a lockable VtxoState.
- If the VTXO doesn’t exist.
- If a database error occurs.
Sourcepub async fn mark_vtxos_as_spent(
&self,
vtxos: impl IntoIterator<Item = impl VtxoRef>,
) -> Result<()>
pub async fn mark_vtxos_as_spent( &self, vtxos: impl IntoIterator<Item = impl VtxoRef>, ) -> Result<()>
Marks VTXOs as VtxoState::Spent.
This operation is idempotent: VTXOs already in VtxoState::Spent will remain spent (a redundant state entry may be added to history).
§Errors
- If the VTXO doesn’t exist.
- If a database error occurs.
Sourcepub async fn set_vtxo_states(
&self,
vtxos: impl IntoIterator<Item = impl VtxoRef>,
state: &VtxoState,
allowed_states: &[VtxoStateKind],
) -> Result<()>
pub async fn set_vtxo_states( &self, vtxos: impl IntoIterator<Item = impl VtxoRef>, state: &VtxoState, allowed_states: &[VtxoStateKind], ) -> Result<()>
Updates the state set the VtxoState of VTXOs corresponding to each given VtxoId while validating if the transition is allowed based on the current state and allowed transitions.
§Parameters
vtxos: The VtxoId of each Vtxo to update.state: A reference to the new VtxoState that the VTXOs should be transitioned to.allowed_states: A slice of VtxoStateKind representing the permissible current states from which the VTXOs are allowed to transition to the givenstate.
§Errors
- The database operation to update the states fails.
- The state transition is invalid or does not match the allowed transitions.
Sourcepub async fn store_locked_vtxos<'a>(
&self,
vtxos: impl IntoIterator<Item = &'a Vtxo>,
movement_id: Option<MovementId>,
) -> Result<()>
pub async fn store_locked_vtxos<'a>( &self, vtxos: impl IntoIterator<Item = &'a Vtxo>, movement_id: Option<MovementId>, ) -> Result<()>
Stores the given collection of VTXOs in the wallet with an initial state of VtxoState::Locked.
§Parameters
vtxos: The VTXOs to store in the wallet.
Sourcepub async fn store_spendable_vtxos<'a>(
&self,
vtxos: impl IntoIterator<Item = &'a Vtxo>,
) -> Result<()>
pub async fn store_spendable_vtxos<'a>( &self, vtxos: impl IntoIterator<Item = &'a Vtxo>, ) -> Result<()>
Stores the given collection of VTXOs in the wallet with an initial state of VtxoState::Spendable.
§Parameters
vtxos: The VTXOs to store in the wallet.
Sourcepub async fn store_spent_vtxos<'a>(
&self,
vtxos: impl IntoIterator<Item = &'a Vtxo>,
) -> Result<()>
pub async fn store_spent_vtxos<'a>( &self, vtxos: impl IntoIterator<Item = &'a Vtxo>, ) -> Result<()>
Stores the given collection of VTXOs in the wallet with an initial state of VtxoState::Spent.
§Parameters
vtxos: The VTXOs to store in the wallet.
Sourcepub async fn store_vtxos<'a>(
&self,
vtxos: impl IntoIterator<Item = &'a Vtxo>,
state: &VtxoState,
) -> Result<()>
pub async fn store_vtxos<'a>( &self, vtxos: impl IntoIterator<Item = &'a Vtxo>, state: &VtxoState, ) -> Result<()>
Stores the given collection of VTXOs in the wallet with the given initial state.
§Parameters
vtxos: The VTXOs to store in the wallet.state: The initial state of the VTXOs.
Sourcepub async fn unlock_vtxos(
&self,
vtxos: impl IntoIterator<Item = impl VtxoRef>,
) -> Result<()>
pub async fn unlock_vtxos( &self, vtxos: impl IntoIterator<Item = impl VtxoRef>, ) -> Result<()>
Attempts to unlock VTXOs with the given VtxoId values. This will only work if the current VtxoState is VtxoStateKind::Locked.
§Errors
- If the VTXO is not currently locked.
- If the VTXO doesn’t exist.
- If a database error occurs.
Source§impl Wallet
impl Wallet
Sourcepub async fn validate_arkoor_address(&self, address: &Address) -> Result<()>
pub async fn validate_arkoor_address(&self, address: &Address) -> Result<()>
Validate if we can send arkoor payments to the given ark::Address, for example an error will be returned if the given ark::Address belongs to a different server (see ark::address::ArkId).
Sourcepub async fn send_arkoor_payment(
&self,
destination: &Address,
amount: Amount,
) -> Result<Vec<Vtxo>>
pub async fn send_arkoor_payment( &self, destination: &Address, amount: Amount, ) -> Result<Vec<Vtxo>>
Makes an out-of-round payment to the given ark::Address. This does not require waiting for a round, so it should be relatively instantaneous.
If the Wallet doesn’t contain a VTXO larger than the given Amount, multiple payments will be chained together, resulting in the recipient receiving multiple VTXOs.
Note that a change Vtxo may be created as a result of this call. With each payment these will become more uneconomical to unilaterally exit, so you should eventually refresh them with Wallet::refresh_vtxos or periodically call Wallet::maintenance_refresh.
Source§impl Wallet
impl Wallet
Sourcepub async fn check_lightning_payment(
&self,
payment_hash: PaymentHash,
wait: bool,
) -> Result<Option<Preimage>>
pub async fn check_lightning_payment( &self, payment_hash: PaymentHash, wait: bool, ) -> Result<Option<Preimage>>
Checks the status of a lightning payment associated with a set of VTXOs, processes the payment result and optionally takes appropriate actions based on the payment outcome.
§Arguments
payment_hash- The PaymentHash identifying the lightning payment.wait- If true, asks the server to wait for payment completion (may block longer).
§Returns
Returns Ok(Some(Preimage)) if the payment is successfully completed and a preimage is
received.
Returns Ok(None) for payments still pending, failed payments or if necessary revocation
or exit processing occurs.
Returns an Err if an error occurs during the process.
§Behavior
- Validates that all HTLC VTXOs share the same invoice, amount and policy.
- Sends a request to the Ark server to check the payment status.
- Depending on the payment status:
- Failed: Revokes the associated VTXOs.
- Pending: Checks if the HTLC has expired based on the tip height. If expired, revokes the VTXOs.
- Complete: Extracts the payment preimage, logs the payment, registers movement in the database and returns the preimage.
Sourcepub async fn pay_lightning_invoice<T>(
&self,
invoice: T,
user_amount: Option<Amount>,
) -> Result<LightningSend>
pub async fn pay_lightning_invoice<T>( &self, invoice: T, user_amount: Option<Amount>, ) -> Result<LightningSend>
Pays a Lightning Invoice using Ark VTXOs. This is also an out-of-round payment so the same Wallet::send_arkoor_payment rules apply.
§Returns
Returns the Invoice for which payment was initiated.
Sourcepub async fn pay_lightning_address(
&self,
addr: &LightningAddress,
amount: Amount,
comment: Option<impl AsRef<str>>,
) -> Result<LightningSend>
pub async fn pay_lightning_address( &self, addr: &LightningAddress, amount: Amount, comment: Option<impl AsRef<str>>, ) -> Result<LightningSend>
Same as Wallet::pay_lightning_invoice but instead it pays a LightningAddress.
Sourcepub async fn pay_lightning_offer(
&self,
offer: Offer,
user_amount: Option<Amount>,
) -> Result<LightningSend>
pub async fn pay_lightning_offer( &self, offer: Offer, user_amount: Option<Amount>, ) -> Result<LightningSend>
Attempts to pay the given BOLT12 Offer using offchain funds.
Sourcepub async fn make_lightning_payment(
&self,
invoice: &Invoice,
original_payment_method: PaymentMethod,
user_amount: Option<Amount>,
) -> Result<LightningSend>
pub async fn make_lightning_payment( &self, invoice: &Invoice, original_payment_method: PaymentMethod, user_amount: Option<Amount>, ) -> Result<LightningSend>
Makes a payment using the Lightning Network. This is a low-level primitive to allow for more fine-grained control over the payment process. The primary purpose of using this method is to support PaymentMethod::Custom for other payment use cases such as LNURL-Pay.
It’s recommended to use the following higher-level functions where suitable:
- BOLT11: Wallet::pay_lightning_invoice
- BOLT12: Wallet::pay_lightning_offer
- Lightning Address: Wallet::pay_lightning_address
§Parameters
invoice: A reference to the BOLT11/BOLT12 invoice to be paid.original_payment_method: The payment method that the given invoice was originally derived from (e.g., BOLT11, an offer, lightning address). This will appear in the stored Movement.user_amount: An optional custom amount to override the amount specified in the invoice. If not provided, the invoice’s amount is used.
§Returns
Returns a LightningSend representing the successful payment.
If an error occurs during the process, an anyhow::Error is returned.
§Errors
This function can return an error for the following reasons:
- If the given payment method is not either an officially supported lightning payment method or PaymentMethod::Custom.
- The
invoicebelongs to a different network than the one configured in the server’s properties. - The
invoicehas already been paid (the payment hash exists in the database). - The
invoicecontains an invalid or tampered signature. - The amount to be sent is smaller than the dust limit (
P2TR_DUST). - The wallet doesn’t have enough funds to cover the payment.
- Validation, signing, server or network issues occur.
§Notes
- A movement won’t be recorded until we receive an intermediary HTLC VTXO.
- This is effectively an arkoor payment with an additional HTLC conversion step, so the same Wallet::send_arkoor_payment rules apply.
Source§impl Wallet
impl Wallet
Sourcepub async fn bolt11_invoice(&self, amount: Amount) -> Result<Bolt11Invoice>
pub async fn bolt11_invoice(&self, amount: Amount) -> Result<Bolt11Invoice>
Create, store and return a Bolt11Invoice for offchain boarding
Sourcepub async fn lightning_receive_status(
&self,
payment: impl Into<PaymentHash>,
) -> Result<Option<LightningReceive>>
pub async fn lightning_receive_status( &self, payment: impl Into<PaymentHash>, ) -> Result<Option<LightningReceive>>
Fetches the status of a lightning receive for the given PaymentHash.
Sourcepub async fn try_claim_lightning_receive(
&self,
payment_hash: PaymentHash,
wait: bool,
token: Option<&str>,
) -> Result<LightningReceive>
pub async fn try_claim_lightning_receive( &self, payment_hash: PaymentHash, wait: bool, token: Option<&str>, ) -> Result<LightningReceive>
Check and claim a Lightning receive
This function checks for an incoming lightning payment with the given PaymentHash and then claims the payment using returned HTLC VTXOs.
§Arguments
payment_hash- The PaymentHash of the lightning payment to check for.wait- Whether to wait for the payment to be received.token- An optional lightning receive token used to authenticate a lightning receive when no spendable VTXOs are owned by this wallet.
§Returns
Returns an anyhow::Result<LightningReceive>, which is:
Ok(LightningReceive)if the claim was completed or is awaiting HTLC VTXOsErrif an error occurs at any stage of the operation.
§Remarks
- The payment hash must be from an invoice previously generated using Wallet::bolt11_invoice.
Sourcepub async fn try_claim_all_lightning_receives(&self, wait: bool) -> Result<()>
pub async fn try_claim_all_lightning_receives(&self, wait: bool) -> Result<()>
Check and claim all opened Lightning receive
This function fetches all opened lightning receives and then concurrently tries to check and claim them.
§Arguments
wait- Whether to wait for each payment to be received.
§Returns
Returns an anyhow::Result<()>, which is:
Ok(())if at least one claim succeeded or there were no pending receives.Errif all claim attempts failed.
Source§impl Wallet
impl Wallet
Sourcepub async fn offboard_all(&self, address: Address) -> Result<Txid>
pub async fn offboard_all(&self, address: Address) -> Result<Txid>
Offboard all VTXOs to a given bitcoin::Address.
Sourcepub async fn offboard_vtxos<V: VtxoRef>(
&self,
vtxos: impl IntoIterator<Item = V>,
address: Address,
) -> Result<Txid>
pub async fn offboard_vtxos<V: VtxoRef>( &self, vtxos: impl IntoIterator<Item = V>, address: Address, ) -> Result<Txid>
Offboard the given VTXOs to a given bitcoin::Address.
Source§impl Wallet
impl Wallet
Sourcepub fn chain_source(config: &Config) -> Result<ChainSourceSpec>
pub fn chain_source(config: &Config) -> Result<ChainSourceSpec>
Creates a chain::ChainSource instance to communicate with an onchain backend from the given Config.
Sourcepub fn require_chainsource_version(&self) -> Result<()>
pub fn require_chainsource_version(&self) -> Result<()>
Verifies that the bark Wallet can be used with the configured chain::ChainSource. More specifically, if the chain::ChainSource connects to Bitcoin Core it must be a high enough version to support ephemeral anchors.
pub async fn network(&self) -> Result<Network>
Sourcepub async fn derive_store_next_keypair(&self) -> Result<(Keypair, u32)>
pub async fn derive_store_next_keypair(&self) -> Result<(Keypair, u32)>
Derive and store the keypair directly after currently last revealed one, together with its index.
Sourcepub async fn peak_keypair(&self, index: u32) -> Result<Keypair>
pub async fn peak_keypair(&self, index: u32) -> Result<Keypair>
Retrieves a keypair based on the provided index and checks if the corresponding public key exists in the Vtxo database.
§Arguments
index- The index used to derive a keypair.
§Returns
Ok(Keypair)- If the keypair is successfully derived and its public key exists in the database.Err(anyhow::Error)- If the public key does not exist in the database or if an error occurs during the database query.
Sourcepub async fn pubkey_keypair(
&self,
public_key: &PublicKey,
) -> Result<Option<(u32, Keypair)>>
pub async fn pubkey_keypair( &self, public_key: &PublicKey, ) -> Result<Option<(u32, Keypair)>>
Retrieves the Keypair for a provided PublicKey
§Arguments
public_key- The public key for which the keypair must be found
§Returns
Ok(Some(u32, Keypair))- If the pubkey is found, the derivation-index and keypair are returnedOk(None)- If the pubkey cannot be found in the databaseErr(anyhow::Error)- If an error occurred related to the database query
Sourcepub async fn get_vtxo_key(&self, vtxo: impl VtxoRef) -> Result<Keypair>
pub async fn get_vtxo_key(&self, vtxo: impl VtxoRef) -> Result<Keypair>
Sourcepub async fn new_address(&self) -> Result<Address>
pub async fn new_address(&self) -> Result<Address>
Generate a new ark::Address.
Sourcepub async fn peak_address(&self, index: u32) -> Result<Address>
pub async fn peak_address(&self, index: u32) -> Result<Address>
Peak for an ark::Address at the given key index.
May return an error if the address at the given index has not been derived yet.
Sourcepub async fn new_address_with_index(&self) -> Result<(Address, u32)>
pub async fn new_address_with_index(&self) -> Result<(Address, u32)>
Generate a new ark::Address and returns the index of the key used to create it.
This derives and stores the keypair directly after currently last revealed one.
Sourcepub async fn create(
mnemonic: &Mnemonic,
network: Network,
config: Config,
db: Arc<dyn BarkPersister>,
force: bool,
) -> Result<Wallet>
pub async fn create( mnemonic: &Mnemonic, network: Network, config: Config, db: Arc<dyn BarkPersister>, force: bool, ) -> Result<Wallet>
Create a new wallet without an optional onchain backend. This will restrict features such as boarding and unilateral exit.
The force flag will allow you to create the wallet even if a connection to the Ark server
cannot be established, it will not overwrite a wallet which has already been created.
Sourcepub async fn create_with_onchain(
mnemonic: &Mnemonic,
network: Network,
config: Config,
db: Arc<dyn BarkPersister>,
onchain: &dyn ExitUnilaterally,
force: bool,
) -> Result<Wallet>
pub async fn create_with_onchain( mnemonic: &Mnemonic, network: Network, config: Config, db: Arc<dyn BarkPersister>, onchain: &dyn ExitUnilaterally, force: bool, ) -> Result<Wallet>
Create a new wallet with an onchain backend. This enables full Ark functionality. A default
implementation of an onchain wallet when the onchain_bdk feature is enabled. See
onchain::OnchainWallet for more details. Alternatively, implement ExitUnilaterally if
you have your own onchain wallet implementation.
The force flag will allow you to create the wallet even if a connection to the Ark server
cannot be established, it will not overwrite a wallet which has already been created.
Sourcepub async fn open(
mnemonic: &Mnemonic,
db: Arc<dyn BarkPersister>,
config: Config,
) -> Result<Wallet>
pub async fn open( mnemonic: &Mnemonic, db: Arc<dyn BarkPersister>, config: Config, ) -> Result<Wallet>
Loads the bark wallet from the given database ensuring the fingerprint remains consistent.
Sourcepub async fn open_with_onchain(
mnemonic: &Mnemonic,
db: Arc<dyn BarkPersister>,
onchain: &dyn ExitUnilaterally,
cfg: Config,
) -> Result<Wallet>
pub async fn open_with_onchain( mnemonic: &Mnemonic, db: Arc<dyn BarkPersister>, onchain: &dyn ExitUnilaterally, cfg: Config, ) -> Result<Wallet>
Similar to Wallet::open however this also unilateral exits using the provided onchain wallet.
Sourcepub async fn properties(&self) -> Result<WalletProperties>
pub async fn properties(&self) -> Result<WalletProperties>
Retrieves the WalletProperties of the current bark Wallet.
Sourcepub fn fingerprint(&self) -> Fingerprint
pub fn fingerprint(&self) -> Fingerprint
Returns the fingerprint of the wallet.
pub async fn refresh_server(&self) -> Result<()>
Sourcepub async fn ark_info(&self) -> Result<Option<ArkInfo>>
pub async fn ark_info(&self) -> Result<Option<ArkInfo>>
Return ArkInfo fetched on last handshake with the Ark server
Sourcepub async fn balance(&self) -> Result<Balance>
pub async fn balance(&self) -> Result<Balance>
Return the Balance of the wallet.
Make sure you sync before calling this method.
Sourcepub async fn validate_vtxo(&self, vtxo: &Vtxo) -> Result<()>
pub async fn validate_vtxo(&self, vtxo: &Vtxo) -> Result<()>
Fetches Vtxo’s funding transaction and validates the VTXO against it.
Sourcepub async fn get_vtxo_by_id(&self, vtxo_id: VtxoId) -> Result<WalletVtxo>
pub async fn get_vtxo_by_id(&self, vtxo_id: VtxoId) -> Result<WalletVtxo>
Sourcepub async fn movements(&self) -> Result<Vec<Movement>>
👎Deprecated since 0.1.0-beta.5: Use Wallet::history instead
pub async fn movements(&self) -> Result<Vec<Movement>>
Fetches all movements ordered from newest to oldest.
Sourcepub async fn history(&self) -> Result<Vec<Movement>>
pub async fn history(&self) -> Result<Vec<Movement>>
Fetches all wallet fund movements ordered from newest to oldest.
Sourcepub async fn all_vtxos(&self) -> Result<Vec<WalletVtxo>>
pub async fn all_vtxos(&self) -> Result<Vec<WalletVtxo>>
Returns all VTXOs from the database.
Sourcepub async fn vtxos(&self) -> Result<Vec<WalletVtxo>>
pub async fn vtxos(&self) -> Result<Vec<WalletVtxo>>
Returns all not spent vtxos
Sourcepub async fn vtxos_with(
&self,
filter: &impl FilterVtxos,
) -> Result<Vec<WalletVtxo>>
pub async fn vtxos_with( &self, filter: &impl FilterVtxos, ) -> Result<Vec<WalletVtxo>>
Returns all vtxos matching the provided predicate
Sourcepub async fn spendable_vtxos(&self) -> Result<Vec<WalletVtxo>>
pub async fn spendable_vtxos(&self) -> Result<Vec<WalletVtxo>>
Returns all spendable vtxos
Sourcepub async fn spendable_vtxos_with(
&self,
filter: &impl FilterVtxos,
) -> Result<Vec<WalletVtxo>>
pub async fn spendable_vtxos_with( &self, filter: &impl FilterVtxos, ) -> Result<Vec<WalletVtxo>>
Returns all spendable vtxos matching the provided predicate
pub async fn pending_boards(&self) -> Result<Vec<PendingBoard>>
Sourcepub async fn pending_board_vtxos(&self) -> Result<Vec<WalletVtxo>>
pub async fn pending_board_vtxos(&self) -> Result<Vec<WalletVtxo>>
Queries the database for any VTXO that is an unregistered board. There is a lag time between when a board is created and when it becomes spendable.
See ArkInfo::required_board_confirmations and Wallet::sync_pending_boards.
Sourcepub async fn pending_round_input_vtxos(&self) -> Result<Vec<WalletVtxo>>
pub async fn pending_round_input_vtxos(&self) -> Result<Vec<WalletVtxo>>
Returns all VTXOs that are locked in a pending round
This excludes all input VTXOs for which the output VTXOs have already been created.
Sourcepub async fn pending_lightning_send_vtxos(&self) -> Result<Vec<WalletVtxo>>
pub async fn pending_lightning_send_vtxos(&self) -> Result<Vec<WalletVtxo>>
Queries the database for any VTXO that is a pending lightning send.
Sourcepub async fn get_expiring_vtxos(
&self,
threshold: BlockHeight,
) -> Result<Vec<WalletVtxo>>
pub async fn get_expiring_vtxos( &self, threshold: BlockHeight, ) -> Result<Vec<WalletVtxo>>
Returns all vtxos that will expire within threshold blocks
Sourcepub async fn sync_pending_boards(&self) -> Result<()>
pub async fn sync_pending_boards(&self) -> Result<()>
Attempts to register all pendings boards with the Ark server. A board transaction must have sufficient confirmations before it will be registered. For more details see ArkInfo::required_board_confirmations.
Sourcepub async fn maintenance(&self) -> Result<()>
pub async fn maintenance(&self) -> Result<()>
Performs maintenance tasks on the offchain wallet.
This can take a long period of time due to syncing rounds, arkoors, checking pending payments, progressing pending rounds, and refreshing VTXOs if necessary.
Sourcepub async fn maintenance_with_onchain<W: PreparePsbt + SignPsbt + ExitUnilaterally>(
&self,
onchain: &mut W,
) -> Result<()>
pub async fn maintenance_with_onchain<W: PreparePsbt + SignPsbt + ExitUnilaterally>( &self, onchain: &mut W, ) -> Result<()>
Performs maintenance tasks on the onchain and offchain wallet.
This can take a long period of time due to syncing the onchain wallet, registering boards, syncing rounds, arkoors, and the exit system, checking pending lightning payments and refreshing VTXOs if necessary.
Sourcepub async fn maybe_schedule_maintenance_refresh(
&self,
) -> Result<Option<RoundStateId>>
pub async fn maybe_schedule_maintenance_refresh( &self, ) -> Result<Option<RoundStateId>>
Checks VTXOs that are due to be refreshed, and schedules a refresh if any
This will include any VTXOs within the expiry threshold (Config::vtxo_refresh_expiry_threshold) or those which are uneconomical to exit due to onchain network conditions.
Returns a RoundStateId if a refresh is scheduled.
Sourcepub async fn maintenance_refresh(&self) -> Result<Option<RoundStatus>>
pub async fn maintenance_refresh(&self) -> Result<Option<RoundStatus>>
Performs a refresh of all VTXOs that are due to be refreshed, if any. This will include any VTXOs within the expiry threshold (Config::vtxo_refresh_expiry_threshold) or those which are uneconomical to exit due to onchain network conditions.
Returns a RoundStatus if a refresh occurs.
Sourcepub async fn sync(&self)
pub async fn sync(&self)
Sync offchain wallet and update onchain fees. This is a much more lightweight alternative to Wallet::maintenance as it will not refresh VTXOs or sync the onchain wallet.
Notes:
- The exit system will not be synced as doing so requires the onchain wallet.
Sourcepub async fn sync_exits(&self, onchain: &mut dyn ExitUnilaterally) -> Result<()>
pub async fn sync_exits(&self, onchain: &mut dyn ExitUnilaterally) -> Result<()>
Sync the transaction status of unilateral exits
This will not progress the unilateral exits in any way, it will merely check the transaction status of each transaction as well as check whether any exits have become claimable or have been claimed.
pub async fn pending_lightning_sends(&self) -> Result<Vec<LightningSend>>
Sourcepub async fn sync_pending_lightning_send_vtxos(&self) -> Result<()>
pub async fn sync_pending_lightning_send_vtxos(&self) -> Result<()>
Syncs pending lightning payments, verifying whether the payment status has changed and creating a revocation VTXO if necessary.
Sourcepub async fn dangerous_drop_vtxo(&self, vtxo_id: VtxoId) -> Result<()>
pub async fn dangerous_drop_vtxo(&self, vtxo_id: VtxoId) -> Result<()>
Drop a specific Vtxo from the database. This is destructive and will result in a loss of funds.
Sourcepub async fn dangerous_drop_all_vtxos(&self) -> Result<()>
pub async fn dangerous_drop_all_vtxos(&self) -> Result<()>
Drop all VTXOs from the database. This is destructive and will result in a loss of funds.
Sourcepub async fn board_amount(
&self,
onchain: &mut dyn Board,
amount: Amount,
) -> Result<PendingBoard>
pub async fn board_amount( &self, onchain: &mut dyn Board, amount: Amount, ) -> Result<PendingBoard>
Board a Vtxo with the given amount.
NB we will spend a little more onchain to cover fees.
Sourcepub async fn board_all(&self, onchain: &mut dyn Board) -> Result<PendingBoard>
pub async fn board_all(&self, onchain: &mut dyn Board) -> Result<PendingBoard>
Board a Vtxo with all the funds in your onchain wallet.
pub async fn sync_oors(&self) -> Result<()>
pub async fn build_refresh_participation<V: VtxoRef>( &self, vtxos: impl IntoIterator<Item = V>, ) -> Result<Option<RoundParticipation>>
Sourcepub async fn refresh_vtxos<V: VtxoRef>(
&self,
vtxos: impl IntoIterator<Item = V>,
) -> Result<Option<RoundStatus>>
pub async fn refresh_vtxos<V: VtxoRef>( &self, vtxos: impl IntoIterator<Item = V>, ) -> Result<Option<RoundStatus>>
This will refresh all provided VTXOs. Note that attempting to refresh a board VTXO which has not yet confirmed will result in an error.
Returns the RoundStatus of the round if a successful refresh occurred. It will return None if no Vtxo needed to be refreshed.
Sourcepub async fn get_vtxos_to_refresh(&self) -> Result<Vec<WalletVtxo>>
pub async fn get_vtxos_to_refresh(&self) -> Result<Vec<WalletVtxo>>
This will find all VTXOs that meets must-refresh criteria. Then, if there are some VTXOs to refresh, it will also add those that meet should-refresh criteria.
Sourcepub async fn get_first_expiring_vtxo_blockheight(
&self,
) -> Result<Option<BlockHeight>>
pub async fn get_first_expiring_vtxo_blockheight( &self, ) -> Result<Option<BlockHeight>>
Returns the block height at which the first VTXO will expire
Sourcepub async fn get_next_required_refresh_blockheight(
&self,
) -> Result<Option<BlockHeight>>
pub async fn get_next_required_refresh_blockheight( &self, ) -> Result<Option<BlockHeight>>
Returns the next block height at which we have a VTXO that we want to refresh
Sourcepub async fn pending_lightning_receives(&self) -> Result<Vec<LightningReceive>>
pub async fn pending_lightning_receives(&self) -> Result<Vec<LightningReceive>>
Fetches all pending lightning receives ordered from newest to oldest.
pub async fn claimable_lightning_receive_balance(&self) -> Result<Amount>
Sourcepub async fn run_daemon(
self: &Arc<Self>,
onchain: Arc<RwLock<dyn DaemonizableOnchainWallet>>,
) -> Result<DaemonHandle>
pub async fn run_daemon( self: &Arc<Self>, onchain: Arc<RwLock<dyn DaemonizableOnchainWallet>>, ) -> Result<DaemonHandle>
Starts a daemon for the wallet.
Note:
- This function doesn’t check if a daemon is already running, so it’s possible to start multiple daemons by mistake.
Trait Implementations§
Source§impl VtxoSigner for Wallet
impl VtxoSigner for Wallet
Source§fn witness<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
clause: &'life1 VtxoClause,
control_block: &'life2 ControlBlock,
sighash: TapSighash,
) -> Pin<Box<dyn Future<Output = Option<Witness>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn witness<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
clause: &'life1 VtxoClause,
control_block: &'life2 ControlBlock,
sighash: TapSighash,
) -> Pin<Box<dyn Future<Output = Option<Witness>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn can_sign<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
clause: &'life1 VtxoClause,
vtxo: &'life2 Vtxo,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
fn can_sign<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
clause: &'life1 VtxoClause,
vtxo: &'life2 Vtxo,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Sync + 'async_trait,
Source§fn find_signable_clause<'life0, 'life1, 'async_trait>(
&'life0 self,
vtxo: &'life1 Vtxo,
) -> Pin<Box<dyn Future<Output = Option<VtxoClause>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
fn find_signable_clause<'life0, 'life1, 'async_trait>(
&'life0 self,
vtxo: &'life1 Vtxo,
) -> Pin<Box<dyn Future<Output = Option<VtxoClause>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: Sync + 'async_trait,
Source§fn sign_input<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
vtxo: &'life1 Vtxo,
input_idx: usize,
sighash_cache: &'life2 mut SighashCache<impl Borrow<Transaction> + Send + Sync + 'async_trait>,
prevouts: &'life3 Prevouts<'_, impl Borrow<TxOut> + Send + Sync + 'async_trait>,
) -> Pin<Box<dyn Future<Output = Result<Witness, CannotSignVtxoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: Sync + 'async_trait,
fn sign_input<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
vtxo: &'life1 Vtxo,
input_idx: usize,
sighash_cache: &'life2 mut SighashCache<impl Borrow<Transaction> + Send + Sync + 'async_trait>,
prevouts: &'life3 Prevouts<'_, impl Borrow<TxOut> + Send + Sync + 'async_trait>,
) -> Pin<Box<dyn Future<Output = Result<Witness, CannotSignVtxoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: Sync + 'async_trait,
Source§fn sign_input_with_clause<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
vtxo: &'life1 Vtxo,
clause: &'life2 VtxoClause,
input_idx: usize,
sighash_cache: &'life3 mut SighashCache<impl Borrow<Transaction> + Send + Sync + 'async_trait>,
prevouts: &'life4 Prevouts<'_, impl Borrow<TxOut> + Send + Sync + 'async_trait>,
) -> Pin<Box<dyn Future<Output = Result<Witness, CannotSignVtxoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: Sync + 'async_trait,
fn sign_input_with_clause<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
vtxo: &'life1 Vtxo,
clause: &'life2 VtxoClause,
input_idx: usize,
sighash_cache: &'life3 mut SighashCache<impl Borrow<Transaction> + Send + Sync + 'async_trait>,
prevouts: &'life4 Prevouts<'_, impl Borrow<TxOut> + Send + Sync + 'async_trait>,
) -> Pin<Box<dyn Future<Output = Result<Witness, CannotSignVtxoError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Self: Sync + 'async_trait,
Auto Trait Implementations§
impl !Freeze for Wallet
impl !RefUnwindSafe for Wallet
impl Send for Wallet
impl Sync for Wallet
impl Unpin for Wallet
impl !UnwindSafe for Wallet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request