Skip to content

Commit 2693e4d

Browse files
author
Jannis Pohlmann
committed
runtime/wasm: Go directly from Asc to BigInt in host exported functions
1 parent 4ca993b commit 2693e4d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

runtime/wasm/src/module/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use graph::components::ethereum::*;
1313
use graph::data::subgraph::DataSource;
1414
use graph::ethabi::LogParam;
1515
use graph::prelude::*;
16-
use graph::web3::types::{Log, H160, H256, U256};
16+
use graph::web3::types::Log;
1717
use host_exports;
1818
use EventHandlerContext;
1919

@@ -79,8 +79,7 @@ const JSON_TO_F64_FUNC_INDEX: usize = 14;
7979
const JSON_TO_BIG_INT_FUNC_INDEX: usize = 15;
8080
const IPFS_CAT_FUNC_INDEX: usize = 16;
8181
const STORE_GET_FUNC_INDEX: usize = 17;
82-
const TYPE_CONVERSION_BIG_INT_FUNC_TO_INT256_INDEX: usize = 18;
83-
const CRYPTO_KECCAK_256_INDEX: usize = 19;
82+
const CRYPTO_KECCAK_256_INDEX: usize = 18;
8483

8584
pub struct WasmiModuleConfig<T, L, S> {
8685
pub subgraph: SubgraphManifest,
@@ -340,8 +339,7 @@ where
340339

341340
/// function typeConversion.bigIntToHex(n: Uint8Array): string
342341
fn big_int_to_hex(&self, big_int_ptr: AscPtr<AscBigInt>) -> Result<Option<RuntimeValue>, Trap> {
343-
let bytes: Vec<u8> = self.heap.asc_get(big_int_ptr);
344-
let n = BigInt::from_signed_bytes_le(&*bytes);
342+
let n: BigInt = self.heap.asc_get(big_int_ptr);
345343
let result = self.host_exports.big_int_to_hex(n);
346344
Ok(Some(RuntimeValue::from(self.heap.asc_new(&result))))
347345
}
@@ -362,8 +360,7 @@ where
362360

363361
/// function typeConversion.i32ToBigInt(i: i32): Uint64Array
364362
fn big_int_to_i32(&self, n_ptr: AscPtr<AscBigInt>) -> Result<Option<RuntimeValue>, Trap> {
365-
let bytes: Vec<u8> = self.heap.asc_get(n_ptr);
366-
let n = BigInt::from_signed_bytes_le(&*bytes);
363+
let n: BigInt = self.heap.asc_get(n_ptr);
367364
let i = self.host_exports.big_int_to_i32(n)?;
368365
Ok(Some(RuntimeValue::from(i)))
369366
}

0 commit comments

Comments
 (0)