Struct mutiny_core::nodemanager::NodeManager
source · 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>
impl<S: MutinyStorage> NodeManager<S>
sourcepub fn has_node_manager(storage: S) -> bool
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.
sourcepub async fn new(
c: MutinyWalletConfig,
storage: S,
session_id: Option<String>
) -> Result<NodeManager<S>, MutinyError>
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.
sourcepub async fn stop(&self) -> Result<(), MutinyError>
pub async fn stop(&self) -> Result<(), MutinyError>
Stops all of the nodes and background processes. Returns after node has been stopped.
sourcepub fn start_sync(nm: Arc<NodeManager<S>>)
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.
sourcepub async fn broadcast_transaction(
&self,
tx: Transaction
) -> Result<(), MutinyError>
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.
sourcepub fn get_network(&self) -> Network
pub fn get_network(&self) -> Network
Returns the network of the wallet.
sourcepub fn get_new_address(
&self,
labels: Vec<String>
) -> Result<Address, MutinyError>
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.
sourcepub fn get_wallet_balance(&self) -> Result<u64, MutinyError>
pub fn get_wallet_balance(&self) -> Result<u64, MutinyError>
Gets the current balance of the on-chain wallet.
sourcepub async fn create_bip21(
&self,
amount: Option<u64>,
labels: Vec<String>
) -> Result<MutinyBip21RawMaterials, MutinyError>
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 aProposalResponse
. -
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.
pub async fn send_payjoin( &self, uri: PjUri<'_>, amount: u64, labels: Vec<String>, fee_rate: Option<f32> ) -> Result<Txid, MutinyError>
sourcepub async fn send_to_address(
&self,
send_to: Address,
amount: u64,
labels: Vec<String>,
fee_rate: Option<f32>
) -> Result<Txid, MutinyError>
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.
sourcepub async fn sweep_wallet(
&self,
send_to: Address,
labels: Vec<String>,
fee_rate: Option<f32>
) -> Result<Txid, MutinyError>
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.
sourcepub fn estimate_tx_fee(
&self,
destination_address: Address,
amount: u64,
fee_rate: Option<f32>
) -> Result<u64, MutinyError>
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.
sourcepub fn estimate_sweep_tx_fee(
&self,
destination_address: Address,
fee_rate: Option<f32>
) -> Result<u64, MutinyError>
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.
sourcepub fn estimate_channel_open_fee(
&self,
amount: u64,
fee_rate: Option<f32>
) -> Result<u64, MutinyError>
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.
sourcepub fn estimate_sweep_channel_open_fee(
&self,
fee_rate: Option<f32>
) -> Result<u64, MutinyError>
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.
sourcepub async fn check_address(
&self,
address: &Address
) -> Result<Option<TransactionDetails>, MutinyError>
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.
sourcepub async fn get_activity(&self) -> Result<Vec<ActivityItem>, MutinyError>
pub async fn get_activity(&self) -> Result<Vec<ActivityItem>, MutinyError>
Returns all the on-chain and lightning activity from the wallet.
sourcepub async fn get_label_activity(
&self,
label: &String
) -> Result<Vec<ActivityItem>, MutinyError>
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
sourcepub fn list_onchain(&self) -> Result<Vec<TransactionDetails>, MutinyError>
pub fn list_onchain(&self) -> Result<Vec<TransactionDetails>, MutinyError>
Lists all the on-chain transactions in the wallet. These are sorted by confirmation time.
sourcepub fn get_transaction(
&self,
txid: Txid
) -> Result<Option<TransactionDetails>, MutinyError>
pub fn get_transaction( &self, txid: Txid ) -> Result<Option<TransactionDetails>, MutinyError>
Gets the details of a specific on-chain transaction.
sourcepub async fn get_balance(&self) -> Result<MutinyBalance, MutinyError>
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.
sourcepub fn list_utxos(&self) -> Result<Vec<LocalUtxo>, MutinyError>
pub fn list_utxos(&self) -> Result<Vec<LocalUtxo>, MutinyError>
Lists all the UTXOs in the wallet.
sourcepub fn estimate_fee_low(&self) -> u32
pub fn estimate_fee_low(&self) -> u32
Gets a fee estimate for a very low priority transaction. Value is in sat/vbyte.
sourcepub fn estimate_fee_normal(&self) -> u32
pub fn estimate_fee_normal(&self) -> u32
Gets a fee estimate for an average priority transaction. Value is in sat/vbyte.
sourcepub fn estimate_fee_high(&self) -> u32
pub fn estimate_fee_high(&self) -> u32
Gets a fee estimate for an high priority transaction. Value is in sat/vbyte.
sourcepub async fn new_node(&self) -> Result<NodeIdentity, MutinyError>
pub async fn new_node(&self) -> Result<NodeIdentity, MutinyError>
Creates a new lightning node and adds it to the manager.
sourcepub async fn list_nodes(&self) -> Result<Vec<PublicKey>, MutinyError>
pub async fn list_nodes(&self) -> Result<Vec<PublicKey>, MutinyError>
Lists the pubkeys of the lightning node in the manager.
sourcepub async fn connect_to_peer(
&self,
self_node_pubkey: &PublicKey,
connection_string: &str,
label: Option<String>
) -> Result<(), MutinyError>
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.
sourcepub async fn disconnect_peer(
&self,
self_node_pubkey: &PublicKey,
peer: PublicKey
) -> Result<(), MutinyError>
pub async fn disconnect_peer( &self, self_node_pubkey: &PublicKey, peer: PublicKey ) -> Result<(), MutinyError>
Disconnects from a peer from the selected node.
sourcepub async fn delete_peer(
&self,
self_node_pubkey: &PublicKey,
peer: &NodeId
) -> Result<(), MutinyError>
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.
sourcepub fn label_peer(
&self,
node_id: &NodeId,
label: Option<String>
) -> Result<(), MutinyError>
pub fn label_peer( &self, node_id: &NodeId, label: Option<String> ) -> Result<(), MutinyError>
Sets the label of a peer from the selected node.
sourcepub async fn create_invoice(
&self,
amount: Option<u64>,
labels: Vec<String>
) -> Result<MutinyInvoice, MutinyError>
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.
sourcepub async fn pay_invoice(
&self,
from_node: &PublicKey,
invoice: &Bolt11Invoice,
amt_sats: Option<u64>,
labels: Vec<String>
) -> Result<MutinyInvoice, MutinyError>
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.
sourcepub async fn keysend(
&self,
from_node: &PublicKey,
to_node: PublicKey,
amt_sats: u64,
message: Option<String>,
labels: Vec<String>
) -> Result<MutinyInvoice, MutinyError>
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.
sourcepub async fn decode_invoice(
&self,
invoice: Bolt11Invoice,
network: Option<Network>
) -> Result<MutinyInvoice, MutinyError>
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.
sourcepub async fn decode_lnurl(
&self,
lnurl: LnUrl
) -> Result<LnUrlParams, MutinyError>
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).
sourcepub async fn lnurl_pay(
&self,
from_node: &PublicKey,
lnurl: &LnUrl,
amount_sats: u64,
zap_npub: Option<XOnlyPublicKey>,
labels: Vec<String>
) -> Result<MutinyInvoice, MutinyError>
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.
sourcepub async fn lnurl_withdraw(
&self,
lnurl: &LnUrl,
amount_sats: u64
) -> Result<bool, MutinyError>
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.
sourcepub async fn lnurl_auth(&self, lnurl: LnUrl) -> Result<(), MutinyError>
pub async fn lnurl_auth(&self, lnurl: LnUrl) -> Result<(), MutinyError>
Authenticate with a LNURL-auth
sourcepub async fn get_invoice(
&self,
invoice: &Bolt11Invoice
) -> Result<MutinyInvoice, MutinyError>
pub async fn get_invoice( &self, invoice: &Bolt11Invoice ) -> Result<MutinyInvoice, MutinyError>
Gets an invoice from the node manager. This includes sent and received invoices.
sourcepub async fn get_invoice_by_hash(
&self,
hash: &Hash
) -> Result<MutinyInvoice, MutinyError>
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.
sourcepub async fn list_invoices(&self) -> Result<Vec<MutinyInvoice>, MutinyError>
pub async fn list_invoices(&self) -> Result<Vec<MutinyInvoice>, MutinyError>
Gets an invoice from the node manager. This includes sent and received invoices.
pub async fn get_channel_closure( &self, user_channel_id: u128 ) -> Result<ChannelClosure, MutinyError>
pub async fn list_channel_closures( &self ) -> Result<Vec<ChannelClosure>, MutinyError>
sourcepub 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>
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.
sourcepub async fn sweep_utxos_to_channel(
&self,
user_chan_id: Option<u128>,
from_node: &PublicKey,
utxos: &[OutPoint],
to_pubkey: Option<PublicKey>
) -> Result<MutinyChannel, MutinyError>
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.
sourcepub async fn sweep_all_to_channel(
&self,
user_chan_id: Option<u128>,
from_node: &PublicKey,
to_pubkey: Option<PublicKey>
) -> Result<MutinyChannel, MutinyError>
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.
sourcepub async fn close_channel(
&self,
outpoint: &OutPoint,
address: Option<Address>,
force: bool,
abandon: bool
) -> Result<(), MutinyError>
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.
sourcepub async fn list_channels(&self) -> Result<Vec<MutinyChannel>, MutinyError>
pub async fn list_channels(&self) -> Result<Vec<MutinyChannel>, MutinyError>
Lists all the channels for all the nodes in the node manager.
sourcepub async fn list_peers(&self) -> Result<Vec<MutinyPeer>, MutinyError>
pub async fn list_peers(&self) -> Result<Vec<MutinyPeer>, MutinyError>
Lists all the peers for all the nodes in the node manager.
sourcepub async fn get_subscription_plans(&self) -> Result<Vec<Plan>, MutinyError>
pub async fn get_subscription_plans(&self) -> Result<Vec<Plan>, MutinyError>
Gets the subscription plans for Mutiny+ subscriptions
sourcepub async fn subscribe_to_plan(
&self,
id: u8
) -> Result<MutinyInvoice, MutinyError>
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.
sourcepub async fn get_bitcoin_price(
&self,
fiat: Option<String>
) -> Result<f32, MutinyError>
pub async fn get_bitcoin_price( &self, fiat: Option<String> ) -> Result<f32, MutinyError>
Gets the current bitcoin price in USD.
sourcepub fn get_logs(
storage: S,
logger: Arc<MutinyLogger>
) -> Result<Option<Vec<String>>, MutinyError>
pub fn get_logs( storage: S, logger: Arc<MutinyLogger> ) -> Result<Option<Vec<String>>, MutinyError>
Retrieves the logs from storage.
sourcepub async fn reset_router(&self) -> Result<(), MutinyError>
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.
sourcepub async fn reset_onchain_tracker(&self) -> Result<(), MutinyError>
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.
sourcepub async fn export_json(storage: S) -> Result<Value, MutinyError>
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>
impl<S: MutinyStorage> LabelStorage for NodeManager<S>
source§fn get_address_labels(
&self
) -> Result<HashMap<String, Vec<String>>, MutinyError>
fn get_address_labels( &self ) -> Result<HashMap<String, Vec<String>>, MutinyError>
source§fn get_invoice_labels(
&self
) -> Result<HashMap<Bolt11Invoice, Vec<String>>, MutinyError>
fn get_invoice_labels( &self ) -> Result<HashMap<Bolt11Invoice, Vec<String>>, MutinyError>
source§fn get_labels(&self) -> Result<HashMap<String, LabelItem>, MutinyError>
fn get_labels(&self) -> Result<HashMap<String, LabelItem>, MutinyError>
source§fn get_label(
&self,
label: impl AsRef<str>
) -> Result<Option<LabelItem>, MutinyError>
fn get_label( &self, label: impl AsRef<str> ) -> Result<Option<LabelItem>, MutinyError>
source§fn set_address_labels(
&self,
address: Address,
labels: Vec<String>
) -> Result<(), MutinyError>
fn set_address_labels( &self, address: Address, labels: Vec<String> ) -> Result<(), MutinyError>
get_address_labels
to get the existing labels,
add the new labels, and then use set_address_labels
to set the new labelssource§fn set_invoice_labels(
&self,
invoice: Bolt11Invoice,
labels: Vec<String>
) -> Result<(), MutinyError>
fn set_invoice_labels( &self, invoice: Bolt11Invoice, labels: Vec<String> ) -> Result<(), MutinyError>
get_invoice_labels
to get the existing labels,
add the new labels, and then use set_invoice_labels
to set the new labels