From 6e2860cabd6507e1ff8665e624a212c1f12df754 Mon Sep 17 00:00:00 2001 From: Boris Oncev Date: Wed, 31 Jan 2024 23:22:26 +0100 Subject: [PATCH] Add wasm helper function to get spend maturity block count --- wasm-crypto/js-bindings/crypto_test.js | 9 +++++++++ wasm-crypto/src/lib.rs | 8 ++++++++ 2 files changed, 17 insertions(+) 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);