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);
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);
int64_t CAmount
Amount in satoshis (Can be negative)
static const CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
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
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
static const uint32_t SEQUENCE_FINAL
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
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
An interface to be implemented by keystores that support signing.
const std::string & get_str() const
int64_t get_int64() const
const UniValue & get_obj() const
const std::vector< std::string > & getKeys() const
bool pushKVs(const UniValue &obj)
bool push_back(const UniValue &val)
const UniValue & get_array() const
bool exists(const std::string &key) const
bool pushKV(const std::string &key, const UniValue &val)
bool push_backV(const std::vector< UniValue > &vec)
std::string ToString() const
int ParseSighashString(const UniValue &sighash)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode=false)
Create the assembly string representation of a CScript object.
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
CTxDestination DecodeDestination(const std::string &str)
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.
CMutableTransaction ConstructTransaction(const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime, bool rbf)
Create a transaction from univalue parameters.
void SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, std::map< int, std::string > &input_errors, UniValue &result)
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 ParsePrevouts(const UniValue &prevTxsUnival, FillableSigningProvider *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.
static const uint32_t LOCKTIME_MAX
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
A mutable version of CTransaction.
std::vector< CTxOut > vout
std::vector< std::vector< unsigned char > > stack
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
const UniValue & find_value(const UniValue &obj, const std::string &name)
bool SignalsOptInRBF(const CTransaction &tx)
static const uint32_t MAX_BIP125_RBF_SEQUENCE
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
uint256 ParseHashO(const UniValue &o, std::string strKey)
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)