From 7fbd62ea9abc5c8f924f42ef27916d474f20a984 Mon Sep 17 00:00:00 2001 From: Sanka Darshana Date: Wed, 23 Aug 2023 07:05:03 +0530 Subject: [PATCH] wasm bug fixing --- lib/blockchain.ts | 21 +++++++++++---------- lib/custom/shared_methods.web.ts | 2 ++ package-lock.json | 18 +++++++++--------- package.json | 4 ++-- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/blockchain.ts b/lib/blockchain.ts index d1732f6..756b973 100644 --- a/lib/blockchain.ts +++ b/lib/blockchain.ts @@ -41,14 +41,15 @@ export default class Blockchain extends WasmWrapper { let callbacks = this.callbacks.get(block_hash); let callbackIndices = this.callbackIndices.get(block_hash); let confirmations = this.confirmations.get(block_hash) || BigInt(-1); - console.log( - `running callbacks for ${block_hash}. callbacks : ${callbacks?.length} indexes : ${callbackIndices?.length} confirmations : ${confirmations} from_blocks_back : ${from_blocks_back}` - ); + // console.debug( + // `running callbacks for ${block_hash}. callbacks : ${callbacks?.length} indexes : ${callbackIndices?.length} confirmations : ${confirmations} from_blocks_back : ${from_blocks_back}` + // ); if (Number(confirmations) && callbacks && callbackIndices) { for (let i = Number(confirmations) + 1; i < from_blocks_back; i++) { for (let j = 0; j < callbacks.length; j++) { try { if (callbacks[j] !== undefined && callbackIndices[j] !== undefined) { + // console.log(`run callback : ${j} for block : ${i}`); await callbacks[j](block, block.transactions[callbackIndices[j]], i); } else { console.log( @@ -63,7 +64,7 @@ export default class Blockchain extends WasmWrapper { } } } else { - console.log(`confirmations : ${confirmations}`); + // console.log(`confirmations : ${confirmations}`); } this.confirmations.set(block_hash, from_blocks_back); } catch (error) { @@ -105,11 +106,11 @@ export default class Blockchain extends WasmWrapper { block_id_to_run_callbacks_from = block_id_to_run_callbacks_from + BigInt(1); } - console.log("block_id_to_run_callbacks_from = " + block_id_to_run_callbacks_from); - console.log( - "block_id_in_which_to_delete_callbacks = " + block_id_in_which_to_delete_callbacks - ); - console.log("block.id = " + block.id); + // console.log("block_id_to_run_callbacks_from = " + block_id_to_run_callbacks_from); + // console.log( + // "block_id_in_which_to_delete_callbacks = " + block_id_in_which_to_delete_callbacks + // ); + // console.log("block.id = " + block.id); if (block_id_to_run_callbacks_from > BigInt(0)) { for (let i = block_id_to_run_callbacks_from; i <= block.id; i += BigInt(1)) { // for (let i = block_id_to_run_callbacks_from; Number(i) <= Number(block.id); i++) { @@ -127,7 +128,7 @@ export default class Blockchain extends WasmWrapper { } } - console.log(`i = ${i} confirmations = ${confirmation_count}`); + // console.log(`i = ${i} confirmations = ${confirmation_count}`); if (run_callbacks) { let callback_block_hash = await this.instance.get_longest_chain_hash_at(i); if (callback_block_hash !== "" && callback_block_hash !== DefaultEmptyBlockHash) { diff --git a/lib/custom/shared_methods.web.ts b/lib/custom/shared_methods.web.ts index 5b9009a..35fbd51 100644 --- a/lib/custom/shared_methods.web.ts +++ b/lib/custom/shared_methods.web.ts @@ -33,6 +33,7 @@ export default class WebSharedMethods extends CustomSharedMethods { }; socket.onclose = () => { try { + console.log("socket.onclose : " + index); Saito.getLibInstance().process_peer_disconnection(index); } catch (error) { console.error(error); @@ -46,6 +47,7 @@ export default class WebSharedMethods extends CustomSharedMethods { } disconnectFromPeer(peerIndex: bigint): void { + console.log("disconnect from peer : " + peerIndex); Saito.getInstance().removeSocket(peerIndex); } diff --git a/package-lock.json b/package-lock.json index ae2d585..59078fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "saito-js", - "version": "0.0.47", + "version": "0.0.48", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "saito-js", - "version": "0.0.47", + "version": "0.0.48", "license": "ISC", "dependencies": { "base-58": "^0.0.1", @@ -18,7 +18,7 @@ "morgan": "~1.10.0", "node-fetch": "^2.6.1", "process": "^0.11.10", - "saito-wasm": "^0.0.33", + "saito-wasm": "^0.0.34", "url": "^0.11.0", "util": "^0.12.5", "ws": "^8.13.0" @@ -4157,9 +4157,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/saito-wasm": { - "version": "0.0.33", - "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.33.tgz", - "integrity": "sha512-KbM2W4cTPmVuh2u8OAsK1C+1hgovbW26tuYpwNiy3ltnTZEWQDeBC+xQlE3QIQRWMhA/yC1pj66Hx9UjRYtccg==", + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.34.tgz", + "integrity": "sha512-qcSIoARLIey5jruin+QXb0/L0an9F2nesuQbnDTgA3hFT9/j4ca69DZQtLhLkco2mhJ5wlEWP7i4U29djtVVyw==", "dependencies": { "cross-env": "^7.0.3", "node-fetch": "^3.3.0" @@ -8206,9 +8206,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "saito-wasm": { - "version": "0.0.33", - "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.33.tgz", - "integrity": "sha512-KbM2W4cTPmVuh2u8OAsK1C+1hgovbW26tuYpwNiy3ltnTZEWQDeBC+xQlE3QIQRWMhA/yC1pj66Hx9UjRYtccg==", + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.34.tgz", + "integrity": "sha512-qcSIoARLIey5jruin+QXb0/L0an9F2nesuQbnDTgA3hFT9/j4ca69DZQtLhLkco2mhJ5wlEWP7i4U29djtVVyw==", "requires": { "cross-env": "^7.0.3", "node-fetch": "^3.3.0" diff --git a/package.json b/package.json index fbd2da4..3f60719 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "saito-js", - "version": "0.0.47", + "version": "0.0.48", "description": "js wrappings around saito-core using wasm", "scripts": { "test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register 'tests/**/*.ts'", @@ -36,7 +36,7 @@ "morgan": "~1.10.0", "node-fetch": "^2.6.1", "process": "^0.11.10", - "saito-wasm": "^0.0.33", + "saito-wasm": "^0.0.34", "url": "^0.11.0", "util": "^0.12.5", "ws": "^8.13.0"