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 #53 from SaitoTech/develop
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
SankaD committed Aug 24, 2023
2 parents 7e7882c + 2f4a7af commit 984cfc6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
19 changes: 19 additions & 0 deletions lib/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,27 @@ export default class Block extends WasmWrapper<WasmBlock> {
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<Transaction> {
try {
return this.instance.transactions.map((tx) => {
Expand Down
13 changes: 6 additions & 7 deletions lib/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
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) {
Expand Down Expand Up @@ -149,8 +149,7 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
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);
Expand All @@ -165,9 +164,9 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
} 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) {
Expand All @@ -176,7 +175,7 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
}
}

public async onNewBlock(block: Block, lc: boolean) {}
public async onNewBlock(block: Block, lc: boolean) { }

public async getLatestBlockId() {
return this.instance.get_latest_block_id();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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'",
Expand Down

0 comments on commit 984cfc6

Please sign in to comment.