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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
crate::ix!();
/**
| A UTXO entry.
|
| Serialized format:
|
| - VARINT((coinbase ? 1 : 0) | (height << 1))
|
| - the non-spent CTxOut (via TxOutCompression)
|
*/
pub struct Coin {
/**
| unspent transaction output
|
*/
pub out: TxOut,
pub bits: CoinBitfield,
}
lazy_static!{
pub static ref COIN_EMPTY: Coin = Coin::empty();
}
impl PartialEq<Coin> for Coin {
#[inline] fn eq(&self, other: &Coin) -> bool {
/*
| Empty Coin objects are always equal.
|
*/
if self.is_spent() && other.is_spent() {
return true;
}
self.bits.coinbase()
== other.bits.coinbase()
&& self.bits.n_height()
== other.bits.n_height()
&& self.out
== other.out
}
}
impl Eq for Coin {}
impl Default for Coin {
/**
| empty constructor
|
*/
fn default() -> Self {
Self::empty()
}
}
impl Clone for Coin {
fn clone(&self) -> Self {
todo!();
/*
: n_height(in.nHeight),
: out(std::move(in.out)),
*/
}
}
impl Coin {
fn empty() -> Self {
Self {
out: TxOut::new(),
bits: CoinBitfield::from_fields(0,false),
}
}
/**
| construct a Coin from a TxOut and height/coinbase
| information.
|
*/
pub fn new(
out_in: &TxOut,
n_height_in: i32,
coin_base_in: bool) -> Self {
todo!();
/*
: out(outIn),
: coin_base(fCoinBaseIn),
: n_height(nHeightIn),
*/
}
pub fn clear(&mut self) {
todo!();
/*
out.SetNull();
fCoinBase = false;
nHeight = 0;
*/
}
pub fn is_coinbase(&self) -> bool {
todo!();
/*
return fCoinBase;
*/
}
pub fn serialize<Stream>(&self, s: &mut Stream) {
todo!();
/*
assert(!IsSpent());
uint32_t code = nHeight * uint32_t{2} + fCoinBase;
::Serialize(s, VARINT(code));
::Serialize(s, Using<TxOutCompression>(out));
*/
}
pub fn unserialize<Stream>(&mut self, s: &mut Stream) {
todo!();
/*
uint32_t code = 0;
::Unserialize(s, VARINT(code));
nHeight = code >> 1;
fCoinBase = code & 1;
::Unserialize(s, Using<TxOutCompression>(out));
*/
}
/**
| Either this coin never existed (see
| e.g. coinEmpty in coins.cpp), or it
| did exist and has been spent.
|
*/
pub fn is_spent(&self) -> bool {
todo!();
/*
return out.IsNull();
*/
}
pub fn dynamic_memory_usage(&self) -> usize {
todo!();
/*
return memusage::DynamicUsage(out.scriptPubKey);
*/
}
}