@@ -360,7 +360,7 @@ static UniValue setlabel(const JSONRPCRequest& request)
360360}
361361
362362
363- static CTransactionRef SendMoney (CWallet* const pwallet, const CTxDestination& address, CAmount nValue, bool fSubtractFeeFromAmount , const CCoinControl& coin_control, mapValue_t mapValue)
363+ static CTransactionRef SendMoney (CWallet* const pwallet, const CTxDestination& address, CAmount nValue, bool fSubtractFeeFromAmount , const CCoinControl& coin_control, mapValue_t mapValue, std::string& feeReason )
364364{
365365 CAmount curBalance = pwallet->GetBalance (0 , coin_control.m_avoid_address_reuse ).m_mine_trusted ;
366366
@@ -381,8 +381,8 @@ static CTransactionRef SendMoney(CWallet* const pwallet, const CTxDestination& a
381381 int nChangePosRet = -1 ;
382382 CRecipient recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount };
383383 vecSend.push_back (recipient);
384- CTransactionRef tx;
385- if (!pwallet->CreateTransaction (vecSend, tx, nFeeRequired, nChangePosRet, error, coin_control)) {
384+ CTransactionRef tx;
385+ if (!pwallet->CreateTransaction (vecSend, tx, nFeeRequired, nChangePosRet, error, coin_control, feeReason )) {
386386 if (!fSubtractFeeFromAmount && nValue + nFeeRequired > curBalance)
387387 error = strprintf (Untranslated (" Error: This transaction requires a transaction fee of at least %s" ), FormatMoney (nFeeRequired));
388388 throw JSONRPCError (RPC_WALLET_ERROR, error.original );
@@ -412,6 +412,8 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
412412 " \" " + FeeModes (" \"\n\" " ) + " \" " },
413413 {" avoid_reuse" , RPCArg::Type::BOOL, /* default */ " true" , " (only available if avoid_reuse wallet flag is set) Avoid spending from dirty addresses; addresses are considered\n "
414414 " dirty if they have previously been used in a transaction." },
415+ {" verbose" , RPCArg::Type::BOOL, /* default */ " false" ,
416+ " Whether to display the fee reason or not." },
415417 },
416418 RPCResult{
417419 RPCResult::Type::STR_HEX, " txid" , " The transaction id."
@@ -470,8 +472,17 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
470472 SetFeeEstimateMode (pwallet, coin_control, request.params [7 ], request.params [6 ]);
471473
472474 EnsureWalletIsUnlocked (pwallet);
475+ UniValue entry (UniValue::VOBJ);
476+ std::string feeReason;
477+ CTransactionRef tx = SendMoney (pwallet, dest, nAmount, fSubtractFeeFromAmount , coin_control, std::move (mapValue), feeReason);
478+
479+ bool verbose = request.params [9 ].isNull () ? false : request.params [9 ].get_bool ();
480+ if (verbose){
481+ entry.pushKV (" hex" , tx->GetHash ().GetHex ());
482+ entry.pushKV (" Fee Reason" , feeReason);
483+ return entry;
484+ }
473485
474- CTransactionRef tx = SendMoney (pwallet, dest, nAmount, fSubtractFeeFromAmount , coin_control, std::move (mapValue));
475486 return tx->GetHash ().GetHex ();
476487}
477488
@@ -813,6 +824,8 @@ static UniValue sendmany(const JSONRPCRequest& request)
813824 {" conf_target" , RPCArg::Type::NUM, /* default */ " wallet default" , " Confirmation target (in blocks), or fee rate (for " + CURRENCY_UNIT + " /kB or " + CURRENCY_ATOM + " /B estimate modes)" },
814825 {" estimate_mode" , RPCArg::Type::STR, /* default */ " unset" , std::string () + " The fee estimate mode, must be one of (case insensitive):\n "
815826 " \" " + FeeModes (" \"\n\" " ) + " \" " },
827+ {" verbose" , RPCArg::Type::BOOL, /* default */ " false" ,
828+ " Whether to display the fee reason or not." },
816829 },
817830 RPCResult{
818831 RPCResult::Type::STR_HEX, " txid" , " The transaction id for the send. Only 1 transaction is created regardless of\n "
@@ -901,10 +914,21 @@ static UniValue sendmany(const JSONRPCRequest& request)
901914 int nChangePosRet = -1 ;
902915 bilingual_str error;
903916 CTransactionRef tx;
904- bool fCreated = pwallet->CreateTransaction (vecSend, tx, nFeeRequired, nChangePosRet, error, coin_control);
917+ UniValue entry (UniValue::VOBJ);
918+ std::string feeReason;
919+ bool fCreated = pwallet->CreateTransaction (vecSend, tx, nFeeRequired, nChangePosRet, error, coin_control, feeReason);
905920 if (!fCreated )
906921 throw JSONRPCError (RPC_WALLET_INSUFFICIENT_FUNDS, error.original );
907922 pwallet->CommitTransaction (tx, std::move (mapValue), {} /* orderForm */ );
923+
924+ bool verbose = request.params [8 ].isNull () ? false : request.params [8 ].get_bool ();
925+
926+ if (verbose){
927+ entry.pushKV (" hex" , tx->GetHash ().GetHex ());
928+ entry.pushKV (" Fee Reason" , feeReason);
929+ return entry;
930+ }
931+
908932 return tx->GetHash ().GetHex ();
909933}
910934
@@ -4198,8 +4222,8 @@ static const CRPCCommand commands[] =
41984222 { " wallet" , " lockunspent" , &lockunspent, {" unlock" ," transactions" } },
41994223 { " wallet" , " removeprunedfunds" , &removeprunedfunds, {" txid" } },
42004224 { " wallet" , " rescanblockchain" , &rescanblockchain, {" start_height" , " stop_height" } },
4201- { " wallet" , " sendmany" , &sendmany, {" dummy" ," amounts" ," minconf" ," comment" ," subtractfeefrom" ," replaceable" ," conf_target" ," estimate_mode" } },
4202- { " wallet" , " sendtoaddress" , &sendtoaddress, {" address" ," amount" ," comment" ," comment_to" ," subtractfeefromamount" ," replaceable" ," conf_target" ," estimate_mode" ," avoid_reuse" } },
4225+ { " wallet" , " sendmany" , &sendmany, {" dummy" ," amounts" ," minconf" ," comment" ," subtractfeefrom" ," replaceable" ," conf_target" ," estimate_mode" , " verbose " } },
4226+ { " wallet" , " sendtoaddress" , &sendtoaddress, {" address" ," amount" ," comment" ," comment_to" ," subtractfeefromamount" ," replaceable" ," conf_target" ," estimate_mode" ," avoid_reuse" , " verbose " } },
42034227 { " wallet" , " sethdseed" , &sethdseed, {" newkeypool" ," seed" } },
42044228 { " wallet" , " setlabel" , &setlabel, {" address" ," label" } },
42054229 { " wallet" , " settxfee" , &settxfee, {" amount" } },
0 commit comments