Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm: chainId RPC implementation #1891

Merged
merged 8 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/rust/crates/ain-grpc/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use crate::codegen::rpc::{
ffi::{
EthAccountsResult, EthBlockInfo, EthBlockNumberResult, EthCallInput, EthCallResult,
EthGetBalanceInput, EthGetBalanceResult, EthGetBlockByHashInput, EthGetBlockByNumberInput,
EthMiningResult, EthTransactionInfo,
EthChainIdResult, EthGetBalanceInput, EthGetBalanceResult, EthGetBlockByHashInput,
EthGetBlockByNumberInput, EthMiningResult, EthTransactionInfo,
},
EthService,
};
use ain_evm::handler::Handlers;
use ain_evm_cpp_ffi::get_chain_id;
use primitive_types::{H256, U256};
use prost::Message;
use std::hash::Hash;
use std::mem::size_of_val;
use std::str::FromStr;
use std::sync::Arc;

pub trait EthServiceApi {
Expand All @@ -33,6 +31,10 @@ pub trait EthServiceApi {
input: EthGetBlockByHashInput,
) -> Result<EthBlockInfo, jsonrpsee_core::Error>;

fn Eth_ChainId(_handler: Arc<Handlers>) -> Result<EthChainIdResult, jsonrpsee_core::Error>;

fn Net_Version(_handler: Arc<Handlers>) -> Result<EthChainIdResult, jsonrpsee_core::Error>;

fn Eth_BlockNumber(
handler: Arc<Handlers>,
) -> Result<EthBlockNumberResult, jsonrpsee_core::Error>;
Expand Down Expand Up @@ -138,6 +140,22 @@ impl EthServiceApi for EthService {
})
}

fn Eth_ChainId(_handler: Arc<Handlers>) -> Result<EthChainIdResult, jsonrpsee_core::Error> {
let chain_id = get_chain_id().unwrap();

Ok(EthChainIdResult {
id: format!("{:#x}", chain_id),
})
}

fn Net_Version(_handler: Arc<Handlers>) -> Result<EthChainIdResult, jsonrpsee_core::Error> {
let chain_id = get_chain_id().unwrap();

Ok(EthChainIdResult {
id: format!("{}", chain_id),
})
}

fn Eth_BlockNumber(
handler: Arc<Handlers>,
) -> Result<EthBlockNumberResult, jsonrpsee_core::Error> {
Expand Down
4 changes: 4 additions & 0 deletions src/rust/protobuf/rpc/eth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ service eth {
/// Returns the balance for the given address.
rpc Eth_SendTransaction(types.EthSendTransactionInput) returns (types.EthSendTransactionResult);

rpc Eth_ChainId(google.protobuf.Empty) returns (types.EthChainIdResult);

rpc Net_Version(google.protobuf.Empty) returns (types.EthChainIdResult);

rpc Eth_BlockNumber(google.protobuf.Empty) returns (types.EthBlockNumberResult);

rpc Eth_GetBlockByNumber(types.EthGetBlockByNumberInput) returns (types.EthBlockInfo);
Expand Down
4 changes: 4 additions & 0 deletions src/rust/protobuf/types/eth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ message EthTransactionInfo {
optional uint64 nonce = 7; // The integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
}

message EthChainIdResult {
string id = 1;
}

message EthBlockInfo {
string blockNumber = 1; // The block number. null when its pending block.
string hash = 2; // Hash of the block. null when its pending block.
Expand Down