diff --git a/lib/block.ts b/lib/block.ts index 09bebaa..7e49cd0 100644 --- a/lib/block.ts +++ b/lib/block.ts @@ -19,8 +19,27 @@ export default class Block extends WasmWrapper { block = new Block.Type(); } super(block!); + + + } + + public toJson(): string { + + try { + return JSON.stringify({ + id: JSON.stringify(this.id), + hash: this.hash, + type: JSON.stringify(this.block_type), + previous_block_hash: this.previousBlockHash, + transactions: this.transactions.map((tx) => tx.toJson()), + }) + } catch (error) { + console.error(error); + } + return "" } + public get transactions(): Array { try { return this.instance.transactions.map((tx) => { diff --git a/lib/blockchain.ts b/lib/blockchain.ts index e01af9f..0feeaaa 100644 --- a/lib/blockchain.ts +++ b/lib/blockchain.ts @@ -22,7 +22,7 @@ export default class Blockchain extends WasmWrapper { return this.instance.reset(); } - public async affixCallbacks(block: Block) {} + public async affixCallbacks(block: Block) { } public async runCallbacks(block_hash: string, from_blocks_back: bigint) { if (block_hash === DefaultEmptyBlockHash) { @@ -149,8 +149,7 @@ export default class Blockchain extends WasmWrapper { block_id_in_which_to_delete_callbacks + BigInt(1) // because block ring starts from 1 ); console.log( - `deleting callbacks for ${ - block_id_in_which_to_delete_callbacks + BigInt(1) + `deleting callbacks for ${block_id_in_which_to_delete_callbacks + BigInt(1) }: ${callback_block_hash}` ); this.callbacks.delete(callback_block_hash); @@ -165,9 +164,9 @@ export default class Blockchain extends WasmWrapper { } else { console.log( "already have processed the callbacks. last_callback_block_id = " + - this.last_callback_block_id + - " block_id = " + - block_id + this.last_callback_block_id + + " block_id = " + + block_id ); } } catch (error) { @@ -176,7 +175,7 @@ export default class Blockchain extends WasmWrapper { } } - public async onNewBlock(block: Block, lc: boolean) {} + public async onNewBlock(block: Block, lc: boolean) { } public async getLatestBlockId() { return this.instance.get_latest_block_id(); diff --git a/package-lock.json b/package-lock.json index 2c6f02f..9c2fd55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "saito-js", - "version": "0.0.49", + "version": "0.0.50", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "saito-js", - "version": "0.0.49", + "version": "0.0.50", "license": "ISC", "dependencies": { "base-58": "^0.0.1", diff --git a/package.json b/package.json index 97d272b..a9c75fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "saito-js", - "version": "0.0.49", + "version": "0.0.50", "description": "js wrappings around saito-core using wasm", "scripts": { "test": "env TS_NODE_PROJECT=\"tsconfig.testing.json\" mocha --require ts-node/register 'tests/**/*.ts'",