aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/api/address_book.cpp54
-rw-r--r--src/wallet/api/wallet.cpp73
-rw-r--r--src/wallet/api/wallet.h5
-rw-r--r--src/wallet/wallet2_api.h20
4 files changed, 133 insertions, 19 deletions
diff --git a/src/wallet/api/address_book.cpp b/src/wallet/api/address_book.cpp
index b878491ce..e397dac04 100644
--- a/src/wallet/api/address_book.cpp
+++ b/src/wallet/api/address_book.cpp
@@ -33,6 +33,7 @@
#include "wallet.h"
#include "crypto/hash.h"
#include "wallet/wallet2.h"
+#include "common_defines.h"
#include <vector>
@@ -43,30 +44,50 @@ AddressBook::~AddressBook() {}
AddressBookImpl::AddressBookImpl(WalletImpl *wallet)
: m_wallet(wallet) {}
-bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &payment_id, const std::string &description)
+bool AddressBookImpl::addRow(const std::string &dst_addr , const std::string &payment_id_str, const std::string &description)
{
- LOG_PRINT_L2("Adding row");
-
clearStatus();
cryptonote::account_public_address addr;
- bool has_payment_id;
+ bool has_short_pid;
crypto::hash8 payment_id_short;
- if(!cryptonote::get_account_integrated_address_from_str(addr, has_payment_id, payment_id_short, m_wallet->m_wallet->testnet(), dst_addr)) {
- m_errorString = "Invalid destination address";
+ if(!cryptonote::get_account_integrated_address_from_str(addr, has_short_pid, payment_id_short, m_wallet->m_wallet->testnet(), dst_addr)) {
+ m_errorString = tr("Invalid destination address");
m_errorCode = Invalid_Address;
return false;
}
- crypto::hash pid32 = cryptonote::null_hash;
- bool long_pid = (payment_id.empty())? false : tools::wallet2::parse_long_payment_id(payment_id, pid32);
- if(!payment_id.empty() && !long_pid) {
- m_errorString = "Invalid payment ID";
+ crypto::hash payment_id = cryptonote::null_hash;
+ bool has_long_pid = (payment_id_str.empty())? false : tools::wallet2::parse_long_payment_id(payment_id_str, payment_id);
+
+ // Short payment id provided
+ if(payment_id_str.length() == 16) {
+ m_errorString = tr("Invalid payment ID. Short payment ID should only be used in an integrated address");
+ m_errorCode = Invalid_Payment_Id;
+ return false;
+ }
+
+ // long payment id provided but not valid
+ if(!payment_id_str.empty() && !has_long_pid) {
+ m_errorString = tr("Invalid payment ID");
+ m_errorCode = Invalid_Payment_Id;
+ return false;
+ }
+
+ // integrated + long payment id provided
+ if(has_long_pid && has_short_pid) {
+ m_errorString = tr("Integrated address and long payment id can't be used at the same time");
m_errorCode = Invalid_Payment_Id;
return false;
}
- bool r = m_wallet->m_wallet->add_address_book_row(addr,pid32,description);
+ // Pad short pid with zeros
+ if (has_short_pid)
+ {
+ memcpy(payment_id.data, payment_id_short.data, 8);
+ }
+
+ bool r = m_wallet->m_wallet->add_address_book_row(addr,payment_id,description);
if (r)
refresh();
else
@@ -87,7 +108,16 @@ void AddressBookImpl::refresh()
std::string payment_id = (row->m_payment_id == cryptonote::null_hash)? "" : epee::string_tools::pod_to_hex(row->m_payment_id);
std::string address = cryptonote::get_account_address_as_str(m_wallet->m_wallet->testnet(),row->m_address);
-
+ // convert the zero padded short payment id to integrated address
+ if (payment_id.length() > 16 && payment_id.substr(16).find_first_not_of('0') == std::string::npos) {
+ payment_id = payment_id.substr(0,16);
+ crypto::hash8 payment_id_short;
+ if(tools::wallet2::parse_short_payment_id(payment_id, payment_id_short)) {
+ address = cryptonote::get_account_integrated_address_as_str(m_wallet->m_wallet->testnet(), row->m_address, payment_id_short);
+ // Don't show payment id when integrated address is used
+ payment_id = "";
+ }
+ }
AddressBookRow * abr = new AddressBookRow(i, address, payment_id, row->m_description);
m_rows.push_back(abr);
}
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index e8ae7c642..353737d6b 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -83,7 +83,7 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
virtual void on_new_block(uint64_t height, const cryptonote::block& block)
{
- LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
+ //LOG_PRINT_L3(__FUNCTION__ << ": new block. height: " << height);
if (m_listener) {
m_listener->newBlock(height);
@@ -662,25 +662,68 @@ UnsignedTransaction *WalletImpl::loadUnsignedTx(const std::string &unsigned_file
bool WalletImpl::submitTransaction(const string &fileName) {
clearStatus();
- PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
+ std::unique_ptr<PendingTransactionImpl> transaction(new PendingTransactionImpl(*this));
-// bool r = m_wallet->load_tx(fileName, transaction->m_pending_tx, [&](const tools::wallet2::signed_tx_set &tx){ return accept_loaded_tx(tx); });
bool r = m_wallet->load_tx(fileName, transaction->m_pending_tx);
if (!r) {
m_errorString = tr("Failed to load transaction from file");
m_status = Status_Ok;
- delete transaction;
return false;
}
if(!transaction->commit()) {
m_errorString = transaction->m_errorString;
m_status = Status_Error;
- delete transaction;
return false;
}
- delete transaction;
+ return true;
+}
+
+bool WalletImpl::exportKeyImages(const string &filename)
+{
+ if (m_wallet->watch_only())
+ {
+ m_errorString = tr("Wallet is view only");
+ m_status = Status_Error;
+ return false;
+ }
+
+ try
+ {
+ if (!m_wallet->export_key_images(filename))
+ {
+ m_errorString = tr("failed to save file ") + filename;
+ m_status = Status_Error;
+ return false;
+ }
+ }
+ catch (std::exception &e)
+ {
+ LOG_ERROR("Error exporting key images: " << e.what());
+ m_errorString = e.what();
+ m_status = Status_Error;
+ return false;
+ }
+ return true;
+}
+
+bool WalletImpl::importKeyImages(const string &filename)
+{
+ try
+ {
+ uint64_t spent = 0, unspent = 0;
+ uint64_t height = m_wallet->import_key_images(filename, spent, unspent);
+ LOG_PRINT_L2("Signed key images imported to height " << height << ", "
+ << print_money(spent) << " spent, " << print_money(unspent) << " unspent");
+ }
+ catch (const std::exception &e)
+ {
+ LOG_ERROR("Error exporting key images: " << e.what());
+ m_errorString = string(tr("Failed to import key images: ")) + e.what();
+ m_status = Status_Error;
+ return false;
+ }
return true;
}
@@ -1217,6 +1260,24 @@ bool WalletImpl::parse_uri(const std::string &uri, std::string &address, std::st
return m_wallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
}
+bool WalletImpl::rescanSpent()
+{
+ clearStatus();
+ if (!trustedDaemon()) {
+ m_status = Status_Error;
+ m_errorString = tr("Rescan spent can only be used with a trusted daemon");
+ return false;
+ }
+ try {
+ m_wallet->rescan_spent();
+ } catch (const std::exception &e) {
+ LOG_ERROR(__FUNCTION__ << " error: " << e.what());
+ m_status = Status_Error;
+ m_errorString = e.what();
+ return false;
+ }
+ return true;
+}
} // namespace
namespace Bitmonero = Monero;
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 5b4064e8e..e26f30d70 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -93,7 +93,7 @@ public:
void setRefreshFromBlockHeight(uint64_t refresh_from_block_height);
void setRecoveringFromSeed(bool recoveringFromSeed);
bool watchOnly() const;
-
+ bool rescanSpent();
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
@@ -102,6 +102,8 @@ public:
virtual PendingTransaction * createSweepUnmixableTransaction();
bool submitTransaction(const std::string &fileName);
virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename);
+ bool exportKeyImages(const std::string &filename);
+ bool importKeyImages(const std::string &filename);
virtual void disposeTransaction(PendingTransaction * t);
virtual TransactionHistory * history() const;
@@ -127,6 +129,7 @@ private:
bool isNewWallet() const;
void doInit(const std::string &daemon_address, uint64_t upper_transaction_size_limit);
+
private:
friend class PendingTransactionImpl;
friend class UnsignedTransactionImpl;
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index daffb48bf..5a13205c5 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -513,6 +513,21 @@ struct Wallet
*/
virtual void disposeTransaction(PendingTransaction * t) = 0;
+ /*!
+ * \brief exportKeyImages - exports key images to file
+ * \param filename
+ * \return - true on success
+ */
+ virtual bool exportKeyImages(const std::string &filename) = 0;
+
+ /*!
+ * \brief importKeyImages - imports key images from file
+ * \param filename
+ * \return - true on success
+ */
+ virtual bool importKeyImages(const std::string &filename) = 0;
+
+
virtual TransactionHistory * history() const = 0;
virtual AddressBook * addressBook() const = 0;
virtual void setListener(WalletListener *) = 0;
@@ -558,6 +573,11 @@ struct Wallet
virtual bool verifySignedMessage(const std::string &message, const std::string &addres, const std::string &signature) const = 0;
virtual bool parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error) = 0;
+ /*
+ * \brief rescanSpent - Rescan spent outputs - Can only be used with trusted daemon
+ * \return true on success
+ */
+ virtual bool rescanSpent() = 0;
};
/**