-
Notifications
You must be signed in to change notification settings - Fork 38.7k
send* RPCs in the wallet returns the "fee reason" #19501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,7 +397,7 @@ void ParseRecipients(const UniValue& address_amounts, const UniValue& subtract_f | |
| } | ||
| } | ||
|
|
||
| UniValue SendMoney(CWallet* const pwallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, mapValue_t map_value) | ||
| UniValue SendMoney(CWallet* const pwallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, mapValue_t map_value, bool verbose) | ||
| { | ||
| EnsureWalletIsUnlocked(pwallet); | ||
|
|
||
|
|
@@ -409,11 +409,18 @@ UniValue SendMoney(CWallet* const pwallet, const CCoinControl &coin_control, std | |
| int nChangePosRet = -1; | ||
| bilingual_str error; | ||
| CTransactionRef tx; | ||
| bool fCreated = pwallet->CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | ||
| FeeCalculation fee_calc_out; | ||
| bool fCreated = pwallet->CreateTransaction(recipients, tx, nFeeRequired, nChangePosRet, error, coin_control, fee_calc_out, !pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); | ||
| if (!fCreated) { | ||
| throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, error.original); | ||
| } | ||
| pwallet->CommitTransaction(tx, std::move(map_value), {} /* orderForm */); | ||
| if (verbose) { | ||
| UniValue entry(UniValue::VOBJ); | ||
| entry.pushKV("txid", tx->GetHash().GetHex()); | ||
| entry.pushKV("fee_reason", StringForFeeReason(fee_calc_out.reason)); | ||
| return entry; | ||
| } | ||
| return tx->GetHash().GetHex(); | ||
| } | ||
|
|
||
|
|
@@ -438,9 +445,19 @@ static RPCHelpMan sendtoaddress() | |
| " \"" + FeeModes("\"\n\"") + "\""}, | ||
| {"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" | ||
| " dirty if they have previously been used in a transaction."}, | ||
| {"verbose", RPCArg::Type::BOOL, /* default */ "false", "If true, return extra information about the transaction."}, | ||
| }, | ||
| RPCResult{ | ||
| RPCResult::Type::STR_HEX, "txid", "The transaction id." | ||
| { | ||
| RPCResult{"if verbose is not set or set to false", | ||
| RPCResult::Type::STR_HEX, "txid", "The transaction id." | ||
| }, | ||
| RPCResult{"if verbose is set to true", | ||
| RPCResult::Type::OBJ, "", "", | ||
| { | ||
| {RPCResult::Type::STR_HEX, "txid", "The transaction id."}, | ||
| {RPCResult::Type::STR, "fee reason", "The transaction fee reason."} | ||
| }, | ||
| }, | ||
| }, | ||
| RPCExamples{ | ||
| HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 0.1") | ||
|
|
@@ -497,8 +514,9 @@ static RPCHelpMan sendtoaddress() | |
|
|
||
| std::vector<CRecipient> recipients; | ||
| ParseRecipients(address_amounts, subtractFeeFromAmount, recipients); | ||
| bool verbose = request.params[9].isNull() ? false: request.params[9].get_bool(); | ||
|
|
||
| return SendMoney(pwallet, coin_control, recipients, mapValue); | ||
| return SendMoney(pwallet, coin_control, recipients, mapValue, verbose); | ||
| }, | ||
| }; | ||
| } | ||
|
|
@@ -853,11 +871,22 @@ static RPCHelpMan sendmany() | |
| {"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)"}, | ||
| {"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n" | ||
| " \"" + FeeModes("\"\n\"") + "\""}, | ||
| {"verbose", RPCArg::Type::BOOL, /* default */ "false", "If true, return extra infomration about the transaction."}, | ||
| }, | ||
| { | ||
| RPCResult{"if verbose is not set or set to false", | ||
| RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. micro-nit: double space between |
||
| "the number of addresses." | ||
| }, | ||
| RPCResult{"if verbose is set to true", | ||
| RPCResult::Type::OBJ, "", "", | ||
| { | ||
| {RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n" | ||
| "the number of addresses."}, | ||
| {RPCResult::Type::STR, "fee reason", "The transaction fee reason."} | ||
| }, | ||
| }, | ||
| }, | ||
| RPCResult{ | ||
| RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n" | ||
| "the number of addresses." | ||
| }, | ||
| RPCExamples{ | ||
| "\nSend two amounts to two different addresses:\n" | ||
| + HelpExampleCli("sendmany", "\"\" \"{\\\"" + EXAMPLE_ADDRESS[0] + "\\\":0.01,\\\"" + EXAMPLE_ADDRESS[1] + "\\\":0.02}\"") + | ||
|
|
@@ -902,12 +931,14 @@ static RPCHelpMan sendmany() | |
|
|
||
| std::vector<CRecipient> recipients; | ||
| ParseRecipients(sendTo, subtractFeeFromAmount, recipients); | ||
| bool verbose = request.params[8].isNull() ? false : request.params[8].get_bool(); | ||
|
|
||
| return SendMoney(pwallet, coin_control, recipients, std::move(mapValue)); | ||
| return SendMoney(pwallet, coin_control, recipients, std::move(mapValue), verbose); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| static RPCHelpMan addmultisigaddress() | ||
| { | ||
| return RPCHelpMan{"addmultisigaddress", | ||
|
|
@@ -4501,8 +4532,8 @@ static const CRPCCommand commands[] = | |
| { "wallet", "removeprunedfunds", &removeprunedfunds, {"txid"} }, | ||
| { "wallet", "rescanblockchain", &rescanblockchain, {"start_height", "stop_height"} }, | ||
| { "wallet", "send", &send, {"outputs","conf_target","estimate_mode","options"} }, | ||
| { "wallet", "sendmany", &sendmany, {"dummy","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode"} }, | ||
| { "wallet", "sendtoaddress", &sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount","replaceable","conf_target","estimate_mode","avoid_reuse"} }, | ||
| { "wallet", "sendmany", &sendmany, {"dummy","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode","verbose"} }, | ||
| { "wallet", "sendtoaddress", &sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount","replaceable","conf_target","estimate_mode","avoid_reuse","verbose"} }, | ||
| { "wallet", "sethdseed", &sethdseed, {"newkeypool","seed"} }, | ||
| { "wallet", "setlabel", &setlabel, {"address","label"} }, | ||
| { "wallet", "settxfee", &settxfee, {"amount"} }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -661,6 +661,17 @@ def run_test(self): | |
| assert_array_result(tx["details"], {"category": "receive"}, expected_receive_vout) | ||
| assert_equal(tx[verbose_field], self.nodes[0].decoderawtransaction(tx["hex"])) | ||
|
|
||
| self.log.info("Test send* RPCs with verbose=True") | ||
| address = self.nodes[0].getnewaddress("test") | ||
| txid_feeReason_one = self.nodes[2].sendtoaddress(address = address, amount = 5, verbose = True) | ||
| assert_equal(txid_feeReason_one["fee_reason"], "Fallback fee") | ||
| txid_feeReason_two = self.nodes[2].sendmany(dummy = '', amounts = {address: 5}, verbose = True) | ||
| assert_equal(txid_feeReason_two["fee_reason"], "Fallback fee") | ||
|
||
| self.log.info("Test send* RPCs with verbose=False") | ||
| txid_feeReason_three = self.nodes[2].sendtoaddress(address = address, amount = 5, verbose = False) | ||
| assert_equal(self.nodes[2].gettransaction(txid_feeReason_three)['txid'], txid_feeReason_three) | ||
| txid_feeReason_four = self.nodes[2].sendmany(dummy = '', amounts = {address: 5}, verbose = False) | ||
| assert_equal(self.nodes[2].gettransaction(txid_feeReason_four)['txid'], txid_feeReason_four) | ||
|
|
||
| if __name__ == '__main__': | ||
| WalletTest().main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
micro-nit: spacing between
false:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason git is ignoring my whitespace changes. Any suggestions on how to fix that?