Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve inscription style #1025

Merged
merged 10 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/subcommand/server/templates/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ impl<'a> Display for ContentHtml<'a> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self.content {
Some(Content::Text(text)) => {
write!(f, "<p>")?;
write!(f, "<pre>")?;
text.escape(f, false)?;
write!(f, "</p>")
write!(f, "</pre>")
}
Some(Content::Image) => write!(f, "<img src=/content/{}>", self.inscription_id),
None => write!(f, "<p>UNKNOWN</p>"),
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/server/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {
.to_string(),
"<h1>Bitcoin-native NFTs</h1>.*<h2>Latest Inscriptions</h2>
<div class=inscriptions>
<a href=/inscription/1111111111111111111111111111111111111111111111111111111111111111><p>HELLOWORLD</p></a>
<a href=/inscription/1111111111111111111111111111111111111111111111111111111111111111><pre>HELLOWORLD</pre></a>
</div>
<h2>Status</h2>
<dl>
Expand Down
20 changes: 16 additions & 4 deletions src/subcommand/server/templates/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ mod tests {
.to_string(),
"
<h1>Inscription ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</h1>
<p>HELLOWORLD</p>
<a class=content href=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
<pre>HELLOWORLD</pre>
</a>
<dl>
<dt>content size</dt>
<dd>10 bytes</dd>
<dt>content type</dt>
<dd>text/plain;charset=utf-8</dd>
<dt>genesis height</dt>
<dd>0</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</a></dd>
<dt>location</dt>
<dd>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
<dd class=monospace>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
</dl>
"
.unindent()
Expand All @@ -68,16 +72,20 @@ mod tests {
.to_string(),
"
<h1>Inscription ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</h1>
<a class=content href=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
<img src=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
</a>
<dl>
<dt>content size</dt>
<dd>100 bytes</dd>
<dt>content type</dt>
<dd>image/png</dd>
<dt>genesis height</dt>
<dd>0</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</a></dd>
<dt>location</dt>
<dd>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
<dd class=monospace>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
</dl>
"
.unindent()
Expand All @@ -99,12 +107,16 @@ mod tests {
.to_string(),
"
<h1>Inscription ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</h1>
<a class=content href=/content/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>
<p>UNKNOWN</p>
</a>
<dl>
<dt>genesis height</dt>
<dd>0</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc>ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc</a></dd>
<dt>location</dt>
<dd>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
<dd class=monospace>1111111111111111111111111111111111111111111111111111111111111111:1:0</dd>
</dl>
"
.unindent()
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/server/templates/sat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod tests {
<dt>rarity</dt><dd><span class=mythic>mythic</span></dd>
<dt>time</dt><dd>1970-01-01 00:00:00</dd>
<dt>inscription</dt>
<dd><p>HELLOWORLD</p></dd>
<dd><a href=/inscription/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc><pre>HELLOWORLD</pre></a></dd>
</dl>
prev
<a href=/sat/1>next</a>
Expand Down Expand Up @@ -151,7 +151,7 @@ mod tests {
<dt>rarity</dt><dd><span class=mythic>mythic</span></dd>
<dt>time</dt><dd>1970-01-01 00:00:00</dd>
<dt>inscription</dt>
<dd><p>&lt;script&gt;alert(&apos;HELLOWORLD&apos;);&lt;/script&gt;</p></dd>
<dd><a href=/inscription/ec90757eb3b164aa43fc548faa2fa0c52025494f2c15d5ddf11260b4034ac6dc><pre>&lt;script&gt;alert(&apos;HELLOWORLD&apos;);&lt;/script&gt;</pre></a></dd>
</dl>
prev
<a href=/sat/1>next</a>
Expand Down
17 changes: 16 additions & 1 deletion static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ a.mythic {
width: 23%;
margin: 1%;
overflow: hidden;
border-radius: 10%;
border-radius: 2%;
}

.inscriptions a img {
Expand All @@ -177,3 +177,18 @@ a.mythic {
min-width: 100%;
image-rendering: pixelated;
}

.content {
display: flex;
justify-content: center;
}

.content img {
min-width: 50%;
image-rendering: pixelated;
}

a.content {
color: inherit;
text-decoration: none;
}
6 changes: 5 additions & 1 deletion templates/inscription.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<h1>Inscription {{ self.inscription_id }}</h1>
<a class=content href=/content/{{self.inscription_id}}>
{{ self.inscription.content_html(self.inscription_id) }}
</a>
<dl>
%% if let Some(content_size) = self.inscription.content_size() {
<dt>content size</dt>
Expand All @@ -11,6 +13,8 @@ <h1>Inscription {{ self.inscription_id }}</h1>
%% }
<dt>genesis height</dt>
<dd>{{ self.genesis_height }}</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/{{ self.inscription_id }}>{{ self.inscription_id }}</a></dd>
<dt>location</dt>
<dd>{{ self.satpoint }}</dd>
<dd class=monospace>{{ self.satpoint }}</dd>
</dl>
2 changes: 1 addition & 1 deletion templates/sat.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>Sat {{ self.sat.n() }}</h1>
<dt>time</dt><dd>{{ self.blocktime }}</dd>
%% if let Some((inscription_id, inscription)) = &self.inscription {
<dt>inscription</dt>
<dd>{{ inscription.content_html(*inscription_id) }}</dd>
<dd><a href=/inscription/{{ inscription_id }}>{{ inscription.content_html(*inscription_id) }}</a></dd>
%% }
</dl>
%% if self.sat.n() > 0 {
Expand Down
2 changes: 1 addition & 1 deletion templates/transaction.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Transaction <span class=monospace>{{self.txid}}</span></h1>
%% if let Some(inscription) = &self.inscription {
<h2>Inscription</h2>
<a href=/inscription/{{self.txid}}>
<a class=content href=/inscription/{{self.txid}}>
{{ inscription.content_html(self.txid) }}
</a>
%% }
Expand Down
41 changes: 12 additions & 29 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,20 @@ fn inscription_page() {
&format!(
".*<meta property=og:image content='/content/{reveal_tx}'>.*
<h1>Inscription {reveal_tx}</h1>
<p>HELLOWORLD</p>
<a class=content href=/content/{reveal_tx}>
<pre>HELLOWORLD</pre>
</a>
<dl>
<dt>content size</dt>
<dd>10 bytes</dd>
<dt>content type</dt>
<dd>text/plain;charset=utf-8</dd>
<dt>genesis height</dt>
<dd>2</dd>
<dt>genesis transaction</dt>
<dd><a class=monospace href=/tx/{reveal_tx}>{reveal_tx}</a></dd>
<dt>location</dt>
<dd>{reveal_tx}:0:0</dd>
<dd class=monospace>{reveal_tx}:0:0</dd>
</dl>.*",
),
);
Expand All @@ -90,13 +94,7 @@ fn inscription_appears_on_reveal_transaction_page() {

TestServer::spawn_with_args(&rpc_server, &[]).assert_response_regex(
&format!("/tx/{}", reveal_tx),
&format!(
".*<h1>Transaction .*</h1>.*
<h2>Inscription</h2>
<a href=/inscription/{reveal_tx}>
<p>HELLOWORLD</p>
</a>.*",
),
".*<h1>Transaction .*</h1>.*HELLOWORLD.*",
);
}

Expand All @@ -121,17 +119,8 @@ fn inscription_page_after_send() {
ord_server.assert_response_regex(
&format!("/inscription/{reveal_txid}"),
&format!(
".*<h1>Inscription {reveal_txid}</h1>
<p>HELLOWORLD</p>
<dl>
<dt>content size</dt>
<dd>10 bytes</dd>
<dt>content type</dt>
<dd>text/plain;charset=utf-8</dd>
<dt>genesis height</dt>
<dd>2</dd>
<dt>location</dt>
<dd>{reveal_txid}:0:0</dd>
".*<h1>Inscription {reveal_txid}</h1>.*HELLOWORLD.*<dl>.*<dt>location</dt>
<dd class=monospace>{reveal_txid}:0:0</dd>
</dl>.*",
),
);
Expand All @@ -150,17 +139,11 @@ fn inscription_page_after_send() {
ord_server.assert_response_regex(
&format!("/inscription/{reveal_txid}"),
&format!(
".*<h1>Inscription {reveal_txid}</h1>
<p>HELLOWORLD</p>
".*<h1>Inscription {reveal_txid}</h1>.*HELLOWORLD.*
<dl>
<dt>content size</dt>
<dd>10 bytes</dd>
<dt>content type</dt>
<dd>text/plain;charset=utf-8</dd>
<dt>genesis height</dt>
<dd>2</dd>
.*
<dt>location</dt>
<dd>{}:0:0</dd>
<dd class=monospace>{}:0:0</dd>
</dl>.*",
txid.trim(),
),
Expand Down
46 changes: 18 additions & 28 deletions tests/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,14 @@ fn send_works_on_signet() {
ord_server.assert_response_regex(
&format!("/inscription/{reveal_txid}"),
&format!(
".*<h1>Inscription {reveal_txid}</h1>
.*
<dl>
".*<h1>Inscription {reveal_txid}</h1>.*<dl>.*
<dt>content size</dt>
<dd>520 bytes</dd>
<dt>content type</dt>
<dd>image/png</dd>
<dt>genesis height</dt>
<dd>2</dd>
.*
<dt>location</dt>
<dd>{send_txid}:0:0</dd>
<dd class=monospace>{send_txid}:0:0</dd>
</dl>
.*",
),
Expand Down Expand Up @@ -153,19 +150,7 @@ fn send_inscribed_sat() {
ord_server.assert_response_regex(
&format!("/inscription/{reveal_txid}"),
&format!(
".*<h1>Inscription {reveal_txid}</h1>
.*
<dl>
<dt>content size</dt>
<dd>520 bytes</dd>
<dt>content type</dt>
<dd>image/png</dd>
<dt>genesis height</dt>
<dd>2</dd>
<dt>location</dt>
<dd>{send_txid}:0:0</dd>
</dl>
.*",
".*<h1>Inscription {reveal_txid}</h1>.*<dt>location</dt>.*<dd class=monospace>{send_txid}:0:0</dd>.*",
),
);
}
Expand Down Expand Up @@ -263,7 +248,7 @@ fn inscribe() {

TestServer::spawn_with_args(&rpc_server, &["--index-sats"]).assert_response_regex(
"/sat/5000000000",
".*<dt>inscription</dt>\n <dd><p>HELLOWORLD</p></dd>.*",
".*<dt>inscription</dt>\n <dd>.*<pre>HELLOWORLD</pre>.*</dd>.*",
);

TestServer::spawn_with_args(&rpc_server, &[]).assert_response_regex(
Expand Down Expand Up @@ -306,21 +291,25 @@ fn inscribe_png() {
let rpc_server = test_bitcoincore_rpc::spawn_with(Network::Regtest, "ord");
let txid = rpc_server.mine_blocks(1)[0].txdata[0].txid();

CommandBuilder::new(format!(
let stdout = CommandBuilder::new(format!(
"--chain regtest --index-sats wallet inscribe --satpoint {txid}:0:0 --file degenerate.png"
))
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.stdout_regex("commit\t[[:xdigit:]]{64}\nreveal\t[[:xdigit:]]{64}\n")
.run();

let txid = reveal_txid_from_inscribe_stdout(&stdout);

rpc_server.mine_blocks(1);

let ord_server = TestServer::spawn_with_args(&rpc_server, &["--index-sats"]);

ord_server.assert_response_regex(
"/sat/5000000000",
".*<dt>inscription</dt>\n <dd><img src=.*",
&format!(
".*<dt>inscription</dt>\n <dd><a href=/inscription/{txid}><img src=/content/{txid}.*"
),
)
}

Expand Down Expand Up @@ -614,10 +603,8 @@ fn inscribe_with_optional_satpoint_arg() {

rpc_server.mine_blocks(1);

TestServer::spawn_with_args(&rpc_server, &["--index-sats"]).assert_response_regex(
"/sat/5000000000",
".*<dt>inscription</dt>\n <dd><p>HELLOWORLD</p></dd>.*",
);
TestServer::spawn_with_args(&rpc_server, &["--index-sats"])
.assert_response_regex("/sat/5000000000", ".*HELLOWORLD.*");

TestServer::spawn_with_args(&rpc_server, &[]).assert_response_regex(
&format!("/inscription/{}", reveal_txid_from_inscribe_stdout(&stdout)),
Expand Down Expand Up @@ -687,14 +674,17 @@ fn inscribe_gif() {
.rpc_server(&rpc_server)
.stdout_regex("commit\t[[:xdigit:]]{64}\nreveal\t[[:xdigit:]]{64}\n")
.run();
let inscription_id = reveal_txid_from_inscribe_stdout(&stdout);

let txid = reveal_txid_from_inscribe_stdout(&stdout);

rpc_server.mine_blocks(1);

let ord_server = TestServer::spawn_with_args(&rpc_server, &["--index-sats"]);

ord_server.assert_response_regex(
"/sat/5000000000",
&format!(".*<dt>inscription</dt>\n <dd><img src=/content/{inscription_id}.*"),
&format!(
".*<dt>inscription</dt>\n <dd><a href=/inscription/{txid}><img src=/content/{txid}.*"
),
)
}