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

Show address on inscription #1187

Merged
merged 10 commits into from
Jan 10, 2023
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
14 changes: 12 additions & 2 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,21 @@ impl Server {

let sat = index.get_sat_by_inscription_id(inscription_id)?;

let output = index
.get_transaction(satpoint.outpoint.txid)?
.ok_or_not_found(|| format!("inscription {inscription_id} current transaction"))?
.output
.into_iter()
.nth(satpoint.outpoint.vout.try_into().unwrap())
.ok_or_not_found(|| format!("inscription {inscription_id} current transaction output"))?;

Ok(
InscriptionHtml {
chain,
genesis_height,
inscription,
inscription_id,
output,
sat,
satpoint,
}
Expand Down Expand Up @@ -1762,7 +1772,7 @@ next.*",
server.assert_response_regex(
format!("/inscription/{inscription_id}"),
StatusCode::OK,
r".*<dl>\s*<dt>sat</dt>\s*<dd><a href=/sat/5000000000>5000000000</a></dd>\s*<dt>content</dt>.*",
r".*<dt>sat</dt>\s*<dd><a href=/sat/5000000000>5000000000</a></dd>\s*<dt>content</dt>.*",
);
}

Expand All @@ -1782,7 +1792,7 @@ next.*",
server.assert_response_regex(
format!("/inscription/{inscription_id}"),
StatusCode::OK,
r".*<dl>\s*<dt>content</dt>.*",
r".*<dt>output value</dt>\s*<dd>5000000000</dd>\s*<dt>content</dt>.*",
);
}
}
11 changes: 11 additions & 0 deletions src/templates/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub(crate) struct InscriptionHtml {
pub(crate) inscription_id: InscriptionId,
pub(crate) sat: Option<Sat>,
pub(crate) satpoint: SatPoint,
pub(crate) chain: Chain,
pub(crate) output: TxOut,
}

impl PageContent for InscriptionHtml {
Expand All @@ -32,11 +34,17 @@ mod tests {
inscription_id: "1111111111111111111111111111111111111111111111111111111111111111".parse().unwrap(),
sat: None,
satpoint: satpoint(1, 0),
chain: Chain::Mainnet,
output: tx_out(1, address()),
},
"
<h1>Inscription 1{64}</h1>
<div class=inscription><a href=/preview/1{64}><iframe .* src=/preview/1{64}></iframe></a></div>
<dl>
<dt>address</dt>
<dd class=monospace>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4</dd>
<dt>output value</dt>
<dd>1</dd>
<dt>content</dt>
<dd><a href=/content/1{64}>link</a></dd>
<dt>content size</dt>
Expand Down Expand Up @@ -70,11 +78,14 @@ mod tests {
.unwrap(),
sat: Some(Sat(1)),
satpoint: satpoint(1, 0),
chain: Chain::Mainnet,
output: tx_out(1, address()),
},
"
<h1>Inscription 1{64}</h1>
.*
<dl>
.*
<dt>sat</dt>
<dd><a href=/sat/1>1</a></dd>
<dt>content</dt>
Expand Down
6 changes: 6 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ pub(crate) fn satpoint(n: u64, offset: u64) -> SatPoint {
}
}

pub(crate) fn address() -> Address {
"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"
.parse()
.unwrap()
}

pub(crate) fn recipient() -> Address {
"tb1q6en7qjxgw4ev8xwx94pzdry6a6ky7wlfeqzunz"
.parse()
Expand Down
6 changes: 6 additions & 0 deletions templates/inscription.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<h1>Inscription {{ self.inscription_id }}</h1>
<div class=inscription>{{Iframe::main(self.inscription_id)}}</div>
<dl>
%% if let Ok(address) = self.chain.address_from_script(&self.output.script_pubkey ) {
<dt>address</dt>
<dd class=monospace>{{ address }}</dd>
%% }
<dt>output value</dt>
<dd>{{ self.output.value }}</dd>
%% if let Some(sat) = self.sat {
<dt>sat</dt>
<dd><a href=/sat/{{sat}}>{{sat}}</a></dd>
Expand Down
6 changes: 4 additions & 2 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ fn inscription_page() {
<h1>Inscription {reveal_tx}</h1>
.*<a href=/preview/{reveal_tx}><iframe .* src=/preview/{reveal_tx}></iframe></a>.*
<dl>
<dt>address</dt>
<dd class=monospace>bc1.*</dd>
<dt>content</dt>
<dd><a href=/content/{reveal_tx}>link</a></dd>
<dt>content size</dt>
Expand Down Expand Up @@ -148,7 +150,7 @@ fn inscription_page_after_send() {
);

let txid = CommandBuilder::new(format!(
"wallet send ord1qcqgs2pps4u4yedfyl5pysdjjncs8et5u8gcumw {reveal_txid}"
"wallet send --cardinal bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv {reveal_txid}"
))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
Expand All @@ -163,7 +165,7 @@ fn inscription_page_after_send() {
ord_server.assert_response_regex(
format!("/inscription/{reveal_txid}"),
format!(
r".*<h1>Inscription {reveal_txid}</h1>.*<dt>location</dt>\s*<dd class=monospace>{send_txid}:0:0</dd>.*",
r".*<h1>Inscription {reveal_txid}</h1>.*<dt>address</dt>\s*<dd class=monospace>bc1qcqgs2pps4u4yedfyl5pysdjjncs8et5utseepv</dd>.*<dt>location</dt>\s*<dd class=monospace>{send_txid}:0:0</dd>.*",
),
)
}
Expand Down
5 changes: 2 additions & 3 deletions tests/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ pub(crate) struct TestServer {
impl TestServer {
pub(crate) fn spawn_with_args(rpc_server: &test_bitcoincore_rpc::Handle, args: &[&str]) -> Self {
let tempdir = TempDir::new().unwrap();
fs::create_dir(tempdir.path().join("regtest")).unwrap();
fs::write(tempdir.path().join("regtest/.cookie"), "foo:bar").unwrap();
fs::write(tempdir.path().join(".cookie"), "foo:bar").unwrap();
let port = TcpListener::bind("127.0.0.1:0")
.unwrap()
.local_addr()
.unwrap()
.port();

let child = Command::new(executable_path("ord")).args(format!(
"--chain regtest --rpc-url {} --bitcoin-data-dir {} --data-dir {} {} server --http-port {port} --address 127.0.0.1",
"--rpc-url {} --bitcoin-data-dir {} --data-dir {} {} server --http-port {port} --address 127.0.0.1",
rpc_server.url(),
tempdir.path().display(),
tempdir.path().display(),
Expand Down