Skip to content

refactor: consolidate sendmany and sendtoaddress code #18202

Merged
meshcollider merged 1 commit into
bitcoin:masterfrom
Sjors:2020/02/refactor_sendmany_sendtoaddress
Jul 12, 2020
Merged

refactor: consolidate sendmany and sendtoaddress code #18202
meshcollider merged 1 commit into
bitcoin:masterfrom
Sjors:2020/02/refactor_sendmany_sendtoaddress

Conversation

@Sjors

@Sjors Sjors commented Feb 24, 2020

Copy link
Copy Markdown
Member

I consolidated code between these two RPC calls, since sendtoaddress is essentially sendmany with 1 destination.

Unless I overlooked something, the only behaviour change is that some sendtoaddress error codes changed from -4 to -6. The release note mentions this.

Salvaged from #18201.

@DrahtBot

DrahtBot commented Feb 24, 2020

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Sjors
Sjors force-pushed the 2020/02/refactor_sendmany_sendtoaddress branch from 771ca9f to c23298f Compare March 27, 2020 11:22
@Sjors

Sjors commented Mar 27, 2020

Copy link
Copy Markdown
Member Author

Rebased and added a helper function ParseRecipients() so that SendMoney is now a lot shorter.

@instagibbs

Copy link
Copy Markdown
Member

reACK a6e1761

even shorter nice

@Sjors
Sjors requested a review from sipa April 26, 2020 11:59
@Sjors
Sjors force-pushed the 2020/02/refactor_sendmany_sendtoaddress branch from a6e1761 to ed2fc36 Compare May 4, 2020 10:51
@Sjors

Sjors commented May 4, 2020

Copy link
Copy Markdown
Member Author

Rebased after #16426

@Sjors
Sjors force-pushed the 2020/02/refactor_sendmany_sendtoaddress branch from ed2fc36 to 443a740 Compare May 4, 2020 18:37
@Sjors

Sjors commented May 4, 2020

Copy link
Copy Markdown
Member Author

Rebased again after #18699

The only new behavior is some error codes are changed from -4 to -6.
@Sjors
Sjors force-pushed the 2020/02/refactor_sendmany_sendtoaddress branch from 443a740 to 08fc6f6 Compare June 19, 2020 09:29

@fjahr fjahr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 08fc6f6

Nice refactor.

Comment thread src/wallet/rpcwallet.cpp
for (unsigned int idx = 0; idx < subtract_fee_outputs.size(); idx++) {
const UniValue& addr = subtract_fee_outputs[idx];
if (addr.get_str() == address) {
subtract_fee = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subtract_fee = true;
subtract_fee = true;
break;

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 08fc6f6

Some suggestions below. Feel free to ignore the style nits.

---------------------

- To make RPC `sendtoaddress` more consistent with `sendmany` the following error
`sendtoaddress` codes were changed from `-4` to `-6`:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

08fc6f6 suggestion

-- To make RPC `sendtoaddress` more consistent with `sendmany` the following error
-    `sendtoaddress` codes were changed from `-4` to `-6`:
+- To make RPC `sendtoaddress` more consistent with `sendmany`, the following
+  `sendtoaddress` error codes are changed from `-4` to `-6`:

Comment thread src/wallet/rpcwallet.cpp
if (nValue > curBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
bool subtract_fee = false;
for (unsigned int idx = 0; idx < subtract_fee_outputs.size(); idx++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while retouching this code, could update to the current convention

Suggested change
for (unsigned int idx = 0; idx < subtract_fee_outputs.size(); idx++) {
for (unsigned int idx = 0; idx < subtract_fee_outputs.size(); ++idx) {

Comment thread src/wallet/rpcwallet.cpp
std::vector<CRecipient> recipients;
ParseRecipients(address_amounts, subtractFeeFromAmount, recipients);

return SendMoney(pwallet, coin_control, recipients, mapValue);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use move for mapValue here as well?

Suggested change
return SendMoney(pwallet, coin_control, recipients, mapValue);
return SendMoney(pwallet, coin_control, recipients, std::move(mapValue));

@Sjors

Sjors commented Jun 23, 2020

Copy link
Copy Markdown
Member Author

Thanks, I'll address the above nits if this PR needs touching.

@meshcollider meshcollider left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review & functional test run ACK 08fc6f6

Nits can be left for followup

@meshcollider
meshcollider merged commit 4db44ac into bitcoin:master Jul 12, 2020
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Jul 13, 2020
Update the Namecoin-specific wallet code (e.g. sending transactions
with name inputs, sendtomany) for the upstream refactor in
bitcoin/bitcoin#18202.
@Sjors
Sjors deleted the 2020/02/refactor_sendmany_sendtoaddress branch July 14, 2020 15:36
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 31, 2021
Summary:
The only new behavior is some error codes are changed from -4 to -6.

This is a backport of [[bitcoin/bitcoin#18202 | core#18202]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9993
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.