30 "Invalid parameter, output argument must be non-null");
40 const bool outputs_is_obj = outputs_in.
isObject();
47 int64_t nLockTime = locktime.
getInt<int64_t>();
48 if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max()) {
50 "Invalid parameter, locktime out of range");
56 for (
size_t idx = 0; idx < inputs.
size(); idx++) {
65 "Invalid parameter, missing vout key");
68 if (!vout_v.
isNum()) {
70 "Invalid parameter, vout must be a number");
73 int nOutput = vout_v.
getInt<
int>();
76 "Invalid parameter, vout cannot be negative");
80 (rawTx.
nLockTime ? std::numeric_limits<uint32_t>::max() - 1
81 : std::numeric_limits<uint32_t>::max());
85 if (sequenceObj.
isNum()) {
86 int64_t seqNr64 = sequenceObj.
getInt<int64_t>();
87 if (seqNr64 < 0 || seqNr64 > std::numeric_limits<uint32_t>::max()) {
90 "Invalid parameter, sequence number is out of range");
93 nSequence = uint32_t(seqNr64);
97 rawTx.
vin.push_back(in);
100 if (!outputs_is_obj) {
103 for (
size_t i = 0; i < outputs.
size(); ++i) {
104 const UniValue &output = outputs[i];
107 "Invalid parameter, key-value pair not an "
108 "object as expected");
110 if (output.
size() != 1) {
112 "Invalid parameter, key-value pair must "
113 "contain exactly one key");
117 outputs = std::move(outputs_dict);
121 std::set<CTxDestination> destinations;
122 bool has_data{
false};
124 for (
const std::string &name_ : outputs.
getKeys()) {
125 if (name_ ==
"data") {
128 "Invalid parameter, duplicate key: data");
131 std::vector<uint8_t> data =
132 ParseHexV(outputs[name_].getValStr(),
"Data");
135 rawTx.
vout.push_back(out);
140 std::string(
"Invalid Bitcoin address: ") +
144 if (!destinations.insert(destination).second) {
147 std::string(
"Invalid parameter, duplicated address: ") +
154 CTxOut out(nAmount, scriptPubKey);
155 rawTx.
vout.push_back(out);
166 const std::string &strMessage) {
172 entry.
pushKV(
"error", strMessage);
178 std::map<COutPoint, Coin> &coins) {
179 if (!prevTxsUnival.
isNull()) {
181 for (
size_t idx = 0; idx < prevTxs.
size(); ++idx) {
185 "expected object with "
186 "{\"txid'\",\"vout\",\"scriptPubKey\"}");
207 "vout cannot be negative");
211 std::vector<uint8_t> 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() &&
217 coin->second.GetTxOut().scriptPubKey != scriptPubKey) {
218 std::string err(
"Previous output scriptPubKey mismatch:\n");
228 if (prevOut.
exists(
"amount")) {
243 coins[out] =
Coin(txout, 1,
false);
255 std::vector<uint8_t> rsData(
ParseHexV(v,
"redeemScript"));
265 const std::map<COutPoint, Coin> &coins,
270 "Signature must use SIGHASH_FORKID");
274 std::map<int, std::string> input_errors;
282 const std::map<COutPoint, Coin> &coins,
283 const std::map<int, std::string> &input_errors,
287 for (
const auto &err_pair : input_errors) {
288 if (err_pair.second ==
"Missing amount") {
293 coins.at(mtx.
vin.at(err_pair.first).prevout)
301 result.
pushKV(
"complete", complete);
302 if (!vErrors.
empty()) {
303 if (result.
exists(
"errors")) {
304 vErrors.
push_backV(result[
"errors"].getValues());
306 result.
pushKV(
"errors", vErrors);
310std::vector<RPCResult>
DecodeTxDoc(
const std::string &txid_field_doc,
327 "The coinbase value (only if coinbase transaction)"},
329 "The transaction id (if not coinbase transaction)"},
331 "The output number (if not coinbase transaction)"},
335 "The script (if not coinbase transaction)",
341 "The script sequence number"},
361 "The required sigs"},
363 "The type, eg 'pubkeyhash'"},
370 "The eCash address (only if a well-defined "
378 "Output script is change (only "
380 : std::vector<RPCResult>{})},
static constexpr Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
const CScript redeemScript
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
A mutable version of CTransaction.
std::vector< CTxOut > vout
An outpoint - a combination of a transaction hash and an index n into its vout.
const TxId & GetTxId() const
Serialized script, used inside transaction inputs and outputs.
bool IsPayToScriptHash() const
The basic transaction that is broadcasted on the network and contained in blocks.
An input of a transaction.
An output of a transaction.
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
Signature hash type wrapper class.
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
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.
SigHashType ParseSighashString(const UniValue &sighash)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
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 SignTransactionResultToJSON(CMutableTransaction &mtx, bool complete, const std::map< COutPoint, Coin > &coins, const std::map< int, std::string > &input_errors, UniValue &result)
CMutableTransaction ConstructTransaction(const CChainParams ¶ms, const UniValue &inputs_in, const UniValue &outputs_in, const UniValue &locktime)
Create a transaction from univalue parameters.
std::vector< RPCResult > DecodeTxDoc(const std::string &txid_field_doc, bool wallet)
Explain the UniValue "decoded" transaction object, may include extra fields if processed by wallet.
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.
Amount AmountFromValue(const UniValue &value)
std::vector< uint8_t > ParseHexV(const UniValue &v, std::string strName)
uint256 ParseHashO(const UniValue &o, std::string strKey)
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
Check for expected keys/value types in an Object.
std::vector< uint8_t > ParseHexO(const UniValue &o, std::string strKey)
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.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
static const Currency & get()
@ 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.
A TxId is the identifier of a transaction.
Wrapper for UniValue::VType, which includes typeAny: used to denote don't care type.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
V Cat(V v1, V &&v2)
Concatenate two vectors, moving elements.