mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
Replace usage of GetScriptForWitness with GetScriptForDestination
This commit is contained in:
parent
8a85377cd0
commit
b887060d06
6 changed files with 36 additions and 45 deletions
|
@ -320,8 +320,8 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str
|
|||
if (!pubkey.IsCompressed()) {
|
||||
throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
|
||||
}
|
||||
// Call GetScriptForWitness() to build a P2WSH scriptPubKey
|
||||
scriptPubKey = GetScriptForWitness(scriptPubKey);
|
||||
// Build a P2WPKH script
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkey));
|
||||
}
|
||||
if (bScriptHash) {
|
||||
// Get the ID for the script, and then construct a P2SH destination for it.
|
||||
|
@ -390,8 +390,8 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
|
|||
throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
|
||||
}
|
||||
}
|
||||
// Call GetScriptForWitness() to build a P2WSH scriptPubKey
|
||||
scriptPubKey = GetScriptForWitness(scriptPubKey);
|
||||
// Build a P2WSH with the multisig script
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(scriptPubKey));
|
||||
}
|
||||
if (bScriptHash) {
|
||||
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
|
||||
|
@ -464,7 +464,7 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
|
|||
}
|
||||
|
||||
if (bSegWit) {
|
||||
scriptPubKey = GetScriptForWitness(scriptPubKey);
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(scriptPubKey));
|
||||
}
|
||||
if (bScriptHash) {
|
||||
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
|
||||
|
|
|
@ -63,8 +63,6 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
|||
int required_ret;
|
||||
(void)ExtractDestinations(script, type_ret, addresses, required_ret);
|
||||
|
||||
(void)GetScriptForWitness(script);
|
||||
|
||||
const FlatSigningProvider signing_provider;
|
||||
(void)InferDescriptor(script, signing_provider);
|
||||
|
||||
|
|
|
@ -349,21 +349,16 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
|
|||
result = GetScriptForMultisig(2, std::vector<CPubKey>(pubkeys, pubkeys + 3));
|
||||
BOOST_CHECK(result == expected);
|
||||
|
||||
// GetScriptForWitness
|
||||
CScript witnessScript;
|
||||
|
||||
witnessScript << ToByteVector(pubkeys[0]) << OP_CHECKSIG;
|
||||
// WitnessV0KeyHash
|
||||
expected.clear();
|
||||
expected << OP_0 << ToByteVector(pubkeys[0].GetID());
|
||||
result = GetScriptForWitness(witnessScript);
|
||||
result = GetScriptForDestination(WitnessV0KeyHash(Hash160(ToByteVector(pubkeys[0]))));
|
||||
BOOST_CHECK(result == expected);
|
||||
result = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0].GetID()));
|
||||
BOOST_CHECK(result == expected);
|
||||
|
||||
witnessScript.clear();
|
||||
witnessScript << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
result = GetScriptForWitness(witnessScript);
|
||||
BOOST_CHECK(result == expected);
|
||||
|
||||
witnessScript.clear();
|
||||
// WitnessV0ScriptHash (multisig)
|
||||
CScript witnessScript;
|
||||
witnessScript << OP_1 << ToByteVector(pubkeys[0]) << OP_1 << OP_CHECKMULTISIG;
|
||||
|
||||
uint256 scriptHash;
|
||||
|
@ -372,7 +367,7 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
|
|||
|
||||
expected.clear();
|
||||
expected << OP_0 << ToByteVector(scriptHash);
|
||||
result = GetScriptForWitness(witnessScript);
|
||||
result = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
||||
BOOST_CHECK(result == expected);
|
||||
}
|
||||
|
||||
|
|
|
@ -154,8 +154,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
|||
|
||||
// P2WPKH witness program
|
||||
{
|
||||
CScript p2pk = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||
CScript scriptPubKey = GetScriptForWitness(p2pk);
|
||||
CScript scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkey));
|
||||
CScript scriptSig = CScript();
|
||||
CScriptWitness scriptWitness;
|
||||
scriptWitness.stack.push_back(std::vector<unsigned char>(0));
|
||||
|
@ -183,8 +182,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
|||
|
||||
// P2WPKH nested in P2SH
|
||||
{
|
||||
CScript p2pk = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||
CScript scriptSig = GetScriptForWitness(p2pk);
|
||||
CScript scriptSig = GetScriptForDestination(WitnessV0KeyHash(pubkey));
|
||||
CScript scriptPubKey = GetScriptForDestination(ScriptHash(scriptSig));
|
||||
scriptSig = CScript() << ToByteVector(scriptSig);
|
||||
CScriptWitness scriptWitness;
|
||||
|
@ -199,7 +197,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
|||
// P2WSH witness program
|
||||
{
|
||||
CScript witnessScript = CScript() << 1 << ToByteVector(pubkey) << ToByteVector(pubkey) << 2 << OP_CHECKMULTISIGVERIFY;
|
||||
CScript scriptPubKey = GetScriptForWitness(witnessScript);
|
||||
CScript scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
||||
CScript scriptSig = CScript();
|
||||
CScriptWitness scriptWitness;
|
||||
scriptWitness.stack.push_back(std::vector<unsigned char>(0));
|
||||
|
@ -215,7 +213,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
|||
// P2WSH nested in P2SH
|
||||
{
|
||||
CScript witnessScript = CScript() << 1 << ToByteVector(pubkey) << ToByteVector(pubkey) << 2 << OP_CHECKMULTISIGVERIFY;
|
||||
CScript redeemScript = GetScriptForWitness(witnessScript);
|
||||
CScript redeemScript = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
||||
CScript scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
CScript scriptSig = CScript() << ToByteVector(redeemScript);
|
||||
CScriptWitness scriptWitness;
|
||||
|
|
|
@ -499,13 +499,13 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
|||
BOOST_CHECK(keystore.AddCScript(scriptPubkey1L));
|
||||
BOOST_CHECK(keystore.AddCScript(scriptPubkey2L));
|
||||
BOOST_CHECK(keystore.AddCScript(scriptMulti));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForWitness(scriptPubkey1)));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForWitness(scriptPubkey2)));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForWitness(scriptPubkey1L)));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForWitness(scriptPubkey2L)));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForWitness(scriptMulti)));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForDestination(WitnessV0KeyHash(pubkey1.GetID()))));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForDestination(WitnessV0KeyHash(pubkey2.GetID()))));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForDestination(WitnessV0KeyHash(pubkey1L.GetID()))));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForDestination(WitnessV0KeyHash(pubkey2L.GetID()))));
|
||||
BOOST_CHECK(keystore.AddCScript(GetScriptForDestination(WitnessV0ScriptHash(scriptMulti))));
|
||||
BOOST_CHECK(keystore2.AddCScript(scriptMulti));
|
||||
BOOST_CHECK(keystore2.AddCScript(GetScriptForWitness(scriptMulti)));
|
||||
BOOST_CHECK(keystore2.AddCScript(GetScriptForDestination(WitnessV0ScriptHash(scriptMulti))));
|
||||
BOOST_CHECK(keystore2.AddKeyPubKey(key3, pubkey3));
|
||||
|
||||
CTransactionRef output1, output2;
|
||||
|
@ -537,8 +537,8 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
|||
CheckWithFlag(output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false);
|
||||
|
||||
// Witness pay-to-compressed-pubkey (v0).
|
||||
CreateCreditAndSpend(keystore, GetScriptForWitness(scriptPubkey1), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForWitness(scriptPubkey2), output2, input2);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(WitnessV0KeyHash(pubkey1.GetID())), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(WitnessV0KeyHash(pubkey2.GetID())), output2, input2);
|
||||
CheckWithFlag(output1, input1, 0, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true);
|
||||
|
@ -549,9 +549,9 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
|||
CheckWithFlag(output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false);
|
||||
|
||||
// P2SH witness pay-to-compressed-pubkey (v0).
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey1))), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey2))), output2, input2);
|
||||
ReplaceRedeemScript(input2.vin[0].scriptSig, GetScriptForWitness(scriptPubkey1));
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0KeyHash(pubkey1.GetID())))), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0KeyHash(pubkey2.GetID())))), output2, input2);
|
||||
ReplaceRedeemScript(input2.vin[0].scriptSig, GetScriptForDestination(WitnessV0KeyHash(pubkey1.GetID())));
|
||||
CheckWithFlag(output1, input1, 0, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_P2SH, true);
|
||||
|
@ -587,12 +587,12 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
|||
CheckWithFlag(output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false);
|
||||
|
||||
// Signing disabled for witness pay-to-uncompressed-pubkey (v1).
|
||||
CreateCreditAndSpend(keystore, GetScriptForWitness(scriptPubkey1L), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForWitness(scriptPubkey2L), output2, input2, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(WitnessV0KeyHash(pubkey1L.GetID())), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(WitnessV0KeyHash(pubkey2L.GetID())), output2, input2, false);
|
||||
|
||||
// Signing disabled for P2SH witness pay-to-uncompressed-pubkey (v1).
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey1L))), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey2L))), output2, input2, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0KeyHash(pubkey1L.GetID())))), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0KeyHash(pubkey2L.GetID())))), output2, input2, false);
|
||||
|
||||
// Normal 2-of-2 multisig
|
||||
CreateCreditAndSpend(keystore, scriptMulti, output1, input1, false);
|
||||
|
@ -616,10 +616,10 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
|||
CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true);
|
||||
|
||||
// Witness 2-of-2 multisig
|
||||
CreateCreditAndSpend(keystore, GetScriptForWitness(scriptMulti), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(WitnessV0ScriptHash(scriptMulti)), output1, input1, false);
|
||||
CheckWithFlag(output1, input1, 0, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForWitness(scriptMulti), output2, input2, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForDestination(WitnessV0ScriptHash(scriptMulti)), output2, input2, false);
|
||||
CheckWithFlag(output2, input2, 0, true);
|
||||
CheckWithFlag(output2, input2, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false);
|
||||
BOOST_CHECK(*output1 == *output2);
|
||||
|
@ -628,10 +628,10 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
|||
CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true);
|
||||
|
||||
// P2SH witness 2-of-2 multisig
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptMulti))), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0ScriptHash(scriptMulti)))), output1, input1, false);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptMulti))), output2, input2, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForDestination(ScriptHash(GetScriptForDestination(WitnessV0ScriptHash(scriptMulti)))), output2, input2, false);
|
||||
CheckWithFlag(output2, input2, SCRIPT_VERIFY_P2SH, true);
|
||||
CheckWithFlag(output2, input2, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false);
|
||||
BOOST_CHECK(*output1 == *output2);
|
||||
|
|
|
@ -157,7 +157,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
|||
CScript p2pk_scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
||||
CScript p2sh_scriptPubKey = GetScriptForDestination(ScriptHash(p2pk_scriptPubKey));
|
||||
CScript p2pkh_scriptPubKey = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
|
||||
CScript p2wpkh_scriptPubKey = GetScriptForWitness(p2pkh_scriptPubKey);
|
||||
CScript p2wpkh_scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(coinbaseKey.GetPubKey()));
|
||||
|
||||
FillableSigningProvider keystore;
|
||||
BOOST_CHECK(keystore.AddKey(coinbaseKey));
|
||||
|
|
Loading…
Add table
Reference in a new issue