MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / AddInputs

Function AddInputs

src/rpc/rawtransaction_util.cpp:26–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#include <util/translation.h>
25
26void 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
75UniValue NormalizeOutputs(const UniValue& outputs_in)
76{

Callers 1

ConstructTransactionFunction · 0.85

Calls 9

ParseHashOFunction · 0.85
JSONRPCErrorFunction · 0.85
isNullMethod · 0.80
isNumMethod · 0.80
COutPointClass · 0.70
CScriptClass · 0.70
sizeMethod · 0.45
value_orMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected