Skip to content

Commit

Permalink
evm: eth_mining RPC implementation (#1892)
Browse files Browse the repository at this point in the history
* eth_mining RPC implementation

* Formatting
  • Loading branch information
shohamc1 authored Apr 12, 2023
1 parent 6989295 commit 92629c3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/masternodes/evm_ffi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include <masternodes/evm_ffi.h>
#include <util/system.h>

uint64_t getChainId() {
return Params().GetConsensus().evmChainId;
}

bool isMining() {
return gArgs.GetBoolArg("-gen", false);
}
1 change: 1 addition & 0 deletions src/masternodes/evm_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#include <chainparams.h>

uint64_t getChainId();
bool isMining();

#endif // DEFI_EVM_FFI_H
9 changes: 8 additions & 1 deletion src/rust/crates/ain-evm-cpp-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ mod ffi {
include!("masternodes/evm_ffi.h");

fn getChainId() -> u64;
fn isMining() -> bool;
}
}

pub fn get_chain_id() -> Result<u64, Box<dyn Error>> {
let chain_id = ffi::getChainId();

return Ok(chain_id);
Ok(chain_id)
}

pub fn is_mining() -> Result<bool, Box<dyn Error>> {
let is_mining = ffi::isMining();

Ok(is_mining)
}
10 changes: 9 additions & 1 deletion src/rust/crates/ain-grpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::codegen::rpc::{
ffi::{
EthAccountsResult, EthBlockInfo, EthBlockNumberResult, EthCallInput, EthCallResult,
EthGetBalanceInput, EthGetBalanceResult, EthGetBlockByHashInput, EthGetBlockByNumberInput,
EthTransactionInfo,
EthMiningResult, EthTransactionInfo,
},
EthService,
};
Expand Down Expand Up @@ -41,6 +41,8 @@ pub trait EthServiceApi {
handler: Arc<Handlers>,
input: EthGetBlockByNumberInput,
) -> Result<EthBlockInfo, jsonrpsee_core::Error>;

fn Eth_Mining(handler: Arc<Handlers>) -> Result<EthMiningResult, jsonrpsee_core::Error>;
}

impl EthServiceApi for EthService {
Expand Down Expand Up @@ -185,6 +187,12 @@ impl EthServiceApi for EthService {
.collect::<Vec<String>>(),
})
}

fn Eth_Mining(handler: Arc<Handlers>) -> Result<EthMiningResult, jsonrpsee_core::Error> {
let mining = ain_evm_cpp_ffi::is_mining().unwrap();

Ok(EthMiningResult { is_mining: mining })
}
}

fn format_hash(hash: H256) -> String {
Expand Down
2 changes: 2 additions & 0 deletions src/rust/protobuf/rpc/eth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ service eth {
rpc Eth_BlockNumber(google.protobuf.Empty) returns (types.EthBlockNumberResult);

rpc Eth_GetBlockByNumber(types.EthGetBlockByNumberInput) returns (types.EthBlockInfo);

rpc Eth_Mining(google.protobuf.Empty) returns (types.EthMiningResult);
}

0 comments on commit 92629c3

Please sign in to comment.