use alloc::string::String;
use core::str::FromStr;
use keetanetwork_client::RepEndpoint as Core;
use num_bigint::BigInt;
use wasm_bindgen::prelude::wasm_bindgen;
use crate::account::Account;
use crate::convert::{coded_error, JsResult};
#[wasm_bindgen]
pub struct RepEndpoint {
inner: Core,
}
#[wasm_bindgen]
impl RepEndpoint {
#[wasm_bindgen(constructor)]
pub fn new(api_url: String, account: &Account, weight: String) -> JsResult<RepEndpoint> {
let weight =
BigInt::from_str(&weight).map_err(|_| coded_error("INVALID_WEIGHT", "weight must be a decimal integer"))?;
Ok(Self { inner: Core::new(api_url, account.inner(), weight) })
}
}
impl RepEndpoint {
pub(crate) fn into_inner(self) -> Core {
self.inner
}
}