33 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
42 int nOutput = vout_v.
getInt<
int>();
48 if (rbf.value_or(
true)) {
58 if (sequenceObj.
isNum()) {
59 int64_t seqNr64 = sequenceObj.
getInt<int64_t>();
63 nSequence = (uint32_t)seqNr64;
69 rawTx.
vin.push_back(in);
79 const bool outputs_is_obj = outputs_in.
isObject();
82 if (!outputs_is_obj) {
85 for (
size_t i = 0; i < outputs.
size(); ++i) {
90 if (output.
size() != 1) {
95 outputs = std::move(outputs_dict);
99 std::set<CTxDestination> destinations;
100 bool has_data{
false};
102 for (
const std::string& name_ : outputs.
getKeys()) {
103 if (name_ ==
"data") {
108 std::vector<unsigned char> data =
ParseHexV(outputs[name_].getValStr(),
"Data");
118 if (!destinations.insert(destination).second) {
136 int64_t nLockTime = locktime.
getInt<int64_t>();
162 entry.
pushKV(
"witness", witness);
165 entry.
pushKV(
"error", strMessage);
171 if (!prevTxsUnival.
isNull()) {
173 for (
unsigned int idx = 0; idx < prevTxs.
size(); ++idx) {
196 std::vector<unsigned char> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
197 CScript scriptPubKey(pkData.begin(), pkData.end());
200 auto coin = coins.find(
out);
201 if (coin != coins.end() && !coin->second.IsSpent() && coin->second.out.scriptPubKey != scriptPubKey) {
202 std::string err(
"Previous output scriptPubKey mismatch:\n");
203 err = err +
ScriptToAsmStr(coin->second.out.scriptPubKey) +
"\nvs:\n"+
210 if (prevOut.
exists(
"amount")) {
214 coins[
out] = std::move(newcoin);
218 const bool is_p2sh = scriptPubKey.IsPayToScriptHash();
219 const bool is_p2wsh = scriptPubKey.IsPayToWitnessScriptHash();
220 if (keystore && (is_p2sh || is_p2wsh)) {
228 if (rs.isNull() && ws.isNull()) {
233 std::vector<unsigned char> scriptData(!ws.isNull() ?
ParseHexV(ws,
"witnessScript") :
ParseHexV(rs,
"redeemScript"));
234 CScript script(scriptData.begin(), scriptData.end());
241 if (!ws.isNull() && !rs.isNull()) {
246 if (ws.get_str() != rs.get_str()) {
247 std::vector<unsigned char> redeemScriptData(
ParseHexV(rs,
"redeemScript"));
248 CScript redeemScript(redeemScriptData.begin(), redeemScriptData.end());
249 if (redeemScript != witness_output_script) {
275 }
else if (is_p2wsh) {
295 std::map<int, bilingual_str> input_errors;
297 bool complete =
SignTransaction(mtx, keystore, coins, nHashType, input_errors);
305 for (
const auto& err_pair : input_errors) {
306 if (err_pair.second.original ==
"Missing amount") {
314 result.
pushKV(
"complete", complete);
315 if (!vErrors.
empty()) {
316 if (result.
exists(
"errors")) {
317 vErrors.
push_backV(result[
"errors"].getValues());
319 result.
pushKV(
"errors", vErrors);
void AddInputs(CMutableTransaction &rawTx, const UniValue &inputs_in, std::optional< bool > rbf)
void push_back(UniValue val)
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
void ParsePrevouts(const UniValue &prevTxsUnival, FillableSigningProvider *keystore, std::map< COutPoint, Coin > &coins)
Parse a prevtxs UniValue array and get the map of coins from it.
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
void pushKVs(UniValue obj)
CScriptWitness scriptWitness
Only serialized through CTransaction.
static const uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
virtual bool AddCScript(const CScript &redeemScript)
int ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
CTxOut out
unspent transaction output
std::vector< std::vector< unsigned char > > stack
const UniValue & get_array() const
const std::vector< std::string > & getKeys() const
bool SignalsOptInRBF(const CTransaction &tx)
Check whether the sequence numbers on this transaction are signaling opt-in to replace-by-fee, according to BIP 125.
static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, const std::string &strMessage)
Pushes a JSON object for script verification or signing errors to vErrorsRet.
void AddOutputs(CMutableTransaction &rawTx, const UniValue &outputs_in)
Normalize univalue-represented outputs and add them to the transaction.
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, bilingual_str > &input_errors, UniValue &result)
Invalid, missing or duplicate parameter.
int64_t CAmount
Amount in satoshis (Can be negative)
const UniValue & find_value(std::string_view key) const
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
uint256 ParseHashO(const UniValue &o, std::string strKey)
static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
UniValue JSONRPCError(int code, const std::string &message)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
static CAmount AmountFromValue(const UniValue &value)
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
An input of a transaction.
bool exists(const std::string &key) const
Fillable signing provider that keeps keys in an address->secret map.
Unexpected type was passed as parameter.
static const uint32_t LOCKTIME_MAX
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, std::optional< bool > rbf)
Create a transaction from univalue parameters.
void push_backV(const std::vector< UniValue > &vec)
An output of a transaction.
std::string ToString() const
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
An interface to be implemented by keystores that support signing.
void pushKV(std::string key, UniValue val)
Serialized script, used inside transaction inputs and outputs.
const UniValue & get_obj() const
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
A mutable version of CTransaction.
static const uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65)...
The basic transaction that is broadcasted on the network and contained in blocks. ...
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
Error parsing or validating structure in raw format.