From 46c162df478f3b71bef8217f214ccf202576b733 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 6 Dec 2018 16:13:53 -0500 Subject: rpc: Avoid creating non-standard raw transactions Github-Pull: #14890 Rebased-From: fa4c8679ed94f215ce895938f7c3c169a2ce101e --- src/rpc/rawtransaction.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/rpc/rawtransaction.cpp') diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 0925b1c0cf..391e744c90 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -396,7 +396,6 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal rawTx.vin.push_back(in); } - std::set destinations; if (!outputs_is_obj) { // Translate array of key-value pairs into dict UniValue outputs_dict = UniValue(UniValue::VOBJ); @@ -412,8 +411,17 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal } outputs = std::move(outputs_dict); } + + // Duplicate checking + std::set destinations; + bool has_data{false}; + for (const std::string& name_ : outputs.getKeys()) { if (name_ == "data") { + if (has_data) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, duplicate key: data"); + } + has_data = true; std::vector data = ParseHexV(outputs[name_].getValStr(), "Data"); CTxOut out(0, CScript() << OP_RETURN << data); @@ -465,7 +473,8 @@ static UniValue createrawtransaction(const JSONRPCRequest& request) " } \n" " ,...\n" " ]\n" - "2. \"outputs\" (array, required) a json array with outputs (key-value pairs)\n" + "2. \"outputs\" (array, required) a json array with outputs (key-value pairs), where none of the keys are duplicated.\n" + "That is, each address can only appear once and there can only be one 'data' object.\n" " [\n" " {\n" " \"address\": x.xxx, (obj, optional) A key-value pair. The key (string) is the bitcoin address, the value (float or string) is the amount in " + CURRENCY_UNIT + "\n" @@ -1690,7 +1699,8 @@ UniValue createpsbt(const JSONRPCRequest& request) " } \n" " ,...\n" " ]\n" - "2. \"outputs\" (array, required) a json array with outputs (key-value pairs)\n" + "2. \"outputs\" (array, required) a json array with outputs (key-value pairs), where none of the keys are duplicated.\n" + "That is, each address can only appear once and there can only be one 'data' object.\n" " [\n" " {\n" " \"address\": x.xxx, (obj, optional) A key-value pair. The key (string) is the bitcoin address, the value (float or string) is the amount in " + CURRENCY_UNIT + "\n" -- cgit v1.2.3