From 2bb53a52c78e0d0b3d620bf0570199c39e3a3e4d Mon Sep 17 00:00:00 2001 From: Sanka Darshana Date: Wed, 23 Aug 2023 14:07:48 +0530 Subject: [PATCH] wasm bug fixing --- lib/block.ts | 11 ++++++++--- lib/blockchain.ts | 5 ++++- lib/custom/shared_methods.web.ts | 4 +++- package-lock.json | 4 ++-- package.json | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/block.ts b/lib/block.ts index a2e07ee..09bebaa 100644 --- a/lib/block.ts +++ b/lib/block.ts @@ -22,9 +22,14 @@ export default class Block extends WasmWrapper { } public get transactions(): Array { - return this.instance.transactions.map((tx) => { - return Saito.getInstance().factory.createTransaction(tx); - }); + try { + return this.instance.transactions.map((tx) => { + return Saito.getInstance().factory.createTransaction(tx); + }); + } catch (error) { + console.error(error); + return []; + } } public get id(): bigint { diff --git a/lib/blockchain.ts b/lib/blockchain.ts index 756b973..e01af9f 100644 --- a/lib/blockchain.ts +++ b/lib/blockchain.ts @@ -58,7 +58,10 @@ export default class Blockchain extends WasmWrapper { } } catch (error) { console.error(error); - console.log("callback index : " + callbackIndices[j]); + console.error("callback index : " + callbackIndices[j]); + console.error("block type : " + block.block_type); + console.error("block id : " + block.id); + console.error("block hash : " + block.hash); console.error("tx causing error", block.transactions[callbackIndices[j]].msg); } } diff --git a/lib/custom/shared_methods.web.ts b/lib/custom/shared_methods.web.ts index 35fbd51..003c270 100644 --- a/lib/custom/shared_methods.web.ts +++ b/lib/custom/shared_methods.web.ts @@ -109,7 +109,9 @@ export default class WebSharedMethods extends CustomSharedMethods { sendMessage(peerIndex: bigint, buffer: Uint8Array): void { // console.debug("sending message to peer : " + peerIndex + " with size : " + buffer.byteLength); let socket = Saito.getInstance().getSocket(peerIndex); - socket.send(buffer); + if (socket) { + socket.send(buffer); + } } sendMessageToAll(buffer: Uint8Array, exceptions: Array): void { diff --git a/package-lock.json b/package-lock.json index 59078fd..2c6f02f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "saito-js", - "version": "0.0.48", + "version": "0.0.49", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "saito-js", - "version": "0.0.48", + "version": "0.0.49", "license": "ISC", "dependencies": { "base-58": "^0.0.1", diff --git a/package.json b/package.json index 3f60719..97d272b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "saito-js", - "version": "0.0.48", + "version": "0.0.49", "description": "js wrappings around saito-core using wasm", "scripts": { "test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register 'tests/**/*.ts'",