1use wasm_bindgen::prelude::*;
4
5use crate::error_conversion::to_js;
6
7#[wasm_bindgen]
9pub struct MinerAddress {}
10
11#[wasm_bindgen]
12impl MinerAddress {
13 pub fn mainnet_fee_address() -> String {
15 ergo_lib::wallet::miner_fee::MINERS_FEE_MAINNET_ADDRESS_STR.clone()
16 }
17 pub fn testnet_fee_address() -> String {
19 ergo_lib::wallet::miner_fee::MINERS_FEE_TESTNET_ADDRESS_STR.clone()
20 }
21}
22
23#[wasm_bindgen]
26#[derive(PartialEq, Eq, Debug, Clone)]
27pub struct I64(i64);
28
29#[wasm_bindgen]
30impl I64 {
31 #[allow(clippy::should_implement_trait)]
33 pub fn from_str(string: &str) -> Result<I64, JsValue> {
34 string.parse::<i64>().map_err(to_js).map(I64)
35 }
36
37 pub fn to_str(&self) -> String {
39 format!("{}", self.0)
40 }
41
42 pub fn as_num(&self) -> js_sys::Number {
44 js_sys::Number::from(self.0 as f64)
45 }
46
47 pub fn checked_add(&self, other: &I64) -> Result<I64, JsValue> {
49 match self.0.checked_add(other.0) {
50 Some(value) => Ok(I64(value)),
51 None => Err(JsValue::from_str("overflow")),
52 }
53 }
54}
55
56impl From<i64> for I64 {
57 fn from(v: i64) -> Self {
58 I64(v)
59 }
60}
61
62impl From<I64> for i64 {
63 fn from(v: I64) -> Self {
64 v.0
65 }
66}
67
68#[allow(dead_code, missing_docs)]
69pub fn set_panic_hook() {
70 #[cfg(feature = "console_error_panic_hook")]
77 console_error_panic_hook::set_once();
78}