aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crypto/crypto.h2
-rw-r--r--src/wallet/api/pending_transaction.cpp9
-rw-r--r--src/wallet/api/pending_transaction.h1
-rw-r--r--src/wallet/api/wallet.cpp109
-rw-r--r--src/wallet/api/wallet.h4
-rw-r--r--src/wallet/wallet2.cpp42
-rw-r--r--src/wallet/wallet2.h24
-rw-r--r--src/wallet/wallet2_api.h28
8 files changed, 196 insertions, 23 deletions
diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h
index b396fc7db..9ca835d9e 100644
--- a/src/crypto/crypto.h
+++ b/src/crypto/crypto.h
@@ -236,6 +236,6 @@ namespace crypto {
}
}
-CRYPTO_MAKE_COMPARABLE(public_key)
+CRYPTO_MAKE_HASHABLE(public_key)
CRYPTO_MAKE_HASHABLE(key_image)
CRYPTO_MAKE_COMPARABLE(signature)
diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp
index 80fb0b9a4..2521decea 100644
--- a/src/wallet/api/pending_transaction.cpp
+++ b/src/wallet/api/pending_transaction.cpp
@@ -80,8 +80,8 @@ std::vector<std::string> PendingTransactionImpl::txid() const
bool PendingTransactionImpl::commit()
{
- LOG_PRINT_L0("m_pending_tx size: " << m_pending_tx.size());
- assert(m_pending_tx.size() == 1);
+ LOG_PRINT_L3("m_pending_tx size: " << m_pending_tx.size());
+
try {
while (!m_pending_tx.empty()) {
auto & ptx = m_pending_tx.back();
@@ -142,5 +142,10 @@ uint64_t PendingTransactionImpl::fee() const
return result;
}
+uint64_t PendingTransactionImpl::txCount() const
+{
+ return m_pending_tx.size();
+}
+
}
diff --git a/src/wallet/api/pending_transaction.h b/src/wallet/api/pending_transaction.h
index 2f06d2f6e..c5e847c97 100644
--- a/src/wallet/api/pending_transaction.h
+++ b/src/wallet/api/pending_transaction.h
@@ -50,6 +50,7 @@ public:
uint64_t dust() const;
uint64_t fee() const;
std::vector<std::string> txid() const;
+ uint64_t txCount() const;
// TODO: continue with interface;
private:
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 3768a7998..6c1c1fea2 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -685,6 +685,98 @@ PendingTransaction *WalletImpl::createTransaction(const string &dst_addr, const
return transaction;
}
+PendingTransaction *WalletImpl::createSweepUnmixableTransaction()
+
+{
+ clearStatus();
+ vector<cryptonote::tx_destination_entry> dsts;
+ cryptonote::tx_destination_entry de;
+
+ PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
+
+ do {
+ try {
+ transaction->m_pending_tx = m_wallet->create_unmixable_sweep_transactions(m_trustedDaemon);
+
+ } catch (const tools::error::daemon_busy&) {
+ // TODO: make it translatable with "tr"?
+ m_errorString = tr("daemon is busy. Please try again later.");
+ m_status = Status_Error;
+ } catch (const tools::error::no_connection_to_daemon&) {
+ m_errorString = tr("no connection to daemon. Please make sure daemon is running.");
+ m_status = Status_Error;
+ } catch (const tools::error::wallet_rpc_error& e) {
+ m_errorString = tr("RPC error: ") + e.to_string();
+ m_status = Status_Error;
+ } catch (const tools::error::get_random_outs_error&) {
+ m_errorString = tr("failed to get random outputs to mix");
+ m_status = Status_Error;
+
+ } catch (const tools::error::not_enough_money& e) {
+ m_status = Status_Error;
+ std::ostringstream writer;
+
+ writer << boost::format(tr("not enough money to transfer, available only %s, sent amount %s")) %
+ print_money(e.available()) %
+ print_money(e.tx_amount());
+ m_errorString = writer.str();
+
+ } catch (const tools::error::tx_not_possible& e) {
+ m_status = Status_Error;
+ std::ostringstream writer;
+
+ writer << boost::format(tr("not enough money to transfer, available only %s, transaction amount %s = %s + %s (fee)")) %
+ print_money(e.available()) %
+ print_money(e.tx_amount() + e.fee()) %
+ print_money(e.tx_amount()) %
+ print_money(e.fee());
+ m_errorString = writer.str();
+
+ } catch (const tools::error::not_enough_outs_to_mix& e) {
+ std::ostringstream writer;
+ writer << tr("not enough outputs for specified mixin_count") << " = " << e.mixin_count() << ":";
+ for (const std::pair<uint64_t, uint64_t> outs_for_amount : e.scanty_outs()) {
+ writer << "\n" << tr("output amount") << " = " << print_money(outs_for_amount.first) << ", " << tr("found outputs to mix") << " = " << outs_for_amount.second;
+ }
+ m_errorString = writer.str();
+ m_status = Status_Error;
+ } catch (const tools::error::tx_not_constructed&) {
+ m_errorString = tr("transaction was not constructed");
+ m_status = Status_Error;
+ } catch (const tools::error::tx_rejected& e) {
+ std::ostringstream writer;
+ writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
+ m_errorString = writer.str();
+ m_status = Status_Error;
+ } catch (const tools::error::tx_sum_overflow& e) {
+ m_errorString = e.what();
+ m_status = Status_Error;
+ } catch (const tools::error::zero_destination&) {
+ m_errorString = tr("one of destinations is zero");
+ m_status = Status_Error;
+ } catch (const tools::error::tx_too_big& e) {
+ m_errorString = tr("failed to find a suitable way to split transactions");
+ m_status = Status_Error;
+ } catch (const tools::error::transfer_error& e) {
+ m_errorString = string(tr("unknown transfer error: ")) + e.what();
+ m_status = Status_Error;
+ } catch (const tools::error::wallet_internal_error& e) {
+ m_errorString = string(tr("internal error: ")) + e.what();
+ m_status = Status_Error;
+ } catch (const std::exception& e) {
+ m_errorString = string(tr("unexpected error: ")) + e.what();
+ m_status = Status_Error;
+ } catch (...) {
+ m_errorString = tr("unknown error");
+ m_status = Status_Error;
+ }
+ } while (false);
+
+ transaction->m_status = m_status;
+ transaction->m_errorString = m_errorString;
+ return transaction;
+}
+
void WalletImpl::disposeTransaction(PendingTransaction *t)
{
delete t;
@@ -752,6 +844,23 @@ std::string WalletImpl::getTxKey(const std::string &txid) const
}
}
+std::string WalletImpl::signMessage(const std::string &message)
+{
+ return m_wallet->sign(message);
+}
+
+bool WalletImpl::verifySignedMessage(const std::string &message, const std::string &address, const std::string &signature) const
+{
+ cryptonote::account_public_address addr;
+ bool has_payment_id;
+ crypto::hash8 payment_id;
+
+ if (!cryptonote::get_account_integrated_address_from_str(addr, has_payment_id, payment_id, m_wallet->testnet(), address))
+ return false;
+
+ return m_wallet->verify(message, addr, signature);
+}
+
bool WalletImpl::connectToDaemon()
{
bool result = m_wallet->check_connection();
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 3f6d2ac7b..f40551fac 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -91,6 +91,7 @@ public:
PendingTransaction * createTransaction(const std::string &dst_addr, const std::string &payment_id,
uint64_t amount, uint32_t mixin_count,
PendingTransaction::Priority priority = PendingTransaction::Priority_Low);
+ virtual PendingTransaction * createSweepUnmixableTransaction();
virtual void disposeTransaction(PendingTransaction * t);
virtual TransactionHistory * history() const;
@@ -101,6 +102,9 @@ public:
virtual std::string getUserNote(const std::string &txid) const;
virtual std::string getTxKey(const std::string &txid) const;
+ virtual std::string signMessage(const std::string &message);
+ virtual bool verifySignedMessage(const std::string &message, const std::string &address, const std::string &signature) const;
+
private:
void clearStatus();
void refreshThreadFunc();
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 08c5c010d..ac8802ca4 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -252,8 +252,6 @@ bool wallet2::wallet_generate_key_image_helper(const cryptonote::account_keys& a
{
if (!cryptonote::generate_key_image_helper(ack, tx_public_key, real_output_index, in_ephemeral, ki))
return false;
- if (m_watch_only)
- memset(&ki, 0, 32);
return true;
}
//----------------------------------------------------------------------------------------------------
@@ -483,12 +481,12 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
THROW_WALLET_EXCEPTION_IF(tx.vout.size() <= o, error::wallet_internal_error, "wrong out in transaction: internal index=" +
std::to_string(o) + ", total_outs=" + std::to_string(tx.vout.size()));
- auto kit = m_key_images.find(ki[o]);
- THROW_WALLET_EXCEPTION_IF(kit != m_key_images.end() && kit->second >= m_transfers.size(),
- error::wallet_internal_error, std::string("Unexpected transfer index from key image: ")
- + "got " + (kit == m_key_images.end() ? "<none>" : boost::lexical_cast<std::string>(kit->second))
+ auto kit = m_pub_keys.find(in_ephemeral[o].pub);
+ THROW_WALLET_EXCEPTION_IF(kit != m_pub_keys.end() && kit->second >= m_transfers.size(),
+ error::wallet_internal_error, std::string("Unexpected transfer index from public key: ")
+ + "got " + (kit == m_pub_keys.end() ? "<none>" : boost::lexical_cast<std::string>(kit->second))
+ ", m_transfers.size() is " + boost::lexical_cast<std::string>(m_transfers.size()));
- if (kit == m_key_images.end())
+ if (kit == m_pub_keys.end())
{
if (!pool)
{
@@ -500,6 +498,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
td.m_tx = (const cryptonote::transaction_prefix&)tx;
td.m_txid = txid();
td.m_key_image = ki[o];
+ td.m_key_image_known = !m_watch_only;
td.m_amount = tx.vout[o].amount;
if (td.m_amount == 0)
{
@@ -519,6 +518,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
}
set_unspent(m_transfers.size()-1);
m_key_images[td.m_key_image] = m_transfers.size()-1;
+ m_pub_keys[in_ephemeral[o].pub] = m_transfers.size()-1;
LOG_PRINT_L0("Received money: " << print_money(td.amount()) << ", with tx: " << txid());
if (0 != m_callback)
m_callback->on_money_received(height, tx, td.m_amount);
@@ -526,14 +526,14 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
}
else if (m_transfers[kit->second].m_spent || m_transfers[kit->second].amount() >= tx.vout[o].amount)
{
- LOG_ERROR("key image " << epee::string_tools::pod_to_hex(kit->first)
+ LOG_ERROR("Public key " << epee::string_tools::pod_to_hex(kit->first)
<< " from received " << print_money(tx.vout[o].amount) << " output already exists with "
<< (m_transfers[kit->second].m_spent ? "spent" : "unspent") << " "
<< print_money(m_transfers[kit->second].amount()) << ", received output ignored");
}
else
{
- LOG_ERROR("key image " << epee::string_tools::pod_to_hex(kit->first)
+ LOG_ERROR("Public key " << epee::string_tools::pod_to_hex(kit->first)
<< " from received " << print_money(tx.vout[o].amount) << " output already exists with "
<< print_money(m_transfers[kit->second].amount()) << ", replacing with new output");
// The new larger output replaced a previous smaller one
@@ -564,7 +564,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
td.m_mask = rct::identity();
td.m_rct = false;
}
- THROW_WALLET_EXCEPTION_IF(td.m_key_image != ki[o], error::wallet_internal_error, "Inconsistent key images");
+ THROW_WALLET_EXCEPTION_IF(td.get_public_key() != in_ephemeral[o].pub, error::wallet_internal_error, "Inconsistent public keys");
THROW_WALLET_EXCEPTION_IF(td.m_spent, error::wallet_internal_error, "Inconsistent spent status");
LOG_PRINT_L0("Received money: " << print_money(td.amount()) << ", with tx: " << txid());
@@ -1344,7 +1344,13 @@ void wallet2::detach_blockchain(uint64_t height)
auto it_ki = m_key_images.find(m_transfers[i].m_key_image);
THROW_WALLET_EXCEPTION_IF(it_ki == m_key_images.end(), error::wallet_internal_error, "key image not found");
m_key_images.erase(it_ki);
- ++transfers_detached;
+ }
+
+ for(size_t i = i_start; i!= m_transfers.size();i++)
+ {
+ auto it_pk = m_pub_keys.find(m_transfers[i].get_public_key());
+ THROW_WALLET_EXCEPTION_IF(it_pk == m_pub_keys.end(), error::wallet_internal_error, "public key not found");
+ m_pub_keys.erase(it_pk);
}
m_transfers.erase(it, m_transfers.end());
@@ -1381,6 +1387,7 @@ bool wallet2::clear()
m_blockchain.clear();
m_transfers.clear();
m_key_images.clear();
+ m_pub_keys.clear();
m_unconfirmed_txs.clear();
m_payments.clear();
m_tx_keys.clear();
@@ -2157,13 +2164,11 @@ void wallet2::rescan_spent()
std::to_string(daemon_resp.spent_status.size()) + ", expected " + std::to_string(key_images.size()));
// update spent status
- key_image zero_ki;
- memset(&zero_ki, 0, 32);
for (size_t i = 0; i < m_transfers.size(); ++i)
{
transfer_details& td = m_transfers[i];
// a view wallet may not know about key images
- if (td.m_key_image == zero_ki)
+ if (!td.m_key_image_known)
continue;
if (td.m_spent != (daemon_resp.spent_status[i] != COMMAND_RPC_IS_KEY_IMAGE_SPENT::UNSPENT))
{
@@ -4309,10 +4314,7 @@ std::vector<std::pair<crypto::key_image, crypto::signature>> wallet2::export_key
cryptonote::keypair in_ephemeral;
cryptonote::generate_key_image_helper(m_account.get_keys(), tx_pub_key, td.m_internal_output_index, in_ephemeral, ki);
- bool zero_key_image = true;
- for (size_t i = 0; i < sizeof(td.m_key_image); ++i)
- zero_key_image &= (td.m_key_image.data[i] == 0);
- THROW_WALLET_EXCEPTION_IF(!zero_key_image && ki != td.m_key_image,
+ THROW_WALLET_EXCEPTION_IF(td.m_key_image_known && ki != td.m_key_image,
error::wallet_internal_error, "key_image generated not matched with cached key image");
THROW_WALLET_EXCEPTION_IF(in_ephemeral.pub != pkey,
error::wallet_internal_error, "key_image generated ephemeral public key not matched with output_key");
@@ -4368,7 +4370,10 @@ uint64_t wallet2::import_key_images(const std::vector<std::pair<crypto::key_imag
}
for (size_t n = 0; n < signed_key_images.size(); ++n)
+ {
m_transfers[n].m_key_image = signed_key_images[n].first;
+ m_transfers[n].m_key_image_known = true;
+ }
m_daemon_rpc_mutex.lock();
bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/is_key_image_spent", req, daemon_resp, m_http_client, 200000);
@@ -4434,6 +4439,7 @@ size_t wallet2::import_outputs(const std::vector<tools::wallet2::transfer_detail
"Public key wasn't found in the transaction extra at index " + i);
cryptonote::generate_key_image_helper(m_account.get_keys(), pub_key_field.pub_key, td.m_internal_output_index, in_ephemeral, td.m_key_image);
+ td.m_key_image_known = true;
THROW_WALLET_EXCEPTION_IF(in_ephemeral.pub != boost::get<cryptonote::txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key,
error::wallet_internal_error, "key_image generated ephemeral public key not matched with output_key at index " + i);
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index cad8550e1..3c4b1015f 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -109,9 +109,11 @@ namespace tools
rct::key m_mask;
uint64_t m_amount;
bool m_rct;
+ bool m_key_image_known;
bool is_rct() const { return m_rct; }
uint64_t amount() const { return m_amount; }
+ const crypto::public_key &get_public_key() const { return boost::get<const cryptonote::txout_to_key>(m_tx.vout[m_internal_output_index].target).key; }
};
struct payment_details
@@ -409,6 +411,19 @@ namespace tools
a & m_unconfirmed_payments;
if(ver < 14)
return;
+ if(ver < 15)
+ {
+ // we're loading an older wallet without a pubkey map, rebuild it
+ for (size_t i = 0; i < m_transfers.size(); ++i)
+ {
+ const transfer_details &td = m_transfers[i];
+ const cryptonote::tx_out &out = td.m_tx.vout[td.m_internal_output_index];
+ const cryptonote::txout_to_key &o = boost::get<const cryptonote::txout_to_key>(out.target);
+ m_pub_keys.emplace(o.key, i);
+ }
+ return;
+ }
+ a & m_pub_keys;
}
/*!
@@ -551,6 +566,7 @@ namespace tools
transfer_container m_transfers;
payment_container m_payments;
std::unordered_map<crypto::key_image, size_t> m_key_images;
+ std::unordered_map<crypto::public_key, size_t> m_pub_keys;
cryptonote::account_public_address m_account_public_address;
std::unordered_map<crypto::hash, std::string> m_tx_notes;
uint64_t m_upper_transaction_size_limit; //TODO: auto-calc this value or request from daemon, now use some fixed value
@@ -575,8 +591,8 @@ namespace tools
bool m_confirm_missing_payment_id;
};
}
-BOOST_CLASS_VERSION(tools::wallet2, 14)
-BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 4)
+BOOST_CLASS_VERSION(tools::wallet2, 15)
+BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 5)
BOOST_CLASS_VERSION(tools::wallet2::payment_details, 1)
BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 6)
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 3)
@@ -605,6 +621,7 @@ namespace boost
{
x.m_rct = x.m_tx.vout[x.m_internal_output_index].amount == 0;
}
+ x.m_key_image_known = true;
}
template <class Archive>
@@ -652,6 +669,9 @@ namespace boost
return;
}
a & x.m_rct;
+ if (ver < 5)
+ return;
+ a & x.m_key_image_known;
}
template <class Archive>
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index da1dbd6e1..f0a9ea68b 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -66,6 +66,11 @@ struct PendingTransaction
virtual uint64_t dust() const = 0;
virtual uint64_t fee() const = 0;
virtual std::vector<std::string> txid() const = 0;
+ /*!
+ * \brief txCount - number of transactions current transaction will be splitted to
+ * \return
+ */
+ virtual uint64_t txCount() const = 0;
};
/**
@@ -331,6 +336,14 @@ struct Wallet
PendingTransaction::Priority = PendingTransaction::Priority_Low) = 0;
/*!
+ * \brief createSweepUnmixableTransaction creates transaction with unmixable outputs.
+ * \return PendingTransaction object. caller is responsible to check PendingTransaction::status()
+ * after object returned
+ */
+
+ virtual PendingTransaction * createSweepUnmixableTransaction() = 0;
+
+ /*!
* \brief disposeTransaction - destroys transaction object
* \param t - pointer to the "PendingTransaction" object. Pointer is not valid after function returned;
*/
@@ -362,6 +375,21 @@ struct Wallet
*/
virtual std::string getUserNote(const std::string &txid) const = 0;
virtual std::string getTxKey(const std::string &txid) const = 0;
+
+ /*
+ * \brief signMessage - sign a message with the spend private key
+ * \param message - the message to sign (arbitrary byte data)
+ * \return the signature
+ */
+ virtual std::string signMessage(const std::string &message) = 0;
+ /*!
+ * \brief verifySignedMessage - verify a signature matches a given message
+ * \param message - the message (arbitrary byte data)
+ * \param address - the address the signature claims to be made with
+ * \param signature - the signature
+ * \return true if the signature verified, false otherwise
+ */
+ virtual bool verifySignedMessage(const std::string &message, const std::string &addres, const std::string &signature) const = 0;
};
/**