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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/test/scriptnum10.h]
pub struct ScriptNum10Error {
}
impl RuntimeErrorInterface for ScriptNum10Error {}
impl From<&str> for ScriptNum10Error {
fn from(str_: &str) -> Self {
todo!();
/*
: std::runtime_error(str)
*/
}
}
pub struct ScriptNum10 {
value: i64,
}
pub mod script_num10 {
pub const N_DEFAULT_MAX_NUM_SIZE: usize = 4;
}
impl PartialEq<i64> for ScriptNum10 {
fn eq(&self, other: &i64) -> bool {
todo!();
/*
return m_value == rhs;
*/
}
}
impl Ord for ScriptNum10 {
fn cmp(&self, other: &ScriptNum10) -> Ordering {
todo!();
/*
return m_value < rhs;
*/
}
}
impl PartialOrd<i64> for ScriptNum10 {
fn partial_cmp(&self, other: &i64) -> Option<Ordering> {
Some(self.cmp(&ScriptNum10{ value: other.clone() }))
}
}
impl PartialEq<ScriptNum10> for ScriptNum10 {
fn eq(&self, other: &ScriptNum10) -> bool {
todo!();
/*
return operator==(rhs.m_value);
*/
}
}
impl Eq for ScriptNum10 {}
impl PartialOrd<ScriptNum10> for ScriptNum10 {
fn partial_cmp(&self, other: &ScriptNum10) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Add<i64> for ScriptNum10 {
type Output = ScriptNum10;
fn add(self, other: i64) -> Self::Output {
todo!();
/*
return CScriptNum10(m_value + rhs);
*/
}
}
impl Sub<i64> for ScriptNum10 {
type Output = ScriptNum10;
fn sub(self, other: i64) -> Self::Output {
todo!();
/*
return CScriptNum10(m_value - rhs);
*/
}
}
impl Add<ScriptNum10> for ScriptNum10 {
type Output = ScriptNum10;
fn add(self, other: ScriptNum10) -> Self::Output {
todo!();
/*
return operator+(rhs.m_value);
*/
}
}
impl Sub<ScriptNum10> for ScriptNum10 {
type Output = ScriptNum10;
fn sub(self, other: ScriptNum10) -> Self::Output {
todo!();
/*
return operator-(rhs.m_value);
*/
}
}
impl AddAssign<ScriptNum10> for ScriptNum10 {
fn add_assign(&mut self, other: ScriptNum10) {
todo!();
/*
return operator+=(rhs.m_value);
*/
}
}
impl SubAssign<ScriptNum10> for ScriptNum10 {
fn sub_assign(&mut self, other: ScriptNum10) {
todo!();
/*
return operator-=(rhs.m_value);
*/
}
}
impl Neg for ScriptNum10 {
type Output = Self;
fn neg(self) -> Self::Output {
todo!();
/*
assert(m_value != std::numeric_limits<int64_t>::min());
return CScriptNum10(-m_value);
*/
}
}
impl AddAssign<i64> for ScriptNum10 {
fn add_assign(&mut self, other: i64) {
todo!();
/*
assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
(rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
m_value += rhs;
return *this;
*/
}
}
impl SubAssign<i64> for ScriptNum10 {
fn sub_assign(&mut self, other: i64) {
todo!();
/*
assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
(rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
m_value -= rhs;
return *this;
*/
}
}
impl ScriptNum10 {
#[inline] pub fn assign_from(&mut self, rhs: &i64) -> &mut ScriptNum10 {
todo!();
/*
m_value = rhs;
return *this;
*/
}
pub fn getint(&self) -> i32 {
todo!();
/*
if (m_value > std::numeric_limits<int>::max())
return std::numeric_limits<int>::max();
else if (m_value < std::numeric_limits<int>::min())
return std::numeric_limits<int>::min();
return m_value;
*/
}
pub fn getvch(&self) -> Vec<u8> {
todo!();
/*
return serialize(m_value);
*/
}
pub fn serialize(value: &i64) -> Vec<u8> {
todo!();
/*
if(value == 0)
return std::vector<unsigned char>();
std::vector<unsigned char> result;
const bool neg = value < 0;
uint64_t absvalue = neg ? -value : value;
while(absvalue)
{
result.push_back(absvalue & 0xff);
absvalue >>= 8;
}
// - If the most significant byte is >= 0x80 and the value is positive, push a
// new zero-byte to make the significant byte < 0x80 again.
// - If the most significant byte is >= 0x80 and the value is negative, push a
// new 0x80 byte that will be popped off when converting to an integral.
// - If the most significant byte is < 0x80 and the value is negative, add
// 0x80 to it, since it will be subtracted and interpreted as a negative when
// converting to an integral.
if (result.back() & 0x80)
result.push_back(neg ? 0x80 : 0);
else if (neg)
result.back() |= 0x80;
return result;
*/
}
pub fn set_vch(vch: &Vec<u8>) -> i64 {
todo!();
/*
if (vch.empty())
return 0;
int64_t result = 0;
for (size_t i = 0; i != vch.size(); ++i)
result |= static_cast<int64_t>(vch[i]) << 8*i;
// If the input vector's most significant byte is 0x80, remove it from
// the result's msb and return a negative.
if (vch.back() & 0x80)
return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
return result;
*/
}
/**
| The ScriptNum implementation from
| Bitcoin Core 0.10.0, for cross-comparison.
|
*/
pub fn new_from_n(n: &i64) -> Self {
todo!();
/*
m_value = n;
*/
}
pub fn new(
vch: &Vec<u8>,
require_minimal: bool,
n_max_num_size: Option<usize>) -> Self {
let n_max_num_size: usize =
n_max_num_size.unwrap_or(script_num::N_DEFAULT_MAX_NUM_SIZE);
todo!();
/*
if (vch.size() > nMaxNumSize) {
throw scriptnum10_error("script number overflow");
}
if (fRequireMinimal && vch.size() > 0) {
// Check that the number is encoded with the minimum possible
// number of bytes.
//
// If the most-significant-byte - excluding the sign bit - is zero
// then we're not minimal. Note how this test also rejects the
// negative-zero encoding, 0x80.
if ((vch.back() & 0x7f) == 0) {
// One exception: if there's more than one byte and the most
// significant bit of the second-most-significant-byte is set
// it would conflict with the sign bit. An example of this case
// is +-255, which encode to 0xff00 and 0xff80 respectively.
// (big-endian).
if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
throw scriptnum10_error("non-minimally encoded script number");
}
}
}
m_value = set_vch(vch);
*/
}
}