Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix types #466

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/wasm-executor/browser-wasm-executor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
19 changes: 9 additions & 10 deletions packages/core/src/wasm-executor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ export type RuntimeVersion = {
export interface WasmExecutor {
getRuntimeVersion: (code: HexString) => Promise<RuntimeVersion>
calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>
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<Record<`0x${string}`, `0x${string}` | null>>
) => Promise<[[HexString, HexString | null]]>
runTask: (
task: {
wasm: HexString
Expand Down Expand Up @@ -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 (
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/wasm-executor/node-wasm-executor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/db/entities.ts
Original file line number Diff line number Diff line change
@@ -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<KeyValueEntry>({
Expand Down
12 changes: 4 additions & 8 deletions packages/web-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
26 changes: 4 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down