-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use {super::*, boilerplate::Display}; | ||
|
||
pub(crate) mod block; | ||
pub(crate) mod ordinal; | ||
pub(crate) mod root; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use super::*; | ||
|
||
#[derive(Display)] | ||
pub(crate) struct BlockHtml { | ||
hash: BlockHash, | ||
txids: Vec<Txid>, | ||
} | ||
|
||
impl BlockHtml { | ||
pub(crate) fn new(block: Block) -> Self { | ||
Self { | ||
hash: block.header.block_hash(), | ||
txids: block.txdata.iter().map(Transaction::txid).collect(), | ||
} | ||
} | ||
} | ||
|
||
impl Content for BlockHtml { | ||
fn title(&self) -> String { | ||
format!("Block {}", self.hash) | ||
} | ||
|
||
fn page(self) -> PageHtml { | ||
PageHtml { | ||
content: Box::new(self), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use {super::*, pretty_assertions::assert_eq, unindent::Unindent}; | ||
|
||
#[test] | ||
fn block_html() { | ||
assert_eq!( | ||
BlockHtml::new(bitcoin::blockdata::constants::genesis_block( | ||
Network::Bitcoin | ||
)) | ||
.to_string(), | ||
" | ||
<h1>Block 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f</h1> | ||
<h2>Transactions</h2> | ||
<ul> | ||
<li><a href=/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b>4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b</a></li> | ||
</ul> | ||
" | ||
.unindent() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<h1>Block {{ self.hash }}</h1> | ||
<h2>Transactions</h2> | ||
<ul> | ||
%% for txid in &self.txids { | ||
<li><a href=/tx/{{txid}}>{{txid}}</a></li> | ||
%% } | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters