Skip to content

Commit

Permalink
Reform
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Apr 11, 2024
1 parent 985b962 commit b3bf670
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 34 deletions.
8 changes: 7 additions & 1 deletion batch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2785,7 +2785,7 @@ mod tests {
<dt>symbol</dt>
<dd>%</dd>
<dt>turbo</dt>
<dd>yes</dd>
<dd>true</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/{txid}>{txid}</a></dd>
<dt>parent</dt>
Expand Down
27 changes: 2 additions & 25 deletions src/templates/rune.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
use super::*;

enum Foo {
No,
Yes,
}

impl From<bool> 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,
Expand Down Expand Up @@ -117,7 +94,7 @@ mod tests {
<dt>symbol</dt>
<dd>%</dd>
<dt>turbo</dt>
<dd>yes</dd>
<dd>true</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/0{64}>0{64}</a></dd>
<dt>parent</dt>
Expand Down Expand Up @@ -189,7 +166,7 @@ mod tests {
"<h1>B•CGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
<dl>.*
<dt>turbo</dt>
<dd>no</dd>
<dd>false</dd>
.*</dl>
"
);
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/batch/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ordinals::Terms> {
Expand All @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion templates/rune.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h1>{{ self.entry.spaced_rune }}</h1>
<dd>{{ symbol }}</dd>
%% }
<dt>turbo</dt>
<dd>{{ Foo::from(self.entry.turbo) }}</dd>
<dd>{{ self.entry.turbo }}</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/{{ self.entry.etching }}>{{ self.entry.etching }}</a></dd>
%% if let Some(parent) = self.parent {
Expand Down
2 changes: 2 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E
<dd>{divisibility}</dd>
<dt>symbol</dt>
<dd>{symbol}</dd>
<dt>turbo</dt>
<dd>{turbo}</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/{reveal}>{reveal}</a></dd>
<dt>parent</dt>
Expand Down
104 changes: 103 additions & 1 deletion tests/wallet/batch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,109 @@ fn batch_can_etch_rune() {
ord.assert_response_regex(
"/rune/AAAAAAAAAAAAA",
format!(
r".*<dt>parent</dt>\s*<dd><a class=monospace href=/inscription/{parent}>{parent}</a></dd>.*"
r".*\s*<dt>turbo</dt>\s*<dd>false</dd>.*<dt>parent</dt>\s*<dd><a class=monospace href=/inscription/{parent}>{parent}</a></dd>.*"
),
);

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>(),
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".*<dt>rune</dt>\s*<dd><a href=/rune/AAAAAAAAAAAAA>AAAAAAAAAAAAA</a></dd>.*",
);

ord.assert_response_regex(
"/rune/AAAAAAAAAAAAA",
format!(
r".*\s*<dt>turbo</dt>\s*<dd>true</dd>.*<dt>parent</dt>\s*<dd><a class=monospace href=/inscription/{parent}>{parent}</a></dd>.*"
),
);

Expand Down

0 comments on commit b3bf670

Please sign in to comment.