Account

Struct Account 

Source
pub struct Account { /* private fields */ }

Implementations§

Source§

impl Account

Source

pub fn new(config: Config) -> Self

Creates a new Account instance with the given configuration.

§Arguments
  • config - The configuration for the account.
§Returns

A new Account instance.

Source

pub fn receiver(&mut self) -> Option<Receiver<Notification>>

Source

pub fn derivator(&self) -> Derivator

Returns the derivator associated with the account.

§Returns

A Derivator instance.

Source

pub fn coins(&self) -> BTreeMap<OutPoint, CoinEntry>

Returns a map of coins associated with the account.

§Returns

A BTreeMap of OutPoint to CoinEntry.

Source

pub fn recv_at(&self, index: u32) -> Address

Returns the receiving address at the specified index.

§Arguments
  • index - The index of the receiving address.
§Returns

A bitcoin::Address instance.

Source

pub fn change_at(&self, index: u32) -> Address

Returns the change address at the specified index.

§Arguments
  • index - The index of the change address.
§Returns

A bitcoin::Address instance.

Source

pub fn new_recv_addr(&mut self) -> Address

Generates a new receiving address for the account.

§Returns

A bitcoin::Address instance.

Source

pub fn new_change_addr(&mut self) -> Address

Generates a new change address for the account.

§Returns

A bitcoin::Address instance.

Source

pub fn recv_watch_tip(&self) -> u32

Returns the current receiving watch tip index.

§Returns

The receiving watch tip index as a u32.

Source

pub fn change_watch_tip(&self) -> u32

Returns the current change watch tip index.

§Returns

The change watch tip index as a u32.

Source

pub fn generate_coins(&mut self)

Re-generate coin_store from tx_store

Source

pub fn spendable_coins(&self) -> CoinState

Returns spendable coins for the account.

Source

pub fn tx_history(&self) -> Vec<Transaction>

Returns a list of all historical transactions

Source

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.
Source

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 the bitcoin::Transaction for 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 miniscript library.
§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.

Source

pub fn get_coin(&self, outpoint: &OutPoint) -> Option<Coin>

Returns the coin matching the given outpoint if found, else None.

Source

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.

Source

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 - A TransactionTemplate containing 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.
§Errors

This function can return an error in the following cases:

  • If both fee_sats and fee_sats_vb are filled, which is not allowed.
  • If neither fee_sats nor fee_sats_vb is filled, which is required.
  • If fee_sats_vb is 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.

Source

pub fn change_index(&self, tx: &Transaction) -> Option<usize>

Source

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 - A TransactionTemplate containing 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.outputs cannot be parsed into valid bitcoin::Address instances.
  • 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.

Source

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 - A TransactionTemplate containing 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 TransactionTemplate is 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.

Source

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.
Source

pub fn start_electrum(&mut self)

Starts the Electrum listener for the account.

Source

pub fn stop_electrum(&mut self)

Stops the Electrum listener for the account.

Source

pub fn set_look_ahead(&mut self, look_ahead: String)

Sets the look-ahead value for the account.

§Arguments
  • look_ahead - The look-ahead value to set.
Source

pub fn get_config(&self) -> Config

Returns the configuration of the account.

§Returns

A boxed Config instance.

Source

pub fn recv_addr_at(&self, index: u32) -> String

Returns the receiving address at the specified index as a string.

§Arguments
  • index - The index of the receiving address.
§Returns

The receiving address as a string.

Source

pub fn change_addr_at(&self, index: u32) -> String

Returns the change address at the specified index as a string.

§Arguments
  • index - The index of the change address.
§Returns

The change address as a string.

Source

pub fn new_addr(&mut self) -> RustAddress

Generates a new receiving address entry for the account.

§Returns

A boxed AddressEntry instance.

Source

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.
Source

pub fn sign(&self, psbt: String)

Trait Implementations§

Source§

impl Debug for Account

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Account

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Account

§

impl !RefUnwindSafe for Account

§

impl Send for Account

§

impl !Sync for Account

§

impl Unpin for Account

§

impl !UnwindSafe for Account

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V