Skip to content

Commit f54f373

Browse files
committed
Merge #13498: [wallet] Fixups from account API deprecation
df10f07 [wallet] Don't use accounts when checking balance in sendmany (John Newbery) e209184 [wallet] deprecate sendfrom RPC method. (John Newbery) Pull request description: A couple of fixups from the accounts API deprecation PR (#12953): - properly deprecate `sendfrom` - don't use accounts when calculating balance in `sendmany` (unless the `-deprecatedrpc=accounts` flag is being used) Tree-SHA512: 1befde055067438c4c3391bbff1aaed0e6249efd708c567db3f1faad40a0f28e64f95e5bad0679ae826d24a0239e4bc8a1c392dc93e2e7502343a7f6b1d1845c
2 parents ee02deb + df10f07 commit f54f373

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,14 @@ static UniValue sendfrom(const JSONRPCRequest& request)
10211021
return NullUniValue;
10221022
}
10231023

1024+
if (!IsDeprecatedRPCEnabled("accounts")) {
1025+
if (request.fHelp) {
1026+
throw std::runtime_error("sendfrom (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
1027+
}
1028+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "sendfrom is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
1029+
}
1030+
1031+
10241032
if (request.fHelp || request.params.size() < 3 || request.params.size() > 6)
10251033
throw std::runtime_error(
10261034
"sendfrom \"fromaccount\" \"toaddress\" amount ( minconf \"comment\" \"comment_to\" )\n"
@@ -1259,9 +1267,11 @@ static UniValue sendmany(const JSONRPCRequest& request)
12591267
EnsureWalletIsUnlocked(pwallet);
12601268

12611269
// Check funds
1262-
CAmount nBalance = pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount);
1263-
if (totalAmount > nBalance)
1270+
if (IsDeprecatedRPCEnabled("accounts") && totalAmount > pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, &strAccount)) {
12641271
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
1272+
} else if (!IsDeprecatedRPCEnabled("accounts") && totalAmount > pwallet->GetLegacyBalance(ISMINE_SPENDABLE, nMinDepth, nullptr)) {
1273+
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Wallet has insufficient funds");
1274+
}
12651275

12661276
// Shuffle recipient list
12671277
std::shuffle(vecSend.begin(), vecSend.end(), FastRandomContext());
@@ -4429,7 +4439,6 @@ static const CRPCCommand commands[] =
44294439
{ "wallet", "listwallets", &listwallets, {} },
44304440
{ "wallet", "loadwallet", &loadwallet, {"filename"} },
44314441
{ "wallet", "lockunspent", &lockunspent, {"unlock","transactions"} },
4432-
{ "wallet", "sendfrom", &sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} },
44334442
{ "wallet", "sendmany", &sendmany, {"fromaccount|dummy","amounts","minconf","comment","subtractfeefrom","replaceable","conf_target","estimate_mode"} },
44344443
{ "wallet", "sendtoaddress", &sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount","replaceable","conf_target","estimate_mode"} },
44354444
{ "wallet", "settxfee", &settxfee, {"amount"} },
@@ -4451,6 +4460,7 @@ static const CRPCCommand commands[] =
44514460
{ "wallet", "listaccounts", &listaccounts, {"minconf","include_watchonly"} },
44524461
{ "wallet", "listreceivedbyaccount", &listreceivedbylabel, {"minconf","include_empty","include_watchonly"} },
44534462
{ "wallet", "setaccount", &setlabel, {"address","account"} },
4463+
{ "wallet", "sendfrom", &sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} },
44544464
{ "wallet", "move", &movecmd, {"fromaccount","toaccount","amount","minconf","comment"} },
44554465

44564466
/** Label functions (to replace non-balance account functions) */

test/functional/wallet_fallbackfee.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def run_test(self):
2121
self.restart_node(0, extra_args=["-fallbackfee=0"])
2222
assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
2323
assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].fundrawtransaction(self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1})))
24-
assert_raises_rpc_error(-4, "Fee estimation failed", lambda: self.nodes[0].sendfrom("", self.nodes[0].getnewaddress(), 1))
2524
assert_raises_rpc_error(-6, "Fee estimation failed", lambda: self.nodes[0].sendmany("", {self.nodes[0].getnewaddress(): 1}))
2625

2726
if __name__ == '__main__':

test/functional/wallet_labels.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def _run_subtest(self, accounts_api, node):
8585
# we want to reset so that the "" label has what's expected.
8686
# otherwise we're off by exactly the fee amount as that's mined
8787
# and matures in the next 100 blocks
88-
node.sendfrom("", common_address, fee)
88+
if accounts_api:
89+
node.sendfrom("", common_address, fee)
8990
amount_to_send = 1.0
9091

9192
# Create labels and make sure subsequent label API calls
@@ -125,7 +126,7 @@ def _run_subtest(self, accounts_api, node):
125126
if accounts_api:
126127
node.sendfrom(label.name, to_label.receive_address, amount_to_send)
127128
else:
128-
node.sendfrom(label.name, to_label.addresses[0], amount_to_send)
129+
node.sendtoaddress(to_label.addresses[0], amount_to_send)
129130
node.generate(1)
130131
for label in labels:
131132
if accounts_api:
@@ -166,7 +167,8 @@ def _run_subtest(self, accounts_api, node):
166167
label.add_address(multisig_address)
167168
label.purpose[multisig_address] = "send"
168169
label.verify(node)
169-
node.sendfrom("", multisig_address, 50)
170+
if accounts_api:
171+
node.sendfrom("", multisig_address, 50)
170172
node.generate(101)
171173
if accounts_api:
172174
for label in labels:

0 commit comments

Comments
 (0)