29 "Invalid parameter, output argument must be non-null");
39 const bool outputs_is_obj = outputs_in.
isObject();
46 int64_t nLockTime = locktime.
getInt<int64_t>();
47 if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max()) {
49 "Invalid parameter, locktime out of range");
55 for (
size_t idx = 0; idx < inputs.
size(); idx++) {
64 "Invalid parameter, missing vout key");
67 if (!vout_v.
isNum()) {
69 "Invalid parameter, vout must be a number");
72 int nOutput = vout_v.
getInt<
int>();
75 "Invalid parameter, vout cannot be negative");
79 (rawTx.
nLockTime ? std::numeric_limits<uint32_t>::max() - 1
80 : std::numeric_limits<uint32_t>::max());
84 if (sequenceObj.
isNum()) {
85 int64_t seqNr64 = sequenceObj.
getInt<int64_t>();
86 if (seqNr64 < 0 || seqNr64 > std::numeric_limits<uint32_t>::max()) {
89 "Invalid parameter, sequence number is out of range");
92 nSequence = uint32_t(seqNr64);
96 rawTx.
vin.push_back(in);
99 if (!outputs_is_obj) {
102 for (
size_t i = 0; i < outputs.
size(); ++i) {
103 const UniValue &output = outputs[i];
106 "Invalid parameter, key-value pair not an "
107 "object as expected");
109 if (output.
size() != 1) {
111 "Invalid parameter, key-value pair must "
112 "contain exactly one key");
116 outputs = std::move(outputs_dict);
120 std::set<CTxDestination> destinations;
121 bool has_data{
false};
123 for (
const std::string &name_ : outputs.
getKeys()) {
124 if (name_ ==
"data") {
127 "Invalid parameter, duplicate key: data");
130 std::vector<uint8_t> data =
131 ParseHexV(outputs[name_].getValStr(),
"Data");
134 rawTx.
vout.push_back(out);
139 std::string(
"Invalid Bitcoin address: ") +
143 if (!destinations.insert(destination).second) {
146 std::string(
"Invalid parameter, duplicated address: ") +
153 CTxOut out(nAmount, scriptPubKey);
154 rawTx.
vout.push_back(out);
165 const std::string &strMessage) {
171 entry.
pushKV(
"error", strMessage);
177 std::map<COutPoint, Coin> &coins) {
178 if (!prevTxsUnival.
isNull()) {
180 for (
size_t idx = 0; idx < prevTxs.
size(); ++idx) {
184 "expected object with "
185 "{\"txid'\",\"vout\",\"scriptPubKey\"}");
206 "vout cannot be negative");
210 std::vector<uint8_t> pkData(
ParseHexO(prevOut,
"scriptPubKey"));
211 CScript scriptPubKey(pkData.begin(), pkData.end());
214 auto coin = coins.find(out);
215 if (coin != coins.end() && !coin->second.IsSpent() &&
216 coin->second.GetTxOut().scriptPubKey != scriptPubKey) {
217 std::string err(
"Previous output scriptPubKey mismatch:\n");
227 if (prevOut.
exists(
"amount")) {
242 coins[out] =
Coin(txout, 1,
false);
254 std::vector<uint8_t> rsData(
ParseHexV(v,
"redeemScript"));
255 CScript redeemScript(rsData.begin(), rsData.end());
264 const std::map<COutPoint, Coin> &coins,
269 "Signature must use SIGHASH_FORKID");
273 std::map<int, std::string> input_errors;
281 const std::map<COutPoint, Coin> &coins,
282 const std::map<int, std::string> &input_errors,
286 for (
const auto &err_pair : input_errors) {
287 if (err_pair.second ==
"Missing amount") {
292 coins.at(mtx.
vin.at(err_pair.first).prevout)
300 result.
pushKV(
"complete", complete);
301 if (!vErrors.
empty()) {
302 if (result.
exists(
"errors")) {
303 vErrors.
push_backV(result[
"errors"].getValues());
305 result.
pushKV(
"errors", vErrors);
static constexpr Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
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 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)
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.
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
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.