aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-01-01 16:06:34 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-01-01 16:06:34 +0000
commit21c5af5a8a20a58cb913ac0a417ba3d508b2ef91 (patch)
tree9d6e7592aa2346f30547ba5ad938d37f3a7de65e /src
parentMerge pull request #1487 (diff)
downloadmonero-21c5af5a8a20a58cb913ac0a417ba3d508b2ef91.tar.xz
wallet2_api: add an address book payment id lookup API
Diffstat (limited to 'src')
-rw-r--r--src/wallet/api/address_book.cpp22
-rw-r--r--src/wallet/api/address_book.h2
-rw-r--r--src/wallet/wallet2_api.h1
3 files changed, 25 insertions, 0 deletions
diff --git a/src/wallet/api/address_book.cpp b/src/wallet/api/address_book.cpp
index bbf96c81a..b878491ce 100644
--- a/src/wallet/api/address_book.cpp
+++ b/src/wallet/api/address_book.cpp
@@ -103,6 +103,28 @@ bool AddressBookImpl::deleteRow(std::size_t rowId)
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() {
for (auto r : m_rows) {
delete r;
diff --git a/src/wallet/api/address_book.h b/src/wallet/api/address_book.h
index 7f30e4387..33d06a078 100644
--- a/src/wallet/api/address_book.h
+++ b/src/wallet/api/address_book.h
@@ -51,6 +51,8 @@ public:
// Error codes. See AddressBook:ErrorCode enum in wallet2_api.h
std::string errorString() const {return m_errorString;}
int errorCode() const {return m_errorCode;}
+
+ int lookupPaymentID(const std::string &payment_id) const;
private:
void clearRows();
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index 2e1d95b58..10590d357 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -175,6 +175,7 @@ struct AddressBook
virtual void refresh() = 0;
virtual std::string errorString() const = 0;
virtual int errorCode() const = 0;
+ virtual int lookupPaymentID(const std::string &payment_id) const = 0;
};
struct WalletListener