|
20 | 20 | #include <deploymentstatus.h> |
21 | 21 | #include <flatfile.h> |
22 | 22 | #include <hash.h> |
| 23 | +#include <index/bip352.h> |
23 | 24 | #include <index/blockfilterindex.h> |
24 | 25 | #include <index/coinstatsindex.h> |
25 | 26 | #include <interfaces/mining.h> |
@@ -723,6 +724,62 @@ const RPCResult getblock_vin{ |
723 | 724 | } |
724 | 725 | }; |
725 | 726 |
|
| 727 | +static RPCHelpMan getsilentpaymentblockdata() |
| 728 | +{ |
| 729 | + return RPCHelpMan{"getsilentpaymentblockdata", |
| 730 | + "Returns an array of hex-encoded strings data for the tweaked public key sum of candidate silent transaction inputs in each transaction.\n", |
| 731 | + { |
| 732 | + {"block_hash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, |
| 733 | + }, |
| 734 | + { |
| 735 | + RPCResult{ |
| 736 | + RPCResult::Type::OBJ, "", "", |
| 737 | + { |
| 738 | + {RPCResult::Type::ARR, "bip352_tweaks", "The tweaked public key for each transaction that could be a silent payment", |
| 739 | + {{RPCResult::Type::STR_HEX, "tweak", "Hex-encoded data for the public key sum of candidate silent transaction inputs in the transaction"}} |
| 740 | + } |
| 741 | + }}, |
| 742 | + }, |
| 743 | + RPCExamples{ |
| 744 | + HelpExampleCli("getsilentpaymentblockdata", "\"00000000000000000002cbdf64ae445b53b545ba1e960f9e83787130d1530484\"") |
| 745 | + + HelpExampleRpc("getsilentpaymentblockdata", "\"00000000000000000002cbdf64ae445b53b545ba1e960f9e83787130d1530484\"") |
| 746 | + }, |
| 747 | + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 748 | +{ |
| 749 | + // TODO: add cut-through argument, check which index to use here |
| 750 | + if (!g_bip352_index) { |
| 751 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "Requires bip352index"); |
| 752 | + } |
| 753 | + |
| 754 | + uint256 block_hash(ParseHashV(request.params[0], "block_hash")); |
| 755 | + { |
| 756 | + ChainstateManager& chainman = EnsureAnyChainman(request.context); |
| 757 | + const CBlockIndex* block_index; |
| 758 | + LOCK(cs_main); |
| 759 | + block_index = chainman.m_blockman.LookupBlockIndex(block_hash); |
| 760 | + if (!block_index) { |
| 761 | + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); |
| 762 | + } |
| 763 | + } |
| 764 | + |
| 765 | + BIP352Index::tweak_index_entry tweak_index_entry; |
| 766 | + if (!g_bip352_index->FindSilentPayment(block_hash, tweak_index_entry)) { |
| 767 | + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block has not been indexed yet"); |
| 768 | + } |
| 769 | + |
| 770 | + UniValue ret(UniValue::VOBJ); |
| 771 | + UniValue tweaks_res(UniValue::VARR); |
| 772 | + |
| 773 | + for (const auto& entry : tweak_index_entry) { |
| 774 | + tweaks_res.push_back(HexStr(entry)); |
| 775 | + } |
| 776 | + |
| 777 | + ret.pushKV("bip352_tweaks", tweaks_res); |
| 778 | + return ret; |
| 779 | +}, |
| 780 | + }; |
| 781 | +} |
| 782 | + |
726 | 783 | static RPCHelpMan getblock() |
727 | 784 | { |
728 | 785 | return RPCHelpMan{ |
@@ -3433,6 +3490,7 @@ void RegisterBlockchainRPCCommands(CRPCTable& t) |
3433 | 3490 | {"blockchain", &getblockfrompeer}, |
3434 | 3491 | {"blockchain", &getblockhash}, |
3435 | 3492 | {"blockchain", &getblockheader}, |
| 3493 | + {"blockchain", &getsilentpaymentblockdata}, |
3436 | 3494 | {"blockchain", &getchaintips}, |
3437 | 3495 | {"blockchain", &getdifficulty}, |
3438 | 3496 | {"blockchain", &getdeploymentinfo}, |
|
0 commit comments