diff --git a/sdk/src/client/api/block_builder/input_selection/core/remainder.rs b/sdk/src/client/api/block_builder/input_selection/core/remainder.rs index 2d1b9d1464..90c9986ff6 100644 --- a/sdk/src/client/api/block_builder/input_selection/core/remainder.rs +++ b/sdk/src/client/api/block_builder/input_selection/core/remainder.rs @@ -32,13 +32,12 @@ impl InputSelection { self.outputs.as_slice(), self.burn.as_ref(), ); - // PANIC: safe to unwrap as treasury outputs can't be used as input. - let required_address = input - .output - .required_and_unlocked_address(self.timestamp, input.output_id(), alias_transition) - .unwrap() - .0; - if remainder_address == required_address { + let required_address = + input + .output + .required_and_unlocked_address(self.timestamp, input.output_id(), alias_transition); + + if matches!(required_address, Ok(a) if a.0 == remainder_address) { return Some((remainder_address, input.chain)); } } diff --git a/sdk/src/client/secret/ledger_nano.rs b/sdk/src/client/secret/ledger_nano.rs index fcc4ef42ab..27d4797f17 100644 --- a/sdk/src/client/secret/ledger_nano.rs +++ b/sdk/src/client/secret/ledger_nano.rs @@ -295,24 +295,24 @@ impl SecretManage for LedgerSecretManager { .map_err(Error::from)?; } else { // figure out the remainder address and bip32 index (if there is one) + #[allow(clippy::option_if_let_else)] let (remainder_address, remainder_bip32): (Option<&Address>, LedgerBIP32Index) = - prepared_transaction.remainder.as_ref().map_or_else( - || (None, LedgerBIP32Index::default()), - |a| { - a.chain.map_or_else( - || (None, LedgerBIP32Index::default()), - |chain| { - ( - Some(&a.address), - LedgerBIP32Index { - bip32_change: chain.change.harden().into(), - bip32_index: chain.address_index.harden().into(), - }, - ) - }, - ) - }, - ); + match &prepared_transaction.remainder { + Some(a) => { + if let Some(chain) = a.chain { + ( + Some(&a.address), + LedgerBIP32Index { + bip32_change: chain.change.harden().into(), + bip32_index: chain.address_index.harden().into(), + }, + ) + } else { + (None, LedgerBIP32Index::default()) + } + } + None => (None, LedgerBIP32Index::default()), + }; let mut remainder_index = 0u16; if let Some(remainder_address) = remainder_address {