Skip to content

Commit

Permalink
Add error when a satpoint's offset exceeds the size of its output (#1857
Browse files Browse the repository at this point in the history
)

Co-authored-by: Greg Martin <gm7t2@gmail.com>
Co-authored-by: raphjaph <raphjaph@protonmail.com>
  • Loading branch information
3 people authored Mar 7, 2023
1 parent 28120d2 commit 98d01be
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/subcommand/wallet/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum Error {
},
NotEnoughCardinalUtxos,
NotInWallet(SatPoint),
OutOfRange(SatPoint, u64),
UtxoContainsAdditionalInscription {
outgoing_satpoint: SatPoint,
inscribed_satpoint: SatPoint,
Expand All @@ -72,6 +73,7 @@ impl fmt::Display for Error {
dust_value,
} => write!(f, "output value is below dust value: {output_value} < {dust_value}"),
Error::NotInWallet(outgoing_satpoint) => write!(f, "outgoing satpoint {outgoing_satpoint} not in wallet"),
Error::OutOfRange(outgoing_satpoint, maximum) => write!(f, "outgoing satpoint {outgoing_satpoint} offset higher than maximum {maximum}"),
Error::NotEnoughCardinalUtxos => write!(
f,
"wallet does not contain enough cardinal UTXOs, please add additional funds to wallet."
Expand Down Expand Up @@ -227,6 +229,10 @@ impl TransactionBuilder {
.get(&self.outgoing.outpoint)
.ok_or(Error::NotInWallet(self.outgoing))?;

if self.outgoing.offset >= amount.to_sat() {
return Err(Error::OutOfRange(self.outgoing, amount.to_sat() - 1));
}

self.utxos.remove(&self.outgoing.outpoint);
self.inputs.push(self.outgoing.outpoint);
self.outputs.push((self.recipient.clone(), amount));
Expand Down

0 comments on commit 98d01be

Please sign in to comment.