forked from ordinals/ord
-
Notifications
You must be signed in to change notification settings - Fork 21
/
output.rs
109 lines (103 loc) Β· 3.04 KB
/
output.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use super::*;
#[derive(Boilerplate)]
pub(crate) struct OutputHtml {
pub(crate) outpoint: OutPoint,
pub(crate) list: Option<List>,
pub(crate) chain: Chain,
pub(crate) output: TxOut,
}
impl PageContent for OutputHtml {
fn title(&self) -> String {
format!("Output {}", self.outpoint)
}
}
#[cfg(test)]
mod tests {
use {
super::*,
bitcoin::{blockdata::script, PubkeyHash, Script},
};
#[test]
fn unspent_output() {
pretty_assert_eq!(
OutputHtml {
outpoint: "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0"
.parse()
.unwrap(),
list: Some(List::Unspent(vec![(0, 1), (1, 3)])),
chain: Chain::Mainnet,
output: TxOut {
value: 3,
script_pubkey: Script::new_p2pkh(&PubkeyHash::all_zeros()),
},
}
.to_string(),
"
<h1>Output <span class=monospace>4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0</span></h1>
<dl>
<dt>value</dt><dd>3</dd>
<dt>script pubkey</dt><dd class=data>OP_DUP OP_HASH160 OP_PUSHBYTES_20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG</dd>
<dt>address</dt><dd class=monospace>1111111111111111111114oLvT2</dd>
</dl>
<h2>2 Sat Ranges</h2>
<ul class=monospace>
<li><a href=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/sat/0 class=mythic>0</a></li>
<li><a href=/range/1/3 class=common>1β3</a></li>
</ul>
"
.unindent()
);
}
#[test]
fn spent_output() {
pretty_assert_eq!(
OutputHtml {
outpoint: "0000000000000000000000000000000000000000000000000000000000000000:0"
.parse()
.unwrap(),
list: Some(List::Spent),
chain: Chain::Mainnet,
output: TxOut {
value: 1,
script_pubkey: script::Builder::new().push_int(0).into_script(),
},
}
.to_string(),
"
<h1>Output <span class=monospace>0000000000000000000000000000000000000000000000000000000000000000:0</span></h1>
<dl>
<dt>value</dt><dd>1</dd>
<dt>script pubkey</dt><dd class=data>OP_0</dd>
</dl>
<p>Output has been spent.</p>
"
.unindent()
);
}
#[test]
fn no_list() {
pretty_assert_eq!(
OutputHtml {
outpoint: "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0"
.parse()
.unwrap(),
list: None,
chain: Chain::Mainnet,
output: TxOut {
value: 3,
script_pubkey: Script::new_p2pkh(&PubkeyHash::all_zeros()),
},
}
.to_string(),
"
<h1>Output <span class=monospace>4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0</span></h1>
<dl>
<dt>value</dt><dd>3</dd>
<dt>script pubkey</dt><dd class=data>OP_DUP OP_HASH160 OP_PUSHBYTES_20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG</dd>
<dt>address</dt><dd class=monospace>1111111111111111111114oLvT2</dd>
</dl>
"
.unindent()
);
}
}