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
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub struct MinerAddress {}
#[wasm_bindgen]
impl MinerAddress {
pub fn mainnet_fee_address() -> String {
ergo_lib::constants::MINERS_FEE_MAINNET_ADDRESS.to_string()
}
pub fn testnet_fee_address() -> String {
ergo_lib::constants::MINERS_FEE_TESTNET_ADDRESS.to_string()
}
}
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct I64(i64);
#[wasm_bindgen]
impl I64 {
#[allow(clippy::should_implement_trait)]
pub fn from_str(string: &str) -> Result<I64, JsValue> {
string
.parse::<i64>()
.map_err(|e| JsValue::from_str(&format! {"{:?}", e}))
.map(I64)
}
pub fn to_str(&self) -> String {
format!("{}", self.0)
}
pub fn as_num(&self) -> js_sys::Number {
js_sys::Number::from(self.0 as f64)
}
pub fn checked_add(&self, other: &I64) -> Result<I64, JsValue> {
match self.0.checked_add(other.0) {
Some(value) => Ok(I64(value)),
None => Err(JsValue::from_str("overflow")),
}
}
}
impl From<i64> for I64 {
fn from(v: i64) -> Self {
I64(v)
}
}
impl From<I64> for i64 {
fn from(v: I64) -> Self {
v.0
}
}
#[allow(dead_code, missing_docs)]
pub fn set_panic_hook() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}