diff --git a/lib/ain-cpp-imports/src/lib.rs b/lib/ain-cpp-imports/src/lib.rs index c7786c7d66..8e57ce8df9 100644 --- a/lib/ain-cpp-imports/src/lib.rs +++ b/lib/ain-cpp-imports/src/lib.rs @@ -8,6 +8,7 @@ mod ffi { fn getChainId() -> u64; fn isMining() -> bool; fn publishEthTransaction(data: Vec) -> bool; + fn getAccounts() -> Vec; } } @@ -25,3 +26,8 @@ pub fn publish_eth_transaction(data: Vec) -> Result> { let publish = ffi::publishEthTransaction(data); Ok(publish) } + +pub fn get_accounts() -> Result, Box> { + let accounts = ffi::getAccounts(); + Ok(accounts) +} diff --git a/lib/ain-grpc/src/rpc.rs b/lib/ain-grpc/src/rpc.rs index e313c51068..816094bb34 100644 --- a/lib/ain-grpc/src/rpc.rs +++ b/lib/ain-grpc/src/rpc.rs @@ -125,8 +125,8 @@ impl EthServiceApi for EthService { } fn Eth_Accounts(_handler: Arc) -> Result { - // Get from wallet - Ok(EthAccountsResult { accounts: vec![] }) + let accounts = ain_cpp_imports::get_accounts().unwrap(); + Ok(EthAccountsResult { accounts }) } fn Eth_GetBalance( diff --git a/src/ffi/ffiexports.cpp b/src/ffi/ffiexports.cpp index 0a2e4f8a32..6333ab0c0e 100644 --- a/src/ffi/ffiexports.cpp +++ b/src/ffi/ffiexports.cpp @@ -1,6 +1,8 @@ #include #include #include +#include + uint64_t getChainId() { return Params().GetConsensus().evmChainId; @@ -48,3 +50,15 @@ bool publishEthTransaction(rust::Vec rawTransaction) { return true; } + +rust::vec getAccounts() { + rust::vec addresses; + std::vector> const wallets = GetWallets(); + for (const std::shared_ptr& wallet : wallets) { + for (auto & it : wallet->mapAddressBook) + if (std::holds_alternative(it.first)) { + addresses.push_back(EncodeDestination(it.first)); + } + } + return addresses; +} diff --git a/src/ffi/ffiexports.h b/src/ffi/ffiexports.h index f5dad89093..5518b7e88b 100644 --- a/src/ffi/ffiexports.h +++ b/src/ffi/ffiexports.h @@ -7,5 +7,6 @@ uint64_t getChainId(); bool isMining(); bool publishEthTransaction(rust::Vec rawTransaction); +rust::vec getAccounts(); #endif // DEFI_EVM_FFI_H