Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #50 from SaitoTech/develop
Browse files Browse the repository at this point in the history
wasm bug fixing
  • Loading branch information
SankaD committed Aug 23, 2023
2 parents 1887bb4 + 7fbd62e commit 7eb8510
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
21 changes: 11 additions & 10 deletions lib/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
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(
Expand All @@ -63,7 +64,7 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
}
}
} else {
console.log(`confirmations : ${confirmations}`);
// console.log(`confirmations : ${confirmations}`);
}
this.confirmations.set(block_hash, from_blocks_back);
} catch (error) {
Expand Down Expand Up @@ -105,11 +106,11 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
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++) {
Expand All @@ -127,7 +128,7 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
}
}

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) {
Expand Down
2 changes: 2 additions & 0 deletions lib/custom/shared_methods.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -46,6 +47,7 @@ export default class WebSharedMethods extends CustomSharedMethods {
}

disconnectFromPeer(peerIndex: bigint): void {
console.log("disconnect from peer : " + peerIndex);
Saito.getInstance().removeSocket(peerIndex);
}

Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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'",
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7eb8510

Please sign in to comment.