35 const bool outputs_is_obj = outputs_in.
isObject();
47 for (
unsigned int idx = 0; idx < inputs.
size(); idx++) {
71 if (sequenceObj.
isNum()) {
72 int64_t seqNr64 = sequenceObj.
get_int64();
76 nSequence = (uint32_t)seqNr64;
82 rawTx.
vin.push_back(in);
85 if (!outputs_is_obj) {
88 for (
size_t i = 0; i < outputs.
size(); ++i) {
93 if (output.
size() != 1) {
98 outputs = std::move(outputs_dict);
102 std::set<CTxDestination> destinations;
103 bool has_data{
false};
105 for (
const std::string& name_ : outputs.
getKeys()) {
106 if (name_ ==
"data") {
111 std::vector<unsigned char> data =
ParseHexV(outputs[name_].getValStr(),
"Data");
114 rawTx.
vout.push_back(out);
121 if (!destinations.insert(destination).second) {
128 CTxOut out(nAmount, scriptPubKey);
129 rawTx.
vout.push_back(out);
150 entry.
pushKV(
"witness", witness);
153 entry.
pushKV(
"error", strMessage);
159 if (!prevTxsUnival.
isNull()) {
161 for (
unsigned int idx = 0; idx < prevTxs.
size(); ++idx) {
184 std::vector<unsigned char> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
185 CScript scriptPubKey(pkData.begin(), pkData.end());
188 auto coin = coins.find(out);
189 if (coin != coins.end() && !coin->second.IsSpent() && coin->second.out.scriptPubKey != scriptPubKey) {
190 std::string err(
"Previous output scriptPubKey mismatch:\n");
191 err = err +
ScriptToAsmStr(coin->second.out.scriptPubKey) +
"\nvs:\n"+
198 if (prevOut.
exists(
"amount")) {
202 coins[out] = std::move(newcoin);
206 const bool is_p2sh = scriptPubKey.IsPayToScriptHash();
207 const bool is_p2wsh = scriptPubKey.IsPayToWitnessScriptHash();
208 if (keystore && (is_p2sh || is_p2wsh)) {
216 if (rs.isNull() && ws.
isNull()) {
221 std::vector<unsigned char> scriptData(!ws.
isNull() ?
ParseHexV(ws,
"witnessScript") :
ParseHexV(rs,
"redeemScript"));
222 CScript script(scriptData.begin(), scriptData.end());
229 if (!ws.
isNull() && !rs.isNull()) {
234 if (ws.
get_str() != rs.get_str()) {
235 std::vector<unsigned char> redeemScriptData(
ParseHexV(rs,
"redeemScript"));
236 CScript redeemScript(redeemScriptData.begin(), redeemScriptData.end());
237 if (redeemScript != witness_output_script) {
263 }
else if (is_p2wsh) {
283 std::map<int, std::string> input_errors;
285 bool complete =
SignTransaction(mtx, keystore, coins, nHashType, input_errors);
293 for (
const auto& err_pair : input_errors) {
294 if (err_pair.second ==
"Missing amount") {
302 result.
pushKV(
"complete", complete);
303 if (!vErrors.
empty()) {
304 if (result.
exists(
"errors")) {
305 vErrors.
push_backV(result[
"errors"].getValues());
307 result.
pushKV(
"errors", vErrors);
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.
static const uint32_t MAX_BIP125_RBF_SEQUENCE
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 > ParseHexO(const UniValue &o, std::string strKey)
static const CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, std::string > &input_errors, UniValue &result)
CScriptWitness scriptWitness
Only serialized through CTransaction.
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
static const uint32_t SEQUENCE_FINAL
virtual bool AddCScript(const CScript &redeemScript)
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CTxOut out
unspent transaction output
std::vector< std::vector< unsigned char > > stack
const std::string & get_str() const
const UniValue & get_array() const
int64_t get_int64() const
bool pushKVs(const UniValue &obj)
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
const std::vector< std::string > & getKeys() const
bool SignalsOptInRBF(const CTransaction &tx)
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, bool rbf)
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.
Invalid, missing or duplicate parameter.
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
const UniValue & find_value(const UniValue &obj, const std::string &name)
int64_t CAmount
Amount in satoshis (Can be negative)
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
UniValue JSONRPCError(int code, const std::string &message)
bool push_back(const UniValue &val)
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)
int ParseSighashString(const UniValue &sighash)
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.
bool pushKV(const std::string &key, const UniValue &val)
An output of a transaction.
std::string ToString() const
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
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)
An interface to be implemented by keystores that support signing.
Serialized script, used inside transaction inputs and outputs.
const UniValue & get_obj() const
bool push_backV(const std::vector< UniValue > &vec)
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
A mutable version of CTransaction.
The basic transaction that is broadcasted on the network and contained in blocks. ...
static const uint32_t LOCKTIME_MAX
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
Error parsing or validating structure in raw format.
uint256 ParseHashO(const UniValue &o, std::string strKey)