Allow multiple data outputs in createrawtransaction and createpsbt #32478

issue 1440000bytes openend this issue on May 13, 2025
  1. 1440000bytes commented at 10:46 am on May 13, 2025: none

    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}
    

    https://github.com/bitcoin/bitcoin/blob/663a9cabf811e2fc53102bc6da00d09fc99d1d81/src/rpc/rawtransaction_util.cpp#L100

    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.

  2. 1440000bytes added the label good first issue on May 13, 2025
  3. maflcko removed the label good first issue on May 13, 2025
  4. maflcko added the label RPC/REST/ZMQ on May 13, 2025
  5. maflcko added this to the milestone 31.0 on May 13, 2025
  6. maflcko commented at 11:00 am on May 13, 2025: member

    If and when #32406 gets merged

    The policy change isn’t merged, and if it was merged, any wallet or rpc features usually come one release later. So I’ve removed the “good first issue” label and moved the milestone back.


1440000bytes maflcko

Labels
RPC/REST/ZMQ

Milestone
31.0


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-05-30 12:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me