use super::*; #[derive(Boilerplate)] pub(crate) struct InscriptionHtml { pub(crate) chain: Chain, pub(crate) children: Vec, pub(crate) genesis_fee: u64, pub(crate) genesis_height: u64, pub(crate) inscription: Inscription, pub(crate) inscription_id: InscriptionId, pub(crate) next: Option, pub(crate) inscription_number: i64, pub(crate) output: Option, pub(crate) parent: Option, pub(crate) previous: Option, pub(crate) sat: Option, pub(crate) satpoint: SatPoint, pub(crate) timestamp: DateTime, } #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct InscriptionJson { pub address: Option, pub children: Vec, pub content_length: Option, pub content_type: Option, pub genesis_fee: u64, pub genesis_height: u64, pub inscription_id: InscriptionId, pub next: Option, pub inscription_number: i64, pub output_value: Option, pub parent: Option, pub previous: Option, pub sat: Option, pub satpoint: SatPoint, pub timestamp: i64, } impl InscriptionJson { pub fn new( chain: Chain, children: Vec, genesis_fee: u64, genesis_height: u64, inscription: Inscription, inscription_id: InscriptionId, parent: Option, next: Option, inscription_number: i64, output: Option, previous: Option, sat: Option, satpoint: SatPoint, timestamp: DateTime, ) -> Self { Self { inscription_id, children, inscription_number, genesis_height, parent, genesis_fee, output_value: output.as_ref().map(|o| o.value), address: output .as_ref() .and_then(|o| chain.address_from_script(&o.script_pubkey).ok()) .map(|address| address.to_string()), sat, satpoint, content_type: inscription.content_type().map(|s| s.to_string()), content_length: inscription.content_length(), timestamp: timestamp.timestamp(), previous, next, } } } impl PageContent for InscriptionHtml { fn title(&self) -> String { format!("Inscription {}", self.inscription_number) } fn preview_image_url(&self) -> Option> { Some(Trusted(format!("/content/{}", self.inscription_id))) } } #[cfg(test)] mod tests { use super::*; #[test] fn without_sat_nav_links_or_output() { assert_regex_match!( InscriptionHtml { children: Vec::new(), parent: None, chain: Chain::Mainnet, genesis_fee: 1, genesis_height: 0, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), inscription_id: inscription_id(1), next: None, inscription_number: 1, output: None, previous: None, sat: None, satpoint: satpoint(1, 0), timestamp: timestamp(0), }, "

Inscription 1

id
1{64}i1
preview
link
content
link
content length
10 bytes
content type
text/plain;charset=utf-8
timestamp
genesis height
0
genesis fee
1
genesis transaction
1{64}
location
1{64}:1:0
output
1{64}:1
offset
0
" .unindent() ); } #[test] fn with_output() { assert_regex_match!( InscriptionHtml { children: Vec::new(), parent: None, chain: Chain::Mainnet, genesis_fee: 1, genesis_height: 0, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), inscription_id: inscription_id(1), next: None, inscription_number: 1, output: Some(tx_out(1, address())), previous: None, sat: None, satpoint: satpoint(1, 0), timestamp: timestamp(0), }, "

Inscription 1

.*
address
bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
output value
1
.*
" .unindent() ); } #[test] fn with_sat() { assert_regex_match!( InscriptionHtml { children: Vec::new(), parent: None, chain: Chain::Mainnet, genesis_fee: 1, genesis_height: 0, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), inscription_id: inscription_id(1), next: None, inscription_number: 1, output: Some(tx_out(1, address())), previous: None, sat: Some(Sat(1)), satpoint: satpoint(1, 0), timestamp: timestamp(0), }, "

Inscription 1

.*
.*
sat
1
preview
.*
" .unindent() ); } #[test] fn with_prev_and_next() { assert_regex_match!( InscriptionHtml { children: Vec::new(), parent: None, chain: Chain::Mainnet, genesis_fee: 1, genesis_height: 0, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), inscription_id: inscription_id(2), next: Some(inscription_id(3)), inscription_number: 1, output: Some(tx_out(1, address())), previous: Some(inscription_id(1)), sat: None, satpoint: satpoint(1, 0), timestamp: timestamp(0), }, "

Inscription 1

.* " .unindent() ); } #[test] fn with_cursed_and_unbound() { assert_regex_match!( InscriptionHtml { children: Vec::new(), parent: None, chain: Chain::Mainnet, genesis_fee: 1, genesis_height: 0, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), inscription_id: inscription_id(2), next: None, inscription_number: -1, output: Some(tx_out(1, address())), previous: None, sat: None, satpoint: SatPoint { outpoint: unbound_outpoint(), offset: 0 }, timestamp: timestamp(0), }, "

Inscription -1 \\(unstable\\)

.*
.*
location
0{64}:0:0 \\(unbound\\)
output
0{64}:0 \\(unbound\\)
.*
" .unindent() ); } #[test] fn with_parent() { assert_regex_match!( InscriptionHtml { children: Vec::new(), parent: Some(inscription_id(2)), chain: Chain::Mainnet, genesis_fee: 1, genesis_height: 0, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), inscription_id: inscription_id(1), next: None, inscription_number: 1, output: None, previous: None, sat: None, satpoint: satpoint(1, 0), timestamp: timestamp(0), }, "

Inscription 1

id
1{64}i1
parent
2{64}i2
preview
link
content
link
content length
10 bytes
content type
text/plain;charset=utf-8
timestamp
genesis height
0
genesis fee
1
genesis transaction
1{64}
location
1{64}:1:0
output
1{64}:1
offset
0
" .unindent() ); } #[test] fn with_children() { assert_regex_match!( InscriptionHtml { children: vec![inscription_id(2), inscription_id(3)], parent: None, chain: Chain::Mainnet, genesis_fee: 1, genesis_height: 0, inscription: inscription("text/plain;charset=utf-8", "HELLOWORLD"), inscription_id: inscription_id(1), next: None, inscription_number: 1, output: None, previous: None, sat: None, satpoint: satpoint(1, 0), timestamp: timestamp(0), }, "

Inscription 1

id
1{64}i1
preview
link
content
link
content length
10 bytes
content type
text/plain;charset=utf-8
timestamp
genesis height
0
genesis fee
1
genesis transaction
1{64}
location
1{64}:1:0
output
1{64}:1
offset
0
children
" .unindent() ); } }