Skip to content

Commit

Permalink
Merge pull request #1525 from mintlayer/feature/wasm-helper-function
Browse files Browse the repository at this point in the history
Add wasm helper function to get spend maturity block count
  • Loading branch information
OBorce committed Feb 1, 2024
2 parents 199bd31 + 6e2860c commit f6eb079
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions wasm-crypto/js-bindings/crypto_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions wasm-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
let output = OutputTimeLock::ForBlockCount(num);
Expand Down

0 comments on commit f6eb079

Please sign in to comment.