aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorIlya Kitaev <mbg033@gmail.com>2016-06-16 16:42:33 +0300
committerIlya Kitaev <mbg033@gmail.com>2016-06-16 16:42:33 +0300
commit3318addafaf6ac7b5489f7d774083a84dce7dfa0 (patch)
tree1c539dc2584ceffd0ff52a8bea39f6973b40dfed /src/wallet
parentwallet::default_mixin exposed to public interface as (diff)
downloadmonero-3318addafaf6ac7b5489f7d774083a84dce7dfa0.tar.xz
double/string to monero integer convertion methods
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/api/wallet.cpp17
-rw-r--r--src/wallet/wallet2_api.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index f6d7a561e..1f414b3bf 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -36,6 +36,7 @@
#include "mnemonics/electrum-words.h"
#include <boost/format.hpp>
+#include <sstream>
using namespace std;
using namespace cryptonote;
@@ -122,6 +123,22 @@ string Wallet::displayAmount(uint64_t amount)
return cryptonote::print_money(amount);
}
+uint64_t Wallet::amountFromString(const string &amount)
+{
+ uint64_t result;
+ cryptonote::parse_amount(result, amount);
+ return result;
+}
+
+uint64_t Wallet::amountFromDouble(double amount)
+{
+ std::stringstream ss;
+ ss << std::fixed << std::setprecision(CRYPTONOTE_DISPLAY_DECIMAL_POINT) << amount;
+ return amountFromString(ss.str());
+}
+
+
+
///////////////////////// WalletImpl implementation ////////////////////////
WalletImpl::WalletImpl(bool testnet)
:m_wallet(nullptr), m_status(Wallet::Status_Ok), m_trustedDaemon(false),
diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h
index 62231820b..34c18f77f 100644
--- a/src/wallet/wallet2_api.h
+++ b/src/wallet/wallet2_api.h
@@ -160,6 +160,8 @@ struct Wallet
virtual uint64_t balance() const = 0;
virtual uint64_t unlockedBalance() const = 0;
static std::string displayAmount(uint64_t amount);
+ static uint64_t amountFromString(const std::string &amount);
+ static uint64_t amountFromDouble(double amount);
// TODO?
// virtual uint64_t unlockedDustBalance() const = 0;
virtual bool refresh() = 0;