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 #30 from SaitoTech/develop
Browse files Browse the repository at this point in the history
wasm bug fixing
  • Loading branch information
SankaD authored Aug 1, 2023
2 parents aaf6778 + c3de796 commit 68a9425
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
4 changes: 4 additions & 0 deletions lib/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default class Block extends WasmWrapper<WasmBlock> {
return this.instance.hash;
}

public get previousBlockHash(): string {
return this.instance.previous_block_hash;
}

public serialize(): Uint8Array {
return this.instance.serialize();
}
Expand Down
12 changes: 12 additions & 0 deletions lib/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@ export default class Blockchain extends WasmWrapper<WasmBlockchain> {
}

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

public async getLatestBlockId() {
return this.instance.get_latest_block_id();
}

public async getLongestChainHashAtId(blockId: bigint) {
return this.instance.get_longest_chain_hash_at_id(blockId);
}

public async getHashesAtId(blockId: bigint) {
return this.instance.get_hashes_at_id(blockId);
}
}
7 changes: 3 additions & 4 deletions lib/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { WasmTransaction } from "saito-wasm/pkg/node/index";
import Slip from "./slip";
import Saito from "../saito";
import Factory from "./factory";
import WasmWrapper from "./wasm_wrapper";

export enum TransactionType {
Expand Down Expand Up @@ -134,10 +133,10 @@ export default class Transaction extends WasmWrapper<WasmTransaction> {
};
}

public static deserialize(buffer: Uint8Array, factory: Factory): Transaction | null {
public deserialize(buffer: Uint8Array) {
try {
let wasmTx = Transaction.Type.deserialize(buffer);
return factory.createTransaction(wasmTx);
this.instance = Transaction.Type.deserialize(buffer);
this.unpackData();
} catch (e) {
console.error(e);
return null;
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.27",
"version": "0.0.28",
"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 @@ -29,7 +29,7 @@
"dependencies": {
"buffer": "^6.0.3",
"cookie-parser": "~1.4.6",
"saito-wasm": "^0.0.16",
"saito-wasm": "^0.0.17",
"cors": "^2.8.5",
"debug": "^4.3.4",
"express": "~4.18.2",
Expand Down
12 changes: 2 additions & 10 deletions saito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,8 @@ export default class Saito {
return this.blockchain;
}

public testBufferIn(buffer: Uint8Array) {
return Saito.getLibInstance().test_buffer_in(buffer);
}

public testBufferOut(): Uint8Array {
return Saito.getLibInstance().test_buffer_out();
}

public printWasmMemUsage() {
// console.log("WASM memory usage : " + wasm.memory.buffer.byteLength);
public async getMempoolTxs() {
return Saito.getLibInstance().get_mempool_txs();
}

// public async loadWallet() {
Expand Down

0 comments on commit 68a9425

Please sign in to comment.