diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index e9be140..c8ee52a 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -208,7 +208,26 @@ namespace monero { return wallet2->get_subaddress_as_str({accountIdx, subaddressIdx}); } - // get address index + MoneroSubaddress MoneroWallet::getAddressIndex(const string& address) const { + cout << "getAddressIndex(" << address << ")" << endl; + + // validate address + cryptonote::address_parse_info info; + if (!get_account_address_from_str(info, wallet2->nettype(), address)) { + throw runtime_error("Invalid address"); + } + + // get index of address in wallet + auto index = wallet2->get_subaddress_index(info.address); + if (!index) throw runtime_error("Address doesn't belong to the wallet"); + + // return indices in subaddress + MoneroSubaddress subaddress; + cryptonote::subaddress_index cnIndex = *index; + subaddress.accountIndex = cnIndex.major; + subaddress.index = cnIndex.minor; + return subaddress; + } string MoneroWallet::getMnemonic() const { epee::wipeable_string wipeablePassword; diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index cb44c77..09a5b52 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -309,14 +309,14 @@ namespace monero { */ string getAddress(const uint32_t accountIdx, const uint32_t subaddressIdx) const; -// /** -// * Get the account and subaddress index of the given address. -// * -// * @param address is the address to get the account and subaddress index from -// * @return the account and subaddress indices -// * @throws exception if address is not a wallet address -// */ -// public MoneroSubaddress getAddressIndex(String address); + /** + * Get the account and subaddress index of the given address. + * + * @param address is the address to get the account and subaddress index from + * @return the account and subaddress indices + * @throws exception if address is not a wallet address + */ + MoneroSubaddress getAddressIndex(const string& address) const; // /** // * Get an integrated address based on this wallet's primary address and the