29 "Invalid parameter, output argument must be non-null");
49 "Invalid parameter, locktime out of range");
52 rawTx.nLockTime = nLockTime;
55 for (
size_t idx = 0; idx < inputs.
size(); idx++) {
64 "Invalid parameter, missing vout key");
69 "Invalid parameter, vout must be a number");
75 "Invalid parameter, vout cannot be negative");
79 (
rawTx.nLockTime ? std::numeric_limits<uint32_t>::max() - 1
80 : std::numeric_limits<uint32_t>::max());
89 "Invalid parameter, sequence number is out of range");
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");
124 if (
name_ ==
"data") {
127 "Invalid parameter, duplicate key: data");
130 std::vector<uint8_t> data =
134 rawTx.vout.push_back(out);
139 std::string(
"Invalid Bitcoin address: ") +
146 std::string(
"Invalid parameter, duplicated address: ") +
153 CTxOut out(nAmount, scriptPubKey);
154 rawTx.vout.push_back(out);
167 entry.
pushKV(
"txid",
txin.prevout.GetTxId().ToString());
177 std::map<COutPoint, Coin> &coins) {
180 for (
size_t idx = 0; idx <
prevTxs.size(); ++idx) {
184 "expected object with "
185 "{\"txid'\",\"vout\",\"scriptPubKey\"}");
203 int nOut =
prevOut.find_value(
"vout").getInt<
int>();
206 "vout cannot be negative");
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);
264 const std::map<COutPoint, Coin> &coins,
269 "Signature must use SIGHASH_FORKID");
281 const std::map<COutPoint, Coin> &coins,
287 if (
err_pair.second ==
"Missing amount") {
300 result.
pushKV(
"complete", complete);
302 if (result.
exists(
"errors")) {
303 vErrors.push_backV(result[
"errors"].getValues());
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.
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
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.
Signature hash type wrapper class.
An interface to be implemented by keystores that support signing.
const UniValue & find_value(std::string_view key) const
const UniValue & get_obj() const
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)
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)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
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.