diff --git a/executor/package.json b/executor/package.json index a3bc3bb6..00209dcf 100644 --- a/executor/package.json +++ b/executor/package.json @@ -12,10 +12,10 @@ "build": "wasm-pack build --target web --out-dir browser; wasm-pack build --target nodejs --out-dir node; scripts/pack-wasm.cjs" }, "dependencies": { + "@polkadot/util": "^12.5.1", "@polkadot/wasm-util": "^7.2.2" }, "devDependencies": { - "@polkadot/util": "^12.4.1", "fflate": "^0.8.0" }, "files": [ diff --git a/packages/core/src/wasm-executor/browser-wasm-executor.mjs b/packages/core/src/wasm-executor/browser-wasm-executor.mjs index b20adf72..15141998 100644 --- a/packages/core/src/wasm-executor/browser-wasm-executor.mjs +++ b/packages/core/src/wasm-executor/browser-wasm-executor.mjs @@ -14,17 +14,12 @@ const calculateStateRoot = async (entries, trie_version) => { const decodeProof = async (trieRootHash, keys, nodes) => { await pkg.wasmReady - const decoded = await pkg.decode_proof(trieRootHash, keys, nodes) - return decoded.reduce((accum, [key, value]) => { - accum[key] = value - return accum - }, {}) + return pkg.decode_proof(trieRootHash, keys, nodes) } const createProof = async (nodes, entries) => { await pkg.wasmReady - const result = await pkg.create_proof(nodes, entries) - return { trieRootHash: result[0], nodes: result[1] } + return pkg.create_proof(nodes, entries) } const runTask = async (task, callback) => { diff --git a/packages/core/src/wasm-executor/index.ts b/packages/core/src/wasm-executor/index.ts index 29f800ce..8b478cff 100644 --- a/packages/core/src/wasm-executor/index.ts +++ b/packages/core/src/wasm-executor/index.ts @@ -27,18 +27,12 @@ export type RuntimeVersion = { export interface WasmExecutor { getRuntimeVersion: (code: HexString) => Promise calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise - createProof: ( - nodes: HexString[], - entries: [HexString, HexString | null][], - ) => Promise<{ - trieRootHash: `0x${string}` - nodes: `0x${string}`[] - }> + createProof: (nodes: HexString[], entries: [HexString, HexString | null][]) => Promise<[HexString, HexString[]]> decodeProof: ( trieRootHash: HexString, keys: HexString[], nodes: HexString[], - ) => Promise> + ) => Promise<[[HexString, HexString | null]]> runTask: ( task: { wasm: HexString @@ -84,12 +78,17 @@ export const calculateStateRoot = async ( export const decodeProof = async (trieRootHash: HexString, keys: HexString[], nodes: HexString[]) => { const worker = await getWorker() - return worker.remote.decodeProof(trieRootHash, keys, nodes) + const result = await worker.remote.decodeProof(trieRootHash, keys, nodes) + return result.reduce((accum, [key, value]) => { + accum[key] = value + return accum + }, {}) } export const createProof = async (nodes: HexString[], entries: [HexString, HexString | null][]) => { const worker = await getWorker() - return worker.remote.createProof(nodes, entries) + const [trieRootHash, newNodes] = await worker.remote.createProof(nodes, entries) + return { trieRootHash, nodes: newNodes } } export const runTask = async ( diff --git a/packages/core/src/wasm-executor/node-wasm-executor.mjs b/packages/core/src/wasm-executor/node-wasm-executor.mjs index 0d368385..1db95675 100644 --- a/packages/core/src/wasm-executor/node-wasm-executor.mjs +++ b/packages/core/src/wasm-executor/node-wasm-executor.mjs @@ -13,16 +13,11 @@ const calculateStateRoot = async (entries, trie_version) => { } const decodeProof = async (trieRootHash, keys, nodes) => { - const decoded = await pkg.decode_proof(trieRootHash, keys, nodes) - return decoded.reduce((accum, [key, value]) => { - accum[key] = value - return accum - }, {}) + return pkg.decode_proof(trieRootHash, keys, nodes) } const createProof = async (nodes, entries) => { - const result = await pkg.create_proof(nodes, entries) - return { trieRootHash: result[0], nodes: result[1] } + return pkg.create_proof(nodes, entries) } const runTask = async (task, callback) => { diff --git a/packages/db/package.json b/packages/db/package.json index 538a5806..1ee6e6c2 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -10,6 +10,8 @@ }, "dependencies": { "@acala-network/chopsticks-core": "workspace:*", + "@polkadot/util": "^12.5.1", + "@polkadot/wasm-util": "^7.2.2", "localforage": "^1.10.0", "sql.js": "^1.8.0", "sqlite3": "^5.1.6", diff --git a/packages/db/src/db/entities.ts b/packages/db/src/db/entities.ts index 26d81fe1..dec79762 100644 --- a/packages/db/src/db/entities.ts +++ b/packages/db/src/db/entities.ts @@ -1,4 +1,4 @@ -import { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core/src/database' +import { BlockEntry, KeyValueEntry } from '@acala-network/chopsticks-core' import { EntitySchema } from 'typeorm' export const KeyValuePair = new EntitySchema({ diff --git a/packages/web-test/package.json b/packages/web-test/package.json index c3d3dcb1..5de6e5c7 100644 --- a/packages/web-test/package.json +++ b/packages/web-test/package.json @@ -7,27 +7,23 @@ "build": "npx vite build", "vite:serve": "npx vite --port 3000 --host", "vite:preview": "npx vite preview --port 3000", - "parcel:serve": "parcel serve index.html --port 3000", + "parcel:serve": "npx parcel serve index.html --port 3000", "test": "playwright test" }, - "dependencies": { + "devDependencies": { "@acala-network/chopsticks-core": "workspace:*", "@acala-network/chopsticks-db": "workspace:*", "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", "@mui/material": "^5.14.11", - "react": "^18.2.0", - "react-dom": "^18.2.0" - }, - "devDependencies": { "@playwright/test": "^1.37.1", "@types/react": "^18", "@types/react-dom": "^18", "@vitejs/plugin-react": "^4.1.0", "crypto-browserify": "^3.12.0", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.3", "path-browserify": "^1.0.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", "stream-browserify": "^3.0.0", "typescript": "^5.1.6" } diff --git a/yarn.lock b/yarn.lock index 3bd59e3a..e0c22b0c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -36,6 +36,8 @@ __metadata: resolution: "@acala-network/chopsticks-db@workspace:packages/db" dependencies: "@acala-network/chopsticks-core": "workspace:*" + "@polkadot/util": ^12.5.1 + "@polkadot/wasm-util": ^7.2.2 "@types/sql.js": ^1.4.4 fflate: ^0.8.0 localforage: ^1.10.0 @@ -62,7 +64,7 @@ __metadata: version: 0.0.0-use.local resolution: "@acala-network/chopsticks-executor@workspace:executor" dependencies: - "@polkadot/util": ^12.4.1 + "@polkadot/util": ^12.5.1 "@polkadot/wasm-util": ^7.2.2 fflate: ^0.8.0 languageName: unknown @@ -124,8 +126,6 @@ __metadata: "@types/react-dom": ^18 "@vitejs/plugin-react": ^4.1.0 crypto-browserify: ^3.12.0 - eslint-plugin-react-hooks: ^4.6.0 - eslint-plugin-react-refresh: ^0.4.3 path-browserify: ^1.0.1 react: ^18.2.0 react-dom: ^18.2.0 @@ -1815,7 +1815,7 @@ __metadata: languageName: node linkType: hard -"@polkadot/util@npm:12.5.1, @polkadot/util@npm:^12.4.1, @polkadot/util@npm:^12.5.1": +"@polkadot/util@npm:12.5.1, @polkadot/util@npm:^12.5.1": version: 12.5.1 resolution: "@polkadot/util@npm:12.5.1" dependencies: @@ -4539,24 +4539,6 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-react-hooks@npm:^4.6.0": - version: 4.6.0 - resolution: "eslint-plugin-react-hooks@npm:4.6.0" - peerDependencies: - eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 - checksum: 23001801f14c1d16bf0a837ca7970d9dd94e7b560384b41db378b49b6e32dc43d6e2790de1bd737a652a86f81a08d6a91f402525061b47719328f586a57e86c3 - languageName: node - linkType: hard - -"eslint-plugin-react-refresh@npm:^0.4.3": - version: 0.4.3 - resolution: "eslint-plugin-react-refresh@npm:0.4.3" - peerDependencies: - eslint: ">=7" - checksum: 0332c950bb46c3058fd06acb1dbdc3ea0af05238645f4c0f575e0e367440dc56afb928f855833d321b9e8109e08c63d5f476cc55d507f883a80c289bfcd509cb - languageName: node - linkType: hard - "eslint-plugin-sort-imports-es6-autofix@npm:^0.6.0": version: 0.6.0 resolution: "eslint-plugin-sort-imports-es6-autofix@npm:0.6.0"