mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-17 18:40:09 +00:00
Merge #8137: Improve CWallet API with new AccountMove function.
9dfaa1c Improve CWallet API with new AccountMove function. (Patrick Strateman)
This commit is contained in:
commit
243ac0c75b
@ -804,33 +804,7 @@ UniValue movecmd(const UniValue& params, bool fHelp)
|
|||||||
if (params.size() > 4)
|
if (params.size() > 4)
|
||||||
strComment = params[4].get_str();
|
strComment = params[4].get_str();
|
||||||
|
|
||||||
CWalletDB walletdb(pwalletMain->strWalletFile);
|
if (!pwalletMain->AccountMove(strFrom, strTo, nAmount, strComment))
|
||||||
if (!walletdb.TxnBegin())
|
|
||||||
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
|
|
||||||
|
|
||||||
int64_t nNow = GetAdjustedTime();
|
|
||||||
|
|
||||||
// Debit
|
|
||||||
CAccountingEntry debit;
|
|
||||||
debit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
|
|
||||||
debit.strAccount = strFrom;
|
|
||||||
debit.nCreditDebit = -nAmount;
|
|
||||||
debit.nTime = nNow;
|
|
||||||
debit.strOtherAccount = strTo;
|
|
||||||
debit.strComment = strComment;
|
|
||||||
pwalletMain->AddAccountingEntry(debit, walletdb);
|
|
||||||
|
|
||||||
// Credit
|
|
||||||
CAccountingEntry credit;
|
|
||||||
credit.nOrderPos = pwalletMain->IncOrderPosNext(&walletdb);
|
|
||||||
credit.strAccount = strTo;
|
|
||||||
credit.nCreditDebit = nAmount;
|
|
||||||
credit.nTime = nNow;
|
|
||||||
credit.strOtherAccount = strFrom;
|
|
||||||
credit.strComment = strComment;
|
|
||||||
pwalletMain->AddAccountingEntry(credit, walletdb);
|
|
||||||
|
|
||||||
if (!walletdb.TxnCommit())
|
|
||||||
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
|
throw JSONRPCError(RPC_DATABASE_ERROR, "database error");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -606,6 +606,40 @@ int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
|
|||||||
return nRet;
|
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()
|
void CWallet::MarkDirty()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
@ -718,6 +718,7 @@ public:
|
|||||||
* @return next transaction order id
|
* @return next transaction order id
|
||||||
*/
|
*/
|
||||||
int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL);
|
int64_t IncOrderPosNext(CWalletDB *pwalletdb = NULL);
|
||||||
|
bool AccountMove(std::string strFrom, std::string strTo, CAmount nAmount, std::string strComment = "");
|
||||||
|
|
||||||
void MarkDirty();
|
void MarkDirty();
|
||||||
bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb);
|
bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user