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

Add Eth_Accounts RPC #1916

Merged
merged 2 commits into from
Apr 17, 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
6 changes: 6 additions & 0 deletions lib/ain-cpp-imports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod ffi {
fn getChainId() -> u64;
fn isMining() -> bool;
fn publishEthTransaction(data: Vec<u8>) -> bool;
fn getAccounts() -> Vec<String>;
}
}

Expand All @@ -25,3 +26,8 @@ pub fn publish_eth_transaction(data: Vec<u8>) -> Result<bool, Box<dyn Error>> {
let publish = ffi::publishEthTransaction(data);
Ok(publish)
}

pub fn get_accounts() -> Result<Vec<String>, Box<dyn Error>> {
let accounts = ffi::getAccounts();
Ok(accounts)
}
4 changes: 2 additions & 2 deletions lib/ain-grpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ impl EthServiceApi for EthService {
}

fn Eth_Accounts(_handler: Arc<Handlers>) -> Result<EthAccountsResult, jsonrpsee_core::Error> {
// Get from wallet
Ok(EthAccountsResult { accounts: vec![] })
let accounts = ain_cpp_imports::get_accounts().unwrap();
Ok(EthAccountsResult { accounts })
}

fn Eth_GetBalance(
Expand Down
14 changes: 14 additions & 0 deletions src/ffi/ffiexports.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <ffi/ffiexports.h>
#include <util/system.h>
#include <masternodes/mn_rpc.h>
#include <key_io.h>


uint64_t getChainId() {
return Params().GetConsensus().evmChainId;
Expand Down Expand Up @@ -48,3 +50,15 @@ bool publishEthTransaction(rust::Vec<uint8_t> rawTransaction) {

return true;
}

rust::vec<rust::string> getAccounts() {
rust::vec<rust::string> addresses;
std::vector<std::shared_ptr<CWallet>> const wallets = GetWallets();
for (const std::shared_ptr<CWallet>& wallet : wallets) {
for (auto & it : wallet->mapAddressBook)
if (std::holds_alternative<WitnessV16EthHash>(it.first)) {
addresses.push_back(EncodeDestination(it.first));
}
}
return addresses;
}
1 change: 1 addition & 0 deletions src/ffi/ffiexports.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
uint64_t getChainId();
bool isMining();
bool publishEthTransaction(rust::Vec<uint8_t> rawTransaction);
rust::vec<rust::string> getAccounts();

#endif // DEFI_EVM_FFI_H