Auto merge of #2790 - bitcartel:2746_payment_disclosure_prefix, r=str4d
Closes #2746. Payment disclosure blobs now use 'zpd:' prefix.
This commit is contained in:
commit
f44a4cea42
|
@ -175,6 +175,17 @@ class PaymentDisclosureTest (BitcoinTestFramework):
|
|||
assert_equal(result["message"], message)
|
||||
assert_equal(result["value"], output_value_sum)
|
||||
|
||||
# Confirm that payment disclosure begins with prefix zpd:
|
||||
assert(pd.startswith("zpd:"))
|
||||
|
||||
# Confirm that payment disclosure without prefix zpd: fails validation
|
||||
try:
|
||||
self.nodes[1].z_validatepaymentdisclosure(pd[4:])
|
||||
assert(False)
|
||||
except JSONRPCException as e:
|
||||
errorString = e.error['message']
|
||||
assert("payment disclosure prefix not found" in errorString)
|
||||
|
||||
# Check that total value of output index 0 and index 1 should equal shielding amount of 40 less standard fee.
|
||||
pd = self.nodes[0].z_getpaymentdisclosure(txid, 0, 1)
|
||||
result = self.nodes[0].z_validatepaymentdisclosure(pd)
|
||||
|
|
|
@ -88,6 +88,8 @@ public:
|
|||
// This test creates random payment disclosure blobs and checks that they can be
|
||||
// 1. inserted and retrieved from a database
|
||||
// 2. serialized and deserialized without corruption
|
||||
// Note that the zpd: prefix is not part of the payment disclosure blob itself. It is only
|
||||
// used as convention to improve the user experience when sharing payment disclosure blobs.
|
||||
TEST(paymentdisclosure, mainnet) {
|
||||
ECC_Start();
|
||||
SelectParams(CBaseChainParams::MAIN);
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
|
||||
#define PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL 0
|
||||
|
||||
#define PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX "zpd:"
|
||||
|
||||
typedef JSOutPoint PaymentDisclosureKey;
|
||||
|
||||
struct PaymentDisclosureInfo {
|
||||
|
|
|
@ -59,7 +59,7 @@ UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp)
|
|||
"3. \"output_index\" (string, required) \n"
|
||||
"4. \"message\" (string, optional) \n"
|
||||
"\nResult:\n"
|
||||
"\"paymentblob\" (string) Hex string of payment blob\n"
|
||||
"\"paymentdisclosure\" (string) Hex data string, with \"zpd:\" prefix.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_getpaymentdisclosure", "96f12882450429324d5f3b48630e3168220e49ab7b0f066e5c2935a6b88bb0f2 0 0 \"refund\"")
|
||||
+ HelpExampleRpc("z_getpaymentdisclosure", "\"96f12882450429324d5f3b48630e3168220e49ab7b0f066e5c2935a6b88bb0f2\", 0, 0, \"refund\"")
|
||||
|
@ -134,7 +134,7 @@ UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp)
|
|||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << pd;
|
||||
string strHex = HexStr(ss.begin(), ss.end());
|
||||
return strHex;
|
||||
return PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX + strHex;
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,10 +160,10 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
|
|||
"\nEXPERIMENTAL FEATURE\n"
|
||||
+ strPaymentDisclosureDisabledMsg +
|
||||
"\nArguments:\n"
|
||||
"1. \"paymentdisclosure\" (string, required) Hex data string\n"
|
||||
"1. \"paymentdisclosure\" (string, required) Hex data string, with \"zpd:\" prefix.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("z_validatepaymentdisclosure", "\"hexblob\"")
|
||||
+ HelpExampleRpc("z_validatepaymentdisclosure", "\"hexblob\"")
|
||||
+ HelpExampleCli("z_validatepaymentdisclosure", "\"zpd:706462ff004c561a0447ba2ec51184e6c204...\"")
|
||||
+ HelpExampleRpc("z_validatepaymentdisclosure", "\"zpd:706462ff004c561a0447ba2ec51184e6c204...\"")
|
||||
);
|
||||
|
||||
if (!fEnablePaymentDisclosure) {
|
||||
|
@ -174,7 +174,13 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
|
|||
|
||||
EnsureWalletIsUnlocked();
|
||||
|
||||
string hexInput = params[0].get_str();
|
||||
// Verify the payment disclosure input begins with "zpd:" prefix.
|
||||
string strInput = params[0].get_str();
|
||||
size_t pos = strInput.find(PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX);
|
||||
if (pos != 0) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, payment disclosure prefix not found.");
|
||||
}
|
||||
string hexInput = strInput.substr(strlen(PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX));
|
||||
if (!IsHex(hexInput))
|
||||
{
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected payment disclosure data in hexadecimal format.");
|
||||
|
|
Loading…
Reference in New Issue