aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet2_api.cpp
diff options
context:
space:
mode:
authorIlya Kitaev <mbg033@gmail.com>2016-04-19 12:25:03 +0300
committerIlya Kitaev <mbg033@gmail.com>2016-06-23 15:50:17 +0300
commit60508e6baecf8c64b4bbd90516ac03f65308a267 (patch)
tree2bef8af5e3fc314d0be9e57cd8eb777850dd445e /src/wallet/wallet2_api.cpp
parentWallet::createTransaction API introduced (diff)
downloadmonero-60508e6baecf8c64b4bbd90516ac03f65308a267.tar.xz
TransactionInfo / TransactionHistory APIs design
Diffstat (limited to 'src/wallet/wallet2_api.cpp')
-rw-r--r--src/wallet/wallet2_api.cpp278
1 files changed, 155 insertions, 123 deletions
diff --git a/src/wallet/wallet2_api.cpp b/src/wallet/wallet2_api.cpp
index edf7d9931..a6fc6ecc5 100644
--- a/src/wallet/wallet2_api.cpp
+++ b/src/wallet/wallet2_api.cpp
@@ -65,48 +65,13 @@ using namespace std;
using namespace cryptonote;
Wallet::~Wallet() {}
-
PendingTransaction::~PendingTransaction() {}
-class WalletImpl;
-
-///////////////////////// Transaction implementation ///////////////////////////
-
-class TransactionImpl : public PendingTransaction
-{
-public:
- TransactionImpl(WalletImpl * wallet);
- ~TransactionImpl();
- int status() const;
- std::string errorString() const;
- bool commit();
- uint64_t amount() const;
- uint64_t dust() const;
- uint64_t fee() const;
- // TODO: continue with interface;
-
-private:
- friend class WalletImpl;
- WalletImpl * m_wallet;
-
- int m_status;
- std::string m_errorString;
- std::vector<tools::wallet2::pending_tx> m_pending_tx;
-};
-
-
-
-
-/////////////////////////////////////////////////////////////////////////////////
-string Wallet::displayAmount(uint64_t amount)
-{
- return cryptonote::print_money(amount);
-}
-///////////////////////// Wallet implementation ////////////////////////////////
+///////////////////////// Wallet implementation ///////////////////////////////
class WalletImpl : public Wallet
{
public:
@@ -120,7 +85,7 @@ public:
std::string seed() const;
std::string getSeedLanguage() const;
void setSeedLanguage(const std::string &arg);
- void setListener(Listener *) {}
+ // void setListener(Listener *) {}
int status() const;
std::string errorString() const;
bool setPassword(const std::string &password);
@@ -133,6 +98,7 @@ public:
bool refresh();
PendingTransaction * createTransaction(const std::string &dst_addr, uint64_t amount);
virtual void disposeTransaction(PendingTransaction * t);
+ virtual TransactionHistory * history() const;
private:
void clearStatus();
@@ -145,6 +111,151 @@ private:
std::string m_password;
};
+
+/////////////////////////////////////////////////////////////////////////////////
+string Wallet::displayAmount(uint64_t amount)
+{
+ return cryptonote::print_money(amount);
+}
+
+///////////////////////// Transaction implementation ///////////////////////////
+
+class TransactionImpl : public PendingTransaction
+{
+public:
+ TransactionImpl(WalletImpl * wallet);
+ ~TransactionImpl();
+ int status() const;
+ std::string errorString() const;
+ bool commit();
+ uint64_t amount() const;
+ uint64_t dust() const;
+ uint64_t fee() const;
+ // TODO: continue with interface;
+
+private:
+ friend class WalletImpl;
+ WalletImpl * m_wallet;
+
+ int m_status;
+ std::string m_errorString;
+ std::vector<tools::wallet2::pending_tx> m_pending_tx;
+};
+
+TransactionImpl::TransactionImpl(WalletImpl *wallet)
+ : m_wallet(wallet)
+{
+
+}
+
+TransactionImpl::~TransactionImpl()
+{
+
+}
+
+int TransactionImpl::status() const
+{
+ return m_status;
+}
+
+string TransactionImpl::errorString() const
+{
+ return m_errorString;
+}
+
+bool TransactionImpl::commit()
+{
+
+ LOG_PRINT_L0("m_pending_tx size: " << m_pending_tx.size());
+ assert(m_pending_tx.size() == 1);
+ try {
+ while (!m_pending_tx.empty()) {
+ auto & ptx = m_pending_tx.back();
+ m_wallet->m_wallet->commit_tx(ptx);
+ // success_msg_writer(true) << tr("Money successfully sent, transaction ") << get_transaction_hash(ptx.tx);
+ // if no exception, remove element from vector
+ m_pending_tx.pop_back();
+ } // TODO: extract method;
+ } 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::tx_rejected& e) {
+ std::ostringstream writer(m_errorString);
+ writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
+ m_status = Status_Error;
+ } catch (std::exception &e) {
+ m_errorString = string(tr("Unknown exception: ")) + e.what();
+ m_status = Status_Error;
+ } catch (...) {
+ m_errorString = tr("Unhandled exception");
+ LOG_ERROR(m_errorString);
+ m_status = Status_Error;
+ }
+
+ return m_status == Status_Ok;
+}
+
+uint64_t TransactionImpl::amount() const
+{
+ uint64_t result = 0;
+ for (const auto &ptx : m_pending_tx) {
+ for (const auto &dest : ptx.dests) {
+ result += dest.amount;
+ }
+ }
+ return result;
+}
+
+uint64_t TransactionImpl::dust() const
+{
+ uint32_t result = 0;
+ for (const auto & ptx : m_pending_tx) {
+ result += ptx.dust;
+ }
+ return result;
+}
+
+uint64_t TransactionImpl::fee() const
+{
+ uint32_t result = 0;
+ for (const auto ptx : m_pending_tx) {
+ result += ptx.fee;
+ }
+ return result;
+}
+
+
+///////////////////////// TransactionInfo implementation ////////////////////////
+class TransactionInfoImpl : public TransactionInfo
+{
+public:
+ TransactionInfoImpl();
+ ~TransactionInfoImpl();
+ virtual bool isHold() const;
+};
+
+TransactionInfoImpl::TransactionInfoImpl()
+{
+
+}
+
+TransactionInfoImpl::~TransactionInfoImpl()
+{
+
+}
+
+bool TransactionInfoImpl::isHold() const
+{
+ return false;
+}
+
+
+
+
WalletImpl::WalletImpl(bool testnet)
:m_wallet(nullptr), m_status(Wallet::Status_Ok)
{
@@ -477,6 +588,11 @@ void WalletImpl::disposeTransaction(PendingTransaction *t)
delete t;
}
+TransactionHistory *WalletImpl::history() const
+{
+ return nullptr;
+}
+
bool WalletImpl::connectToDaemon()
{
bool result = m_wallet->check_connection();
@@ -496,92 +612,6 @@ void WalletImpl::clearStatus()
-TransactionImpl::TransactionImpl(WalletImpl *wallet)
- : m_wallet(wallet)
-{
-
-}
-
-TransactionImpl::~TransactionImpl()
-{
-
-}
-
-int TransactionImpl::status() const
-{
- return m_status;
-}
-
-string TransactionImpl::errorString() const
-{
- return m_errorString;
-}
-
-bool TransactionImpl::commit()
-{
-
- LOG_PRINT_L0("m_pending_tx size: " << m_pending_tx.size());
- assert(m_pending_tx.size() == 1);
- try {
- while (!m_pending_tx.empty()) {
- auto & ptx = m_pending_tx.back();
- m_wallet->m_wallet->commit_tx(ptx);
- // success_msg_writer(true) << tr("Money successfully sent, transaction ") << get_transaction_hash(ptx.tx);
- // if no exception, remove element from vector
- m_pending_tx.pop_back();
- } // TODO: extract method;
- } 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::tx_rejected& e) {
- std::ostringstream writer(m_errorString);
- writer << (boost::format(tr("transaction %s was rejected by daemon with status: ")) % get_transaction_hash(e.tx())) << e.status();
- m_status = Status_Error;
- } catch (std::exception &e) {
- m_errorString = string(tr("Unknown exception: ")) + e.what();
- m_status = Status_Error;
- } catch (...) {
- m_errorString = tr("Unhandled exception");
- LOG_ERROR(m_errorString);
- m_status = Status_Error;
- }
-
- return m_status == Status_Ok;
-}
-
-uint64_t TransactionImpl::amount() const
-{
- uint64_t result = 0;
- for (const auto &ptx : m_pending_tx) {
- for (const auto &dest : ptx.dests) {
- result += dest.amount;
- }
- }
- return result;
-}
-
-uint64_t TransactionImpl::dust() const
-{
- uint32_t result = 0;
- for (const auto & ptx : m_pending_tx) {
- result += ptx.dust;
- }
- return result;
-}
-
-uint64_t TransactionImpl::fee() const
-{
- uint32_t result = 0;
- for (const auto ptx : m_pending_tx) {
- result += ptx.fee;
- }
- return result;
-}
-
///////////////////////// WalletManager implementation /////////////////////////
@@ -671,4 +701,6 @@ WalletManager *WalletManagerFactory::getWalletManager()
+
+
}