From c37c856d6d9694da33866145f1b69339fed787b1 Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Sun, 3 Apr 2016 14:34:38 +0300 Subject: [PATCH] Wallet::transfer in progress --- src/wallet/wallet2_api.cpp | 40 ++++++++++++++++++++++++++++++++++++++ src/wallet/wallet2_api.h | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet2_api.cpp b/src/wallet/wallet2_api.cpp index e6ed249c..dcd17d80 100644 --- a/src/wallet/wallet2_api.cpp +++ b/src/wallet/wallet2_api.cpp @@ -32,7 +32,11 @@ #include "wallet2.h" #include "mnemonics/electrum-words.h" #include "cryptonote_core/cryptonote_format_utils.h" +#include "cryptonote_core/cryptonote_basic_impl.h" + + #include +#include namespace epee { unsigned int g_test_dbg_lock_sleep = 0; @@ -44,11 +48,16 @@ struct WalletManagerImpl; namespace { static WalletManagerImpl * g_walletManager = nullptr; + // copy-pasted from + static const size_t DEFAULT_MIX = 4; } + +using namespace std; + Wallet::~Wallet() {} ///////////////////////// Wallet implementation //////////////////////////////// @@ -77,6 +86,7 @@ public: uint64_t unlockedBalance() const; std::string displayAmount(uint64_t amount) const; bool refresh(); + bool transfer(const std::string &dst_addr, uint64_t amount); private: @@ -306,6 +316,36 @@ bool WalletImpl::refresh() return m_status == Status_Ok; } +bool WalletImpl::transfer(const std::string &dst_addr, uint64_t amount) +{ + clearStatus(); + vector dsts; + cryptonote::tx_destination_entry de; + bool has_payment_id; + bool payment_id_seen = false; + crypto::hash8 new_payment_id; + size_t fake_outs_count = DEFAULT_MIX; + if(!cryptonote::get_account_integrated_address_from_str(de.addr, has_payment_id, new_payment_id, m_wallet->testnet(), dst_addr)) { + // TODO: copy-paste 'if treating as an address fails, try as url' from simplewallet.cpp:1982 + m_status = Status_Error; + m_errorString = "Invalid destination address"; + return false; + } + + de.amount = amount; + if (de.amount <= 0) { + m_status = Status_Error; + m_errorString = "Invalid amount"; + return false; + } + dsts.push_back(de); + + + + + return m_status == Status_Ok; +} + bool WalletImpl::connectToDaemon() { bool result = m_wallet->check_connection(); diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index c818608e..1c3cd595 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -74,9 +74,10 @@ struct Wallet virtual std::string displayAmount(uint64_t amount) const = 0; // TODO? // virtual uint64_t unlockedDustBalance() const = 0; - // TODO refresh virtual bool refresh() = 0; // TODO transfer + virtual bool transfer(const std::string &dst_addr, uint64_t amount) = 0; + }; /**