diff --git a/src/core/modules/impl/wasm/rust-wasm-imports.ts b/src/core/modules/impl/wasm/rust-wasm-imports.ts index ba469fdf..076c3b2e 100644 --- a/src/core/modules/impl/wasm/rust-wasm-imports.ts +++ b/src/core/modules/impl/wasm/rust-wasm-imports.ts @@ -83,306 +83,24 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal } }; - // mapping from base function names (without mangled suffixes) - // to functions normally generated by the wasm-bindgen - // - the "glue" code between js and wasm. - const baseImports = { - __wbg_log_: function (arg0, arg1) { - rawImports.console.log(getStringFromWasm0(arg0, arg1)); - }, - __wbindgen_json_parse: function (arg0, arg1) { - var ret = JSON.parse(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }, - __wbindgen_json_serialize: function (arg0, arg1) { - const obj = getObject(arg1); - var ret = JSON.stringify(obj === undefined ? null : obj); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbindgen_is_null: function (arg0) { - return getObject(arg0) === null; - }, - __wbindgen_object_drop_ref: function (arg0) { - takeObject(arg0); - }, - __wbindgen_cb_drop: function (arg0) { - const obj = takeObject(arg0).original; - if (obj.cnt-- == 1) { - obj.a = 0; - return true; - } - var ret = false; - return ret; - }, - __wbg_kvPut: function (arg0, arg1, arg2) { - return handleError(function (arg0, arg1, arg2) { - var ret = rawImports.KV.put(getStringFromWasm0(arg0, arg1), takeObject(arg2)); - return addHeapObject(ret); - }, arguments); - }, - __wbg_kvGet: function (arg0, arg1) { - return handleError(function (arg0, arg1) { - var ret = rawImports.KV.get(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }, arguments); - }, - __wbg_readContractState: function (arg0, arg1) { - return handleError(function (arg0, arg1) { - var ret = rawImports.SmartWeave.readContractState(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }, arguments); - }, - __wbg_viewContractState: function (arg0, arg1, arg2) { - return handleError(function (arg0, arg1, arg2) { - var ret = rawImports.SmartWeave.viewContractState(getStringFromWasm0(arg0, arg1), takeObject(arg2)); - return addHeapObject(ret); - }, arguments); - }, - __wbg_caller: function (arg0) { - var ret = rawImports.SmartWeave.caller(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_write: function (arg0, arg1, arg2) { - return handleError(function (arg0, arg1, arg2) { - var ret = rawImports.SmartWeave.write(getStringFromWasm0(arg0, arg1), takeObject(arg2)); - return addHeapObject(ret); - }, arguments); - }, - __wbg_refreshState: function (arg0, arg1) { - // TODO - }, - __wbg_indephash: function (arg0) { - var ret = rawImports.Block.indep_hash(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_height: function () { - var ret = rawImports.Block.height(); - return ret; - }, - __wbg_timestamp: function () { - var ret = rawImports.Block.timestamp(); - return ret; - }, - __wbg_id: function (arg0) { - var ret = rawImports.Transaction.id(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_contractOwner: function (arg0) { - var ret = rawImports.Contract.owner(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_contractId: function (arg0) { - var ret = rawImports.Contract.id(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_owner: function (arg0) { - var ret = rawImports.Transaction.owner(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_target: function (arg0) { - var ret = rawImports.Transaction.target(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_call: function () { - return handleError(function (arg0, arg1, arg2) { - var ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); - return addHeapObject(ret); - }, arguments); - }, - __wbg_new_4: function (arg0, arg1) { - try { - var state0 = { a: arg0, b: arg1 }; - var cb0 = (arg0, arg1) => { - const a = state0.a; - state0.a = 0; - try { - return __wbg_adapter_42(a, state0.b, arg0, arg1); - } finally { - state0.a = a; - } - }; - var ret = new Promise(cb0); - return addHeapObject(ret); - } finally { - state0.a = state0.b = 0; - } - }, - __wbg_new_6: function() { - var ret = new Error(); - return addHeapObject(ret); - }, - __wbg_stack: function(arg0, arg1) { - let limit = Error.stackTraceLimit; - Error.stackTraceLimit = 25; - var ret = getObject(arg1).stack; - var ptr0 = passStringToWasm0(ret, wasmInstance.exports.__wbindgen_malloc, wasmInstance.exports.__wbindgen_realloc); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - Error.stackTraceLimit = limit; - }, - __wbg_error: function(arg0, arg1) { - try { - rawImports.console.log(getStringFromWasm0(arg0, arg1)); - } finally { - wasmInstance.exports.__wbindgen_free(arg0, arg1); - } - }, - __wbg_resolve: function (arg0) { - var ret = Promise.resolve(getObject(arg0)); - return addHeapObject(ret); - }, - __wbg_then_a: function (arg0, arg1) { - var ret = getObject(arg0).then(getObject(arg1)); - return addHeapObject(ret); - }, - __wbg_then_5: function (arg0, arg1, arg2) { - var ret = getObject(arg0).then(getObject(arg1), getObject(arg2)); - return addHeapObject(ret); - }, - __wbindgen_debug_string: function (arg0, arg1) { - var ret = debugString(getObject(arg1)); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbindgen_throw: function (arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); - }, - __wbindgen_closure_wrapper: function (arg0, arg1, arg2) { - var ret = makeMutClosure(arg0, arg1, dtorValue, __wbg_adapter_14); - return addHeapObject(ret); - }, - __wbindgen_string_new: function (arg0, arg1) { - var ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); - }, - __wbindgen_string_get: function (arg0, arg1) { - const obj = getObject(arg1); - var ret = typeof obj === 'string' ? obj : undefined; - var ptr0 = isLikeNone(ret) - ? 0 - : passStringToWasm0(ret, wasmInstance.exports.__wbindgen_malloc, wasmInstance.exports.__wbindgen_realloc); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - __wbg_value: function (arg0) { - var ret = rawImports.Vrf.value(); - var ptr0 = passStringToWasm0( - ret, - wasmInstance.exports.__wbindgen_malloc, - wasmInstance.exports.__wbindgen_realloc - ); - var len0 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len0; - getInt32Memory0()[arg0 / 4 + 0] = ptr0; - }, - - __wbg_randomInt: function (arg0) { - var ret = rawImports.Vrf.randomInt(arg0); - return ret; - } - }; - - const baseImportsKeys = Object.keys(baseImports); - - // assigning functions to "real" import names from the currently - // compiled wasm module - let module: any = wbindgenImports.reduce((acc, wbindgenKey) => { - const baseImportsKey = baseImportsKeys.find((key) => wbindgenKey.startsWith(key)); - if (baseImportsKey === undefined) { - throw new Error(`Cannot find import mapping for ${wbindgenKey}`); - } - acc[wbindgenKey] = baseImports[baseImportsKey]; - return acc; - }, {}); - - // the rest of the code is basically left untouched from what - // wasm-bindgen generates - let imports: any = {}; - - imports['__wbindgen_placeholder__'] = module; - let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); - let cachegetUint8Memory0 = null; + let cachedUint8Memory0 = null; function getUint8Memory0() { - if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasmInstance.exports.memory.buffer) { - cachegetUint8Memory0 = new Uint8Array(wasmInstance.exports.memory.buffer); + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasmInstance.exports.memory.buffer); } - return cachegetUint8Memory0; + return cachedUint8Memory0; } function getStringFromWasm0(ptr, len) { return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); } - const heap = new Array(32).fill(undefined); + const heap = new Array(128).fill(undefined); heap.push(undefined, null, true, false); @@ -393,6 +111,8 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal const idx = heap_next; heap_next = heap[idx]; + if (typeof (heap_next) !== 'number') throw new Error('corrupt heap'); + heap[idx] = obj; return idx; } @@ -401,32 +121,65 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal return heap[idx]; } + function _assertBoolean(n) { + if (typeof (n) !== 'boolean') { + throw new Error('expected a boolean argument'); + } + } + + function isLikeNone(x) { + return x === undefined || x === null; + } + + function _assertNum(n) { + if (typeof (n) !== 'number') throw new Error('expected a number argument'); + } + + let cachedFloat64Memory0 = null; + + function getFloat64Memory0() { + if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { + cachedFloat64Memory0 = new Float64Array(wasmInstance.exports.memory.buffer); + } + return cachedFloat64Memory0; + } + + let cachedInt32Memory0 = null; + + function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasmInstance.exports.memory.buffer); + } + return cachedInt32Memory0; + } + let WASM_VECTOR_LEN = 0; // @ts-ignore let cachedTextEncoder = new TextEncoder('utf-8'); const encodeString = - typeof cachedTextEncoder.encodeInto === 'function' + (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); - } + return cachedTextEncoder.encodeInto(arg, view); + } : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length }; + }); function passStringToWasm0(arg, malloc, realloc) { + + if (typeof (arg) !== 'string') throw new Error('expected a string argument'); + if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length); - getUint8Memory0() - .subarray(ptr, ptr + buf.length) - .set(buf); + getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; } @@ -440,7 +193,7 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal for (; offset < len; offset++) { const code = arg.charCodeAt(offset); - if (code > 0x7f) break; + if (code > 0x7F) break; mem[ptr + offset] = code; } @@ -448,10 +201,10 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal if (offset !== 0) { arg = arg.slice(offset); } - ptr = realloc(ptr, len, (len = offset + arg.length * 3)); + ptr = realloc(ptr, len, len = offset + arg.length * 3); const view = getUint8Memory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view); - + if (ret.read !== arg.length) throw new Error('failed to pass whole string'); offset += ret.written; } @@ -459,21 +212,8 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal return ptr; } - let cachegetInt32Memory0 = null; - - function getInt32Memory0() { - if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasmInstance.exports.memory.buffer) { - cachegetInt32Memory0 = new Int32Array(wasmInstance.exports.memory.buffer); - } - return cachegetInt32Memory0; - } - - function isLikeNone(x) { - return x === undefined || x === null; - } - function dropObject(idx) { - if (idx < 36) return; + if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } @@ -549,6 +289,19 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal return className; } + function _assertBigInt(n) { + if (typeof (n) !== 'bigint') throw new Error('expected a bigint argument'); + } + + let cachedBigInt64Memory0 = null; + + function getBigInt64Memory0() { + if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) { + cachedBigInt64Memory0 = new BigInt64Array(wasmInstance.exports.memory.buffer); + } + return cachedBigInt64Memory0; + } + function makeMutClosure(arg0, arg1, dtor, f) { const state = { a: arg0, b: arg1, cnt: 1, dtor }; const real = (...args) => { @@ -573,7 +326,24 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal return real; } - function __wbg_adapter_14(arg0, arg1, arg2) { + function logError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + let error = (function () { + try { + return e instanceof Error ? `${e.message}\n\nStack:\n${e.stack}` : e.toString(); + } catch (_) { + return ""; + } + }()); + console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:", error); + throw e; + } + } + function __wbg_adapter_52(arg0, arg1, arg2) { + _assertNum(arg0); + _assertNum(arg1); wasmInstance.modifiedExports._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__( arg0, arg1, @@ -585,32 +355,22 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal * @param {any} interaction * @returns {Promise} */ - module.warpContractWrite = function (interaction) { - var ret = wasmInstance.exports.warpContractWrite(addHeapObject(interaction)); + function warpContractWrite(interaction) { + const ret = wasmInstance.exports.warpContractWrite(addHeapObject(interaction)); return takeObject(ret); }; - /** - * @param {any} interaction - * @returns {Promise} - */ - module.warpContractView = function (interaction) { - var ret = wasmInstance.exports.warpContractView(addHeapObject(interaction)); - return takeObject(ret); - }; - - let stack_pointer = 32; + let stack_pointer = 128; function addBorrowedObject(obj) { if (stack_pointer == 1) throw new Error('out of js stack'); heap[--stack_pointer] = obj; return stack_pointer; } - /** * @param {any} state */ - module.initState = function (state) { + function initState(state) { try { wasmInstance.exports.initState(addBorrowedObject(state)); } finally { @@ -621,44 +381,47 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal /** * @returns {any} */ - module.currentState = function () { - var ret = wasmInstance.exports.currentState(); + function currentState() { + const ret = wasmInstance.exports.currentState(); return takeObject(ret); }; /** - * @returns {string} + * @returns {number} */ - module.lang = function () { - try { - const retptr = wasmInstance.exports.__wbindgen_add_to_stack_pointer(-16); - wasmInstance.exports.lang(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - return getStringFromWasm0(r0, r1); - } finally { - wasmInstance.exports.__wbindgen_add_to_stack_pointer(16); - wasmInstance.exports.__wbindgen_free(r0, r1); - } + function version() { + const ret = wasmInstance.exports.version(); + return ret }; /** * @returns {number} */ - module.type = function () { - var ret = wasmInstance.exports.type(); - return ret; + function lang() { + const ret = wasmInstance.exports.lang(); + return ret }; - function handleError(f, args) { - try { - return f.apply(this, args); - } catch (e) { - wasmInstance.exports.__wbindgen_exn_store(addHeapObject(e)); - } + /** + * @param {any} interaction + * @returns {Promise} + */ + function warpContractView(interaction) { + const ret = wasmInstance.exports.warpContractView(addHeapObject(interaction)); + return takeObject(ret); + }; + + function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + wasmInstance.exports.__wbindgen_exn_store(addHeapObject(e)); + } } function __wbg_adapter_42(arg0, arg1, arg2, arg3) { + _assertNum(arg0); + _assertNum(arg1); wasmInstance.modifiedExports.wasm_bindgen__convert__closures__invoke2_mut__( arg0, arg1, @@ -667,15 +430,585 @@ export const rustWasmImports = (swGlobal, wbindgenImports, wasmInstance, dtorVal ); } + // mapping from base function names (without mangled suffixes) + // to functions normally generated by the wasm-bindgen + // - the "glue" code between js and wasm. + const baseImports = { + __wbindgen_json_parse: function (arg0, arg1) { + const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }, + + __wbindgen_json_serialize: function (arg0, arg1) { + const obj = getObject(arg1); + const ret = JSON.stringify(obj === undefined ? null : obj); + const ptr0 = passStringToWasm0( + ret, + wasmInstance.exports.__wbindgen_malloc, + wasmInstance.exports.__wbindgen_realloc + ); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, + + __wbindgen_error_new: function (arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }, + + __wbindgen_is_undefined: function (arg0) { + const ret = getObject(arg0) === undefined; + _assertBoolean(ret); + return ret; + }, + + __wbindgen_in: function (arg0, arg1) { + const ret = getObject(arg0) in getObject(arg1); + _assertBoolean(ret); + return ret; + }, + + __wbindgen_number_get: function (arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof (obj) === 'number' ? obj : undefined; + if (!isLikeNone(ret)) { + _assertNum(ret); + } + getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; + getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); + }, + + __wbindgen_boolean_get: function (arg0) { + const v = getObject(arg0); + const ret = typeof (v) === 'boolean' ? (v ? 1 : 0) : 2; + _assertNum(ret); + return ret; + }, + + __wbindgen_is_null: function (arg0) { + const ret = getObject(arg0) === null; + _assertBoolean(ret); + return ret; + }, + + __wbindgen_string_new: function (arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }, + + __wbindgen_string_get: function (arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof (obj) === 'string' ? obj : undefined; + var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasmInstance.exports.__wbindgen_malloc, wasmInstance.exports.__wbindgen_realloc); + var len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, + + __wbindgen_is_bigint: function (arg0) { + const ret = typeof (getObject(arg0)) === 'bigint'; + _assertBoolean(ret); + return ret; + }, + + __wbindgen_is_object: function (arg0) { + const val = getObject(arg0); + const ret = typeof (val) === 'object' && val !== null; + _assertBoolean(ret); + return ret; + }, + + __wbindgen_object_clone_ref: function (arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }, + + __wbindgen_jsval_eq: function (arg0, arg1) { + const ret = getObject(arg0) === getObject(arg1); + _assertBoolean(ret); + return ret; + }, + + __wbindgen_bigint_from_i64: function (arg0) { + const ret = arg0; + return addHeapObject(ret); + }, + + __wbindgen_bigint_from_u64: function (arg0) { + const ret = BigInt.asUintN(64, arg0); + return addHeapObject(ret); + }, + + __wbg_readContractState: function () { + return handleError(function (arg0, arg1) { + const ret = rawImports.SmartWeave.readContractState(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }, arguments); + }, + + __wbg_viewContractState: function () { + return handleError(function (arg0, arg1, arg2) { + const ret = rawImports.SmartWeave.viewContractState(getStringFromWasm0(arg0, arg1), takeObject(arg2)); + return addHeapObject(ret); + }, arguments); + }, + + __wbg_write: function () { + return handleError(function (arg0, arg1, arg2) { + const ret = rawImports.SmartWeave.write(getStringFromWasm0(arg0, arg1), takeObject(arg2)); + return addHeapObject(ret); + }, arguments); + }, + + __wbg_refreshState: function (arg0, arg1) { + // TODO + }, + + __wbg_kvGet: function () { + return handleError(function (arg0, arg1) { + const ret = rawImports.KV.get(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }, arguments); + }, + + __wbg_kvPut: function () { + return handleError(function (arg0, arg1, arg2) { + const ret = rawImports.KV.put(getStringFromWasm0(arg0, arg1), takeObject(arg2)); + return addHeapObject(ret); + }, arguments); + }, + + __wbindgen_object_drop_ref: function (arg0) { + takeObject(arg0); + }, + + __wbg_error: function () { + return logError(function (arg0, arg1) { + try { + rawImports.console.log(getStringFromWasm0(arg0, arg1)); + } finally { + wasmInstance.exports.__wbindgen_free(arg0, arg1); + } + }, arguments) + }, + + __wbg_new_a: function () { + return logError(function () { + const ret = new Error(); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_stack: function () { + return logError(function (arg0, arg1) { + let limit = Error.stackTraceLimit; + Error.stackTraceLimit = 25; + const ret = getObject(arg1).stack; + const ptr0 = passStringToWasm0(ret, wasmInstance.exports.__wbindgen_malloc, wasmInstance.exports.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + Error.stackTraceLimit = limit; + }, arguments) + }, + + __wbg_owner: function () { + return logError(function (arg0) { + const ret = rawImports.Transaction.owner(); + const ptr0 = passStringToWasm0( + ret, + wasmInstance.exports.__wbindgen_malloc, + wasmInstance.exports.__wbindgen_realloc + ); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, arguments) + }, + + __wbg_caller: function () { + return logError(function (arg0) { + const ret = rawImports.SmartWeave.caller(); + const ptr0 = passStringToWasm0( + ret, + wasmInstance.exports.__wbindgen_malloc, + wasmInstance.exports.__wbindgen_realloc + ); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, arguments) + }, + + __wbg_log_c: function () { + return logError(function (arg0, arg1) { + rawImports.console.log(getStringFromWasm0(arg0, arg1)); + }, arguments) + }, + + __wbindgen_cb_drop: function (arg0) { + const obj = takeObject(arg0).original; + if (obj.cnt-- == 1) { + obj.a = 0; + return true; + } + const ret = false; + _assertBoolean(ret); + return ret; + }, + + __wbg_log_7: function () { + return logError(function (arg0) { + console.log(getObject(arg0)); + }, arguments) + }, + + __wbindgen_number_new: function (arg0) { + const ret = arg0; + return addHeapObject(ret); + }, + + __wbindgen_jsval_loose_eq: function (arg0, arg1) { + const ret = getObject(arg0) == getObject(arg1); + _assertBoolean(ret); + return ret; + }, + + __wbg_getwithrefkey: function () { + return logError(function (arg0, arg1) { + const ret = getObject(arg0)[getObject(arg1)]; + return addHeapObject(ret); + }, arguments) + }, + + __wbg_set_8: function () { + return logError(function (arg0, arg1, arg2) { + getObject(arg0)[takeObject(arg1)] = takeObject(arg2); + }, arguments) + }, + + __wbg_String: function () { + return logError(function (arg0, arg1) { + const ret = String(getObject(arg1)); + const ptr0 = passStringToWasm0(ret, wasmInstance.exports.__wbindgen_malloc, wasmInstance.exports.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, arguments) + }, + + __wbg_get_2: function () { + return logError(function (arg0, arg1) { + const ret = getObject(arg0)[arg1 >>> 0]; + return addHeapObject(ret); + }, arguments) + }, + + __wbg_isArray: function () { + return logError(function (arg0) { + const ret = Array.isArray(getObject(arg0)); + _assertBoolean(ret); + return ret; + }, arguments) + }, + + __wbg_length_e: function () { + return logError(function (arg0) { + const ret = getObject(arg0).length; + _assertNum(ret); + return ret; + }, arguments) + }, + + __wbg_instanceof_ArrayBuffer: function () { + return logError(function (arg0) { + let result; + try { + result = getObject(arg0) instanceof ArrayBuffer; + } catch { + result = false; + } + const ret = result; + _assertBoolean(ret); + return ret; + }, arguments) + }, + + __wbg_call_95: function () { + return handleError(function (arg0, arg1) { + const ret = getObject(arg0).call(getObject(arg1)); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_call_94: function () { + return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments); + }, + + __wbg_new_f8: function () { + return logError(function () { + const ret = new Map(); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_set_3: function () { + return logError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).set(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_next_8: function () { + return handleError(function (arg0) { + const ret = getObject(arg0).next(); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_next_b: function () { + return logError(function (arg0) { + const ret = getObject(arg0).next; + return addHeapObject(ret); + }, arguments) + }, + + __wbg_done: function () { + return logError(function (arg0) { + const ret = getObject(arg0).done; + _assertBoolean(ret); + return ret; + }, arguments) + }, + + __wbg_value: function () { + return logError(function (arg0) { + const ret = getObject(arg0).value; + return addHeapObject(ret); + }, arguments) + }, + + __wbg_isSafeInteger: function () { + return logError(function (arg0) { + const ret = Number.isSafeInteger(getObject(arg0)); + _assertBoolean(ret); + return ret; + }, arguments) + }, + + __wbg_entries: function () { + return logError(function (arg0) { + const ret = Object.entries(getObject(arg0)); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_new_f9: function () { + return logError(function () { + const ret = new Object(); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_iterator: function () { + return logError(function () { + const ret = Symbol.iterator; + return addHeapObject(ret); + }, arguments) + }, + + __wbg_new_9: function () { + return logError(function (arg0, arg1) { + try { + var state0 = { a: arg0, b: arg1 }; + var cb0 = (arg0, arg1) => { + const a = state0.a; + state0.a = 0; + try { + return __wbg_adapter_42(a, state0.b, arg0, arg1); + } finally { + state0.a = a; + } + }; + const ret = new Promise(cb0); + return addHeapObject(ret); + } finally { + state0.a = state0.b = 0; + } + }, arguments) + }, + + __wbg_resolve: function () { + return logError(function (arg0) { + const ret = Promise.resolve(getObject(arg0)); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_then_e: function () { + return logError(function (arg0, arg1) { + const ret = getObject(arg0).then(getObject(arg1)); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_then_f: function () { + return logError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).then(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_instanceof_Uint8Array: function () { + return logError(function (arg0) { + let result; + try { + result = getObject(arg0) instanceof Uint8Array; + } catch { + result = false; + } + const ret = result; + _assertBoolean(ret); + return ret; + }, arguments) + }, + + __wbg_new_53: function () { + return logError(function (arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_length_2: function () { + return logError(function (arg0) { + const ret = getObject(arg0).length; + _assertNum(ret); + return ret; + }, arguments) + }, + + __wbg_set_1: function () { + return logError(function (arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); + }, arguments) + }, + + __wbindgen_is_function: function (arg0) { + const ret = typeof (getObject(arg0)) === 'function'; + _assertBoolean(ret); + return ret; + }, + + __wbindgen_is_string: function (arg0) { + const ret = typeof (getObject(arg0)) === 'string'; + _assertBoolean(ret); + return ret; + }, + + __wbg_buffer: function () { + return logError(function (arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }, arguments) + }, + + __wbg_get_b: function () { + return handleError(function (arg0, arg1) { + const ret = Reflect.get(getObject(arg0), getObject(arg1)); + return addHeapObject(ret); + }, arguments) + }, + + __wbindgen_debug_string: function (arg0, arg1) { + const ret = debugString(getObject(arg1)); + const ptr0 = passStringToWasm0( + ret, + wasmInstance.exports.__wbindgen_malloc, + wasmInstance.exports.__wbindgen_realloc + ); + const len0 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len0; + getInt32Memory0()[arg0 / 4 + 0] = ptr0; + }, + + __wbindgen_bigint_get_as_i64: function (arg0, arg1) { + const v = getObject(arg1); + const ret = typeof (v) === 'bigint' ? v : undefined; + if (!isLikeNone(ret)) { + _assertBigInt(ret); + } + getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret; + getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); + }, + + __wbindgen_throw: function (arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }, + + __wbindgen_memory: function () { + const ret = wasmInstance.exports.memory; + return addHeapObject(ret); + }, + + __wbindgen_closure_wrapper: function () { + return logError(function (arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, dtorValue, __wbg_adapter_52); + return addHeapObject(ret); + }, arguments) + }, + + __wbg_randomInt: function (arg0) { + const ret = rawImports.Vrf.randomInt(arg0); + return ret; + } + }; + + const baseImportsKeys = Object.keys(baseImports); + + // assigning functions to "real" import names from the currently + // compiled wasm module + let module: any = wbindgenImports.reduce((acc, wbindgenKey) => { + const baseImportsKey = baseImportsKeys.find((key) => wbindgenKey.startsWith(key)); + if (baseImportsKey === undefined) { + throw new Error(`Cannot find import mapping for ${wbindgenKey}. Please file a bug.`); + } + if (baseImportsKeys.filter((key) => wbindgenKey.startsWith(key)).length != 1) { + throw new Error(`Multiple import mappings for ${wbindgenKey}. Please file a bug.`); + } + if (acc.usedKeys.has(baseImportsKey)) { + throw new Error(`Multiple methods maps to ${baseImportsKey}. Please file a bug.`); + } + acc.res[wbindgenKey] = baseImports[baseImportsKey]; + acc.usedKeys.add(baseImportsKey); + return acc; + }, { res: {}, usedKeys: new Set() }).res; + + module.warpContractWrite = warpContractWrite; + module.initState = initState; + module.currentState = currentState; + module.version = version; + module.lang = lang; + module.warpContractView = warpContractView; + + // the rest of the code is basically left untouched from what + // wasm-bindgen generates + let imports: any = {}; + + imports['__wbindgen_placeholder__'] = module; + /** - */ +*/ class StateWrapper { __destroy_into_raw() { // @ts-ignore const ptr = this.ptr; // @ts-ignore this.ptr = 0; - return ptr; }