iop_sdk_wasm/hydra/
parameters.rs

1use super::*;
2
3/// Parameters of a Hydra account added to a {@link Vault}
4#[wasm_bindgen(js_name = HydraParameters)]
5pub struct JsHydraParameters {
6    inner: HydraParameters,
7}
8
9#[wasm_bindgen(js_class = HydraParameters)]
10impl JsHydraParameters {
11    /// Creates a parameter object for a Hydra account. The network name needs to be one of {@link allNetworkNames} and the account
12    /// index must be an 31-bit non-negative number. Most wallets use only a few accounts, and there is no way yet to name the account
13    /// in the current version.
14    ///
15    /// Note that there is a negligable chance that the given account cannot be used with the given seed, in which case an error is
16    /// thrown and another index needs to be tried.
17    #[wasm_bindgen(constructor)]
18    pub fn new(network: &str, account: i32) -> Result<JsHydraParameters, JsValue> {
19        let network = Networks::by_name(network).map_err_to_js()?;
20        let inner = HydraParameters::new(network, account);
21        Ok(JsHydraParameters::from(inner))
22    }
23}
24
25impl From<HydraParameters> for JsHydraParameters {
26    fn from(inner: HydraParameters) -> Self {
27        Self { inner }
28    }
29}
30
31impl Wraps<HydraParameters> for JsHydraParameters {
32    fn inner(&self) -> &HydraParameters {
33        &self.inner
34    }
35}