diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index e3edc7a1f..3fdd06804 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -890,6 +890,27 @@ std::string WalletImpl::address(uint32_t accountIndex, uint32_t addressIndex) co return m_wallet->get_subaddress_as_str({accountIndex, addressIndex}); } +bool WalletImpl::subaddressIndex(std::string address, std::pair &index) const +{ + clearStatus(); + cryptonote::address_parse_info info; + + if (!cryptonote::get_account_address_from_str(info, m_wallet->nettype(), address)) { + setStatusError(tr("Failed to parse address")); + return false; + } + + auto i = m_wallet->get_subaddress_index(info.address); + if (!i) { + setStatusError(tr("Address doesn't belong to the wallet")); + return false; + } + + index.first = i->major; + index.second = i->minor; + return true; +} + std::string WalletImpl::integratedAddress(const std::string &payment_id) const { crypto::hash8 pid; diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 92cfd1cb4..0c954033d 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -100,6 +100,7 @@ public: bool setDevicePin(const std::string &password) override; bool setDevicePassphrase(const std::string &password) override; std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const override; + bool subaddressIndex(std::string address, std::pair &index) const override; std::string integratedAddress(const std::string &payment_id) const override; std::string secretViewKey() const override; std::string publicViewKey() const override; diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index 5cf8a0cbd..0edeaae0e 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h @@ -556,6 +556,7 @@ struct Wallet virtual bool setDevicePin(const std::string &pin) { (void)pin; return false; }; virtual bool setDevicePassphrase(const std::string &passphrase) { (void)passphrase; return false; }; virtual std::string address(uint32_t accountIndex = 0, uint32_t addressIndex = 0) const = 0; + virtual bool subaddressIndex(std::string address, std::pair &index) const = 0; std::string mainAddress() const { return address(0, 0); } virtual std::string path() const = 0; virtual NetworkType nettype() const = 0;