| 100 | } |
| 101 | |
| 102 | std::vector<std::pair<CTxDestination, CAmount>> ParseOutputs(const UniValue& outputs) |
| 103 | { |
| 104 | // Duplicate checking |
| 105 | std::set<CTxDestination> destinations; |
| 106 | std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs; |
| 107 | bool has_data{false}; |
| 108 | for (const std::string& name_ : outputs.getKeys()) { |
| 109 | if (name_ == "data") { |
| 110 | if (has_data) { |
| 111 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, duplicate key: data"); |
| 112 | } |
| 113 | has_data = true; |
| 114 | std::vector<unsigned char> data = ParseHexV(outputs[name_].getValStr(), "Data"); |
| 115 | CTxDestination destination{CNoDestination{CScript() << OP_RETURN << data}}; |
| 116 | CAmount amount{0}; |
| 117 | parsed_outputs.emplace_back(destination, amount); |
| 118 | } else { |
| 119 | CTxDestination destination{DecodeDestination(name_)}; |
| 120 | CAmount amount{AmountFromValue(outputs[name_])}; |
| 121 | if (!IsValidDestination(destination)) { |
| 122 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Bitcoin address: ") + name_); |
| 123 | } |
| 124 | |
| 125 | if (!destinations.insert(destination).second) { |
| 126 | throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated address: ") + name_); |
| 127 | } |
| 128 | parsed_outputs.emplace_back(destination, amount); |
| 129 | } |
| 130 | } |
| 131 | return parsed_outputs; |
| 132 | } |
| 133 | |
| 134 | void AddOutputs(CMutableTransaction& rawTx, const UniValue& outputs_in) |
| 135 | { |
no test coverage detected