mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
refactor: move SignSignature
helpers to test utils
These helpers haven't been used in production code since segwit was
merged more than eight years ago (see commit 605e8473
, PR #8149),
so it seems appropriate to move them to the test utils module.
Can be reviewed via `--color-moved=dimmed-zebra`.
This commit is contained in:
parent
81276540d3
commit
58499b00d0
7 changed files with 44 additions and 40 deletions
|
@ -694,27 +694,6 @@ void SignatureData::MergeSignatureData(SignatureData sigdata)
|
||||||
signatures.insert(std::make_move_iterator(sigdata.signatures.begin()), std::make_move_iterator(sigdata.signatures.end()));
|
signatures.insert(std::make_move_iterator(sigdata.signatures.begin()), std::make_move_iterator(sigdata.signatures.end()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data)
|
|
||||||
{
|
|
||||||
assert(nIn < txTo.vin.size());
|
|
||||||
|
|
||||||
MutableTransactionSignatureCreator creator(txTo, nIn, amount, nHashType);
|
|
||||||
|
|
||||||
bool ret = ProduceSignature(provider, creator, fromPubKey, sig_data);
|
|
||||||
UpdateInput(txTo.vin.at(nIn), sig_data);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType, SignatureData& sig_data)
|
|
||||||
{
|
|
||||||
assert(nIn < txTo.vin.size());
|
|
||||||
const CTxIn& txin = txTo.vin[nIn];
|
|
||||||
assert(txin.prevout.n < txFrom.vout.size());
|
|
||||||
const CTxOut& txout = txFrom.vout[txin.prevout.n];
|
|
||||||
|
|
||||||
return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, sig_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/** Dummy signature checker which accepts all signatures. */
|
/** Dummy signature checker which accepts all signatures. */
|
||||||
class DummySignatureChecker final : public BaseSignatureChecker
|
class DummySignatureChecker final : public BaseSignatureChecker
|
||||||
|
|
|
@ -97,25 +97,6 @@ struct SignatureData {
|
||||||
/** Produce a script signature using a generic signature creator. */
|
/** Produce a script signature using a generic signature creator. */
|
||||||
bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& scriptPubKey, SignatureData& sigdata);
|
bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& scriptPubKey, SignatureData& sigdata);
|
||||||
|
|
||||||
/**
|
|
||||||
* Produce a satisfying script (scriptSig or witness).
|
|
||||||
*
|
|
||||||
* @param provider Utility containing the information necessary to solve a script.
|
|
||||||
* @param fromPubKey The script to produce a satisfaction for.
|
|
||||||
* @param txTo The spending transaction.
|
|
||||||
* @param nIn The index of the input in `txTo` referring the output being spent.
|
|
||||||
* @param amount The value of the output being spent.
|
|
||||||
* @param nHashType Signature hash type.
|
|
||||||
* @param sig_data Additional data provided to solve a script. Filled with the resulting satisfying
|
|
||||||
* script and whether the satisfaction is complete.
|
|
||||||
*
|
|
||||||
* @return True if the produced script is entirely satisfying `fromPubKey`.
|
|
||||||
**/
|
|
||||||
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo,
|
|
||||||
unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data);
|
|
||||||
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo,
|
|
||||||
unsigned int nIn, int nHashType, SignatureData& sig_data);
|
|
||||||
|
|
||||||
/** Extract signature data from a transaction input, and insert it. */
|
/** Extract signature data from a transaction input, and insert it. */
|
||||||
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
|
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn, const CTxOut& txout);
|
||||||
void UpdateInput(CTxIn& input, const SignatureData& data);
|
void UpdateInput(CTxIn& input, const SignatureData& data);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
|
#include <test/util/transaction_utils.h>
|
||||||
#include <util/chaintype.h>
|
#include <util/chaintype.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
#include <test/util/transaction_utils.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
#include <test/util/transaction_utils.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -90,3 +90,24 @@ void BulkTransaction(CMutableTransaction& tx, int32_t target_weight)
|
||||||
assert(GetTransactionWeight(CTransaction(tx)) >= target_weight);
|
assert(GetTransactionWeight(CTransaction(tx)) >= target_weight);
|
||||||
assert(GetTransactionWeight(CTransaction(tx)) <= target_weight + 3);
|
assert(GetTransactionWeight(CTransaction(tx)) <= target_weight + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo, unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data)
|
||||||
|
{
|
||||||
|
assert(nIn < txTo.vin.size());
|
||||||
|
|
||||||
|
MutableTransactionSignatureCreator creator(txTo, nIn, amount, nHashType);
|
||||||
|
|
||||||
|
bool ret = ProduceSignature(provider, creator, fromPubKey, sig_data);
|
||||||
|
UpdateInput(txTo.vin.at(nIn), sig_data);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo, unsigned int nIn, int nHashType, SignatureData& sig_data)
|
||||||
|
{
|
||||||
|
assert(nIn < txTo.vin.size());
|
||||||
|
const CTxIn& txin = txTo.vin[nIn];
|
||||||
|
assert(txin.prevout.n < txFrom.vout.size());
|
||||||
|
const CTxOut& txout = txFrom.vout[txin.prevout.n];
|
||||||
|
|
||||||
|
return SignSignature(provider, txout.scriptPubKey, txTo, nIn, txout.nValue, nHashType, sig_data);
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
|
#define BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
|
||||||
|
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
#include <script/sign.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
@ -30,4 +31,23 @@ std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keyst
|
||||||
// by appending a single output with padded output script
|
// by appending a single output with padded output script
|
||||||
void BulkTransaction(CMutableTransaction& tx, int32_t target_weight);
|
void BulkTransaction(CMutableTransaction& tx, int32_t target_weight);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produce a satisfying script (scriptSig or witness).
|
||||||
|
*
|
||||||
|
* @param provider Utility containing the information necessary to solve a script.
|
||||||
|
* @param fromPubKey The script to produce a satisfaction for.
|
||||||
|
* @param txTo The spending transaction.
|
||||||
|
* @param nIn The index of the input in `txTo` referring the output being spent.
|
||||||
|
* @param amount The value of the output being spent.
|
||||||
|
* @param nHashType Signature hash type.
|
||||||
|
* @param sig_data Additional data provided to solve a script. Filled with the resulting satisfying
|
||||||
|
* script and whether the satisfaction is complete.
|
||||||
|
*
|
||||||
|
* @return True if the produced script is entirely satisfying `fromPubKey`.
|
||||||
|
**/
|
||||||
|
bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo,
|
||||||
|
unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data);
|
||||||
|
bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo,
|
||||||
|
unsigned int nIn, int nHashType, SignatureData& sig_data);
|
||||||
|
|
||||||
#endif // BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
|
#endif // BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue