Skip to content

Commit d84f83b

Browse files
committed
chore: migration: from_script now returns Result instead of Option
see rust-bitcoin/rust-bitcoin#1038
1 parent 950f9b7 commit d84f83b

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

bitcoin/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ impl TransactionExt for Transaction {
10511051
/// Get the amount of btc that self sent to `dest`, if any
10521052
fn get_payment_amount_to(&self, dest: Payload) -> Option<u64> {
10531053
self.output.iter().find_map(|uxto| {
1054-
let payload = Payload::from_script(&uxto.script_pubkey)?;
1054+
let payload = Payload::from_script(&uxto.script_pubkey).ok()?;
10551055
if payload == dest {
10561056
Some(uxto.value)
10571057
} else {
@@ -1075,7 +1075,7 @@ impl TransactionExt for Transaction {
10751075
.iter()
10761076
.enumerate()
10771077
.filter(|(_, x)| x.value > 0)
1078-
.filter_map(|(idx, tx_out)| Some((idx, Payload::from_script(&tx_out.script_pubkey)?)))
1078+
.filter_map(|(idx, tx_out)| Some((idx, Payload::from_script(&tx_out.script_pubkey).ok()?)))
10791079
.collect()
10801080
}
10811081

bitcoin/src/light/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl Wallet {
212212
}
213213

214214
pub fn get_priv_key(&self, script_pubkey: &Script) -> Result<PrivateKey, Error> {
215-
let address = Address::from_script(script_pubkey, self.network).ok_or(Error::InvalidAddress)?;
215+
let address = Address::from_script(script_pubkey, self.network)?;
216216
let key_store = self.key_store.read()?;
217217
let private_key = key_store.get(&address).ok_or(Error::NoPrivateKey)?;
218218
Ok(*private_key)

runtime/src/addr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl PartialAddress for BtcAddress {
4949
Self::P2WSHv0(hash) => Script::new_v0_wsh(&WScriptHash::from_slice(hash.as_bytes())?),
5050
};
5151

52-
Payload::from_script(&script).ok_or(ConversionError::InvalidPayload)
52+
Ok(Payload::from_script(&script)?)
5353
}
5454

5555
fn from_address(address: Address) -> Result<Self, ConversionError> {

0 commit comments

Comments
 (0)