Skip to content

Commit

Permalink
Misc wasm bindings (#295)
Browse files Browse the repository at this point in the history
Mint::as_positive_multiasset()/as_negative_multiasset()

deposit.rs (excluding internal functions - why are these public?)

min_ada.rs

Still missing genesis but that is more work (discussed previously)
  • Loading branch information
rooooooooob authored Dec 30, 2023
1 parent cd32fb6 commit f069de9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions chain/wasm/src/assets/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ impl Mint {
.map(Into::into)
.map_err(Into::into)
}

/// Returns the multiasset where only positive (minting) entries are present
pub fn as_positive_multiasset(&self) -> MultiAsset {
self.0.as_positive_multiasset().into()
}

/// Returns the multiasset where only negative (burning) entries are present
pub fn as_negative_multiasset(&self) -> MultiAsset {
self.0.as_negative_multiasset().into()
}
}

impl_wasm_conversions!(cml_chain::assets::Mint, Mint);
Expand Down
26 changes: 26 additions & 0 deletions chain/wasm/src/deposit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use wasm_bindgen::prelude::{wasm_bindgen, JsError};

use crate::{
assets::{Coin, Value},
transaction::TransactionBody,
};

#[wasm_bindgen]
pub fn get_implicit_input(
txbody: &TransactionBody,
pool_deposit: Coin, // // protocol parameter
key_deposit: Coin, // protocol parameter
) -> Result<Value, JsError> {
cml_chain::deposit::get_implicit_input(txbody.as_ref(), pool_deposit, key_deposit)
.map(Into::into)
.map_err(Into::into)
}

#[wasm_bindgen]
pub fn get_deposit(
txbody: &TransactionBody,
pool_deposit: Coin, // // protocol parameter
key_deposit: Coin, // protocol parameter
) -> Result<Coin, JsError> {
cml_chain::deposit::get_deposit(txbody.as_ref(), pool_deposit, key_deposit).map_err(Into::into)
}
2 changes: 2 additions & 0 deletions chain/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ pub mod builders;
pub mod byron;
pub mod certs;
pub mod crypto;
pub mod deposit;
pub mod fees;
pub mod governance;
pub mod json;
pub mod min_ada;
pub mod plutus;
pub mod transaction;
pub mod utils;
Expand Down
11 changes: 11 additions & 0 deletions chain/wasm/src/min_ada.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use wasm_bindgen::prelude::{wasm_bindgen, JsError};

use crate::{assets::Coin, transaction::TransactionOutput};

#[wasm_bindgen]
pub fn min_ada_required(
output: &TransactionOutput,
coins_per_utxo_byte: Coin, // protocol parameter (in lovelace)
) -> Result<Coin, JsError> {
cml_chain::min_ada::min_ada_required(output.as_ref(), coins_per_utxo_byte).map_err(Into::into)
}

0 comments on commit f069de9

Please sign in to comment.