pub struct Account { /* private fields */ }Implementations§
Source§impl Account
impl Account
pub fn receiver(&mut self) -> Option<Receiver<Notification>>
Sourcepub fn new_recv_addr(&mut self) -> Address
pub fn new_recv_addr(&mut self) -> Address
Sourcepub fn new_change_addr(&mut self) -> Address
pub fn new_change_addr(&mut self) -> Address
Sourcepub fn recv_watch_tip(&self) -> u32
pub fn recv_watch_tip(&self) -> u32
Sourcepub fn change_watch_tip(&self) -> u32
pub fn change_watch_tip(&self) -> u32
Sourcepub fn generate_coins(&mut self)
pub fn generate_coins(&mut self)
Re-generate coin_store from tx_store
Sourcepub fn spendable_coins(&self) -> CoinState
pub fn spendable_coins(&self) -> CoinState
Returns spendable coins for the account.
Sourcepub fn tx_history(&self) -> Vec<Transaction>
pub fn tx_history(&self) -> Vec<Transaction>
Returns a list of all historical transactions
Sourcepub fn input_satisfaction_size(&self) -> Result<usize, Error>
pub fn input_satisfaction_size(&self) -> Result<usize, Error>
Calculates the satisfaction size for an input, returning the result in weight units (WU).
This function estimates the size required to satisfy the inputs of a transaction based on the account’s descriptor.
§Returns
A Result<usize, Error> where:
Ok(usize)indicates the estimated satisfaction size in weight units (WU).Err(Error)indicates an error occurred during the calculation.
§Errors
This function can return an error in the following cases:
- If the descriptor is invalid or cannot be parsed, leading to an inability to determine the satisfaction size for the inputs.
Sourcepub fn tx_estimated_weight(&self, tx: &Transaction) -> Result<u64, Error>
pub fn tx_estimated_weight(&self, tx: &Transaction) -> Result<u64, Error>
Estimates the maximum possible weight in weight units of an unsigned
transaction, tx, after satisfaction, assuming all inputs of tx are
from this descriptor.
§Arguments
tx- A reference to thebitcoin::Transactionfor which the weight is to be estimated.
§Returns
A Result<u64, Error> containing:
Ok(u64)- The estimated weight of the transaction in weight units (WU).Err(Error)- An error if the estimation fails.
§Errors
This function can return an error in the following cases:
- If the satisfaction size for the inputs cannot be calculated due to an invalid descriptor.
- If the input satisfaction size exceeds the maximum allowable weight, leading to an overflow.
- If the transaction contains no inputs, which would make weight estimation impossible.
- If there is an issue with the underlying logic of the weight calculation,
such as unexpected behavior from the
miniscriptlibrary.
§Note
The weight is calculated based on the number of inputs and their respective satisfaction sizes. The function takes into account the Segwit marker and flag, ensuring that the weight is accurately represented according to Bitcoin’s transaction weight rules. This logic have been borrowed from Liana wallet.
Sourcepub fn get_coin(&self, outpoint: &OutPoint) -> Option<Coin>
pub fn get_coin(&self, outpoint: &OutPoint) -> Option<Coin>
Returns the coin matching the given outpoint if found, else None.
Sourcepub fn dummy_spk(&self) -> ScriptBuf
pub fn dummy_spk(&self) -> ScriptBuf
Generates a static dummy script public key (SPK) for change outputs.
This function always returns the same dummy spk, It is useful for simulating change outputs in a non-final transaction while allowing for easy replacement of this SPK later during the final crafting of the transaction.
§Returns
A ScriptBuf representing the dummy script public key for the change address.
§Note
The SPK returned by this function is not intended for actual use in transactions until it is replaced with a valid SPK at the time of final transaction crafting.
Sourcepub fn process_transaction(
&self,
tx_template: &TransactionTemplate,
) -> Result<(Vec<CoinEntry>, Vec<(TxOut, Option<(AddrAccount, u32)>)>, bool), String>
pub fn process_transaction( &self, tx_template: &TransactionTemplate, ) -> Result<(Vec<CoinEntry>, Vec<(TxOut, Option<(AddrAccount, u32)>)>, bool), String>
Preprocesses a transaction based on the provided TransactionTemplate.
This function processes the transaction template to estimate whether the transaction can be successfully executed, including whether it is spendable and if it requires change.
§Arguments
tx_template- ATransactionTemplatecontaining the details of the transaction to be processed.
§Returns
A Result containing:
- A tuple with three elements:
- A
Vec<CoinEntry>representing the inputs for the transaction. - A
Vec<(TxOut, Option<(AddrAccount, u32)>)>representing the outputs for the transaction. - A boolean indicating if the transaction contains a change output.
- A
§Errors
This function can return an error in the following cases:
- If both
fee_satsandfee_sats_vbare filled, which is not allowed. - If neither
fee_satsnorfee_sats_vbis filled, which is required. - If
fee_sats_vbis filled with a value less than 1.0, which is below the minimum allowed fee rate. - If the provided outpoints do not match any available coins in the coin store. (external inputs are not allowed for now)
- If the total inputs amount is less than the total outputs amount, making the transaction invalid.
- If the maximum output is selected but there are not enough reserves to fill it.
- If the estimated fees exceed the available reserves.
- If there is an issue while handling the transaction history or if the transaction cannot be created for any other reason.
§Note
This function is intended for use in scenarios where users need to gather information about the transaction before finalizing it, allowing for adjustments based on the simulation results.
pub fn change_index(&self, tx: &Transaction) -> Option<usize>
Sourcepub fn simulate_transaction(
&self,
tx_template: TransactionTemplate,
) -> TransactionSimulation
pub fn simulate_transaction( &self, tx_template: TransactionTemplate, ) -> TransactionSimulation
Simulates a transaction based on the provided TransactionTemplate
This function processes the transaction template to estimate whether the transaction can be successfully executed, including whether it is spendable and if it requires change. It also calculates the estimated weight of the transaction in weight units (WU).
§Arguments
tx_template- ATransactionTemplatecontaining the details of the transaction to be simulated.
§Returns
A Result containing:
- A tuple with three elements:
- A boolean indicating if the transaction is spendable.
- A boolean indicating if the transaction has change.
- An estimated weight of the transaction in weight units (WU).
§Errors
This function can return an error in the following cases:
- If the transaction processing fails due to invalid outpoints in
tx_template.inputs. - If the provided outpoints do not match any available coins in the coin store
- If the addresses in
tx_template.outputscannot be parsed into validbitcoin::Addressinstances. - If the parsed addresses are not valid for the current network.
- If the total inputs amount is less than the total outputs amount, making the transaction invalid.
- If there is an issue while handling the transaction history or if the transaction cannot be created for any other reason.
§Note
This function is intended for use in scenarios where users need to gather information about the transaction before finalizing it, allowing for adjustments based on the simulation results.
Sourcepub fn prepare_transaction(
&mut self,
tx_template: TransactionTemplate,
) -> Result<String, String>
pub fn prepare_transaction( &mut self, tx_template: TransactionTemplate, ) -> Result<String, String>
Prepares a PSBT from a given TransactionTemplate.
This function processes the provided transaction template to create a PSBT that is ready for signing. It gathers the necessary inputs and outputs based on the transaction template and populates the PSBT with the appropriate descriptors for each input and output.
§Arguments
tx_template- ATransactionTemplatecontaining the details of the transaction to be processed. This includes inputs, outputs, and fee information.
§Returns
A Box<PsbtResult> containing the following:
Ok(psbt)- A successfully created PSBT as a string.Err(String)- An error message if the PSBT could not be created.
§Errors
This function can return an error in the following cases:
- If the provided
TransactionTemplateis invalid or does not contain the necessary information. - If the inputs specified in the transaction template do not match any available coins in the coin store.
- If the outputs specified in the transaction template cannot be parsed into valid Bitcoin addresses.
- If the total input amount is less than the total output amount, making the transaction invalid.
- If the fee specified is greater than the available reserves, preventing the transaction from being processed.
- If there is an issue while creating the PSBT from the unsigned transaction, such as invalid input data.
- If the function encounters any unexpected errors during processing.
§Note
This function is intended for use in scenarios where users need to prepare a transaction for signing, allowing for adjustments based on the provided transaction template before finalizing the transaction.
Sourcepub fn set_electrum(&mut self, url: String, port: String)
pub fn set_electrum(&mut self, url: String, port: String)
Sets the Electrum server URL and port for the account.
§Arguments
url- The URL of the Electrum server.port- The port of the Electrum server.
Sourcepub fn start_electrum(&mut self)
pub fn start_electrum(&mut self)
Starts the Electrum listener for the account.
Sourcepub fn stop_electrum(&mut self)
pub fn stop_electrum(&mut self)
Stops the Electrum listener for the account.
Sourcepub fn set_look_ahead(&mut self, look_ahead: String)
pub fn set_look_ahead(&mut self, look_ahead: String)
Sourcepub fn get_config(&self) -> Config
pub fn get_config(&self) -> Config
Sourcepub fn recv_addr_at(&self, index: u32) -> String
pub fn recv_addr_at(&self, index: u32) -> String
Sourcepub fn change_addr_at(&self, index: u32) -> String
pub fn change_addr_at(&self, index: u32) -> String
Sourcepub fn new_addr(&mut self) -> RustAddress
pub fn new_addr(&mut self) -> RustAddress
Sourcepub fn edit_coin_label(&self, outpoint: String, label: String)
pub fn edit_coin_label(&self, outpoint: String, label: String)
Edits the label of a coin identified by the given outpoint.
§Arguments
outpoint- A string representation of the outpoint for the coin.label- The new label to set for the coin. If the label is empty, the label will be removed.