Skip to content

Commit

Permalink
psbt: verify address network upon a construction
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jan 11, 2025
1 parent f81848a commit 7d81b69
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions psbt/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ pub enum ConstructionError {
output_value: Sats,
fee: Sats,
},

/// network for address {0} mismatch the one used by the wallet.
NetworkMismatch(Address),
}

#[derive(Clone, Debug, Display, Error, From)]
Expand Down Expand Up @@ -231,6 +234,9 @@ pub trait PsbtConstructor {
let mut max = Vec::new();
let mut output_value = Sats::ZERO;
for beneficiary in beneficiaries {
if beneficiary.address.network != self.network().into() {
return Err(ConstructionError::NetworkMismatch(beneficiary.address));
}
let amount = beneficiary.amount.unwrap_or(Sats::ZERO);
output_value
.checked_add_assign(amount)
Expand Down

0 comments on commit 7d81b69

Please sign in to comment.