From 61345ae70320f2242e83181c799eb044e6af3461 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 7 Dec 2017 10:11:43 -0800 Subject: [PATCH] Closes #2746. Payment disclosure blobs now use 'zpd:' prefix. --- qa/rpc-tests/paymentdisclosure.py | 11 +++++++++++ src/gtest/test_paymentdisclosure.cpp | 4 +++- src/paymentdisclosure.h | 2 ++ src/wallet/rpcdisclosure.cpp | 18 ++++++++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/paymentdisclosure.py b/qa/rpc-tests/paymentdisclosure.py index 60d6f188f..bc873897a 100755 --- a/qa/rpc-tests/paymentdisclosure.py +++ b/qa/rpc-tests/paymentdisclosure.py @@ -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) diff --git a/src/gtest/test_paymentdisclosure.cpp b/src/gtest/test_paymentdisclosure.cpp index e87c89297..ddab3c7e6 100644 --- a/src/gtest/test_paymentdisclosure.cpp +++ b/src/gtest/test_paymentdisclosure.cpp @@ -87,7 +87,9 @@ 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 +// 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); diff --git a/src/paymentdisclosure.h b/src/paymentdisclosure.h index b4f56eb45..e6a995ab4 100644 --- a/src/paymentdisclosure.h +++ b/src/paymentdisclosure.h @@ -28,6 +28,8 @@ #define PAYMENT_DISCLOSURE_VERSION_EXPERIMENTAL 0 +#define PAYMENT_DISCLOSURE_BLOB_STRING_PREFIX "zpd:" + typedef JSOutPoint PaymentDisclosureKey; struct PaymentDisclosureInfo { diff --git a/src/wallet/rpcdisclosure.cpp b/src/wallet/rpcdisclosure.cpp index c1c8cb87c..539cf4b2a 100644 --- a/src/wallet/rpcdisclosure.cpp +++ b/src/wallet/rpcdisclosure.cpp @@ -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.");