1use cml_core_wasm::impl_wasm_conversions;
2use wasm_bindgen::prelude::{wasm_bindgen, JsError};
3
4use crate::{plutus::ExUnitPrices, transaction::Transaction, Coin};
5
6#[wasm_bindgen]
9#[derive(Clone, Debug)]
10pub struct LinearFee(cml_chain::fees::LinearFee);
11
12impl_wasm_conversions!(cml_chain::fees::LinearFee, LinearFee);
13
14#[wasm_bindgen]
15impl LinearFee {
16 pub fn new(coefficient: Coin, constant: Coin, ref_script_cost_per_byte: Coin) -> Self {
22 cml_chain::fees::LinearFee::new(coefficient, constant, ref_script_cost_per_byte).into()
23 }
24
25 pub fn coefficient(&self) -> Coin {
27 self.0.coefficient
28 }
29
30 pub fn constant(&self) -> Coin {
32 self.0.constant
33 }
34
35 pub fn ref_script_cost_per_byte(&self) -> Coin {
37 self.0.ref_script_cost_per_byte
38 }
39}
40
41#[wasm_bindgen]
45pub fn min_script_fee(tx: &Transaction, ex_unit_prices: &ExUnitPrices) -> Result<Coin, JsError> {
46 cml_chain::fees::min_script_fee(tx.as_ref(), ex_unit_prices.as_ref()).map_err(Into::into)
47}
48
49pub fn min_ref_script_fee(
54 linear_fee: &LinearFee,
55 total_ref_script_size: u64,
56) -> Result<Coin, JsError> {
57 cml_chain::fees::min_ref_script_fee(linear_fee.as_ref(), total_ref_script_size)
58 .map_err(Into::into)
59}
60
61#[wasm_bindgen]
62pub fn min_no_script_fee(tx: &Transaction, linear_fee: &LinearFee) -> Result<Coin, JsError> {
63 cml_chain::fees::min_no_script_fee(tx.as_ref(), linear_fee.as_ref()).map_err(Into::into)
64}
65
66#[wasm_bindgen]
71pub fn min_fee(
72 tx: &Transaction,
73 linear_fee: &LinearFee,
74 ex_unit_prices: &ExUnitPrices,
75 total_ref_script_size: u64,
76) -> Result<Coin, JsError> {
77 cml_chain::fees::min_fee(
78 tx.as_ref(),
79 linear_fee.as_ref(),
80 ex_unit_prices.as_ref(),
81 total_ref_script_size,
82 )
83 .map_err(Into::into)
84}