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: eth_mining RPC implementation #1892

Merged
merged 2 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
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);
}