Skip to content

Commit

Permalink
Fix eth_call output
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Apr 18, 2023
1 parent 53c84f0 commit da17804
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions lib/ain-grpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,10 @@ pub trait MetachainRPC {
) -> Result<EthSendRawTransactionResult, jsonrpsee::core::Error>;

#[method(name = "eth_getTransactionCount")]
fn get_transaction_count(
&self,
input: String
) -> Result<String, jsonrpsee::core::Error>;
fn get_transaction_count(&self, input: String) -> Result<String, jsonrpsee::core::Error>;

#[method(name = "eth_estimateGas")]
fn estimate_gas(
&self
) -> Result<String, jsonrpsee::core::Error>;
fn estimate_gas(&self) -> Result<String, jsonrpsee::core::Error>;
}

pub struct MetachainRPCModule {
Expand All @@ -131,15 +126,17 @@ impl MetachainRPCServer for MetachainRPCModule {

let from = from.map(|addr| addr.parse::<H160>().expect("Wrong `from` address format"));
let to = to.map(|addr| addr.parse::<H160>().expect("Wrong `to` address format"));
let value: U256 = value.map(|addr| addr.parse::<U256>().expect("Wrong `value` address format")).unwrap_or_default();
let value: U256 = value
.map(|addr| addr.parse::<U256>().expect("Wrong `value` address format"))
.unwrap_or_default();
let gas: u64 = gas.unwrap_or_default();

let (_, data) = self
.handler
.evm
.call(from, to, value, data.as_bytes(), gas, vec![]);

Ok(data)
Ok(Hex::encode(data))
}

fn accounts(&self) -> Result<Vec<H160>, jsonrpsee::core::Error> {
Expand Down Expand Up @@ -355,19 +352,14 @@ impl MetachainRPCServer for MetachainRPCModule {
})
}

fn get_transaction_count(
&self,
input: String
) -> Result<String, jsonrpsee::core::Error> {
fn get_transaction_count(&self, input: String) -> Result<String, jsonrpsee::core::Error> {
let input = input.parse().expect("Invalid address");
let nonce = self.handler.evm.get_nonce(input);

Ok(format!("{:#x}", nonce))
}

fn estimate_gas(
&self
) -> Result<String, jsonrpsee::core::Error> {
fn estimate_gas(&self) -> Result<String, jsonrpsee::core::Error> {
Ok(format!("{:#x}", 21000))
}
}

0 comments on commit da17804

Please sign in to comment.