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);
103 std::set<CTxDestination> destinations;
104 std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs;
105 bool has_data{
false};
106 for (
const std::string& name_ : outputs.
getKeys()) {
107 if (name_ ==
"data") {
112 std::vector<unsigned char>
data =
ParseHexV(outputs[name_].getValStr(),
"Data");
115 parsed_outputs.emplace_back(destination, amount);
123 if (!destinations.insert(destination).second) {
126 parsed_outputs.emplace_back(destination, amount);
129 return parsed_outputs;
137 std::vector<std::pair<CTxDestination, CAmount>> parsed_outputs =
ParseOutputs(outputs);
138 for (
const auto& [destination, nAmount] : parsed_outputs) {
151 int64_t nLockTime = locktime.
getInt<int64_t>();
177 entry.
pushKV(
"witness", std::move(witness));
180 entry.
pushKV(
"error", strMessage);
186 if (!prevTxsUnival.
isNull()) {
188 for (
unsigned int idx = 0; idx < prevTxs.
size(); ++idx) {
211 std::vector<unsigned char> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
212 CScript scriptPubKey(pkData.begin(), pkData.end());
215 auto coin = coins.find(
out);
216 if (coin != coins.end() && !coin->second.IsSpent() && coin->second.out.scriptPubKey != scriptPubKey) {
217 std::string err(
"Previous output scriptPubKey mismatch:\n");
218 err = err +
ScriptToAsmStr(coin->second.out.scriptPubKey) +
"\nvs:\n"+
225 if (prevOut.
exists(
"amount")) {
229 coins[
out] = std::move(newcoin);
235 if (keystore && (is_p2sh || is_p2wsh)) {
243 if (rs.isNull() && ws.isNull()) {
248 std::vector<unsigned char> scriptData(!ws.isNull() ?
ParseHexV(ws,
"witnessScript") :
ParseHexV(rs,
"redeemScript"));
254 keystore->
scripts.emplace(
CScriptID(witness_output_script), witness_output_script);
256 if (!ws.isNull() && !rs.isNull()) {
261 if (ws.get_str() != rs.get_str()) {
262 std::vector<unsigned char> redeemScriptData(
ParseHexV(rs,
"redeemScript"));
263 CScript redeemScript(redeemScriptData.begin(), redeemScriptData.end());
264 if (redeemScript != witness_output_script) {
290 }
else if (is_p2wsh) {
310 std::map<int, bilingual_str> input_errors;
312 bool complete =
SignTransaction(mtx, keystore, coins, nHashType, input_errors);
320 for (
const auto& err_pair : input_errors) {
321 if (err_pair.second.original ==
"Missing amount") {
329 result.
pushKV(
"complete", complete);
330 if (!vErrors.
empty()) {
331 if (result.
exists(
"errors")) {
332 vErrors.
push_backV(result[
"errors"].getValues());
334 result.
pushKV(
"errors", std::move(vErrors));
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)
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=false)
Create the assembly string representation of a CScript object.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, bilingual_str > &input_errors, UniValue &result)
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, std::optional< bool > rbf)
Create a transaction from univalue parameters.
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.
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.
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)
int ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
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)
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
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