From 4990542ad063346f68312dab71ba88d3a2bb8ec5 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 23 Mar 2024 13:45:27 -0700 Subject: [PATCH] Assert etched runestone is correct (#3354) --- src/wallet/inscribe/batch.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/wallet/inscribe/batch.rs b/src/wallet/inscribe/batch.rs index d2f1bc7d33..619b0dcc04 100644 --- a/src/wallet/inscribe/batch.rs +++ b/src/wallet/inscribe/batch.rs @@ -426,6 +426,7 @@ impl Batch { let rune; let premine; + let runestone; if let Some(etch) = self.etch { let mut edicts = Vec::new(); @@ -455,7 +456,7 @@ impl Batch { destination = None; } - let script_pubkey = Runestone { + let inner = Runestone { cenotaph: false, claim: None, default_output: None, @@ -476,8 +477,11 @@ impl Batch { spacers: etch.rune.spacers, symbol: Some(etch.symbol), }), - } - .encipher(); + }; + + let script_pubkey = inner.encipher(); + + runestone = Some(inner); ensure!( script_pubkey.len() <= 82, @@ -494,6 +498,7 @@ impl Batch { } else { premine = 0; rune = None; + runestone = None; } let commit_input = usize::from(self.parent_info.is_some()) + self.reveal_satpoints.len(); @@ -632,6 +637,18 @@ impl Batch { let total_fees = Self::calculate_fee(&unsigned_commit_tx, &utxos) + Self::calculate_fee(&reveal_tx, &utxos); + match (Runestone::from_transaction(&reveal_tx), runestone) { + (Some(actual), Some(expected)) => assert_eq!( + actual, expected, + "commit transaction runestone did not match expected runestone" + ), + (Some(_), None) => panic!("commit transaction contained runestone, but none was expected"), + (None, Some(_)) => { + panic!("commit transaction did not contain runestone, but one was expected") + } + (None, None) => {} + } + let rune = rune.map(|(destination, rune, vout)| RuneInfo { destination: destination.map(|destination| uncheck(&destination)), location: vout.map(|vout| OutPoint {