diff --git a/packages/namada/NamadaConnection.ts b/packages/namada/NamadaConnection.ts index 44656a5afd..236a724bd1 100644 --- a/packages/namada/NamadaConnection.ts +++ b/packages/namada/NamadaConnection.ts @@ -122,12 +122,19 @@ export async function fetchProtocolParameters ( ) { const keys = connection.decode.storage_keys(); const [ - maxBlockDuration, maxGasForBlock, feeUnshieldingGasLimit, gasCostTable, + maxBlockDuration, + maxGasForBlock, + feeUnshieldingGasLimit, + gasCostTable, ] = await Promise.all([ - connection.fetchStorageValueImpl(keys.maxBlockDuration), - connection.fetchStorageValueImpl(keys.maxGasForBlock), - connection.fetchStorageValueImpl(keys.feeUnshieldingGasLimit), - connection.fetchStorageValueImpl(keys.gasCostTable), + connection.fetchStorageValueImpl(keys.maxBlockDuration) + .then(x=>connection.decode.u64(x)), + connection.fetchStorageValueImpl(keys.maxGasForBlock) + .then(x=>connection.decode.u64(x)), + connection.fetchStorageValueImpl(keys.feeUnshieldingGasLimit) + .then(x=>connection.decode.u64(x)), + connection.fetchStorageValueImpl(keys.gasCostTable) + .then(x=>connection.decode.gas_cost_table(x)), ]) return { maxBlockDuration, diff --git a/packages/namada/NamadaDecode.ts b/packages/namada/NamadaDecode.ts index e2eb0d0782..e76cc47776 100644 --- a/packages/namada/NamadaDecode.ts +++ b/packages/namada/NamadaDecode.ts @@ -14,10 +14,12 @@ export async function initDecoder (decoder: string|URL|Uint8Array): Promise addresses (_: Uint8Array): string[] address (_: Uint8Array): string epoch_duration (_: Uint8Array): { minNumOfBlocks: number, minDuration: number } + gas_cost_table (_: Uint8Array): Record gov_parameters (_: Uint8Array): Partial gov_proposal (_: Uint8Array): Partial gov_votes (_: Uint8Array): Partial[] diff --git a/packages/namada/pkg/fadroma_namada.d.ts b/packages/namada/pkg/fadroma_namada.d.ts index e5b77c8dee..9618c5ed69 100644 --- a/packages/namada/pkg/fadroma_namada.d.ts +++ b/packages/namada/pkg/fadroma_namada.d.ts @@ -5,6 +5,11 @@ export class Decode { free(): void; /** +* @param {Uint8Array} source +* @returns {bigint} +*/ + static u64(source: Uint8Array): bigint; +/** * @returns {object} */ static storage_keys(): object; @@ -16,6 +21,11 @@ export class Decode { /** * @param {Uint8Array} source * @returns {object} +*/ + static gas_cost_table(source: Uint8Array): object; +/** +* @param {Uint8Array} source +* @returns {object} */ static tx(source: Uint8Array): object; /** @@ -96,8 +106,10 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl export interface InitOutput { readonly memory: WebAssembly.Memory; readonly __wbg_decode_free: (a: number) => void; + readonly decode_u64: (a: number, b: number) => void; readonly decode_storage_keys: (a: number) => void; readonly decode_epoch_duration: (a: number, b: number) => void; + readonly decode_gas_cost_table: (a: number, b: number) => void; readonly decode_tx: (a: number, b: number) => void; readonly decode_address: (a: number, b: number) => void; readonly decode_addresses: (a: number, b: number) => void; diff --git a/packages/namada/pkg/fadroma_namada.js b/packages/namada/pkg/fadroma_namada.js index 1148da4168..de9ea83bf5 100644 --- a/packages/namada/pkg/fadroma_namada.js +++ b/packages/namada/pkg/fadroma_namada.js @@ -173,6 +173,25 @@ export class Decode { wasm.__wbg_decode_free(ptr); } /** + * @param {Uint8Array} source + * @returns {bigint} + */ + static u64(source) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.decode_u64(retptr, addHeapObject(source)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** * @returns {object} */ static storage_keys() { @@ -213,6 +232,25 @@ export class Decode { * @param {Uint8Array} source * @returns {object} */ + static gas_cost_table(source) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.decode_gas_cost_table(retptr, addHeapObject(source)); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return takeObject(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {Uint8Array} source + * @returns {object} + */ static tx(source) { try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); diff --git a/packages/namada/pkg/fadroma_namada_bg.wasm.d.ts b/packages/namada/pkg/fadroma_namada_bg.wasm.d.ts index 53695443fb..d6bcc2b892 100644 --- a/packages/namada/pkg/fadroma_namada_bg.wasm.d.ts +++ b/packages/namada/pkg/fadroma_namada_bg.wasm.d.ts @@ -2,8 +2,10 @@ /* eslint-disable */ export const memory: WebAssembly.Memory; export function __wbg_decode_free(a: number): void; +export function decode_u64(a: number, b: number): void; export function decode_storage_keys(a: number): void; export function decode_epoch_duration(a: number, b: number): void; +export function decode_gas_cost_table(a: number, b: number): void; export function decode_tx(a: number, b: number): void; export function decode_address(a: number, b: number): void; export function decode_addresses(a: number, b: number): void; diff --git a/packages/namada/src/decode.rs b/packages/namada/src/decode.rs index 373b1f8acb..a0f66fd18c 100644 --- a/packages/namada/src/decode.rs +++ b/packages/namada/src/decode.rs @@ -6,6 +6,13 @@ pub struct Decode; #[wasm_bindgen] impl Decode { + #[wasm_bindgen] + pub fn u64 (source: Uint8Array) -> Result { + let value = u64::try_from_slice(&to_bytes(&source)) + .map_err(|e|Error::new(&format!("{e}")))?; + Ok(BigInt::from(value)) + } + #[wasm_bindgen] pub fn storage_keys () -> Result { Ok(to_object! { @@ -13,6 +20,8 @@ impl Decode { get_epoch_duration_storage_key().to_string(), "maxBlockDuration" = get_max_expected_time_per_block_key().to_string(), + "vpAllowlist" = + get_tx_allowlist_storage_key().to_string(), "maxGasForBlock" = get_max_block_gas_key().to_string(), "feeUnshieldingGasLimit" = @@ -34,6 +43,17 @@ impl Decode { }) } + #[wasm_bindgen] + pub fn gas_cost_table (source: Uint8Array) -> Result { + let data = BTreeMap:: + ::try_from_slice(&to_bytes(&source)).map_err(|e|Error::new(&format!("{e}")))?; + let result = Object::new(); + for (key, val) in data.iter() { + Reflect::set(&result, &format!("{key}").into(), &format!("{val}").into())?; + } + Ok(result) + } + #[wasm_bindgen] pub fn tx (source: Uint8Array) -> Result { let tx = Tx::try_from_slice(&to_bytes(&source)).map_err(|e|Error::new(&format!("{e}")))?; diff --git a/packages/namada/src/lib.rs b/packages/namada/src/lib.rs index dc8b75aa22..b64d4a3bf0 100644 --- a/packages/namada/src/lib.rs +++ b/packages/namada/src/lib.rs @@ -67,6 +67,7 @@ pub(crate) use namada::{ get_max_block_gas_key, get_fee_unshielding_gas_limit_key, get_gas_cost_key, + get_tx_allowlist_storage_key, }, }, storage::KeySeg,