@@ -404,7 +404,7 @@ UniValue getaddressesbyaccount(const JSONRPCRequest& request)
404
404
return ret;
405
405
}
406
406
407
- static void SendMoney (CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount , CWalletTx& wtxNew, const CCoinControl& coin_control)
407
+ static CTransactionRef SendMoney (CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount , const CCoinControl& coin_control, mapValue_t mapValue, std::string fromAccount )
408
408
{
409
409
CAmount curBalance = pwallet->GetBalance ();
410
410
@@ -430,16 +430,18 @@ static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CA
430
430
int nChangePosRet = -1 ;
431
431
CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount };
432
432
vecSend.push_back (recipient);
433
- if (!pwallet->CreateTransaction (vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strError, coin_control)) {
433
+ CTransactionRef tx;
434
+ if (!pwallet->CreateTransaction (vecSend, tx, reservekey, nFeeRequired, nChangePosRet, strError, coin_control)) {
434
435
if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance)
435
436
strError = strprintf (" Error: This transaction requires a transaction fee of at least %s" , FormatMoney (nFeeRequired));
436
437
throw JSONRPCError (RPC_WALLET_ERROR, strError);
437
438
}
438
439
CValidationState state;
439
- if (!pwallet->CommitTransaction (wtxNew , reservekey, g_connman.get (), state)) {
440
+ if (!pwallet->CommitTransaction (tx, std::move (mapValue), {} /* orderForm */ , std::move (fromAccount) , reservekey, g_connman.get (), state)) {
440
441
strError = strprintf (" Error: The transaction was rejected! Reason given: %s" , FormatStateMessage (state));
441
442
throw JSONRPCError (RPC_WALLET_ERROR, strError);
442
443
}
444
+ return tx;
443
445
}
444
446
445
447
UniValue sendtoaddress (const JSONRPCRequest& request)
@@ -498,11 +500,11 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
498
500
throw JSONRPCError (RPC_TYPE_ERROR, " Invalid amount for send" );
499
501
500
502
// Wallet comments
501
- CWalletTx wtx ;
503
+ mapValue_t mapValue ;
502
504
if (!request.params [2 ].isNull () && !request.params [2 ].get_str ().empty ())
503
- wtx. mapValue [" comment" ] = request.params [2 ].get_str ();
505
+ mapValue[" comment" ] = request.params [2 ].get_str ();
504
506
if (!request.params [3 ].isNull () && !request.params [3 ].get_str ().empty ())
505
- wtx. mapValue [" to" ] = request.params [3 ].get_str ();
507
+ mapValue[" to" ] = request.params [3 ].get_str ();
506
508
507
509
bool fSubtractFeeFromAmount = false ;
508
510
if (!request.params [4 ].isNull ()) {
@@ -527,9 +529,8 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
527
529
528
530
EnsureWalletIsUnlocked (pwallet);
529
531
530
- SendMoney (pwallet, dest, nAmount, fSubtractFeeFromAmount , wtx, coin_control);
531
-
532
- return wtx.GetHash ().GetHex ();
532
+ CTransactionRef tx = SendMoney (pwallet, dest, nAmount, fSubtractFeeFromAmount , coin_control, std::move (mapValue), {} /* fromAccount */ );
533
+ return tx->GetHash ().GetHex ();
533
534
}
534
535
535
536
UniValue listaddressgroupings (const JSONRPCRequest& request)
@@ -995,12 +996,11 @@ UniValue sendfrom(const JSONRPCRequest& request)
995
996
if (!request.params [3 ].isNull ())
996
997
nMinDepth = request.params [3 ].get_int ();
997
998
998
- CWalletTx wtx;
999
- wtx.strFromAccount = strAccount;
999
+ mapValue_t mapValue;
1000
1000
if (!request.params [4 ].isNull () && !request.params [4 ].get_str ().empty ())
1001
- wtx. mapValue [" comment" ] = request.params [4 ].get_str ();
1001
+ mapValue[" comment" ] = request.params [4 ].get_str ();
1002
1002
if (!request.params [5 ].isNull () && !request.params [5 ].get_str ().empty ())
1003
- wtx. mapValue [" to" ] = request.params [5 ].get_str ();
1003
+ mapValue[" to" ] = request.params [5 ].get_str ();
1004
1004
1005
1005
EnsureWalletIsUnlocked (pwallet);
1006
1006
@@ -1010,9 +1010,8 @@ UniValue sendfrom(const JSONRPCRequest& request)
1010
1010
throw JSONRPCError (RPC_WALLET_INSUFFICIENT_FUNDS, " Account has insufficient funds" );
1011
1011
1012
1012
CCoinControl no_coin_control; // This is a deprecated API
1013
- SendMoney (pwallet, dest, nAmount, false , wtx, no_coin_control);
1014
-
1015
- return wtx.GetHash ().GetHex ();
1013
+ CTransactionRef tx = SendMoney (pwallet, dest, nAmount, false , no_coin_control, std::move (mapValue), std::move (strAccount));
1014
+ return tx->GetHash ().GetHex ();
1016
1015
}
1017
1016
1018
1017
@@ -1083,10 +1082,9 @@ UniValue sendmany(const JSONRPCRequest& request)
1083
1082
if (!request.params [2 ].isNull ())
1084
1083
nMinDepth = request.params [2 ].get_int ();
1085
1084
1086
- CWalletTx wtx;
1087
- wtx.strFromAccount = strAccount;
1085
+ mapValue_t mapValue;
1088
1086
if (!request.params [3 ].isNull () && !request.params [3 ].get_str ().empty ())
1089
- wtx. mapValue [" comment" ] = request.params [3 ].get_str ();
1087
+ mapValue[" comment" ] = request.params [3 ].get_str ();
1090
1088
1091
1089
UniValue subtractFeeFromAmount (UniValue::VARR);
1092
1090
if (!request.params [4 ].isNull ())
@@ -1152,16 +1150,17 @@ UniValue sendmany(const JSONRPCRequest& request)
1152
1150
CAmount nFeeRequired = 0 ;
1153
1151
int nChangePosRet = -1 ;
1154
1152
std::string strFailReason;
1155
- bool fCreated = pwallet->CreateTransaction (vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason, coin_control);
1153
+ CTransactionRef tx;
1154
+ bool fCreated = pwallet->CreateTransaction (vecSend, tx, keyChange, nFeeRequired, nChangePosRet, strFailReason, coin_control);
1156
1155
if (!fCreated )
1157
1156
throw JSONRPCError (RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
1158
1157
CValidationState state;
1159
- if (!pwallet->CommitTransaction (wtx , keyChange, g_connman.get (), state)) {
1158
+ if (!pwallet->CommitTransaction (tx, std::move (mapValue), {} /* orderForm */ , std::move (strAccount) , keyChange, g_connman.get (), state)) {
1160
1159
strFailReason = strprintf (" Transaction commit failed:: %s" , FormatStateMessage (state));
1161
1160
throw JSONRPCError (RPC_WALLET_ERROR, strFailReason);
1162
1161
}
1163
1162
1164
- return wtx. GetHash ().GetHex ();
1163
+ return tx-> GetHash ().GetHex ();
1165
1164
}
1166
1165
1167
1166
UniValue addmultisigaddress (const JSONRPCRequest& request)
0 commit comments