Skip to content

Commit

Permalink
rpc: add getsilentpaymenttxdata
Browse files Browse the repository at this point in the history
Co-authored-by: w0xlt <woltx@protonmail.com>
  • Loading branch information
Sjors and w0xlt committed Sep 20, 2023
1 parent 0235ff2 commit 8b63994
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index/silentpaymentindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,9 @@ bool SilentPaymentIndex::CustomAppend(const interfaces::BlockInfo& block)
return m_db->WriteSilentPayments(items);
}

bool SilentPaymentIndex::FindSilentPayment(const uint256& tx_hash, CPubKey& tweakedPubKeySum) const
{
return m_db->Read(std::make_pair(DB_SILENT_PAYMENT_INDEX, tx_hash), tweakedPubKeySum);
}

BaseIndex::DB& SilentPaymentIndex::GetDB() const { return *m_db; }
1 change: 1 addition & 0 deletions src/index/silentpaymentindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SilentPaymentIndex final : public BaseIndex
// Destructor is declared because this class contains a unique_ptr to an incomplete type.
virtual ~SilentPaymentIndex() override;

bool FindSilentPayment(const uint256& tx_hash, CPubKey& tweakedPubKeySum) const;
};

/// The global txo silent payment index. May be null.
Expand Down
41 changes: 41 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <hash.h>
#include <index/blockfilterindex.h>
#include <index/coinstatsindex.h>
#include <index/silentpaymentindex.h>
#include <kernel/coinstats.h>
#include <logging/timer.h>
#include <net.h>
Expand Down Expand Up @@ -640,6 +641,45 @@ const RPCResult getblock_vin{
}
};

static RPCHelpMan getsilentpaymenttxdata()
{
return RPCHelpMan{"getsilentpaymenttxdata",
"\nReturns a string that is serialized, hex-encoded data for the public key sum of candidate silent transaction inputs in the transaction.\n",
{
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hash"},
},
{
RPCResult{
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR_HEX, "data", "A string that is serialized, hex-encoded data for the public key sum of candidate silent transaction inputs in the transaction"},
}},
},
RPCExamples{
HelpExampleCli("getsilentpaymenttxdata", "\"00000000000000000002cbdf64ae445b53b545ba1e960f9e83787130d1530484\"")
+ HelpExampleRpc("getsilentpaymenttxdata", "\"00000000000000000002cbdf64ae445b53b545ba1e960f9e83787130d1530484\"")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
if (!g_silent_payment_index) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Requires silentpaymentindex");
}

uint256 txid(ParseHashV(request.params[0], "txid"));

CPubKey tweak;
// TODO: this shouldn't be an error
if (!g_silent_payment_index->FindSilentPayment(txid, tweak)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Not a silent payment");
}

UniValue ret(UniValue::VOBJ);
ret.pushKV("data", HexStr(tweak));
return ret;
},
};
}

static RPCHelpMan getblock()
{
return RPCHelpMan{"getblock",
Expand Down Expand Up @@ -2711,6 +2751,7 @@ void RegisterBlockchainRPCCommands(CRPCTable& t)
{"blockchain", &getblockfrompeer},
{"blockchain", &getblockhash},
{"blockchain", &getblockheader},
{"blockchain", &getsilentpaymenttxdata},
{"blockchain", &getchaintips},
{"blockchain", &getdifficulty},
{"blockchain", &getdeploymentinfo},
Expand Down
1 change: 1 addition & 0 deletions src/test/fuzz/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
"waitforblock",
"waitforblockheight",
"waitfornewblock",
"getsilentpaymenttxdata"
};

std::string ConsumeScalarRPCArgument(FuzzedDataProvider& fuzzed_data_provider)
Expand Down

0 comments on commit 8b63994

Please sign in to comment.