Skip to content

Commit a4fa271

Browse files
committed
f Account for keysmanager methods returning a Result
1 parent c621a1a commit a4fa271

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/wallet.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use lightning::chain::chaininterface::{
66
BroadcasterInterface, ConfirmationTarget, FeeEstimator, FEERATE_FLOOR_SATS_PER_KW,
77
};
88

9+
use lightning::ln::msgs::{DecodeError, UnsignedGossipMessage};
10+
use lightning::ln::script::ShutdownScript;
911
use lightning::sign::{
1012
EntropySource, InMemorySigner, KeyMaterial, KeysManager, NodeSigner, Recipient, SignerProvider,
1113
SpendableOutputDescriptor,
1214
};
13-
use lightning::ln::msgs::{DecodeError, UnsignedGossipMessage};
14-
use lightning::ln::script::ShutdownScript;
1515

1616
use bdk::blockchain::{Blockchain, EsploraBlockchain};
1717
use bdk::database::BatchDatabase;
@@ -435,19 +435,16 @@ where
435435
self.inner.read_chan_signer(reader)
436436
}
437437

438-
fn get_destination_script(&self) -> Script {
439-
let address =
440-
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet.");
441-
address.script_pubkey()
438+
fn get_destination_script(&self) -> Result<Script, ()> {
439+
let address = self.wallet.get_new_address().map_err(|_| ())?;
440+
Ok(address.script_pubkey())
442441
}
443442

444-
fn get_shutdown_scriptpubkey(&self) -> ShutdownScript {
445-
let address =
446-
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet.");
443+
fn get_shutdown_scriptpubkey(&self) -> Result<ShutdownScript, ()> {
444+
let address = self.wallet.get_new_address().map_err(|_| ())?;
447445
match address.payload {
448446
bitcoin::util::address::Payload::WitnessProgram { version, program } => {
449-
return ShutdownScript::new_witness_program(version, &program)
450-
.expect("Invalid shutdown script.");
447+
ShutdownScript::new_witness_program(version, &program).map_err(|_| ())
451448
}
452449
_ => panic!("Tried to use a non-witness address. This must not ever happen."),
453450
}

0 commit comments

Comments
 (0)