pub struct NodeManager<S: MutinyStorage> {
    pub safe_mode: bool,
    /* private fields */
}
Expand description

The NodeManager is the main entry point for interacting with the Mutiny Wallet. It is responsible for managing the on-chain wallet and the lightning nodes.

It can be used to create a new wallet, or to load an existing wallet.

It can be configured to use all different custom backend services, or to use the default services provided by Mutiny.

Fields§

§safe_mode: bool

Implementations§

source§

impl<S: MutinyStorage> NodeManager<S>

source

pub fn has_node_manager(storage: S) -> bool

Returns if there is a saved wallet in storage. This is checked by seeing if a mnemonic seed exists in storage.

source

pub async fn new( c: MutinyWalletConfig, storage: S, session_id: Option<String> ) -> Result<NodeManager<S>, MutinyError>

Creates a new NodeManager with the given parameters. The mnemonic seed is read from storage, unless one is provided. If no mnemonic is provided, a new one is generated and stored.

source

pub async fn stop(&self) -> Result<(), MutinyError>

Stops all of the nodes and background processes. Returns after node has been stopped.

source

pub fn start_sync(nm: Arc<NodeManager<S>>)

Creates a background process that will sync the wallet with the blockchain. This will also update the fee estimates every 10 minutes.

source

pub async fn broadcast_transaction( &self, tx: Transaction ) -> Result<(), MutinyError>

Broadcast a transaction to the network. The transaction is broadcast through the configured esplora server.

source

pub fn get_network(&self) -> Network

Returns the network of the wallet.

source

pub fn get_new_address( &self, labels: Vec<String> ) -> Result<Address, MutinyError>

Gets a new bitcoin address from the wallet. Will generate a new address on every call.

It is recommended to create a new address for every transaction.

source

pub fn get_wallet_balance(&self) -> Result<u64, MutinyError>

Gets the current balance of the on-chain wallet.

source

pub async fn create_bip21( &self, amount: Option<u64>, labels: Vec<String> ) -> Result<MutinyBip21RawMaterials, MutinyError>

Creates a BIP 21 invoice. This creates a new address and a lightning invoice. The lightning invoice may return errors related to the LSP. Check the error and fallback to get_new_address and warn the user that Lightning is not available.

Errors that might be returned include:

  • MutinyError::LspGenericError: This is returned for various reasons, including if a request to the LSP server fails for any reason, or if the server returns a status other than 500 that can’t be parsed into a ProposalResponse.

  • MutinyError::LspFundingError: Returned if the LSP server returns an error with a status of 500, indicating an “Internal Server Error”, and a message stating “Cannot fund new channel at this time”. This means that the LSP cannot support a new channel at this time.

  • MutinyError::LspAmountTooHighError: Returned if the LSP server returns an error with a status of 500, indicating an “Internal Server Error”, and a message stating “Invoice amount is too high”. This means that the LSP cannot support the amount that the user requested. The user should request a smaller amount from the LSP.

  • MutinyError::LspConnectionError: Returned if the LSP server returns an error with a status of 500, indicating an “Internal Server Error”, and a message that starts with “Failed to connect to peer”. This means that the LSP is not connected to our node.

If the server returns a status of 500 with a different error message, a MutinyError::LspGenericError is returned.

source

pub async fn send_payjoin( &self, uri: PjUri<'_>, amount: u64, labels: Vec<String>, fee_rate: Option<f32> ) -> Result<Txid, MutinyError>

source

pub async fn send_to_address( &self, send_to: Address, amount: u64, labels: Vec<String>, fee_rate: Option<f32> ) -> Result<Txid, MutinyError>

Sends an on-chain transaction to the given address. The amount is in satoshis and the fee rate is in sat/vbyte.

If a fee rate is not provided, one will be used from the fee estimator.

source

pub async fn sweep_wallet( &self, send_to: Address, labels: Vec<String>, fee_rate: Option<f32> ) -> Result<Txid, MutinyError>

Sweeps all the funds from the wallet to the given address. The fee rate is in sat/vbyte.

If a fee rate is not provided, one will be used from the fee estimator.

source

pub fn estimate_tx_fee( &self, destination_address: Address, amount: u64, fee_rate: Option<f32> ) -> Result<u64, MutinyError>

Estimates the onchain fee for a transaction sending to the given address. The amount is in satoshis and the fee rate is in sat/vbyte.

source

pub fn estimate_sweep_tx_fee( &self, destination_address: Address, fee_rate: Option<f32> ) -> Result<u64, MutinyError>

Estimates the onchain fee for a transaction sweep our on-chain balance to the given address.

The fee rate is in sat/vbyte.

source

pub fn estimate_channel_open_fee( &self, amount: u64, fee_rate: Option<f32> ) -> Result<u64, MutinyError>

Estimates the onchain fee for a opening a lightning channel. The amount is in satoshis and the fee rate is in sat/vbyte.

source

pub fn estimate_sweep_channel_open_fee( &self, fee_rate: Option<f32> ) -> Result<u64, MutinyError>

Estimates the onchain fee for sweeping our on-chain balance to open a lightning channel. The fee rate is in sat/vbyte.

source

pub async fn check_address( &self, address: &Address ) -> Result<Option<TransactionDetails>, MutinyError>

Checks if the given address has any transactions. If it does, it returns the details of the first transaction.

This should be used to check if a payment has been made to an address.

source

pub async fn get_activity(&self) -> Result<Vec<ActivityItem>, MutinyError>

Returns all the on-chain and lightning activity from the wallet.

source

pub async fn get_label_activity( &self, label: &String ) -> Result<Vec<ActivityItem>, MutinyError>

Returns all the on-chain and lightning activity for a given label

source

pub fn list_onchain(&self) -> Result<Vec<TransactionDetails>, MutinyError>

Lists all the on-chain transactions in the wallet. These are sorted by confirmation time.

source

pub fn get_transaction( &self, txid: Txid ) -> Result<Option<TransactionDetails>, MutinyError>

Gets the details of a specific on-chain transaction.

source

pub async fn get_balance(&self) -> Result<MutinyBalance, MutinyError>

Gets the current balance of the wallet. This includes both on-chain and lightning funds.

This will not include any funds in an unconfirmed lightning channel.

source

pub fn list_utxos(&self) -> Result<Vec<LocalUtxo>, MutinyError>

Lists all the UTXOs in the wallet.

source

pub fn estimate_fee_low(&self) -> u32

Gets a fee estimate for a very low priority transaction. Value is in sat/vbyte.

source

pub fn estimate_fee_normal(&self) -> u32

Gets a fee estimate for an average priority transaction. Value is in sat/vbyte.

source

pub fn estimate_fee_high(&self) -> u32

Gets a fee estimate for an high priority transaction. Value is in sat/vbyte.

source

pub async fn new_node(&self) -> Result<NodeIdentity, MutinyError>

Creates a new lightning node and adds it to the manager.

source

pub async fn list_nodes(&self) -> Result<Vec<PublicKey>, MutinyError>

Lists the pubkeys of the lightning node in the manager.

source

pub async fn connect_to_peer( &self, self_node_pubkey: &PublicKey, connection_string: &str, label: Option<String> ) -> Result<(), MutinyError>

Attempts to connect to a peer from the selected node.

source

pub async fn disconnect_peer( &self, self_node_pubkey: &PublicKey, peer: PublicKey ) -> Result<(), MutinyError>

Disconnects from a peer from the selected node.

source

pub async fn delete_peer( &self, self_node_pubkey: &PublicKey, peer: &NodeId ) -> Result<(), MutinyError>

Deletes a peer from the selected node. This will make it so that the node will not attempt to reconnect to the peer.

source

pub fn label_peer( &self, node_id: &NodeId, label: Option<String> ) -> Result<(), MutinyError>

Sets the label of a peer from the selected node.

source

pub async fn create_invoice( &self, amount: Option<u64>, labels: Vec<String> ) -> Result<MutinyInvoice, MutinyError>

Creates a lightning invoice. The amount should be in satoshis. If no amount is provided, the invoice will be created with no amount. If no description is provided, the invoice will be created with no description.

If the manager has more than one node it will create a phantom invoice. If there is only one node it will create an invoice just for that node.

source

pub async fn pay_invoice( &self, from_node: &PublicKey, invoice: &Bolt11Invoice, amt_sats: Option<u64>, labels: Vec<String> ) -> Result<MutinyInvoice, MutinyError>

Pays a lightning invoice from the selected node. An amount should only be provided if the invoice does not have an amount. The amount should be in satoshis.

source

pub async fn keysend( &self, from_node: &PublicKey, to_node: PublicKey, amt_sats: u64, message: Option<String>, labels: Vec<String> ) -> Result<MutinyInvoice, MutinyError>

Sends a spontaneous payment to a node from the selected node. The amount should be in satoshis.

source

pub async fn decode_invoice( &self, invoice: Bolt11Invoice, network: Option<Network> ) -> Result<MutinyInvoice, MutinyError>

Decodes a lightning invoice into useful information. Will return an error if the invoice is for a different network.

source

pub async fn decode_lnurl( &self, lnurl: LnUrl ) -> Result<LnUrlParams, MutinyError>

Calls upon a LNURL to get the parameters for it. This contains what kind of LNURL it is (pay, withdrawal, auth, etc).

source

pub async fn lnurl_pay( &self, from_node: &PublicKey, lnurl: &LnUrl, amount_sats: u64, zap_npub: Option<XOnlyPublicKey>, labels: Vec<String> ) -> Result<MutinyInvoice, MutinyError>

Calls upon a LNURL and pays it. This will fail if the LNURL is not a LNURL pay.

source

pub async fn lnurl_withdraw( &self, lnurl: &LnUrl, amount_sats: u64 ) -> Result<bool, MutinyError>

Calls upon a LNURL and withdraws from it. This will fail if the LNURL is not a LNURL withdrawal.

source

pub async fn lnurl_auth(&self, lnurl: LnUrl) -> Result<(), MutinyError>

Authenticate with a LNURL-auth

source

pub async fn get_invoice( &self, invoice: &Bolt11Invoice ) -> Result<MutinyInvoice, MutinyError>

Gets an invoice from the node manager. This includes sent and received invoices.

source

pub async fn get_invoice_by_hash( &self, hash: &Hash ) -> Result<MutinyInvoice, MutinyError>

Gets an invoice from the node manager. This includes sent and received invoices.

source

pub async fn list_invoices(&self) -> Result<Vec<MutinyInvoice>, MutinyError>

Gets an invoice from the node manager. This includes sent and received invoices.

source

pub async fn get_channel_closure( &self, user_channel_id: u128 ) -> Result<ChannelClosure, MutinyError>

source

pub async fn list_channel_closures( &self ) -> Result<Vec<ChannelClosure>, MutinyError>

source

pub async fn open_channel( &self, from_node: &PublicKey, to_pubkey: Option<PublicKey>, amount: u64, fee_rate: Option<f32>, user_channel_id: Option<u128> ) -> Result<MutinyChannel, MutinyError>

Opens a channel from our selected node to the given pubkey. The amount is in satoshis.

The node must be online and have a connection to the peer. The wallet much have enough funds to open the channel.

source

pub async fn sweep_utxos_to_channel( &self, user_chan_id: Option<u128>, from_node: &PublicKey, utxos: &[OutPoint], to_pubkey: Option<PublicKey> ) -> Result<MutinyChannel, MutinyError>

Opens a channel from our selected node to the given pubkey. It will spend the given utxos in full to fund the channel.

The node must be online and have a connection to the peer. The UTXOs must all exist in the wallet.

source

pub async fn sweep_all_to_channel( &self, user_chan_id: Option<u128>, from_node: &PublicKey, to_pubkey: Option<PublicKey> ) -> Result<MutinyChannel, MutinyError>

Opens a channel from our selected node to the given pubkey. It will spend the all the on-chain utxo in full to fund the channel.

The node must be online and have a connection to the peer.

source

pub async fn close_channel( &self, outpoint: &OutPoint, address: Option<Address>, force: bool, abandon: bool ) -> Result<(), MutinyError>

Closes a channel with the given outpoint.

If force is true, the channel will be force closed.

If abandon is true, the channel will be abandoned. This will force close without broadcasting the latest transaction. This should only be used if the channel will never actually be opened.

If both force and abandon are true, an error will be returned.

source

pub async fn list_channels(&self) -> Result<Vec<MutinyChannel>, MutinyError>

Lists all the channels for all the nodes in the node manager.

source

pub async fn list_peers(&self) -> Result<Vec<MutinyPeer>, MutinyError>

Lists all the peers for all the nodes in the node manager.

source

pub async fn get_subscription_plans(&self) -> Result<Vec<Plan>, MutinyError>

Gets the subscription plans for Mutiny+ subscriptions

source

pub async fn subscribe_to_plan( &self, id: u8 ) -> Result<MutinyInvoice, MutinyError>

Subscribes to a Mutiny+ plan with a specific plan id.

Returns a lightning invoice so that the plan can be paid for to start it.

source

pub async fn get_bitcoin_price( &self, fiat: Option<String> ) -> Result<f32, MutinyError>

Gets the current bitcoin price in USD.

source

pub fn get_logs( storage: S, logger: Arc<MutinyLogger> ) -> Result<Option<Vec<String>>, MutinyError>

Retrieves the logs from storage.

source

pub async fn reset_router(&self) -> Result<(), MutinyError>

Resets the scorer and network graph. This can be useful if you get stuck in a bad state.

source

pub async fn reset_onchain_tracker(&self) -> Result<(), MutinyError>

Resets BDK’s keychain tracker. This will require a re-sync of the blockchain.

This can be useful if you get stuck in a bad state.

source

pub async fn export_json(storage: S) -> Result<Value, MutinyError>

Exports the current state of the node manager to a json object.

Trait Implementations§

source§

impl<S: MutinyStorage> LabelStorage for NodeManager<S>

source§

fn get_address_labels( &self ) -> Result<HashMap<String, Vec<String>>, MutinyError>

Get a map of addresses to labels. This can be used to get all the labels for an address
source§

fn get_invoice_labels( &self ) -> Result<HashMap<Bolt11Invoice, Vec<String>>, MutinyError>

Get a map of invoices to labels. This can be used to get all the labels for an invoice
source§

fn get_labels(&self) -> Result<HashMap<String, LabelItem>, MutinyError>

Get all the existing labels
source§

fn get_label( &self, label: impl AsRef<str> ) -> Result<Option<LabelItem>, MutinyError>

Get information about a label
source§

fn set_address_labels( &self, address: Address, labels: Vec<String> ) -> Result<(), MutinyError>

Set the labels for an address, replacing any existing labels If you do not want to replace any existing labels, use get_address_labels to get the existing labels, add the new labels, and then use set_address_labels to set the new labels
source§

fn set_invoice_labels( &self, invoice: Bolt11Invoice, labels: Vec<String> ) -> Result<(), MutinyError>

Set the labels for an invoice, replacing any existing labels If you do not want to replace any existing labels, use get_invoice_labels to get the existing labels, add the new labels, and then use set_invoice_labels to set the new labels
source§

fn get_contacts(&self) -> Result<HashMap<String, Contact>, MutinyError>

Get all the existing contacts
source§

fn get_contact( &self, label: impl AsRef<str> ) -> Result<Option<Contact>, MutinyError>

Get a contact by label, the label should be a uuid
source§

fn create_contact_from_label( &self, label: impl AsRef<str>, contact: Contact ) -> Result<String, MutinyError>

Create a new contact from an existing label and returns the new identifying label
source§

fn create_new_contact(&self, contact: Contact) -> Result<String, MutinyError>

Create a new contact and return the identifying label
source§

fn archive_contact(&self, id: impl AsRef<str>) -> Result<(), MutinyError>

Marks a contact as archived
source§

fn edit_contact( &self, id: impl AsRef<str>, contact: Contact ) -> Result<(), MutinyError>

Edits an existing contact and replaces the existing contact
source§

fn get_tag_items(&self) -> Result<Vec<TagItem>, MutinyError>

Gets all the existing tags (labels and contacts)
source§

fn get_contact_for_lnurl( &self, lnurl: &LnUrl ) -> Result<Option<String>, MutinyError>

Finds a contact that has the given lnurl as either a lnurl or a lightning address
source§

impl<S: MutinyStorage> RedshiftManager for NodeManager<S>

source§

async fn init_redshift( &self, utxo: OutPoint, recipient: RedshiftRecipient, introduction_node: Option<PublicKey>, connection_string: Option<&str> ) -> Result<Redshift, MutinyError>

Initializes a redshift. Creates a new node and attempts to open a channel to the introduction node.
source§

fn get_redshift(&self, id: &[u8; 16]) -> Result<Option<Redshift>, MutinyError>

source§

async fn attempt_payments(&self, rs: Redshift) -> Result<(), MutinyError>

source§

async fn close_channels(&self, rs: Redshift) -> Result<(), MutinyError>

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for NodeManager<S>

§

impl<S> !Send for NodeManager<S>

§

impl<S> !Sync for NodeManager<S>

§

impl<S> Unpin for NodeManager<S>where S: Unpin,

§

impl<S> !UnwindSafe for NodeManager<S>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more