| 24 | #include <util/translation.h> |
| 25 | |
| 26 | void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, std::optional<bool> rbf) |
| 27 | { |
| 28 | UniValue inputs; |
| 29 | if (inputs_in.isNull()) { |
| 30 | inputs = UniValue::VARR; |
| 31 | } else { |
| 32 | inputs = inputs_in.get_array(); |
| 33 | } |
| 34 | |
| 35 | for (unsigned int idx = 0; idx < inputs.size(); idx++) { |
| 36 | const UniValue& input = inputs[idx]; |
| 37 | const UniValue& o = input.get_obj(); |
| 38 | |
| 39 | Txid txid = Txid::FromUint256(ParseHashO(o, "txid")); |
| 40 | |
| 41 | const UniValue& vout_v = o.find_value("vout"); |
| 42 | if (!vout_v.isNum()) |
| 43 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); |
| 44 | int nOutput = vout_v.getInt<int>(); |
| 45 | if (nOutput < 0) |
| 46 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); |
| 47 | |
| 48 | uint32_t nSequence; |
| 49 | |
| 50 | if (rbf.value_or(true)) { |
| 51 | nSequence = MAX_BIP125_RBF_SEQUENCE; /* CTxIn::SEQUENCE_FINAL - 2 */ |
| 52 | } else if (rawTx.nLockTime) { |
| 53 | nSequence = CTxIn::MAX_SEQUENCE_NONFINAL; /* CTxIn::SEQUENCE_FINAL - 1 */ |
| 54 | } else { |
| 55 | nSequence = CTxIn::SEQUENCE_FINAL; |
| 56 | } |
| 57 | |
| 58 | // set the sequence number if passed in the parameters object |
| 59 | const UniValue& sequenceObj = o.find_value("sequence"); |
| 60 | if (sequenceObj.isNum()) { |
| 61 | int64_t seqNr64 = sequenceObj.getInt<int64_t>(); |
| 62 | if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL) { |
| 63 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range"); |
| 64 | } else { |
| 65 | nSequence = (uint32_t)seqNr64; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence); |
| 70 | |
| 71 | rawTx.vin.push_back(in); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | UniValue NormalizeOutputs(const UniValue& outputs_in) |
| 76 | { |
no test coverage detected