From 0bc38afa9967767cc4d6055c82f172c970d9eebe Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 2 Jul 2019 12:06:36 -0400 Subject: [PATCH] implemented get/set tx notes --- src/wallet/MoneroWallet.cpp | 35 ++++++++++++++++++++ src/wallet/MoneroWallet.h | 64 ++++++++++++++++++------------------- 2 files changed, 67 insertions(+), 32 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 93ba8e0..17e446b 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -1287,6 +1287,41 @@ namespace monero { return txIds; } + string MoneroWallet::getTxNote(const string& txId) const { + cout << "MoneroWallet::getTxNote" << endl; + cryptonote::blobdata txBlob; + if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) { + throw runtime_error("TX ID has invalid format"); + } + crypto::hash txHash = *reinterpret_cast(txBlob.data()); + return wallet2->get_tx_note(txHash); + } + + void MoneroWallet::setTxNote(const string& txId, const string& note) { + cout << "MoneroWallet::setTxNote" << endl; + cryptonote::blobdata txBlob; + if (!epee::string_tools::parse_hexstr_to_binbuff(txId, txBlob) || txBlob.size() != sizeof(crypto::hash)) { + throw runtime_error("TX ID has invalid format"); + } + crypto::hash txHash = *reinterpret_cast(txBlob.data()); + wallet2->set_tx_note(txHash, note); + } + + vector MoneroWallet::getTxNotes(const vector& txIds) const { + cout << "MoneroWallet::getTxNotes()" << endl; + vector txNotes; + for (const auto& txId : txIds) txNotes.push_back(getTxNote(txId)); + return txNotes; + } + + void MoneroWallet::setTxNotes(const vector& txIds, const vector& txNotes) { + cout << "MoneroWallet::setTxNotes()" << endl; + if (txIds.size() != txNotes.size()) throw runtime_error("Different amount of txids and notes"); + for (int i = 0; i < txIds.size(); i++) { + setTxNote(txIds[i], txNotes[i]); + } + } + string MoneroWallet::createPaymentUri(const MoneroSendRequest& request) const { cout << "createPaymentUri()" << endl; diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index 7671466..f6a5324 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -759,38 +759,38 @@ namespace monero { */ vector relayTxs(const vector& txMetadatas); -// /** -// * Get a transaction note. -// * -// * @param txId specifies the transaction to get the note of -// * @return the tx note -// */ -// public string getTxNote(string txId); -// -// /** -// * Set a note for a specific transaction. -// * -// * @param txId specifies the transaction -// * @param note specifies the note -// */ -// public void setTxNote(string txId, string note); -// -// /** -// * Get notes for multiple transactions. -// * -// * @param txIds identify the transactions to get notes for -// * @preturns notes for the transactions -// */ -// public List getTxNotes(Collection txIds); -// -// /** -// * Set notes for multiple transactions. -// * -// * @param txIds specify the transactions to set notes for -// * @param notes are the notes to set for the transactions -// */ -// public void setTxNotes(Collection txIds, Collection notes); -// + /** + * Get a transaction note. + * + * @param txId specifies the transaction to get the note of + * @return the tx note + */ + string getTxNote(const string& txId) const; + + /** + * Set a note for a specific transaction. + * + * @param txId specifies the transaction + * @param note specifies the note + */ + void setTxNote(const string& txId, const string& note); + + /** + * Get notes for multiple transactions. + * + * @param txIds identify the transactions to get notes for + * @preturns notes for the transactions + */ + vector getTxNotes(const vector& txIds) const; + + /** + * Set notes for multiple transactions. + * + * @param txIds specify the transactions to set notes for + * @param notes are the notes to set for the transactions + */ + void setTxNotes(const vector& txIds, const vector& notes); + // /** // * Sign a message. // *