aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2016-06-02 06:00:59 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2016-06-02 06:00:59 -0700
commit9dfaa1cb70670eb0a4c82a7ddfcba71ba5ebea94 (patch)
treecf290bd04f11acbbe0a8254b26352a19e2597502 /src/wallet/wallet.cpp
parent715e9fd7454f7a48d7adba7d42f662c20a3e3367 (diff)
Improve CWallet API with new AccountMove function.
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index da0d6f272b..482eb6aa65 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -606,6 +606,40 @@ int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
return nRet;
}
+bool CWallet::AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment)
+{
+ CWalletDB walletdb(strWalletFile);
+ if (!walletdb.TxnBegin())
+ return false;
+
+ int64_t nNow = GetAdjustedTime();
+
+ // Debit
+ CAccountingEntry debit;
+ debit.nOrderPos = IncOrderPosNext(&walletdb);
+ debit.strAccount = strFrom;
+ debit.nCreditDebit = -nAmount;
+ debit.nTime = nNow;
+ debit.strOtherAccount = strTo;
+ debit.strComment = strComment;
+ AddAccountingEntry(debit, walletdb);
+
+ // Credit
+ CAccountingEntry credit;
+ credit.nOrderPos = IncOrderPosNext(&walletdb);
+ credit.strAccount = strTo;
+ credit.nCreditDebit = nAmount;
+ credit.nTime = nNow;
+ credit.strOtherAccount = strFrom;
+ credit.strComment = strComment;
+ AddAccountingEntry(credit, walletdb);
+
+ if (!walletdb.TxnCommit())
+ return false;
+
+ return true;
+}
+
void CWallet::MarkDirty()
{
{