Skip to content

Commit

Permalink
fix(namada): return PGFSteward/PGFPayment ops as Array rather than Set
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Oct 7, 2024
1 parent 56ea540 commit 19681c1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
62 changes: 33 additions & 29 deletions packages/namada/pkg/fadroma_namada.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
let wasm;

const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);

function getObject(idx) { return heap[idx]; }

let heap_next = heap.length;

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];

if (typeof(heap_next) !== 'number') throw new Error('corrupt heap');

heap[idx] = obj;
return idx;
}

const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );

if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
Expand All @@ -37,6 +18,25 @@ function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);

let heap_next = heap.length;

function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];

if (typeof(heap_next) !== 'number') throw new Error('corrupt heap');

heap[idx] = obj;
return idx;
}

function getObject(idx) { return heap[idx]; }

function dropObject(idx) {
if (idx < 132) return;
heap[idx] = heap_next;
Expand Down Expand Up @@ -692,23 +692,19 @@ async function __wbg_load(module, imports) {
function __wbg_get_imports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
const ret = getObject(arg0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
const ret = BigInt.asUintN(64, arg0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
const ret = getObject(arg0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
const ret = arg0;
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
const ret = BigInt.asUintN(64, arg0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_number_new = function(arg0) {
Expand All @@ -719,6 +715,10 @@ function __wbg_get_imports() {
const ret = arg0 << BigInt(64) | BigInt.asUintN(64, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
const ret = arg0;
return addHeapObject(ret);
};
imports.wbg.__wbg_new_a220cf903aa02ca2 = function() { return logError(function () {
const ret = new Array();
return addHeapObject(ret);
Expand All @@ -735,6 +735,10 @@ function __wbg_get_imports() {
const ret = new Set(getObject(arg0));
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_from_0791d740a9d37830 = function() { return logError(function (arg0) {
const ret = Array.from(getObject(arg0));
return addHeapObject(ret);
}, arguments) };
imports.wbg.__wbg_push_37c89022f34c01ca = function() { return logError(function (arg0, arg1) {
const ret = getObject(arg0).push(getObject(arg1));
_assertNum(ret);
Expand Down
4 changes: 2 additions & 2 deletions packages/namada/src/to_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ impl ToJS for ProposalType {
set.add(&op.to_js()?);
}
Reflect::set(&object, &"type".into(), &"PGFSteward".into())?;
Reflect::set(&object, &"ops".into(), &set.into())?;
Reflect::set(&object, &"ops".into(), &Array::from(&set.into()).into())?;
},
Self::PGFPayment(actions) => {
let set = Set::new(&JsValue::UNDEFINED);
for op in actions {
set.add(&op.to_js()?);
}
Reflect::set(&object, &"type".into(), &"PGFPayment".into())?;
Reflect::set(&object, &"ops".into(), &set.into())?;
Reflect::set(&object, &"ops".into(), &Array::from(&set.into()).into())?;
}
};
Ok(object.into())
Expand Down

0 comments on commit 19681c1

Please sign in to comment.