From 4459fd5844ae66ecfd61b7eb1a3269805e0d9958 Mon Sep 17 00:00:00 2001 From: smupyknight Date: Tue, 23 Feb 2021 19:38:28 +0800 Subject: [PATCH 1/5] Make wasm repo importable from webpack --- build/hack_hydra_dx_wasm.js | 2 +- build/hack_hydra_dx_wasm_bg.js | 8 ++++++-- package.json | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 package.json diff --git a/build/hack_hydra_dx_wasm.js b/build/hack_hydra_dx_wasm.js index 1939b44..2244a7f 100644 --- a/build/hack_hydra_dx_wasm.js +++ b/build/hack_hydra_dx_wasm.js @@ -1,2 +1,2 @@ -import * as wasm from "./hack_hydra_dx_wasm_bg.wasm"; +// import * as wasm from "./hack_hydra_dx_wasm_bg.wasm"; export * from "./hack_hydra_dx_wasm_bg.js"; \ No newline at end of file diff --git a/build/hack_hydra_dx_wasm_bg.js b/build/hack_hydra_dx_wasm_bg.js index f283797..2aed71d 100644 --- a/build/hack_hydra_dx_wasm_bg.js +++ b/build/hack_hydra_dx_wasm_bg.js @@ -1,5 +1,4 @@ -import * as wasm from './hack_hydra_dx_wasm_bg.wasm'; - +// import * as wasm from './hack_hydra_dx_wasm_bg.wasm'; const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); @@ -8,6 +7,7 @@ cachedTextDecoder.decode(); let cachegetUint8Memory0 = null; function getUint8Memory0() { + const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) { cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer); } @@ -79,6 +79,7 @@ function passStringToWasm0(arg, malloc, realloc) { let cachegetInt32Memory0 = null; function getInt32Memory0() { + const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); } @@ -92,6 +93,7 @@ function getInt32Memory0() { */ export function get_buy_price(s, b, a) { try { + const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; wasm.__wbindgen_export_0.value = retptr; var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -118,6 +120,7 @@ export function get_buy_price(s, b, a) { */ export function get_sell_price(s, b, a) { try { + const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; wasm.__wbindgen_export_0.value = retptr; var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -144,6 +147,7 @@ export function get_sell_price(s, b, a) { */ export function get_spot_price(s, b, a) { try { + const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; wasm.__wbindgen_export_0.value = retptr; var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); diff --git a/package.json b/package.json new file mode 100644 index 0000000..80007ab --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "name": "hack-hydra-dx-wasm", + "version": "0.1.0", + "private": true, + "main": "build/hack_hydra_dx_wasm.js" +} From 0ab073314da124970c4d31b35d3f4f411856831e Mon Sep 17 00:00:00 2001 From: smupyknight Date: Sat, 6 Mar 2021 16:02:35 +0100 Subject: [PATCH 2/5] Add async to the funcction --- build/hack_hydra_dx_wasm_bg.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/hack_hydra_dx_wasm_bg.js b/build/hack_hydra_dx_wasm_bg.js index 2aed71d..4cb6b90 100644 --- a/build/hack_hydra_dx_wasm_bg.js +++ b/build/hack_hydra_dx_wasm_bg.js @@ -6,7 +6,7 @@ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true cachedTextDecoder.decode(); let cachegetUint8Memory0 = null; -function getUint8Memory0() { +async function getUint8Memory0() { const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) { cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer); From 605ec7166865f6233d8a55c4a4e7e4e0da29a516 Mon Sep 17 00:00:00 2001 From: smupyknight Date: Sat, 6 Mar 2021 17:08:42 +0100 Subject: [PATCH 3/5] Add missing file to package.json --- build/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/build/package.json b/build/package.json index 5d7155a..a967ee8 100644 --- a/build/package.json +++ b/build/package.json @@ -7,6 +7,7 @@ "files": [ "hack_hydra_dx_wasm_bg.wasm", "hack_hydra_dx_wasm.js", + "hack_hydra_dx_wasm_bg.js", "hack_hydra_dx_wasm.d.ts" ], "module": "hack_hydra_dx_wasm.js", From 6e12117f3dd1b9e5b062a37d44d4bc8bbc0f3c50 Mon Sep 17 00:00:00 2001 From: smupyknight Date: Sat, 6 Mar 2021 17:22:22 +0100 Subject: [PATCH 4/5] Add missing await --- build/hack_hydra_dx_wasm_bg.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/hack_hydra_dx_wasm_bg.js b/build/hack_hydra_dx_wasm_bg.js index 4cb6b90..4b3c478 100644 --- a/build/hack_hydra_dx_wasm_bg.js +++ b/build/hack_hydra_dx_wasm_bg.js @@ -78,7 +78,7 @@ function passStringToWasm0(arg, malloc, realloc) { } let cachegetInt32Memory0 = null; -function getInt32Memory0() { +async function getInt32Memory0() { const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) { cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer); @@ -91,7 +91,7 @@ function getInt32Memory0() { * @param {string} a * @returns {string} */ -export function get_buy_price(s, b, a) { +export async function get_buy_price(s, b, a) { try { const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; @@ -118,7 +118,7 @@ export function get_buy_price(s, b, a) { * @param {string} a * @returns {string} */ -export function get_sell_price(s, b, a) { +export async function get_sell_price(s, b, a) { try { const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; @@ -145,7 +145,7 @@ export function get_sell_price(s, b, a) { * @param {string} a * @returns {string} */ -export function get_spot_price(s, b, a) { +export async function get_spot_price(s, b, a) { try { const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; From e6afe06cfe8e746821d3adb561094817b9ed5a9f Mon Sep 17 00:00:00 2001 From: smupyknight Date: Tue, 16 Mar 2021 13:56:18 +0100 Subject: [PATCH 5/5] Fix issues --- build/hack_hydra_dx_wasm_bg.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/hack_hydra_dx_wasm_bg.js b/build/hack_hydra_dx_wasm_bg.js index 4b3c478..4fdfd46 100644 --- a/build/hack_hydra_dx_wasm_bg.js +++ b/build/hack_hydra_dx_wasm_bg.js @@ -92,8 +92,9 @@ async function getInt32Memory0() { * @returns {string} */ export async function get_buy_price(s, b, a) { + const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); + try { - const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; wasm.__wbindgen_export_0.value = retptr; var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); @@ -119,8 +120,9 @@ export async function get_buy_price(s, b, a) { * @returns {string} */ export async function get_sell_price(s, b, a) { + const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); + try { - const wasm = await import('./hack_hydra_dx_wasm_bg.wasm'); const retptr = wasm.__wbindgen_export_0.value - 16; wasm.__wbindgen_export_0.value = retptr; var ptr0 = passStringToWasm0(s, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);