35 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
44 int nOutput = vout_v.
getInt<
int>();
50 if (rbf.value_or(
true)) {
60 if (sequenceObj.
isNum()) {
61 int64_t seqNr64 = sequenceObj.
getInt<int64_t>();
65 nSequence = (uint32_t)seqNr64;
71 rawTx.
vin.push_back(in);
81 const bool outputs_is_obj = outputs_in.
isObject();
84 if (!outputs_is_obj) {
87 for (
size_t i = 0; i < outputs.
size(); ++i) {
92 if (output.
size() != 1) {
97 outputs = std::move(outputs_dict);
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") {
114 std::vector<unsigned char>
data =
ParseHexV(outputs[name_].getValStr(),
"Data");
117 parsed_outputs.emplace_back(destination, amount);
125 if (!destinations.insert(destination).second) {
128 parsed_outputs.emplace_back(destination, amount);
131 return parsed_outputs;
139 std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs =
ParseOutputs(outputs);
140 for (
const auto& [destination, nAmount] : parsed_outputs) {
153 int64_t nLockTime = locktime.
getInt<int64_t>();
184 entry.
pushKV(
"witness", std::move(witness));
187 entry.
pushKV(
"error", strMessage);
193 if (!prevTxsUnival.
isNull()) {
195 for (
unsigned int idx = 0; idx < prevTxs.
size(); ++idx) {
218 std::vector<unsigned char> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
219 CScript scriptPubKey(pkData.begin(), pkData.end());
222 auto coin = coins.find(
out);
223 if (coin != coins.end() && !coin->second.IsSpent() && coin->second.out.scriptPubKey != scriptPubKey) {
224 std::string err(
"Previous output scriptPubKey mismatch:\n");
225 err = err +
ScriptToAsmStr(coin->second.out.scriptPubKey) +
"\nvs:\n"+
232 if (prevOut.
exists(
"amount")) {
236 coins[
out] = std::move(newcoin);
242 if (keystore && (is_p2sh || is_p2wsh)) {
250 if (rs.isNull() && ws.isNull()) {
255 std::vector<unsigned char> scriptData(!ws.isNull() ?
ParseHexV(ws,
"witnessScript") :
ParseHexV(rs,
"redeemScript"));
261 keystore->
scripts.emplace(
CScriptID(witness_output_script), witness_output_script);
263 if (!ws.isNull() && !rs.isNull()) {
268 if (ws.get_str() != rs.get_str()) {
269 std::vector<unsigned char> redeemScriptData(
ParseHexV(rs,
"redeemScript"));
270 CScript redeemScript(redeemScriptData.begin(), redeemScriptData.end());
271 if (redeemScript != witness_output_script) {
297 }
else if (is_p2wsh) {
320 std::map<int, bilingual_str> input_errors;
322 bool complete =
SignTransaction(mtx, keystore, coins, {.sighash_type = *nHashType}, input_errors);
330 for (
const auto& err_pair : input_errors) {
331 if (err_pair.second.original ==
"Missing amount") {
339 result.
pushKV(
"complete", complete);
340 if (!vErrors.
empty()) {
341 if (result.
exists(
"errors")) {
342 vErrors.
push_backV(result[
"errors"].getValues());
344 result.
pushKV(
"errors", std::move(vErrors));
355 const std::string fee_doc{opts.
fee_doc.value_or(
356 "transaction fee in " +
CURRENCY_UNIT +
", omitted if block undo data is not available")};
357 const std::string prevout_doc{opts.
prevout_doc.value_or(
358 "The previous output, omitted if block undo data is not available")};
359 const std::string vin_item_doc{opts.
vin_item_doc.value_or(
"utxo being spent")};
361 auto vin_inner = std::vector<RPCResult>{
376 vin_inner.emplace_back(
378 std::vector<RPCResult>{
379 {RPCResult::Type::BOOL,
"generated",
"Coinbase or not"},
380 {RPCResult::Type::NUM,
"height",
"The height of the prevout"},
381 {RPCResult::Type::STR_AMOUNT,
"value",
"The value in " + CURRENCY_UNIT},
382 {RPCResult::Type::OBJ,
"scriptPubKey",
"", ScriptPubKeyDoc()},
388 if (opts.vin_inner_elision) {
389 vin_inner =
ElideGroup(std::move(vin_inner), *opts.vin_inner_elision);
392 std::vector<RPCResult> new_vin;
393 new_vin.reserve(vin_inner.size());
394 for (
const auto& r : vin_inner) {
395 if (r.m_key_name ==
"prevout") {
398 new_vin.emplace_back(r, std::move(unopts));
400 new_vin.push_back(r);
403 vin_inner = std::move(new_vin);
407 auto fields = std::vector<RPCResult>{
411 {
RPCResult::Type::NUM,
"vsize",
"The virtual transaction size (differs from size for witness transactions)"},
428 std::vector<RPCResult>{{
RPCResult::Type::BOOL,
"ischange",
true,
"Output script is change (only present if true)"}} :
429 std::vector<RPCResult>{}
439 std::vector<RPCResult> new_fields;
440 new_fields.reserve(fields.size());
442 for (
const auto& f : fields) {
443 if (!silent && f.m_key_name ==
"fee") {
444 new_fields.push_back(f);
447 if (f.m_key_name ==
"vin" && opts.vin_inner_elision) {
448 new_fields.push_back(f);
451 if (!silent && first) {
454 new_fields.emplace_back(f, std::move(eopts));
459 new_fields.emplace_back(f, std::move(eopts));
462 fields = std::move(new_fields);
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination corresponds to one with an address.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
int64_t CAmount
Amount in satoshis (Can be negative)
static CAmount AmountFromValue(const UniValue &value)
#define CHECK_NONFATAL(condition)
Identity function.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
bool IsPayToScriptHash() const
bool IsPayToWitnessScriptHash() const
A reference to a CScript: the Hash160 of its serialization.
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
static const uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
static const uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
CScriptWitness scriptWitness
Only serialized through CTransaction.
An output of a transaction.
CTxOut out
unspent transaction output
uint32_t nHeight
at which height this containing transaction was included in the active block chain
An interface to be implemented by keystores that support signing.
void push_back(UniValue val)
const UniValue & find_value(std::string_view key) const
const UniValue & get_obj() const
void pushKVs(UniValue obj)
const std::vector< std::string > & getKeys() const
const UniValue & get_array() const
bool exists(const std::string &key) const
void pushKV(std::string key, UniValue val)
void push_backV(const std::vector< UniValue > &vec)
std::string ToString() const
static transaction_identifier FromUint256(const uint256 &id)
std::string EncodeHexTx(const CTransaction &tx)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode)
Create the assembly string representation of a CScript object.
const std::string CURRENCY_UNIT
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
static constexpr decltype(CTransaction::version) TX_MIN_STANDARD_VERSION
static constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, bilingual_str > &input_errors, UniValue &result)
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 AddInputs(CMutableTransaction &rawTx, const UniValue &inputs_in, std::optional< bool > rbf)
void AddOutputs(CMutableTransaction &rawTx, const UniValue &outputs_in)
Normalize, parse, and add outputs to the transaction.
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, std::optional< bool > rbf, const uint32_t version)
Create a transaction from univalue parameters.
static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, const std::string &strMessage)
Pushes a JSON object for script verification or signing errors to vErrorsRet.
std::vector< std::pair< CTxDestination, CAmount > > ParseOutputs(const UniValue &outputs)
Parse normalized outputs into destination, amount tuples.
UniValue NormalizeOutputs(const UniValue &outputs_in)
Normalize univalue-represented outputs.
void ParsePrevouts(const UniValue &prevTxsUnival, FlatSigningProvider *keystore, std::map< COutPoint, Coin > &coins)
Parse a prevtxs UniValue array and get the map of coins from it.
std::vector< RPCResult > TxDoc(const TxDocOptions &opts)
Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet.
@ WithSummary
first field carries elision_summary as "...", rest skipped
@ Silent
all top-level fields skipped silently (no "..." line)
@ None
no elision, all top-level fields rendered normally
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_TYPE_ERROR
Unexpected type was passed as parameter.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
std::vector< RPCResult > ElideGroup(std::vector< RPCResult > fields, std::string summary)
Stamp elision onto an entire vector of RPCResult fields at once.
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
std::optional< int > ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
std::vector< RPCResult > ScriptPubKeyDoc()
static const uint32_t LOCKTIME_MAX
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< std::vector< unsigned char > > stack
std::map< CScriptID, CScript > scripts
Controls how an RPCResult is rendered in human-readable help text.field printed normally.
@ NUM_TIME
Special numeric to denote unix epoch time.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
HelpElision print_elision
std::optional< std::string > prevout_doc
Customize the prevout field's description (only meaningful when prevout is true)
std::optional< std::string > vin_item_doc
Customize the vin item object's description (only meaningful when vin_inner_elision is set)
std::optional< std::string > elision_summary
Summary text shown as "..." required for elision_mode == WithSummary.
std::optional< std::string > vin_inner_elision
Elide vin inner fields but keep vin array with prevout expanded.
bool prevout
Include prevout field.
std::optional< std::string > fee_doc
Customize the fee field's description (only meaningful when fee is true)
ElisionMode elision_mode
Controls top-level field elision in the help.
bool fee
Include fee field.
bool prevout_optional
Mark prevout field as optional (omitted when undo data unavailable)
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
bool SignalsOptInRBF(const CTransaction &tx)
Check whether the sequence numbers on this transaction are signaling opt-in to replace-by-fee,...
static constexpr uint32_t MAX_BIP125_RBF_SEQUENCE
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.