aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2015-03-24 18:06:54 +0100
committerWladimir J. van der Laan <[email protected]>2015-03-24 18:12:56 +0100
commit8d2fbfa49141172e1c63f5ab7b684a1f9e210571 (patch)
treef8cc7e9b3268bea6b3333a9bc9f3a3f48eb87fbb /src/wallet/wallet.cpp
parentMerge pull request #5890 (diff)
parentIncludes: Do not include main.h from any other header (diff)
downloaddiscoin-8d2fbfa49141172e1c63f5ab7b684a1f9e210571.tar.xz
discoin-8d2fbfa49141172e1c63f5ab7b684a1f9e210571.zip
Merge pull request #5681
8a893c9 Includes: Do not include main.h from any other header (Jorge Timón) eca0b1e Includes: MOVEONLY: move more method definitions out of wallet.h (Jorge Timón) 26c16d9 Includes: Refactor: Move CValidationInterface and CMainSignals out of main (Jorge Timón)
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 167639b53..09bcda577 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -8,6 +8,7 @@
#include "base58.h"
#include "checkpoints.h"
#include "coincontrol.h"
+#include "main.h"
#include "net.h"
#include "script/script.h"
#include "script/sign.h"
@@ -817,6 +818,18 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
return 0;
}
+isminetype CWallet::IsMine(const CTxOut& txout) const
+{
+ return ::IsMine(*this, txout.scriptPubKey);
+}
+
+CAmount CWallet::GetCredit(const CTxOut& txout, const isminefilter& filter) const
+{
+ if (!MoneyRange(txout.nValue))
+ throw std::runtime_error("CWallet::GetCredit(): value out of range");
+ return ((IsMine(txout) & filter) ? txout.nValue : 0);
+}
+
bool CWallet::IsChange(const CTxOut& txout) const
{
// TODO: fix handling of 'change' outputs. The assumption is that any
@@ -839,6 +852,62 @@ bool CWallet::IsChange(const CTxOut& txout) const
return false;
}
+CAmount CWallet::GetChange(const CTxOut& txout) const
+{
+ if (!MoneyRange(txout.nValue))
+ throw std::runtime_error("CWallet::GetChange(): value out of range");
+ return (IsChange(txout) ? txout.nValue : 0);
+}
+
+bool CWallet::IsMine(const CTransaction& tx) const
+{
+ BOOST_FOREACH(const CTxOut& txout, tx.vout)
+ if (IsMine(txout))
+ return true;
+ return false;
+}
+
+bool CWallet::IsFromMe(const CTransaction& tx) const
+{
+ return (GetDebit(tx, ISMINE_ALL) > 0);
+}
+
+CAmount CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) const
+{
+ CAmount nDebit = 0;
+ BOOST_FOREACH(const CTxIn& txin, tx.vin)
+ {
+ nDebit += GetDebit(txin, filter);
+ if (!MoneyRange(nDebit))
+ throw std::runtime_error("CWallet::GetDebit(): value out of range");
+ }
+ return nDebit;
+}
+
+CAmount CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) const
+{
+ CAmount nCredit = 0;
+ BOOST_FOREACH(const CTxOut& txout, tx.vout)
+ {
+ nCredit += GetCredit(txout, filter);
+ if (!MoneyRange(nCredit))
+ throw std::runtime_error("CWallet::GetCredit(): value out of range");
+ }
+ return nCredit;
+}
+
+CAmount CWallet::GetChange(const CTransaction& tx) const
+{
+ CAmount nChange = 0;
+ BOOST_FOREACH(const CTxOut& txout, tx.vout)
+ {
+ nChange += GetChange(txout);
+ if (!MoneyRange(nChange))
+ throw std::runtime_error("CWallet::GetChange(): value out of range");
+ }
+ return nChange;
+}
+
int64_t CWalletTx::GetTxTime() const
{
int64_t n = nTimeSmart;