Skip to content

Commit

Permalink
chore: add get_block_by_hash & use mapToObj in helios-ts (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaan7 authored Mar 5, 2025
1 parent 50c86d4 commit 3bf38d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
31 changes: 21 additions & 10 deletions helios-ts/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,41 @@ export class HeliosProvider {
return this.#client.send_raw_transaction(req.params[0]);
}
case "eth_getTransactionReceipt": {
return this.#client.get_transaction_receipt(req.params[0]);
}
case "eth_getTransactionByHash": {
return this.#client.get_transaction_by_hash(req.params[0]);
const receipt = await this.#client.get_transaction_receipt(req.params[0]);
return mapToObj(receipt);
}
case "eth_getTransactionByBlockHashAndIndex": {
return this.#client.get_transaction_by_block_hash_and_index(
const tx = await this.#client.get_transaction_by_block_hash_and_index(
req.params[0],
req.params[1]
);
return mapToObj(tx);
}
case "eth_getTransactionByBlockNumberAndIndex": {
return this.#client.get_transaction_by_block_number_and_index(
const tx = await this.#client.get_transaction_by_block_number_and_index(
req.params[0],
req.params[1]
);
return mapToObj(tx);
}
case "eth_getBlockReceipts": {
return this.#client.get_block_receipts(req.params[0]);
const receipts = await this.#client.get_block_receipts(req.params[0]);
return receipts.map(mapToObj);
}
case "eth_getLogs": {
return this.#client.get_logs(req.params[0]);
const logs = await this.#client.get_logs(req.params[0]);
return logs.map(mapToObj);
}
case "eth_getFilterChanges": {
return this.#client.get_filter_changes(req.params[0]);
const changes = await this.#client.get_filter_changes(req.params[0]);
if (changes.length > 0 && typeof changes[0] === "object") {
return changes.map(mapToObj);
}
return changes;
}
case "eth_getFilterLogs": {
return this.#client.get_filter_logs(req.params[0]);
const logs = await this.#client.get_filter_logs(req.params[0]);
return logs.map(mapToObj);
}
case "eth_uninstallFilter": {
return this.#client.uninstall_filter(req.params[0]);
Expand All @@ -150,6 +157,10 @@ export class HeliosProvider {
const block = await this.#client.get_block_by_number(req.params[0], req.params[1]);
return mapToObj(block);
}
case "eth_getBlockByHash": {
const block = await this.#client.get_block_by_hash(req.params[0], req.params[1]);
return mapToObj(block);
}
case "web3_clientVersion": {
return this.#client.client_version();
}
Expand Down
7 changes: 7 additions & 0 deletions helios-ts/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ impl EthereumClient {
Ok(serde_wasm_bindgen::to_value(&block)?)
}

#[wasm_bindgen]
pub async fn get_block_by_hash(&self, hash: String, full_tx: bool) -> Result<JsValue, JsError> {
let hash = B256::from_str(&hash)?;
let block = map_err(self.inner.get_block_by_hash(hash, full_tx).await)?;
Ok(serde_wasm_bindgen::to_value(&block)?)
}

#[wasm_bindgen]
pub async fn get_code(&self, addr: JsValue, block: JsValue) -> Result<String, JsError> {
let addr: Address = serde_wasm_bindgen::from_value(addr)?;
Expand Down
7 changes: 7 additions & 0 deletions helios-ts/src/opstack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ impl OpStackClient {
Ok(serde_wasm_bindgen::to_value(&block)?)
}

#[wasm_bindgen]
pub async fn get_block_by_hash(&self, hash: String, full_tx: bool) -> Result<JsValue, JsError> {
let hash = B256::from_str(&hash)?;
let block = map_err(self.inner.get_block_by_hash(hash, full_tx).await)?;
Ok(serde_wasm_bindgen::to_value(&block)?)
}

#[wasm_bindgen]
pub async fn get_code(&self, addr: JsValue, block: JsValue) -> Result<String, JsError> {
let addr: Address = serde_wasm_bindgen::from_value(addr)?;
Expand Down

0 comments on commit 3bf38d4

Please sign in to comment.