Merge pull request #1521

21c5af5a wallet2_api: add an address book payment id lookup API (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2017-01-08 16:42:08 -08:00
commit 6cbfe0f849
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
3 changed files with 25 additions and 0 deletions

View file

@ -103,6 +103,28 @@ bool AddressBookImpl::deleteRow(std::size_t rowId)
return r; return r;
} }
int AddressBookImpl::lookupPaymentID(const std::string &payment_id) const
{
// turn short ones into long ones for comparison
const std::string long_payment_id = payment_id + std::string(64 - payment_id.size(), '0');
int idx = -1;
for (const auto &row: m_rows) {
++idx;
// this does short/short and long/long
if (payment_id == row->getPaymentId())
return idx;
// short/long
if (long_payment_id == row->getPaymentId())
return idx;
// one case left: payment_id was long, row's is short
const std::string long_row_payment_id = row->getPaymentId() + std::string(64 - row->getPaymentId().size(), '0');
if (payment_id == long_row_payment_id)
return idx;
}
return -1;
}
void AddressBookImpl::clearRows() { void AddressBookImpl::clearRows() {
for (auto r : m_rows) { for (auto r : m_rows) {
delete r; delete r;

View file

@ -52,6 +52,8 @@ public:
std::string errorString() const {return m_errorString;} std::string errorString() const {return m_errorString;}
int errorCode() const {return m_errorCode;} int errorCode() const {return m_errorCode;}
int lookupPaymentID(const std::string &payment_id) const;
private: private:
void clearRows(); void clearRows();
void clearStatus(); void clearStatus();

View file

@ -175,6 +175,7 @@ struct AddressBook
virtual void refresh() = 0; virtual void refresh() = 0;
virtual std::string errorString() const = 0; virtual std::string errorString() const = 0;
virtual int errorCode() const = 0; virtual int errorCode() const = 0;
virtual int lookupPaymentID(const std::string &payment_id) const = 0;
}; };
struct WalletListener struct WalletListener