Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115522
D7118.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D7118.diff
View Options
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -865,8 +865,10 @@
}
FindCoins(coins);
- return SignTransaction(mtx, request.params[2], &keystore, coins, true,
- request.params[3]);
+ // Parse the prevtxs array
+ ParsePrevouts(request.params[2], &keystore, coins);
+
+ return SignTransaction(mtx, &keystore, coins, request.params[3]);
}
static UniValue sendrawtransaction(const Config &config,
diff --git a/src/rpc/rawtransaction_util.h b/src/rpc/rawtransaction_util.h
--- a/src/rpc/rawtransaction_util.h
+++ b/src/rpc/rawtransaction_util.h
@@ -13,26 +13,37 @@
class CMutableTransaction;
class Coin;
class COutPoint;
+class SigningProvider;
class UniValue;
/**
* Sign a transaction with the given keystore and previous transactions
*
* @param mtx The transaction to-be-signed
- * @param prevTxs Array of previous txns outputs that tx depends on but
- * may not yet be in the block chain
* @param keystore Temporary keystore containing signing keys
* @param coins Map of unspent outputs - coins in mempool and current
* chain UTXO set, may be extended by previous txns outputs after call
- * @param tempKeystore Whether to use temporary keystore
* @param hashType The signature hash type
* @returns JSON object with details of signed transaction
*/
-UniValue SignTransaction(CMutableTransaction &mtx, const UniValue &prevTxs,
- FillableSigningProvider *keystore,
- std::map<COutPoint, Coin> &coins, bool tempKeystore,
+UniValue SignTransaction(CMutableTransaction &mtx,
+ const SigningProvider *keystore,
+ std::map<COutPoint, Coin> &coins,
const UniValue &hashType);
+/**
+ * Parse a prevtxs UniValue array and get the map of coins from it
+ *
+ * @param prevTxs Array of previous txns outputs that tx depends on but
+ * may not yet be in the block chain
+ * @param keystore A pointer to the temprorary keystore if there is one
+ * @param coins Map of unspent outputs - coins in mempool and current
+ * chain UTXO set, may be extended by previous txns outputs after call
+ */
+void ParsePrevouts(const UniValue &prevTxsUnival,
+ FillableSigningProvider *keystore,
+ std::map<COutPoint, Coin> &coins);
+
/** Create a transaction from univalue parameters */
CMutableTransaction ConstructTransaction(const CChainParams ¶ms,
const UniValue &inputs_in,
diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp
--- a/src/rpc/rawtransaction_util.cpp
+++ b/src/rpc/rawtransaction_util.cpp
@@ -157,12 +157,9 @@
vErrorsRet.push_back(entry);
}
-UniValue SignTransaction(CMutableTransaction &mtx,
- const UniValue &prevTxsUnival,
- FillableSigningProvider *keystore,
- std::map<COutPoint, Coin> &coins,
- bool is_temp_keystore, const UniValue &hashType) {
- // Add previous txouts given in the RPC call:
+void ParsePrevouts(const UniValue &prevTxsUnival,
+ FillableSigningProvider *keystore,
+ std::map<COutPoint, Coin> &coins) {
if (!prevTxsUnival.isNull()) {
UniValue prevTxs = prevTxsUnival.get_array();
for (size_t idx = 0; idx < prevTxs.size(); ++idx) {
@@ -232,7 +229,7 @@
// If redeemScript and private keys were given, add redeemScript to
// the keystore so it can be signed
- if (is_temp_keystore && scriptPubKey.IsPayToScriptHash()) {
+ if (keystore && scriptPubKey.IsPayToScriptHash()) {
RPCTypeCheckObj(
prevOut, {
{"redeemScript", UniValueType(UniValue::VSTR)},
@@ -246,7 +243,12 @@
}
}
}
+}
+UniValue SignTransaction(CMutableTransaction &mtx,
+ const SigningProvider *keystore,
+ std::map<COutPoint, Coin> &coins,
+ const UniValue &hashType) {
SigHashType sigHashType = ParseSighashString(hashType);
if (!sigHashType.hasForkId()) {
throw JSONRPCError(RPC_INVALID_PARAMETER,
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -3816,8 +3816,10 @@
}
pwallet->chain().findCoins(coins);
- return SignTransaction(mtx, request.params[1], pwallet, coins, false,
- request.params[2]);
+ // Parse the prevtxs array
+ ParsePrevouts(request.params[1], nullptr, coins);
+
+ return SignTransaction(mtx, pwallet, coins, request.params[2]);
}
UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 11:18 (9 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187563
Default Alt Text
D7118.diff (4 KB)
Attached To
D7118: [backport#16798] Refactor rawtransaction_util's SignTransaction to separate prevtx parsing
Event Timeline
Log In to Comment