Skip to content

Commit 85c68f5

Browse files
authored
Implement eth_estimateGas JSON RPC endpoint (#4011)
* replace chain-libs version * implement estimate_gas function * fic build * fix clippy * update chain-libs * update
1 parent 523fc5e commit 85c68f5

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jormungandr/src/jrpc/eth_transaction/logic.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,13 @@ pub fn sign_transaction(_tx: Transaction, _context: &Context) -> Result<Bytes, E
128128
Ok(Default::default())
129129
}
130130

131-
pub fn estimate_gas(_tx: Transaction, _context: &Context) -> Result<Number, Error> {
132-
// TODO implement
133-
Ok(0.into())
131+
pub async fn estimate_gas(tx: Transaction, context: &Context) -> Result<Number, Error> {
132+
let blockchain_tip = context.blockchain_tip()?.get_ref().await;
133+
Ok(blockchain_tip
134+
.ledger()
135+
.estimate_evm_transaction(tx.into())
136+
.map_err(Box::new)?
137+
.into())
134138
}
135139

136140
pub fn sign(_address: H160, _message: Bytes, _context: &Context) -> Result<H512, Error> {

jormungandr/src/jrpc/eth_transaction/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub fn eth_transaction_module(context: ContextLock) -> RpcModule<ContextLock> {
8585
let context = context.read().await;
8686
let tx = params.parse()?;
8787
logic::estimate_gas(tx, &context)
88+
.await
8889
.map_err(|err| jsonrpsee_core::Error::Custom(err.to_string()))
8990
})
9091
.unwrap();

jormungandr/src/jrpc/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
context::ContextLock,
1818
intercom::{self, TransactionMsg},
1919
};
20+
use chain_impl_mockchain::ledger::Error as LedgerError;
2021
use futures::channel::mpsc::TrySendError;
2122
use jormungandr_lib::interfaces::FragmentsProcessingSummary;
2223
use jsonrpsee_http_server::{HttpServerBuilder, RpcModule};
@@ -41,6 +42,8 @@ pub enum Error {
4142
AccountLedgerError(#[from] chain_impl_mockchain::account::LedgerError),
4243
#[error(transparent)]
4344
TxMsgSendError(#[from] Box<TrySendError<TransactionMsg>>),
45+
#[error("Can not estimate gas fees transaction, error: {0}")]
46+
EstimationError(#[from] Box<LedgerError>),
4447
#[error("Could not process fragment")]
4548
Fragment(FragmentsProcessingSummary),
4649
#[error("Cound not decode Ethereum transaction bytes, erorr: {0}")]

0 commit comments

Comments
 (0)