Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc wasm bindings #295

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading