Skip to content

Commit d42ca88

Browse files
committed
rpc: add dust arg to getsilentpaymentblockdata
1 parent f8817a6 commit d42ca88

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/rpc/blockchain.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ static RPCHelpMan getsilentpaymentblockdata()
720720
"\nReturns an array of hex-encoded strings data for the tweaked public key sum of candidate silent transaction inputs in each transaction.\n",
721721
{
722722
{"block_hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
723+
{"dust", RPCArg::Type::AMOUNT, RPCArg::Default{CAmount(0)}, strprintf("Dust threshold in satoshi (max %d): all outputs must be greater or equal. This filter has limited precision.", BIP352Index::max_dust_threshold)},
723724
},
724725
{
725726
RPCResult{
@@ -752,6 +753,14 @@ static RPCHelpMan getsilentpaymentblockdata()
752753
}
753754
}
754755

756+
CAmount dust_threshold{0};
757+
if (!request.params[1].isNull()) {
758+
dust_threshold = AmountFromValue(request.params[1], 0);
759+
if (dust_threshold > BIP352Index::max_dust_threshold) {
760+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("dust argument must be <= %d", BIP352Index::max_dust_threshold));
761+
}
762+
}
763+
755764
BIP352Index::tweak_index_entry tweak_index_entry;
756765
if (!g_bip352_index->FindSilentPayment(block_hash, tweak_index_entry)) {
757766
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block has not been indexed yet");
@@ -761,7 +770,9 @@ static RPCHelpMan getsilentpaymentblockdata()
761770
UniValue tweaks_res(UniValue::VARR);
762771

763772
for (const auto& entry : tweak_index_entry) {
764-
tweaks_res.push_back(HexStr(entry.first));
773+
if ((CAmount(entry.second) << BIP352Index::dust_shift) >= dust_threshold) {
774+
tweaks_res.push_back(HexStr(entry.first));
775+
}
765776
}
766777

767778
ret.pushKV("bip352_tweaks", tweaks_res);

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
310310
{ "stop", 0, "wait" },
311311
{ "addnode", 2, "v2transport" },
312312
{ "addconnection", 2, "v2transport" },
313+
{ "getsilentpaymentblockdata", 1, "dust"},
313314
};
314315
// clang-format on
315316

0 commit comments

Comments
 (0)