diff --git a/lib/block.ts b/lib/block.ts index 7f98dc3..8466005 100644 --- a/lib/block.ts +++ b/lib/block.ts @@ -34,6 +34,10 @@ export default class Block extends WasmWrapper { return this.instance.hash; } + public get previousBlockHash(): string { + return this.instance.previous_block_hash; + } + public serialize(): Uint8Array { return this.instance.serialize(); } diff --git a/lib/blockchain.ts b/lib/blockchain.ts index 65d03dd..af5923b 100644 --- a/lib/blockchain.ts +++ b/lib/blockchain.ts @@ -120,4 +120,16 @@ export default class Blockchain extends WasmWrapper { } 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); + } } diff --git a/lib/transaction.ts b/lib/transaction.ts index 93618aa..216e82c 100644 --- a/lib/transaction.ts +++ b/lib/transaction.ts @@ -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 { @@ -134,10 +133,10 @@ export default class Transaction extends WasmWrapper { }; } - 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; diff --git a/package-lock.json b/package-lock.json index 14e03e0..4d58691 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "saito-js", - "version": "0.0.27", + "version": "0.0.28", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "saito-js", - "version": "0.0.27", + "version": "0.0.28", "license": "ISC", "dependencies": { "buffer": "^6.0.3", @@ -17,7 +17,7 @@ "morgan": "~1.10.0", "node-fetch": "^2.6.1", "process": "^0.11.10", - "saito-wasm": "^0.0.16", + "saito-wasm": "^0.0.17", "url": "^0.11.0", "util": "^0.12.5", "ws": "^8.13.0" @@ -4151,9 +4151,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/saito-wasm": { - "version": "0.0.16", - "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.16.tgz", - "integrity": "sha512-VvZ7+ZzR9mYc3/z9tq8Njln4QR8QwkiWzhmTkG8uQthMTxhBSLwACTFrXq5xFX5+l3l+tiqvSGao0LRPkqmtaA==", + "version": "0.0.17", + "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.17.tgz", + "integrity": "sha512-1BPfAerMlmiOXHlgTpd891H6jBLci2cOJBcAiAmepxdlzG06qScgu9rKgN6pe4molSyTRKEkNY7MuCx96bgDFw==", "dependencies": { "cross-env": "^7.0.3", "node-fetch": "^3.3.0" @@ -8195,9 +8195,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "saito-wasm": { - "version": "0.0.16", - "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.16.tgz", - "integrity": "sha512-VvZ7+ZzR9mYc3/z9tq8Njln4QR8QwkiWzhmTkG8uQthMTxhBSLwACTFrXq5xFX5+l3l+tiqvSGao0LRPkqmtaA==", + "version": "0.0.17", + "resolved": "https://registry.npmjs.org/saito-wasm/-/saito-wasm-0.0.17.tgz", + "integrity": "sha512-1BPfAerMlmiOXHlgTpd891H6jBLci2cOJBcAiAmepxdlzG06qScgu9rKgN6pe4molSyTRKEkNY7MuCx96bgDFw==", "requires": { "cross-env": "^7.0.3", "node-fetch": "^3.3.0" diff --git a/package.json b/package.json index 3445849..411f04a 100644 --- a/package.json +++ b/package.json @@ -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'", @@ -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", diff --git a/saito.ts b/saito.ts index 3245a6d..e47d4d3 100644 --- a/saito.ts +++ b/saito.ts @@ -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() {