Skip to content

Commit

Permalink
update wasm init (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Nov 13, 2023
1 parent ffa92ad commit a773e75
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
5 changes: 2 additions & 3 deletions executor/scripts/pack-wasm.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ const BYTES = '${base64}';
import { base64Decode, unzlibSync } from '@polkadot/wasm-util';
const WASM_BYTES = unzlibSync(base64Decode(BYTES, new Uint8Array(LEN_IN)), new Uint8Array(LEN_OUT));
import wasmInit, { initSync } from "./chopsticks_executor.js";
const blob = new Blob([WASM_BYTES], { type: "application/wasm" });
export const wasmReady = typeof Bun !== undefined ? Promise.resolve(initSync(WASM_BYTES)) : wasmInit(URL.createObjectURL(blob));
import { initSync } from "./chopsticks_executor.js";
initSync(new WebAssembly.Module(WASM_BYTES));
export * from "./chopsticks_executor.js";
`);
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/wasm-executor/browser-wasm-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,23 @@ import * as Comlink from 'comlink'
import * as pkg from '@acala-network/chopsticks-executor'

const getRuntimeVersion = async (code) => {
await pkg.wasmReady
return pkg.get_runtime_version(code)
}

// trie_version: 0 for old trie, 1 for new trie
const calculateStateRoot = async (entries, trie_version) => {
await pkg.wasmReady
return pkg.calculate_state_root(entries, trie_version)
}

const decodeProof = async (trieRootHash, keys, nodes) => {
await pkg.wasmReady
return pkg.decode_proof(trieRootHash, keys, nodes)
}

const createProof = async (nodes, entries) => {
await pkg.wasmReady
return pkg.create_proof(nodes, entries)
}

const runTask = async (task, callback) => {
await pkg.wasmReady
return pkg.run_task(task, callback, 'info')
}

Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/wasm-executor/node-wasm-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@ import { parentPort } from 'node:worker_threads'
import nodeEndpoint from 'comlink/dist/umd/node-adapter.js'

const getRuntimeVersion = async (code) => {
await pkg.wasmReady
return pkg.get_runtime_version(code)
}

// trie_version: 0 for old trie, 1 for new trie
const calculateStateRoot = async (entries, trie_version) => {
await pkg.wasmReady
return pkg.calculate_state_root(entries, trie_version)
}

const decodeProof = async (trieRootHash, keys, nodes) => {
await pkg.wasmReady
return pkg.decode_proof(trieRootHash, keys, nodes)
}

const createProof = async (nodes, entries) => {
await pkg.wasmReady
return pkg.create_proof(nodes, entries)
}

const runTask = async (task, callback) => {
await pkg.wasmReady
return pkg.run_task(task, callback, process.env.RUST_LOG)
}

Expand Down

0 comments on commit a773e75

Please sign in to comment.