@@ -528,11 +528,26 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
528
528
if (!params[1 ].isNull ())
529
529
min_depth = params[1 ].get_int ();
530
530
531
+ const bool include_immature_coinbase{params[2 ].isNull () ? false : params[2 ].get_bool ()};
532
+
533
+ // Excluding coinbase outputs is deprecated
534
+ // It can be enabled by setting deprecatedrpc=exclude_coinbase
535
+ const bool include_coinbase{!wallet.chain ().rpcEnableDeprecated (" exclude_coinbase" )};
536
+
537
+ if (include_immature_coinbase && !include_coinbase) {
538
+ throw JSONRPCError (RPC_INVALID_PARAMETER, " include_immature_coinbase is incompatible with deprecated exclude_coinbase" );
539
+ }
540
+
531
541
// Tally
532
542
CAmount amount = 0 ;
533
543
for (const std::pair<const uint256, CWalletTx>& wtx_pair : wallet.mapWallet ) {
534
544
const CWalletTx& wtx = wtx_pair.second ;
535
- if (wtx.IsCoinBase () || !wallet.chain ().checkFinalTx (*wtx.tx ) || wallet.GetTxDepthInMainChain (wtx) < min_depth) {
545
+ int depth{wallet.GetTxDepthInMainChain (wtx)};
546
+ if (depth < min_depth
547
+ // Coinbase with less than 1 confirmation is no longer in the main chain
548
+ || (wtx.IsCoinBase () && (depth < 1 || !include_coinbase))
549
+ || (wallet.IsTxImmatureCoinBase (wtx) && !include_immature_coinbase)
550
+ || !wallet.chain ().checkFinalTx (*wtx.tx )) {
536
551
continue ;
537
552
}
538
553
@@ -555,6 +570,7 @@ static RPCHelpMan getreceivedbyaddress()
555
570
{
556
571
{" address" , RPCArg::Type::STR, RPCArg::Optional::NO, " The bitcoin address for transactions." },
557
572
{" minconf" , RPCArg::Type::NUM, RPCArg::Default{1 }, " Only include transactions confirmed at least this many times." },
573
+ {" include_immature_coinbase" , RPCArg::Type::BOOL, RPCArg::Default{false }, " Include immature coinbase transactions." },
558
574
},
559
575
RPCResult{
560
576
RPCResult::Type::STR_AMOUNT, " amount" , " The total amount in " + CURRENCY_UNIT + " received at this address."
@@ -566,6 +582,8 @@ static RPCHelpMan getreceivedbyaddress()
566
582
+ HelpExampleCli (" getreceivedbyaddress" , " \" " + EXAMPLE_ADDRESS[0 ] + " \" 0" ) +
567
583
" \n The amount with at least 6 confirmations\n "
568
584
+ HelpExampleCli (" getreceivedbyaddress" , " \" " + EXAMPLE_ADDRESS[0 ] + " \" 6" ) +
585
+ " \n The amount with at least 6 confirmations including immature coinbase outputs\n "
586
+ + HelpExampleCli (" getreceivedbyaddress" , " \" " + EXAMPLE_ADDRESS[0 ] + " \" 6 true" ) +
569
587
" \n As a JSON-RPC call\n "
570
588
+ HelpExampleRpc (" getreceivedbyaddress" , " \" " + EXAMPLE_ADDRESS[0 ] + " \" , 6" )
571
589
},
@@ -593,6 +611,7 @@ static RPCHelpMan getreceivedbylabel()
593
611
{
594
612
{" label" , RPCArg::Type::STR, RPCArg::Optional::NO, " The selected label, may be the default label using \"\" ." },
595
613
{" minconf" , RPCArg::Type::NUM, RPCArg::Default{1 }, " Only include transactions confirmed at least this many times." },
614
+ {" include_immature_coinbase" , RPCArg::Type::BOOL, RPCArg::Default{false }, " Include immature coinbase transactions." },
596
615
},
597
616
RPCResult{
598
617
RPCResult::Type::STR_AMOUNT, " amount" , " The total amount in " + CURRENCY_UNIT + " received for this label."
@@ -604,8 +623,10 @@ static RPCHelpMan getreceivedbylabel()
604
623
+ HelpExampleCli (" getreceivedbylabel" , " \" tabby\" 0" ) +
605
624
" \n The amount with at least 6 confirmations\n "
606
625
+ HelpExampleCli (" getreceivedbylabel" , " \" tabby\" 6" ) +
626
+ " \n The amount with at least 6 confirmations including immature coinbase outputs\n "
627
+ + HelpExampleCli (" getreceivedbylabel" , " \" tabby\" 6 true" ) +
607
628
" \n As a JSON-RPC call\n "
608
- + HelpExampleRpc (" getreceivedbylabel" , " \" tabby\" , 6" )
629
+ + HelpExampleRpc (" getreceivedbylabel" , " \" tabby\" , 6, true " )
609
630
},
610
631
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
611
632
{
@@ -894,7 +915,7 @@ struct tallyitem
894
915
}
895
916
};
896
917
897
- static UniValue ListReceived (const CWallet& wallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
918
+ static UniValue ListReceived (const CWallet& wallet, const UniValue& params, const bool by_label, const bool include_immature_coinbase ) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
898
919
{
899
920
// Minimum confirmations
900
921
int nMinDepth = 1 ;
@@ -914,27 +935,38 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, bool
914
935
915
936
bool has_filtered_address = false ;
916
937
CTxDestination filtered_address = CNoDestination ();
917
- if (!by_label && params. size () > 3 ) {
938
+ if (!by_label && ! params[ 3 ]. isNull () && !params[ 3 ]. get_str (). empty () ) {
918
939
if (!IsValidDestinationString (params[3 ].get_str ())) {
919
940
throw JSONRPCError (RPC_WALLET_ERROR, " address_filter parameter was invalid" );
920
941
}
921
942
filtered_address = DecodeDestination (params[3 ].get_str ());
922
943
has_filtered_address = true ;
923
944
}
924
945
946
+ // Excluding coinbase outputs is deprecated
947
+ // It can be enabled by setting deprecatedrpc=exclude_coinbase
948
+ const bool include_coinbase{!wallet.chain ().rpcEnableDeprecated (" exclude_coinbase" )};
949
+
950
+ if (include_immature_coinbase && !include_coinbase) {
951
+ throw JSONRPCError (RPC_INVALID_PARAMETER, " include_immature_coinbase is incompatible with deprecated exclude_coinbase" );
952
+ }
953
+
925
954
// Tally
926
955
std::map<CTxDestination, tallyitem> mapTally;
927
956
for (const std::pair<const uint256, CWalletTx>& pairWtx : wallet.mapWallet ) {
928
957
const CWalletTx& wtx = pairWtx.second ;
929
958
930
- if (wtx.IsCoinBase () || !wallet.chain ().checkFinalTx (*wtx.tx )) {
931
- continue ;
932
- }
933
-
934
959
int nDepth = wallet.GetTxDepthInMainChain (wtx);
935
960
if (nDepth < nMinDepth)
936
961
continue ;
937
962
963
+ // Coinbase with less than 1 confirmation is no longer in the main chain
964
+ if ((wtx.IsCoinBase () && (nDepth < 1 || !include_coinbase))
965
+ || (wallet.IsTxImmatureCoinBase (wtx) && !include_immature_coinbase)
966
+ || !wallet.chain ().checkFinalTx (*wtx.tx )) {
967
+ continue ;
968
+ }
969
+
938
970
for (const CTxOut& txout : wtx.tx ->vout )
939
971
{
940
972
CTxDestination address;
@@ -1049,7 +1081,8 @@ static RPCHelpMan listreceivedbyaddress()
1049
1081
{" minconf" , RPCArg::Type::NUM, RPCArg::Default{1 }, " The minimum number of confirmations before payments are included." },
1050
1082
{" include_empty" , RPCArg::Type::BOOL, RPCArg::Default{false }, " Whether to include addresses that haven't received any payments." },
1051
1083
{" include_watchonly" , RPCArg::Type::BOOL, RPCArg::DefaultHint{" true for watch-only wallets, otherwise false" }, " Whether to include watch-only addresses (see 'importaddress')" },
1052
- {" address_filter" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " If present, only return information on this address." },
1084
+ {" address_filter" , RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, " If present and non-empty, only return information on this address." },
1085
+ {" include_immature_coinbase" , RPCArg::Type::BOOL, RPCArg::Default{false }, " Include immature coinbase transactions." },
1053
1086
},
1054
1087
RPCResult{
1055
1088
RPCResult::Type::ARR, " " , " " ,
@@ -1071,8 +1104,9 @@ static RPCHelpMan listreceivedbyaddress()
1071
1104
RPCExamples{
1072
1105
HelpExampleCli (" listreceivedbyaddress" , " " )
1073
1106
+ HelpExampleCli (" listreceivedbyaddress" , " 6 true" )
1107
+ + HelpExampleCli (" listreceivedbyaddress" , " 6 true true \"\" true" )
1074
1108
+ HelpExampleRpc (" listreceivedbyaddress" , " 6, true, true" )
1075
- + HelpExampleRpc (" listreceivedbyaddress" , " 6, true, true, \" " + EXAMPLE_ADDRESS[0 ] + " \" " )
1109
+ + HelpExampleRpc (" listreceivedbyaddress" , " 6, true, true, \" " + EXAMPLE_ADDRESS[0 ] + " \" , true " )
1076
1110
},
1077
1111
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1078
1112
{
@@ -1083,9 +1117,11 @@ static RPCHelpMan listreceivedbyaddress()
1083
1117
// the user could have gotten from another RPC command prior to now
1084
1118
pwallet->BlockUntilSyncedToCurrentChain ();
1085
1119
1120
+ const bool include_immature_coinbase{request.params [4 ].isNull () ? false : request.params [4 ].get_bool ()};
1121
+
1086
1122
LOCK (pwallet->cs_wallet );
1087
1123
1088
- return ListReceived (*pwallet, request.params , false );
1124
+ return ListReceived (*pwallet, request.params , false , include_immature_coinbase );
1089
1125
},
1090
1126
};
1091
1127
}
@@ -1098,6 +1134,7 @@ static RPCHelpMan listreceivedbylabel()
1098
1134
{" minconf" , RPCArg::Type::NUM, RPCArg::Default{1 }, " The minimum number of confirmations before payments are included." },
1099
1135
{" include_empty" , RPCArg::Type::BOOL, RPCArg::Default{false }, " Whether to include labels that haven't received any payments." },
1100
1136
{" include_watchonly" , RPCArg::Type::BOOL, RPCArg::DefaultHint{" true for watch-only wallets, otherwise false" }, " Whether to include watch-only addresses (see 'importaddress')" },
1137
+ {" include_immature_coinbase" , RPCArg::Type::BOOL, RPCArg::Default{false }, " Include immature coinbase transactions." },
1101
1138
},
1102
1139
RPCResult{
1103
1140
RPCResult::Type::ARR, " " , " " ,
@@ -1114,7 +1151,7 @@ static RPCHelpMan listreceivedbylabel()
1114
1151
RPCExamples{
1115
1152
HelpExampleCli (" listreceivedbylabel" , " " )
1116
1153
+ HelpExampleCli (" listreceivedbylabel" , " 6 true" )
1117
- + HelpExampleRpc (" listreceivedbylabel" , " 6, true, true" )
1154
+ + HelpExampleRpc (" listreceivedbylabel" , " 6, true, true, true " )
1118
1155
},
1119
1156
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1120
1157
{
@@ -1125,9 +1162,11 @@ static RPCHelpMan listreceivedbylabel()
1125
1162
// the user could have gotten from another RPC command prior to now
1126
1163
pwallet->BlockUntilSyncedToCurrentChain ();
1127
1164
1165
+ const bool include_immature_coinbase{request.params [3 ].isNull () ? false : request.params [3 ].get_bool ()};
1166
+
1128
1167
LOCK (pwallet->cs_wallet );
1129
1168
1130
- return ListReceived (*pwallet, request.params , true );
1169
+ return ListReceived (*pwallet, request.params , true , include_immature_coinbase );
1131
1170
},
1132
1171
};
1133
1172
}
0 commit comments