Skip to content

Commit ec4d35d

Browse files
fix: optional block id in estimate gas, hex output (#781)
1 parent 4a32ac1 commit ec4d35d

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

core/src/client/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub trait HeliosApi<N: NetworkSpec>: Send + Sync + 'static {
6565
async fn estimate_gas(
6666
&self,
6767
tx: &N::TransactionRequest,
68-
block_id: BlockId,
68+
block_id: Option<BlockId>,
6969
state_overrides: Option<StateOverride>,
7070
) -> Result<u64>;
7171
async fn create_access_list(

core/src/client/node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ impl<N: NetworkSpec, C: Consensus<N::BlockResponse>, E: ExecutionProvider<N>> He
215215
async fn estimate_gas(
216216
&self,
217217
tx: &N::TransactionRequest,
218-
block_id: BlockId,
218+
block_id: Option<BlockId>,
219219
state_overrides: Option<StateOverride>,
220220
) -> Result<u64> {
221+
let block_id = block_id.unwrap_or(BlockId::latest());
221222
self.check_blocktag_age(&block_id).await?;
222223

223224
let (result, ..) = N::transact(

core/src/jsonrpc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ trait EthRpc<
9797
async fn estimate_gas(
9898
&self,
9999
tx: TXR,
100-
block: BlockId,
100+
block: Option<BlockId>,
101101
state_overrides: Option<StateOverride>,
102102
) -> Result<U64, ErrorObjectOwned>;
103103
#[method(name = "createAccessList")]
@@ -268,7 +268,7 @@ impl<N: NetworkSpec>
268268
async fn estimate_gas(
269269
&self,
270270
tx: N::TransactionRequest,
271-
block: BlockId,
271+
block: Option<BlockId>,
272272
state_overrides: Option<StateOverride>,
273273
) -> Result<U64, ErrorObjectOwned> {
274274
let res = self

helios-ts/src/ethereum.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,13 @@ impl EthereumClient {
343343
opts: JsValue,
344344
block: JsValue,
345345
state_overrides: JsValue,
346-
) -> Result<u32, JsError> {
346+
) -> Result<String, JsError> {
347347
let opts: TransactionRequest = serde_wasm_bindgen::from_value(opts)?;
348-
let block: BlockId = serde_wasm_bindgen::from_value(block)?;
348+
let block: Option<BlockId> = serde_wasm_bindgen::from_value(block)?;
349349
let state_overrides: Option<StateOverride> =
350350
serde_wasm_bindgen::from_value(state_overrides)?;
351-
Ok(map_err(self.inner.estimate_gas(&opts, block, state_overrides).await)? as u32)
351+
let gas = map_err(self.inner.estimate_gas(&opts, block, state_overrides).await)?;
352+
Ok(format!("0x{gas:x}"))
352353
}
353354

354355
#[wasm_bindgen]

helios-ts/src/linea.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,13 @@ impl LineaClient {
265265
opts: JsValue,
266266
block: JsValue,
267267
state_overrides: JsValue,
268-
) -> Result<u32, JsError> {
268+
) -> Result<String, JsError> {
269269
let opts: TransactionRequest = serde_wasm_bindgen::from_value(opts)?;
270-
let block: BlockId = serde_wasm_bindgen::from_value(block)?;
270+
let block: Option<BlockId> = serde_wasm_bindgen::from_value(block)?;
271271
let state_overrides: Option<StateOverride> =
272272
serde_wasm_bindgen::from_value(state_overrides)?;
273-
Ok(map_err(self.inner.estimate_gas(&opts, block, state_overrides).await)? as u32)
273+
let gas = map_err(self.inner.estimate_gas(&opts, block, state_overrides).await)?;
274+
Ok(format!("0x{gas:x}"))
274275
}
275276

276277
#[wasm_bindgen]

helios-ts/src/opstack.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,13 @@ impl OpStackClient {
283283
opts: JsValue,
284284
block: JsValue,
285285
state_overrides: JsValue,
286-
) -> Result<u32, JsError> {
286+
) -> Result<String, JsError> {
287287
let opts: OpTransactionRequest = serde_wasm_bindgen::from_value(opts)?;
288-
let block: BlockId = serde_wasm_bindgen::from_value(block)?;
288+
let block: Option<BlockId> = serde_wasm_bindgen::from_value(block)?;
289289
let state_overrides: Option<StateOverride> =
290290
serde_wasm_bindgen::from_value(state_overrides)?;
291-
Ok(map_err(self.inner.estimate_gas(&opts, block, state_overrides).await)? as u32)
291+
let gas = map_err(self.inner.estimate_gas(&opts, block, state_overrides).await)?;
292+
Ok(format!("0x{gas:x}"))
292293
}
293294

294295
#[wasm_bindgen]

0 commit comments

Comments
 (0)