Merge #15784: rpc: Remove dependency on interfaces::Chain in SignTransaction
99e88a372
rpc: Remove dependency on interfaces::Chain in SignTransaction (Antoine Riard)
Pull request description:
Assuming wallet RPCs and node RPCs will go into different processes, signrawtransactionwithkey doesn't need to access Coins via interfaces::Chain, it may use directly utility in node/coins.cpp
Obviously will need rebase after #15638
Tree-SHA512: 42ee8fcbcd38643bbd82210db6f68249bed5ee036a4c930a1db534d0469a133e287b8869c977bf0cc79a7296dde04f72adb74d24e1cd20f4a280f4c2b7fceb74
This commit is contained in:
commit
703414994a
4 changed files with 34 additions and 19 deletions
|
@ -15,6 +15,7 @@
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <keystore.h>
|
#include <keystore.h>
|
||||||
#include <merkleblock.h>
|
#include <merkleblock.h>
|
||||||
|
#include <node/coin.h>
|
||||||
#include <node/psbt.h>
|
#include <node/psbt.h>
|
||||||
#include <node/transaction.h>
|
#include <node/transaction.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
|
@ -770,7 +771,14 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
|
||||||
keystore.AddKey(key);
|
keystore.AddKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SignTransaction(*g_rpc_interfaces->chain, mtx, request.params[2], &keystore, true, request.params[3]);
|
// Fetch previous transactions (inputs):
|
||||||
|
std::map<COutPoint, Coin> coins;
|
||||||
|
for (const CTxIn& txin : mtx.vin) {
|
||||||
|
coins[txin.prevout]; // Create empty map entry keyed by prevout.
|
||||||
|
}
|
||||||
|
FindCoins(coins);
|
||||||
|
|
||||||
|
return SignTransaction(mtx, request.params[2], &keystore, coins, true, request.params[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue sendrawtransaction(const JSONRPCRequest& request)
|
static UniValue sendrawtransaction(const JSONRPCRequest& request)
|
||||||
|
|
|
@ -149,18 +149,8 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::
|
||||||
vErrorsRet.push_back(entry);
|
vErrorsRet.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(https://github.com/bitcoin/bitcoin/pull/10973#discussion_r267084237):
|
UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival, CBasicKeyStore* keystore, std::map<COutPoint, Coin>& coins, bool is_temp_keystore, const UniValue& hashType)
|
||||||
// The dependency on interfaces::Chain should be removed, so
|
|
||||||
// signrawtransactionwithkey doesn't need access to a Chain instance.
|
|
||||||
UniValue SignTransaction(interfaces::Chain& chain, CMutableTransaction& mtx, const UniValue& prevTxsUnival, CBasicKeyStore *keystore, bool is_temp_keystore, const UniValue& hashType)
|
|
||||||
{
|
{
|
||||||
// Fetch previous transactions (inputs):
|
|
||||||
std::map<COutPoint, Coin> coins;
|
|
||||||
for (const CTxIn& txin : mtx.vin) {
|
|
||||||
coins[txin.prevout]; // Create empty map entry keyed by prevout.
|
|
||||||
}
|
|
||||||
chain.findCoins(coins);
|
|
||||||
|
|
||||||
// Add previous txouts given in the RPC call:
|
// Add previous txouts given in the RPC call:
|
||||||
if (!prevTxsUnival.isNull()) {
|
if (!prevTxsUnival.isNull()) {
|
||||||
UniValue prevTxs = prevTxsUnival.get_array();
|
UniValue prevTxs = prevTxsUnival.get_array();
|
||||||
|
|
|
@ -5,16 +5,26 @@
|
||||||
#ifndef BITCOIN_RPC_RAWTRANSACTION_UTIL_H
|
#ifndef BITCOIN_RPC_RAWTRANSACTION_UTIL_H
|
||||||
#define BITCOIN_RPC_RAWTRANSACTION_UTIL_H
|
#define BITCOIN_RPC_RAWTRANSACTION_UTIL_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class CBasicKeyStore;
|
class CBasicKeyStore;
|
||||||
class UniValue;
|
class UniValue;
|
||||||
struct CMutableTransaction;
|
struct CMutableTransaction;
|
||||||
|
class Coin;
|
||||||
|
class COutPoint;
|
||||||
|
|
||||||
namespace interfaces {
|
/**
|
||||||
class Chain;
|
* Sign a transaction with the given keystore and previous transactions
|
||||||
} // namespace interfaces
|
*
|
||||||
|
* @param mtx The transaction to-be-signed
|
||||||
/** Sign a transaction with the given keystore and previous transactions */
|
* @param prevTxs Array of previous txns outputs that tx depends on but may not yet be in the block chain
|
||||||
UniValue SignTransaction(interfaces::Chain& chain, CMutableTransaction& mtx, const UniValue& prevTxs, CBasicKeyStore *keystore, bool tempKeystore, const UniValue& hashType);
|
* @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, CBasicKeyStore* keystore, std::map<COutPoint, Coin>& coins, bool tempKeystore, const UniValue& hashType);
|
||||||
|
|
||||||
/** Create a transaction from univalue parameters */
|
/** Create a transaction from univalue parameters */
|
||||||
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, const UniValue& rbf);
|
CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniValue& outputs_in, const UniValue& locktime, const UniValue& rbf);
|
||||||
|
|
|
@ -3150,7 +3150,14 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
|
||||||
LOCK(pwallet->cs_wallet);
|
LOCK(pwallet->cs_wallet);
|
||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(pwallet);
|
||||||
|
|
||||||
return SignTransaction(pwallet->chain(), mtx, request.params[1], pwallet, false, request.params[2]);
|
// Fetch previous transactions (inputs):
|
||||||
|
std::map<COutPoint, Coin> coins;
|
||||||
|
for (const CTxIn& txin : mtx.vin) {
|
||||||
|
coins[txin.prevout]; // Create empty map entry keyed by prevout.
|
||||||
|
}
|
||||||
|
pwallet->chain().findCoins(coins);
|
||||||
|
|
||||||
|
return SignTransaction(mtx, request.params[1], pwallet, coins, false, request.params[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue bumpfee(const JSONRPCRequest& request)
|
static UniValue bumpfee(const JSONRPCRequest& request)
|
||||||
|
|
Loading…
Reference in a new issue