Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/rawtransaction_util.cpp
Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | static void TxInErrorToJSON(const CTxIn &txin, UniValue &vErrorsRet, | ||||
entry.pushKV("vout", uint64_t(txin.prevout.GetN())); | entry.pushKV("vout", uint64_t(txin.prevout.GetN())); | ||||
entry.pushKV("scriptSig", | entry.pushKV("scriptSig", | ||||
HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||||
entry.pushKV("sequence", uint64_t(txin.nSequence)); | entry.pushKV("sequence", uint64_t(txin.nSequence)); | ||||
entry.pushKV("error", strMessage); | entry.pushKV("error", strMessage); | ||||
vErrorsRet.push_back(entry); | vErrorsRet.push_back(entry); | ||||
} | } | ||||
UniValue SignTransaction(CMutableTransaction &mtx, | void ParsePrevouts(const UniValue &prevTxsUnival, | ||||
const UniValue &prevTxsUnival, | |||||
FillableSigningProvider *keystore, | FillableSigningProvider *keystore, | ||||
std::map<COutPoint, Coin> &coins, | std::map<COutPoint, Coin> &coins) { | ||||
bool is_temp_keystore, const UniValue &hashType) { | |||||
// Add previous txouts given in the RPC call: | |||||
if (!prevTxsUnival.isNull()) { | if (!prevTxsUnival.isNull()) { | ||||
UniValue prevTxs = prevTxsUnival.get_array(); | UniValue prevTxs = prevTxsUnival.get_array(); | ||||
for (size_t idx = 0; idx < prevTxs.size(); ++idx) { | for (size_t idx = 0; idx < prevTxs.size(); ++idx) { | ||||
const UniValue &p = prevTxs[idx]; | const UniValue &p = prevTxs[idx]; | ||||
if (!p.isObject()) { | if (!p.isObject()) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | ||||
"expected object with " | "expected object with " | ||||
"{\"txid'\",\"vout\",\"scriptPubKey\"}"); | "{\"txid'\",\"vout\",\"scriptPubKey\"}"); | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (!prevTxsUnival.isNull()) { | ||||
// eg getbalance returns "3.14152" rather than 3.14152 | // eg getbalance returns "3.14152" rather than 3.14152 | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing amount"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Missing amount"); | ||||
} | } | ||||
coins[out] = Coin(txout, 1, false); | coins[out] = Coin(txout, 1, false); | ||||
} | } | ||||
// If redeemScript and private keys were given, add redeemScript to | // If redeemScript and private keys were given, add redeemScript to | ||||
// the keystore so it can be signed | // the keystore so it can be signed | ||||
if (is_temp_keystore && scriptPubKey.IsPayToScriptHash()) { | if (keystore && scriptPubKey.IsPayToScriptHash()) { | ||||
RPCTypeCheckObj( | RPCTypeCheckObj( | ||||
prevOut, { | prevOut, { | ||||
{"redeemScript", UniValueType(UniValue::VSTR)}, | {"redeemScript", UniValueType(UniValue::VSTR)}, | ||||
}); | }); | ||||
UniValue v = find_value(prevOut, "redeemScript"); | UniValue v = find_value(prevOut, "redeemScript"); | ||||
if (!v.isNull()) { | if (!v.isNull()) { | ||||
std::vector<uint8_t> rsData(ParseHexV(v, "redeemScript")); | std::vector<uint8_t> rsData(ParseHexV(v, "redeemScript")); | ||||
CScript redeemScript(rsData.begin(), rsData.end()); | CScript redeemScript(rsData.begin(), rsData.end()); | ||||
keystore->AddCScript(redeemScript); | keystore->AddCScript(redeemScript); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
UniValue SignTransaction(CMutableTransaction &mtx, | |||||
const SigningProvider *keystore, | |||||
std::map<COutPoint, Coin> &coins, | |||||
const UniValue &hashType) { | |||||
SigHashType sigHashType = ParseSighashString(hashType); | SigHashType sigHashType = ParseSighashString(hashType); | ||||
if (!sigHashType.hasForkId()) { | if (!sigHashType.hasForkId()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Signature must use SIGHASH_FORKID"); | "Signature must use SIGHASH_FORKID"); | ||||
} | } | ||||
// Script verification errors. | // Script verification errors. | ||||
UniValue vErrors(UniValue::VARR); | UniValue vErrors(UniValue::VARR); | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |