From f4f6758f50ec65aa7cd06af2245bf2aea28b373b Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 18 Mar 2024 19:20:40 -0700 Subject: [PATCH] Invalid runestones are cenotaphs --- src/index/updater/rune_updater.rs | 10 +++--- src/runes.rs | 16 +++++----- src/runes/flag.rs | 4 +-- src/runes/runestone.rs | 52 +++++++++++++++---------------- src/runes/tag.rs | 4 +-- src/wallet/inscribe/batch.rs | 2 +- tests/wallet/send.rs | 2 +- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/index/updater/rune_updater.rs b/src/index/updater/rune_updater.rs index 1ced08b1e1..6963fb7193 100644 --- a/src/index/updater/rune_updater.rs +++ b/src/index/updater/rune_updater.rs @@ -52,9 +52,9 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { let mut unallocated = self.unallocated(tx)?; - let burn = runestone + let cenotaph = runestone .as_ref() - .map(|runestone| runestone.burn) + .map(|runestone| runestone.cenotaph) .unwrap_or_default(); let default_output = runestone.as_ref().and_then(|runestone| { @@ -81,7 +81,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { let mut etched = self.etched(tx_index, tx, &runestone)?; - if !burn { + if !cenotaph { for Edict { id, amount, output } in runestone.edicts { let Ok(output) = usize::try_from(output) else { continue; @@ -158,13 +158,13 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> { } if let Some(etched) = etched { - self.create_rune_entry(txid, burn, etched)?; + self.create_rune_entry(txid, cenotaph, etched)?; } } let mut burned: HashMap = HashMap::new(); - if burn { + if cenotaph { for (id, balance) in unallocated { *burned.entry(id).or_default() += balance; } diff --git a/src/runes.rs b/src/runes.rs index d95a6f0903..8c94d867ea 100644 --- a/src/runes.rs +++ b/src/runes.rs @@ -748,7 +748,7 @@ mod tests { } #[test] - fn etched_rune_is_allocated_with_zero_supply_for_burned_runestone() { + fn etched_rune_is_allocated_with_zero_supply_for_cenotaph() { let context = Context::builder().arg("--index-runes").build(); let (txid0, id) = context.etch( @@ -763,7 +763,7 @@ mod tests { ..Default::default() }), default_output: None, - burn: true, + cenotaph: true, ..Default::default() }, 1, @@ -784,7 +784,7 @@ mod tests { } #[test] - fn etched_rune_open_etching_parameters_are_unset_for_burned_runestone() { + fn etched_rune_open_etching_parameters_are_unset_for_cenotaph() { let context = Context::builder().arg("--index-runes").build(); let (txid0, id) = context.etch( @@ -805,7 +805,7 @@ mod tests { symbol: Some('$'), spacers: 1, }), - burn: true, + cenotaph: true, ..Default::default() }, 1, @@ -834,7 +834,7 @@ mod tests { } #[test] - fn etched_reserved_rune_is_allocated_with_zero_supply_for_burned_runestone() { + fn etched_reserved_rune_is_allocated_with_zero_supply_in_cenotaph() { let context = Context::builder().arg("--index-runes").build(); context.mine_blocks(1); @@ -849,7 +849,7 @@ mod tests { output: 0, }], etching: Some(Etching::default()), - burn: true, + cenotaph: true, ..Default::default() } .encipher(), @@ -920,7 +920,7 @@ mod tests { inputs: &[(id.block.try_into().unwrap(), 1, 0, Witness::new())], op_return: Some( Runestone { - burn: true, + cenotaph: true, ..Default::default() } .encipher(), @@ -3855,7 +3855,7 @@ mod tests { inputs: &[(5, 0, 0, Witness::new())], op_return: Some( Runestone { - burn: true, + cenotaph: true, claim: Some(id), edicts: vec![Edict { id, diff --git a/src/runes/flag.rs b/src/runes/flag.rs index e0c9f93160..13e05b7151 100644 --- a/src/runes/flag.rs +++ b/src/runes/flag.rs @@ -2,7 +2,7 @@ pub(super) enum Flag { Etch = 0, Mint = 1, #[allow(unused)] - Burn = 127, + Cenotaph = 127, } impl Flag { @@ -29,7 +29,7 @@ mod tests { #[test] fn mask() { assert_eq!(Flag::Etch.mask(), 0b1); - assert_eq!(Flag::Burn.mask(), 1 << 127); + assert_eq!(Flag::Cenotaph.mask(), 1 << 127); } #[test] diff --git a/src/runes/runestone.rs b/src/runes/runestone.rs index 5e85bfe698..95a7b2b21a 100644 --- a/src/runes/runestone.rs +++ b/src/runes/runestone.rs @@ -4,7 +4,7 @@ const MAX_SPACERS: u32 = 0b00000111_11111111_11111111_11111111; #[derive(Default, Serialize, Debug, PartialEq)] pub struct Runestone { - pub burn: bool, + pub cenotaph: bool, pub claim: Option, pub default_output: Option, pub edicts: Vec, @@ -12,7 +12,7 @@ pub struct Runestone { } struct Message { - burn: bool, + cenotaph: bool, edicts: Vec, fields: HashMap, } @@ -21,7 +21,7 @@ impl Message { fn from_integers(tx: &Transaction, payload: &[u128]) -> Self { let mut edicts = Vec::new(); let mut fields = HashMap::new(); - let mut burn = false; + let mut cenotaph = false; for i in (0..payload.len()).step_by(2) { let tag = payload[i]; @@ -34,7 +34,7 @@ impl Message { if let Some(edict) = Edict::from_integers(tx, id, chunk[1], chunk[2]) { edicts.push(edict); } else { - burn = true; + cenotaph = true; } } break; @@ -48,7 +48,7 @@ impl Message { } Self { - burn, + cenotaph, edicts, fields, } @@ -68,7 +68,7 @@ impl Runestone { let integers = Runestone::integers(&payload); let Message { - burn, + cenotaph, edicts, mut fields, } = Message::from_integers(transaction, &integers); @@ -133,7 +133,7 @@ impl Runestone { }; Ok(Some(Self { - burn: burn || flags != 0 || fields.keys().any(|tag| tag % 2 == 0), + cenotaph: cenotaph || flags != 0 || fields.keys().any(|tag| tag % 2 == 0), claim: claim.and_then(|claim| claim.try_into().ok()), default_output, edicts, @@ -193,8 +193,8 @@ impl Runestone { Tag::DefaultOutput.encode(default_output.into(), &mut payload); } - if self.burn { - Tag::Burn.encode(0, &mut payload); + if self.cenotaph { + Tag::Cenotaph.encode(0, &mut payload); } if !self.edicts.is_empty() { @@ -733,10 +733,10 @@ mod tests { } #[test] - fn unrecognized_even_tag_is_burn() { + fn runestone_with_unrecognized_even_tag_is_cenotaph() { assert_eq!( decipher(&[ - Tag::Burn.into(), + Tag::Cenotaph.into(), 0, Tag::Body.into(), rune_id(1).into(), @@ -749,18 +749,18 @@ mod tests { amount: 2, output: 0, }], - burn: true, + cenotaph: true, ..Default::default() }, ); } #[test] - fn unrecognized_flag_is_burn() { + fn runestone_with_unrecognized_flag_is_cenotaph() { assert_eq!( decipher(&[ Tag::Flags.into(), - Flag::Burn.mask(), + Flag::Cenotaph.mask(), Tag::Body.into(), rune_id(1).into(), 2, @@ -772,31 +772,31 @@ mod tests { amount: 2, output: 0, }], - burn: true, + cenotaph: true, ..Default::default() }, ); } #[test] - fn rune_id_with_zero_block_and_nonzero_tx_is_burn() { + fn runestone_with_edict_id_with_zero_block_and_nonzero_tx_is_cenotaph() { pretty_assert_eq!( decipher(&[Tag::Body.into(), RuneId { block: 0, tx: 1 }.into(), 2, 0]), Runestone { edicts: Vec::new(), - burn: true, + cenotaph: true, ..Default::default() }, ); } #[test] - fn output_over_max_is_burn() { + fn runestone_with_output_over_max_is_cenotaph() { pretty_assert_eq!( decipher(&[Tag::Body.into(), 1, 2, 2]), Runestone { edicts: Vec::new(), - burn: true, + cenotaph: true, ..Default::default() }, ); @@ -1128,7 +1128,7 @@ mod tests { amount: 2, output: 0, }], - burn: true, + cenotaph: true, ..Default::default() }, ); @@ -1588,7 +1588,7 @@ mod tests { }, ], default_output: Some(11), - burn: true, + cenotaph: true, claim: Some(RuneId::try_from(12).unwrap()), }, &[ @@ -1612,7 +1612,7 @@ mod tests { 12, Tag::DefaultOutput.into(), 11, - Tag::Burn.into(), + Tag::Cenotaph.into(), 0, Tag::Body.into(), rune_id(6).into(), @@ -1633,7 +1633,7 @@ mod tests { rune: Some(Rune(3)), spacers: 0, }), - burn: false, + cenotaph: false, ..Default::default() }, &[Tag::Flags.into(), Flag::Etch.mask(), Tag::Rune.into(), 3], @@ -1648,7 +1648,7 @@ mod tests { rune: None, spacers: 0, }), - burn: false, + cenotaph: false, ..Default::default() }, &[Tag::Flags.into(), Flag::Etch.mask()], @@ -1656,10 +1656,10 @@ mod tests { case( Runestone { - burn: true, + cenotaph: true, ..Default::default() }, - &[Tag::Burn.into(), 0], + &[Tag::Cenotaph.into(), 0], ); } diff --git a/src/runes/tag.rs b/src/runes/tag.rs index 9cb95bd9a5..e8ef0c3510 100644 --- a/src/runes/tag.rs +++ b/src/runes/tag.rs @@ -11,7 +11,7 @@ pub(super) enum Tag { DefaultOutput = 12, Claim = 14, #[allow(unused)] - Burn = 126, + Cenotaph = 126, Divisibility = 1, Spacers = 3, @@ -86,7 +86,7 @@ mod tests { #[test] fn burn_and_nop_are_one_byte() { let mut payload = Vec::new(); - Tag::Burn.encode(0, &mut payload); + Tag::Cenotaph.encode(0, &mut payload); assert_eq!(payload.len(), 2); let mut payload = Vec::new(); diff --git a/src/wallet/inscribe/batch.rs b/src/wallet/inscribe/batch.rs index eee366a577..29c775c587 100644 --- a/src/wallet/inscribe/batch.rs +++ b/src/wallet/inscribe/batch.rs @@ -456,7 +456,7 @@ impl Batch { } let script_pubkey = Runestone { - burn: false, + cenotaph: false, claim: None, default_output: None, edicts, diff --git a/tests/wallet/send.rs b/tests/wallet/send.rs index 8b0a98e3bd..3e54507e29 100644 --- a/tests/wallet/send.rs +++ b/tests/wallet/send.rs @@ -1047,7 +1047,7 @@ fn sending_rune_creates_transaction_with_expected_runestone() { amount: 750, output: 2 }], - burn: false, + cenotaph: false, claim: None, }, );