aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/api')
-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
4 files changed, 121 insertions, 2 deletions
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();