Motivation
Each key may only appear once, i.e. there can only be one ‘data’ output, and no address may be duplicated.
https://bitcoincore.org/en/doc/29.0.0/rpc/rawtransactions/createrawtransaction/
If and when #32406 gets merged, it will be helpful to use multiple data outputs while creating a transaction.
Related comment: #32406 (comment)
Possible solution
Remove the check for duplicate data key.
Relevant function:
0std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs)
1{
2 // Duplicate checking
3 std::set<CTxDestination> destinations;
4 std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs;
5 bool has_data{false};
6 for (const std::string& name_ : outputs.getKeys()) {
7 if (name_ == "data") {
8 if (has_data) {
9 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, duplicate key: data");
10 }
11 has_data = true;
12 std::vector<unsigned char> data = ParseHexV(outputs[name_].getValStr(), "Data");
13 CTxDestination destination{CNoDestination{CScript() << OP_RETURN << data}};
14 CAmount amount{0};
15 parsed_outputs.emplace_back(destination, amount);
16 } else {
17 CTxDestination destination{DecodeDestination(name_)};
18 CAmount amount{AmountFromValue(outputs[name_])};
19 if (!IsValidDestination(destination)) {
20 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ") + name_);
21 }
22
23 if (!destinations.insert(destination).second) {
24 throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + name_);
25 }
26 parsed_outputs.emplace_back(destination, amount);
27 }
28 }
29 return parsed_outputs;
30}
Useful Skills
- Compiling Bitcoin Core from source
- Running the C++ unit tests and the Python functional tests
Guidance for new contributors
Want to work on this issue?
For guidance on contributing, please read CONTRIBUTING.md before opening your pull request.