diff --git a/wasm-crypto/js-bindings/crypto_test.js b/wasm-crypto/js-bindings/crypto_test.js index 559742e942..f4a58ad2fa 100644 --- a/wasm-crypto/js-bindings/crypto_test.js +++ b/wasm-crypto/js-bindings/crypto_test.js @@ -28,6 +28,7 @@ import { SignatureHashType, encode_input_for_account_outpoint, estimate_transaction_size, + staking_pool_spend_maturity_block_count, } from "../pkg/wasm_crypto.js"; function assert_eq_arrays(arr1, arr2) { @@ -171,6 +172,14 @@ export async function run_test() { } } + { + const lock_for_blocks = staking_pool_spend_maturity_block_count(BigInt(1000)); + console.log(`lock for blocks ${lock_for_blocks}`) + if (lock_for_blocks != 7200) { + throw new Error("Incorrect lock for blocks"); + } + } + { try { encode_input_for_utxo("asd", 1); diff --git a/wasm-crypto/src/lib.rs b/wasm-crypto/src/lib.rs index 5509d956a9..98c5a32ac8 100644 --- a/wasm-crypto/src/lib.rs +++ b/wasm-crypto/src/lib.rs @@ -280,6 +280,14 @@ pub fn encode_output_transfer( Ok(output.encode()) } +#[wasm_bindgen] +pub fn staking_pool_spend_maturity_block_count(current_block_height: u64, network: Network) -> u64 { + let chain_config = Builder::new(network.into()).build(); + chain_config + .staking_pool_spend_maturity_block_count(BlockHeight::new(current_block_height)) + .to_int() +} + #[wasm_bindgen] pub fn encode_lock_for_block_count(num: u64) -> Vec { let output = OutputTimeLock::ForBlockCount(num);