From b3bf670160e1e90289a26685f6cdd6cb520d7d64 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 10 Apr 2024 17:50:47 -0700 Subject: [PATCH] Reform --- batch.yaml | 8 ++- src/subcommand/server.rs | 2 +- src/templates/rune.rs | 27 +-------- src/wallet/batch/plan.rs | 10 ++-- templates/rune.html | 2 +- tests/lib.rs | 2 + tests/wallet/batch_command.rs | 104 +++++++++++++++++++++++++++++++++- 7 files changed, 121 insertions(+), 34 deletions(-) diff --git a/batch.yaml b/batch.yaml index 5666497d84..20c05b3831 100644 --- a/batch.yaml +++ b/batch.yaml @@ -45,7 +45,13 @@ etching: offset: start: 1000 end: 9000 - turbo: true, + # future runes protocol changes may be opt-in. this may be for a variety of + # reasons, including that they make light client validation harder, or simply + # because they are too degenerate. + # + # setting `turbo` to `true` opts in to these future protocol changes, + # whatever they may be. + turbo: true # inscriptions to inscribe inscriptions: diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index ab44727548..43da2e9c58 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -2785,7 +2785,7 @@ mod tests {
symbol
%
turbo
-
yes
+
true
etching
{txid}
parent
diff --git a/src/templates/rune.rs b/src/templates/rune.rs index 79fe2433e0..9e4aaf404a 100644 --- a/src/templates/rune.rs +++ b/src/templates/rune.rs @@ -1,28 +1,5 @@ use super::*; -enum Foo { - No, - Yes, -} - -impl From for Foo { - fn from(b: bool) -> Self { - match b { - false => Self::No, - true => Self::Yes, - } - } -} - -impl Display for Foo { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - match self { - Self::No => write!(f, "no"), - Self::Yes => write!(f, "yes"), - } - } -} - #[derive(Boilerplate, Debug, PartialEq, Serialize, Deserialize)] pub struct RuneHtml { pub entry: RuneEntry, @@ -117,7 +94,7 @@ mod tests {
symbol
%
turbo
-
yes
+
true
etching
0{64}
parent
@@ -189,7 +166,7 @@ mod tests { "

B•CGDENLQRQWDSLRUGSNLBTMFIJAV

.*
turbo
-
no
+
false
.*
" ); diff --git a/src/wallet/batch/plan.rs b/src/wallet/batch/plan.rs index 44f02d3faf..ed37d47adf 100644 --- a/src/wallet/batch/plan.rs +++ b/src/wallet/batch/plan.rs @@ -446,6 +446,10 @@ impl Plan { edicts: Vec::new(), etching: Some(ordinals::Etching { divisibility: (etching.divisibility > 0).then_some(etching.divisibility), + premine: (premine > 0).then_some(premine), + rune: Some(etching.rune.rune), + spacers: (etching.rune.spacers > 0).then_some(etching.rune.spacers), + symbol: Some(etching.symbol), terms: etching .terms .map(|terms| -> Result { @@ -463,11 +467,7 @@ impl Plan { }) }) .transpose()?, - turbo: false, - premine: (premine > 0).then_some(premine), - rune: Some(etching.rune.rune), - spacers: (etching.rune.spacers > 0).then_some(etching.rune.spacers), - symbol: Some(etching.symbol), + turbo: etching.turbo, }), mint: None, pointer: (premine > 0).then_some((reveal_outputs.len() - 1).try_into().unwrap()), diff --git a/templates/rune.html b/templates/rune.html index 0c5d4d33db..63f4f8e86d 100644 --- a/templates/rune.html +++ b/templates/rune.html @@ -63,7 +63,7 @@

{{ self.entry.spaced_rune }}

{{ symbol }}
%% }
turbo
-
{{ Foo::from(self.entry.turbo) }}
+
{{ self.entry.turbo }}
etching
{{ self.entry.etching }}
%% if let Some(parent) = self.parent { diff --git a/tests/lib.rs b/tests/lib.rs index d56971cbf7..96f51a375b 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -342,6 +342,8 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E
{divisibility}
symbol
{symbol}
+
turbo
+
{turbo}
etching
{reveal}
parent
diff --git a/tests/wallet/batch_command.rs b/tests/wallet/batch_command.rs index 426eaa4183..eb8c22aa88 100644 --- a/tests/wallet/batch_command.rs +++ b/tests/wallet/batch_command.rs @@ -1464,7 +1464,109 @@ fn batch_can_etch_rune() { ord.assert_response_regex( "/rune/AAAAAAAAAAAAA", format!( - r".*
parent
\s*
{parent}
.*" + r".*\s*
turbo
\s*
false
.*
parent
\s*
{parent}
.*" + ), + ); + + let destination = batch + .output + .rune + .unwrap() + .destination + .unwrap() + .require_network(Network::Regtest) + .unwrap(); + + assert!(core.state().is_wallet_address(&destination)); + + let reveal = core.tx_by_id(batch.output.reveal); + + assert_eq!( + reveal.input[0].sequence, + Sequence::from_height(Runestone::COMMIT_CONFIRMATIONS - 1) + ); + + let Artifact::Runestone(runestone) = Runestone::decipher(&reveal).unwrap() else { + panic!(); + }; + + let pointer = reveal.output.len() - 2; + + assert_eq!(runestone.pointer, Some(pointer.try_into().unwrap())); + + assert_eq!( + reveal.output[pointer].script_pubkey, + destination.script_pubkey(), + ); + + assert_eq!( + CommandBuilder::new("--regtest wallet balance") + .core(&core) + .ord(&ord) + .run_and_deserialize_output::(), + Balance { + cardinal: 44999980000, + ordinal: 10000, + runic: Some(10000), + runes: Some(vec![(rune, 1000)].into_iter().collect()), + total: 450 * COIN_VALUE, + } + ); +} + +#[test] +fn batch_can_etch_turbo_rune() { + let core = mockcore::builder().network(Network::Regtest).build(); + + let ord = TestServer::spawn_with_server_args(&core, &["--regtest", "--index-runes"], &[]); + + create_wallet(&core, &ord); + + core.mine_blocks(1); + + let rune = SpacedRune { + rune: Rune(RUNE), + spacers: 0, + }; + + let batch = batch( + &core, + &ord, + batch::File { + etching: Some(batch::Etching { + divisibility: 0, + rune, + supply: "1000".parse().unwrap(), + premine: "1000".parse().unwrap(), + symbol: '¢', + terms: None, + turbo: true, + }), + inscriptions: vec![batch::Entry { + file: "inscription.jpeg".into(), + ..default() + }], + ..default() + }, + ); + + let parent = batch.output.inscriptions[0].id; + + let request = ord.request(format!("/content/{parent}")); + + assert_eq!(request.status(), 200); + assert_eq!(request.headers().get("content-type").unwrap(), "image/jpeg"); + assert_eq!(request.text().unwrap(), "inscription"); + + ord.assert_response_regex( + format!("/inscription/{parent}"), + r".*
rune
\s*
AAAAAAAAAAAAA
.*", + ); + + ord.assert_response_regex( + "/rune/AAAAAAAAAAAAA", + format!( + r".*\s*
turbo
\s*
true
.*
parent
\s*
{parent}
.*" ), );