mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-18 03:27:41 +02:00
Merge #15452: Replace CScriptID and CKeyID in CTxDestination with dedicated types
78e407ad0cGetKeyBirthTimes should return key ids, not destinations (Gregory Sanders)70946e7feeReplace CScriptID and CKeyID in CTxDestination with dedicated types (Gregory Sanders) Pull request description: The current usage seems to be an overloading of meanings. `CScriptID` is used in the wallet as a lookup key, as well as a destination, and `CKeyID` likewise. Instead, have all destinations be dedicated types. New types: `CScriptID`->`ScriptHash` `CKeyID`->`PKHash` ACKs for commit 78e407: ryanofsky: utACK78e407ad0c. Only changes are removing extra CScriptID()s and fixing the test case. Sjors: utACK78e407ameshcollider: utACK78e407ad0cTree-SHA512: 437f59fc3afb83a40540da3351507aef5aed44e3a7f15b01ddad6226854edeee762ff0b0ef336fe3654c4cd99a205cef175211de8b639abe1130c8a6313337b9
This commit is contained in:
@@ -166,7 +166,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, TestChain100Setup)
|
||||
LOCK(cs_main);
|
||||
tip = ::ChainActive().Tip();
|
||||
}
|
||||
CScript coinbase_script_pub_key = GetScriptForDestination(coinbaseKey.GetPubKey().GetID());
|
||||
CScript coinbase_script_pub_key = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
|
||||
std::vector<std::shared_ptr<CBlock>> chainA, chainB;
|
||||
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainA));
|
||||
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key, 10, chainB));
|
||||
|
||||
@@ -485,7 +485,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
|
||||
BOOST_CHECK_EQUAL(cc1.fCoinBase, false);
|
||||
BOOST_CHECK_EQUAL(cc1.nHeight, 203998U);
|
||||
BOOST_CHECK_EQUAL(cc1.out.nValue, CAmount{60000000000});
|
||||
BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(CKeyID(uint160(ParseHex("816115944e077fe7c803cfa57f29b36bf87c1d35"))))));
|
||||
BOOST_CHECK_EQUAL(HexStr(cc1.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160(ParseHex("816115944e077fe7c803cfa57f29b36bf87c1d35"))))));
|
||||
|
||||
// Good example
|
||||
CDataStream ss2(ParseHex("8ddf77bbd123008c988f1a4a4de2161e0f50aac7f17e7f9555caa4"), SER_DISK, CLIENT_VERSION);
|
||||
@@ -494,7 +494,7 @@ BOOST_AUTO_TEST_CASE(ccoins_serialization)
|
||||
BOOST_CHECK_EQUAL(cc2.fCoinBase, true);
|
||||
BOOST_CHECK_EQUAL(cc2.nHeight, 120891U);
|
||||
BOOST_CHECK_EQUAL(cc2.out.nValue, 110397);
|
||||
BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(CKeyID(uint160(ParseHex("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4"))))));
|
||||
BOOST_CHECK_EQUAL(HexStr(cc2.out.scriptPubKey), HexStr(GetScriptForDestination(PKHash(uint160(ParseHex("8c988f1a4a4de2161e0f50aac7f17e7f9555caa4"))))));
|
||||
|
||||
// Smallest possible example
|
||||
CDataStream ss3(ParseHex("000006"), SER_DISK, CLIENT_VERSION);
|
||||
|
||||
@@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
|
||||
tx.vin[0].scriptSig << OP_1;
|
||||
tx.vout.resize(1);
|
||||
tx.vout[0].nValue = 1*CENT;
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
|
||||
|
||||
AddOrphanTx(MakeTransactionRef(tx), i);
|
||||
}
|
||||
@@ -397,7 +397,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
|
||||
tx.vin[0].prevout.hash = txPrev->GetHash();
|
||||
tx.vout.resize(1);
|
||||
tx.vout[0].nValue = 1*CENT;
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
|
||||
BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL));
|
||||
|
||||
AddOrphanTx(MakeTransactionRef(tx), i);
|
||||
@@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
|
||||
CMutableTransaction tx;
|
||||
tx.vout.resize(1);
|
||||
tx.vout[0].nValue = 1*CENT;
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
|
||||
tx.vin.resize(2777);
|
||||
for (unsigned int j = 0; j < tx.vin.size(); j++)
|
||||
{
|
||||
|
||||
@@ -68,10 +68,10 @@ BOOST_AUTO_TEST_CASE(key_test1)
|
||||
BOOST_CHECK(!key2C.VerifyPubKey(pubkey2));
|
||||
BOOST_CHECK(key2C.VerifyPubKey(pubkey2C));
|
||||
|
||||
BOOST_CHECK(DecodeDestination(addr1) == CTxDestination(pubkey1.GetID()));
|
||||
BOOST_CHECK(DecodeDestination(addr2) == CTxDestination(pubkey2.GetID()));
|
||||
BOOST_CHECK(DecodeDestination(addr1C) == CTxDestination(pubkey1C.GetID()));
|
||||
BOOST_CHECK(DecodeDestination(addr2C) == CTxDestination(pubkey2C.GetID()));
|
||||
BOOST_CHECK(DecodeDestination(addr1) == CTxDestination(PKHash(pubkey1)));
|
||||
BOOST_CHECK(DecodeDestination(addr2) == CTxDestination(PKHash(pubkey2)));
|
||||
BOOST_CHECK(DecodeDestination(addr1C) == CTxDestination(PKHash(pubkey1C)));
|
||||
BOOST_CHECK(DecodeDestination(addr2C) == CTxDestination(PKHash(pubkey2C)));
|
||||
|
||||
for (int n=0; n<16; n++)
|
||||
{
|
||||
|
||||
@@ -399,7 +399,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
tx.vin[0].scriptSig = CScript() << OP_1;
|
||||
tx.vout[0].nValue = BLOCKSUBSIDY-LOWFEE;
|
||||
script = CScript() << OP_0;
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
|
||||
tx.vout[0].scriptPubKey = GetScriptForDestination(ScriptHash(script));
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
||||
tx.vin[0].prevout.hash = hash;
|
||||
|
||||
@@ -69,14 +69,14 @@ BOOST_AUTO_TEST_CASE(sign)
|
||||
// different keys, straight/P2SH, pubkey/pubkeyhash
|
||||
CScript standardScripts[4];
|
||||
standardScripts[0] << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
|
||||
standardScripts[1] = GetScriptForDestination(key[1].GetPubKey().GetID());
|
||||
standardScripts[1] = GetScriptForDestination(PKHash(key[1].GetPubKey()));
|
||||
standardScripts[2] << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
|
||||
standardScripts[3] = GetScriptForDestination(key[2].GetPubKey().GetID());
|
||||
standardScripts[3] = GetScriptForDestination(PKHash(key[2].GetPubKey()));
|
||||
CScript evalScripts[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
BOOST_CHECK(keystore.AddCScript(standardScripts[i]));
|
||||
evalScripts[i] = GetScriptForDestination(CScriptID(standardScripts[i]));
|
||||
evalScripts[i] = GetScriptForDestination(ScriptHash(standardScripts[i]));
|
||||
}
|
||||
|
||||
CMutableTransaction txFrom; // Funding transaction:
|
||||
@@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(norecurse)
|
||||
CScript invalidAsScript;
|
||||
invalidAsScript << OP_INVALIDOPCODE << OP_INVALIDOPCODE;
|
||||
|
||||
CScript p2sh = GetScriptForDestination(CScriptID(invalidAsScript));
|
||||
CScript p2sh = GetScriptForDestination(ScriptHash(invalidAsScript));
|
||||
|
||||
CScript scriptSig;
|
||||
scriptSig << Serialize(invalidAsScript);
|
||||
@@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(norecurse)
|
||||
|
||||
// Try to recur, and verification should succeed because
|
||||
// the inner HASH160 <> EQUAL should only check the hash:
|
||||
CScript p2sh2 = GetScriptForDestination(CScriptID(p2sh));
|
||||
CScript p2sh2 = GetScriptForDestination(ScriptHash(p2sh));
|
||||
CScript scriptSig2;
|
||||
scriptSig2 << Serialize(invalidAsScript) << Serialize(p2sh);
|
||||
|
||||
@@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(set)
|
||||
}
|
||||
|
||||
CScript inner[4];
|
||||
inner[0] = GetScriptForDestination(key[0].GetPubKey().GetID());
|
||||
inner[0] = GetScriptForDestination(PKHash(key[0].GetPubKey()));
|
||||
inner[1] = GetScriptForMultisig(2, std::vector<CPubKey>(keys.begin(), keys.begin()+2));
|
||||
inner[2] = GetScriptForMultisig(1, std::vector<CPubKey>(keys.begin(), keys.begin()+2));
|
||||
inner[3] = GetScriptForMultisig(2, std::vector<CPubKey>(keys.begin(), keys.begin()+3));
|
||||
@@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(set)
|
||||
CScript outer[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
outer[i] = GetScriptForDestination(CScriptID(inner[i]));
|
||||
outer[i] = GetScriptForDestination(ScriptHash(inner[i]));
|
||||
BOOST_CHECK(keystore.AddCScript(inner[i]));
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(switchover)
|
||||
CScript scriptSig;
|
||||
scriptSig << Serialize(notValid);
|
||||
|
||||
CScript fund = GetScriptForDestination(CScriptID(notValid));
|
||||
CScript fund = GetScriptForDestination(ScriptHash(notValid));
|
||||
|
||||
|
||||
// Validation should succeed under old rules (hash is correct):
|
||||
@@ -284,11 +284,11 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
||||
txFrom.vout.resize(7);
|
||||
|
||||
// First three are standard:
|
||||
CScript pay1 = GetScriptForDestination(key[0].GetPubKey().GetID());
|
||||
CScript pay1 = GetScriptForDestination(PKHash(key[0].GetPubKey()));
|
||||
BOOST_CHECK(keystore.AddCScript(pay1));
|
||||
CScript pay1of3 = GetScriptForMultisig(1, keys);
|
||||
|
||||
txFrom.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(pay1)); // P2SH (OP_CHECKSIG)
|
||||
txFrom.vout[0].scriptPubKey = GetScriptForDestination(ScriptHash(pay1)); // P2SH (OP_CHECKSIG)
|
||||
txFrom.vout[0].nValue = 1000;
|
||||
txFrom.vout[1].scriptPubKey = pay1; // ordinary OP_CHECKSIG
|
||||
txFrom.vout[1].nValue = 2000;
|
||||
@@ -303,7 +303,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
||||
oneAndTwo << OP_2 << ToByteVector(key[3].GetPubKey()) << ToByteVector(key[4].GetPubKey()) << ToByteVector(key[5].GetPubKey());
|
||||
oneAndTwo << OP_3 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(keystore.AddCScript(oneAndTwo));
|
||||
txFrom.vout[3].scriptPubKey = GetScriptForDestination(CScriptID(oneAndTwo));
|
||||
txFrom.vout[3].scriptPubKey = GetScriptForDestination(ScriptHash(oneAndTwo));
|
||||
txFrom.vout[3].nValue = 4000;
|
||||
|
||||
// vout[4] is max sigops:
|
||||
@@ -312,24 +312,24 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
||||
fifteenSigops << ToByteVector(key[i%3].GetPubKey());
|
||||
fifteenSigops << OP_15 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(keystore.AddCScript(fifteenSigops));
|
||||
txFrom.vout[4].scriptPubKey = GetScriptForDestination(CScriptID(fifteenSigops));
|
||||
txFrom.vout[4].scriptPubKey = GetScriptForDestination(ScriptHash(fifteenSigops));
|
||||
txFrom.vout[4].nValue = 5000;
|
||||
|
||||
// vout[5/6] are non-standard because they exceed MAX_P2SH_SIGOPS
|
||||
CScript sixteenSigops; sixteenSigops << OP_16 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(keystore.AddCScript(sixteenSigops));
|
||||
txFrom.vout[5].scriptPubKey = GetScriptForDestination(CScriptID(sixteenSigops));
|
||||
txFrom.vout[5].scriptPubKey = GetScriptForDestination(ScriptHash(sixteenSigops));
|
||||
txFrom.vout[5].nValue = 5000;
|
||||
CScript twentySigops; twentySigops << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(keystore.AddCScript(twentySigops));
|
||||
txFrom.vout[6].scriptPubKey = GetScriptForDestination(CScriptID(twentySigops));
|
||||
txFrom.vout[6].scriptPubKey = GetScriptForDestination(ScriptHash(twentySigops));
|
||||
txFrom.vout[6].nValue = 6000;
|
||||
|
||||
AddCoins(coins, CTransaction(txFrom), 0);
|
||||
|
||||
CMutableTransaction txTo;
|
||||
txTo.vout.resize(1);
|
||||
txTo.vout[0].scriptPubKey = GetScriptForDestination(key[1].GetPubKey().GetID());
|
||||
txTo.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[1].GetPubKey()));
|
||||
|
||||
txTo.vin.resize(5);
|
||||
for (int i = 0; i < 5; i++)
|
||||
@@ -352,7 +352,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
||||
|
||||
CMutableTransaction txToNonStd1;
|
||||
txToNonStd1.vout.resize(1);
|
||||
txToNonStd1.vout[0].scriptPubKey = GetScriptForDestination(key[1].GetPubKey().GetID());
|
||||
txToNonStd1.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[1].GetPubKey()));
|
||||
txToNonStd1.vout[0].nValue = 1000;
|
||||
txToNonStd1.vin.resize(1);
|
||||
txToNonStd1.vin[0].prevout.n = 5;
|
||||
@@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
|
||||
|
||||
CMutableTransaction txToNonStd2;
|
||||
txToNonStd2.vout.resize(1);
|
||||
txToNonStd2.vout[0].scriptPubKey = GetScriptForDestination(key[1].GetPubKey().GetID());
|
||||
txToNonStd2.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[1].GetPubKey()));
|
||||
txToNonStd2.vout[0].nValue = 1000;
|
||||
txToNonStd2.vin.resize(1);
|
||||
txToNonStd2.vin[0].prevout.n = 6;
|
||||
|
||||
@@ -179,23 +179,23 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
||||
s.clear();
|
||||
s << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
BOOST_CHECK(boost::get<CKeyID>(&address) &&
|
||||
*boost::get<CKeyID>(&address) == pubkey.GetID());
|
||||
BOOST_CHECK(boost::get<PKHash>(&address) &&
|
||||
*boost::get<PKHash>(&address) == PKHash(pubkey));
|
||||
|
||||
// TX_PUBKEYHASH
|
||||
s.clear();
|
||||
s << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
BOOST_CHECK(boost::get<CKeyID>(&address) &&
|
||||
*boost::get<CKeyID>(&address) == pubkey.GetID());
|
||||
BOOST_CHECK(boost::get<PKHash>(&address) &&
|
||||
*boost::get<PKHash>(&address) == PKHash(pubkey));
|
||||
|
||||
// TX_SCRIPTHASH
|
||||
CScript redeemScript(s); // initialize with leftover P2PKH script
|
||||
s.clear();
|
||||
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
|
||||
BOOST_CHECK(ExtractDestination(s, address));
|
||||
BOOST_CHECK(boost::get<CScriptID>(&address) &&
|
||||
*boost::get<CScriptID>(&address) == CScriptID(redeemScript));
|
||||
BOOST_CHECK(boost::get<ScriptHash>(&address) &&
|
||||
*boost::get<ScriptHash>(&address) == ScriptHash(redeemScript));
|
||||
|
||||
// TX_MULTISIG
|
||||
s.clear();
|
||||
@@ -255,8 +255,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TX_PUBKEY);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(boost::get<CKeyID>(&addresses[0]) &&
|
||||
*boost::get<CKeyID>(&addresses[0]) == pubkeys[0].GetID());
|
||||
BOOST_CHECK(boost::get<PKHash>(&addresses[0]) &&
|
||||
*boost::get<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
||||
|
||||
// TX_PUBKEYHASH
|
||||
s.clear();
|
||||
@@ -265,8 +265,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TX_PUBKEYHASH);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(boost::get<CKeyID>(&addresses[0]) &&
|
||||
*boost::get<CKeyID>(&addresses[0]) == pubkeys[0].GetID());
|
||||
BOOST_CHECK(boost::get<PKHash>(&addresses[0]) &&
|
||||
*boost::get<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
||||
|
||||
// TX_SCRIPTHASH
|
||||
CScript redeemScript(s); // initialize with leftover P2PKH script
|
||||
@@ -276,8 +276,8 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TX_SCRIPTHASH);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(boost::get<CScriptID>(&addresses[0]) &&
|
||||
*boost::get<CScriptID>(&addresses[0]) == CScriptID(redeemScript));
|
||||
BOOST_CHECK(boost::get<ScriptHash>(&addresses[0]) &&
|
||||
*boost::get<ScriptHash>(&addresses[0]) == ScriptHash(redeemScript));
|
||||
|
||||
// TX_MULTISIG
|
||||
s.clear();
|
||||
@@ -289,10 +289,10 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
BOOST_CHECK_EQUAL(whichType, TX_MULTISIG);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 2U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 2);
|
||||
BOOST_CHECK(boost::get<CKeyID>(&addresses[0]) &&
|
||||
*boost::get<CKeyID>(&addresses[0]) == pubkeys[0].GetID());
|
||||
BOOST_CHECK(boost::get<CKeyID>(&addresses[1]) &&
|
||||
*boost::get<CKeyID>(&addresses[1]) == pubkeys[1].GetID());
|
||||
BOOST_CHECK(boost::get<PKHash>(&addresses[0]) &&
|
||||
*boost::get<PKHash>(&addresses[0]) == PKHash(pubkeys[0]));
|
||||
BOOST_CHECK(boost::get<PKHash>(&addresses[1]) &&
|
||||
*boost::get<PKHash>(&addresses[1]) == PKHash(pubkeys[1]));
|
||||
|
||||
// TX_NULL_DATA
|
||||
s.clear();
|
||||
@@ -311,17 +311,17 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
|
||||
|
||||
CScript expected, result;
|
||||
|
||||
// CKeyID
|
||||
// PKHash
|
||||
expected.clear();
|
||||
expected << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
result = GetScriptForDestination(pubkeys[0].GetID());
|
||||
result = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
BOOST_CHECK(result == expected);
|
||||
|
||||
// CScriptID
|
||||
CScript redeemScript(result);
|
||||
expected.clear();
|
||||
expected << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
|
||||
result = GetScriptForDestination(CScriptID(redeemScript));
|
||||
result = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
BOOST_CHECK(result == expected);
|
||||
|
||||
// CNoDestination
|
||||
@@ -421,7 +421,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
// P2PKH compressed
|
||||
{
|
||||
CBasicKeyStore keystore;
|
||||
scriptPubKey = GetScriptForDestination(pubkeys[0].GetID());
|
||||
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
|
||||
// Keystore does not have key
|
||||
result = IsMine(keystore, scriptPubKey);
|
||||
@@ -436,7 +436,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
// P2PKH uncompressed
|
||||
{
|
||||
CBasicKeyStore keystore;
|
||||
scriptPubKey = GetScriptForDestination(uncompressedPubkey.GetID());
|
||||
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
|
||||
|
||||
// Keystore does not have key
|
||||
result = IsMine(keystore, scriptPubKey);
|
||||
@@ -452,8 +452,8 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
{
|
||||
CBasicKeyStore keystore;
|
||||
|
||||
CScript redeemScript = GetScriptForDestination(pubkeys[0].GetID());
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(redeemScript));
|
||||
CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
|
||||
// Keystore does not have redeemScript or key
|
||||
result = IsMine(keystore, scriptPubKey);
|
||||
@@ -474,9 +474,9 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
{
|
||||
CBasicKeyStore keystore;
|
||||
|
||||
CScript redeemscript_inner = GetScriptForDestination(pubkeys[0].GetID());
|
||||
CScript redeemscript = GetScriptForDestination(CScriptID(redeemscript_inner));
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(redeemscript));
|
||||
CScript redeemscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
CScript redeemscript = GetScriptForDestination(ScriptHash(redeemscript_inner));
|
||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemscript));
|
||||
|
||||
BOOST_CHECK(keystore.AddCScript(redeemscript));
|
||||
BOOST_CHECK(keystore.AddCScript(redeemscript_inner));
|
||||
@@ -490,8 +490,8 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
{
|
||||
CBasicKeyStore keystore;
|
||||
|
||||
CScript redeemscript = GetScriptForDestination(pubkeys[0].GetID());
|
||||
CScript witnessscript = GetScriptForDestination(CScriptID(redeemscript));
|
||||
CScript redeemscript = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
CScript witnessscript = GetScriptForDestination(ScriptHash(redeemscript));
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
|
||||
|
||||
BOOST_CHECK(keystore.AddCScript(witnessscript));
|
||||
@@ -506,7 +506,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
{
|
||||
CBasicKeyStore keystore;
|
||||
|
||||
CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0].GetID()));
|
||||
CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
|
||||
|
||||
BOOST_CHECK(keystore.AddCScript(witnessscript));
|
||||
@@ -520,7 +520,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
{
|
||||
CBasicKeyStore keystore;
|
||||
|
||||
CScript witnessscript_inner = GetScriptForDestination(pubkeys[0].GetID());
|
||||
CScript witnessscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||
CScript witnessscript = GetScriptForDestination(WitnessV0ScriptHash(witnessscript_inner));
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
|
||||
|
||||
@@ -537,7 +537,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
CBasicKeyStore keystore;
|
||||
BOOST_CHECK(keystore.AddKey(keys[0]));
|
||||
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0].GetID()));
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
||||
|
||||
// Keystore implicitly has key and P2SH redeemScript
|
||||
BOOST_CHECK(keystore.AddCScript(scriptPubKey));
|
||||
@@ -550,7 +550,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
CBasicKeyStore keystore;
|
||||
BOOST_CHECK(keystore.AddKey(uncompressedKey));
|
||||
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(uncompressedPubkey.GetID()));
|
||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(uncompressedPubkey)));
|
||||
|
||||
// Keystore has key, but no P2SH redeemScript
|
||||
result = IsMine(keystore, scriptPubKey);
|
||||
@@ -598,7 +598,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
BOOST_CHECK(keystore.AddKey(keys[1]));
|
||||
|
||||
CScript redeemScript = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(redeemScript));
|
||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
|
||||
// Keystore has no redeemScript
|
||||
result = IsMine(keystore, scriptPubKey);
|
||||
@@ -664,7 +664,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
|
||||
|
||||
CScript witnessScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
|
||||
CScript redeemScript = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(redeemScript));
|
||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
|
||||
// Keystore has no witnessScript, P2SH redeemScript, or keys
|
||||
result = IsMine(keystore, scriptPubKey);
|
||||
|
||||
@@ -1211,7 +1211,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
|
||||
BOOST_CHECK(keystore.AddKey(key));
|
||||
}
|
||||
|
||||
CMutableTransaction txFrom = BuildCreditingTransaction(GetScriptForDestination(keys[0].GetPubKey().GetID()));
|
||||
CMutableTransaction txFrom = BuildCreditingTransaction(GetScriptForDestination(PKHash(keys[0].GetPubKey())));
|
||||
CMutableTransaction txTo = BuildSpendingTransaction(CScript(), CScriptWitness(), CTransaction(txFrom));
|
||||
CScript& scriptPubKey = txFrom.vout[0].scriptPubKey;
|
||||
SignatureData scriptSig;
|
||||
@@ -1237,7 +1237,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
|
||||
// P2SH, single-signature case:
|
||||
CScript pkSingle; pkSingle << ToByteVector(keys[0].GetPubKey()) << OP_CHECKSIG;
|
||||
BOOST_CHECK(keystore.AddCScript(pkSingle));
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(pkSingle));
|
||||
scriptPubKey = GetScriptForDestination(ScriptHash(pkSingle));
|
||||
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, SIGHASH_ALL));
|
||||
scriptSig = DataFromTransaction(txTo, 0, txFrom.vout[0]);
|
||||
combined = CombineSignatures(txFrom.vout[0], txTo, scriptSig, empty);
|
||||
|
||||
@@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 3U);
|
||||
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 21U);
|
||||
|
||||
CScript p2sh = GetScriptForDestination(CScriptID(s1));
|
||||
CScript p2sh = GetScriptForDestination(ScriptHash(s1));
|
||||
CScript scriptSig;
|
||||
scriptSig << OP_0 << Serialize(s1);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(scriptSig), 3U);
|
||||
@@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(GetSigOpCount)
|
||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(true), 3U);
|
||||
BOOST_CHECK_EQUAL(s2.GetSigOpCount(false), 20U);
|
||||
|
||||
p2sh = GetScriptForDestination(CScriptID(s2));
|
||||
p2sh = GetScriptForDestination(ScriptHash(s2));
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(true), 0U);
|
||||
BOOST_CHECK_EQUAL(p2sh.GetSigOpCount(false), 0U);
|
||||
CScript scriptSig2;
|
||||
@@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
||||
// Multisig nested in P2SH
|
||||
{
|
||||
CScript redeemScript = CScript() << 1 << ToByteVector(pubkey) << ToByteVector(pubkey) << 2 << OP_CHECKMULTISIGVERIFY;
|
||||
CScript scriptPubKey = GetScriptForDestination(CScriptID(redeemScript));
|
||||
CScript scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
CScript scriptSig = CScript() << OP_0 << OP_0 << ToByteVector(redeemScript);
|
||||
|
||||
BuildTxs(spendingTx, coins, creationTx, scriptPubKey, scriptSig, CScriptWitness());
|
||||
@@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
||||
{
|
||||
CScript p2pk = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
|
||||
CScript scriptSig = GetScriptForWitness(p2pk);
|
||||
CScript scriptPubKey = GetScriptForDestination(CScriptID(scriptSig));
|
||||
CScript scriptPubKey = GetScriptForDestination(ScriptHash(scriptSig));
|
||||
scriptSig = CScript() << ToByteVector(scriptSig);
|
||||
CScriptWitness scriptWitness;
|
||||
scriptWitness.stack.push_back(std::vector<unsigned char>(0));
|
||||
@@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(GetTxSigOpCost)
|
||||
{
|
||||
CScript witnessScript = CScript() << 1 << ToByteVector(pubkey) << ToByteVector(pubkey) << 2 << OP_CHECKMULTISIGVERIFY;
|
||||
CScript redeemScript = GetScriptForWitness(witnessScript);
|
||||
CScript scriptPubKey = GetScriptForDestination(CScriptID(redeemScript));
|
||||
CScript scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||
CScript scriptSig = CScript() << ToByteVector(redeemScript);
|
||||
CScriptWitness scriptWitness;
|
||||
scriptWitness.stack.push_back(std::vector<unsigned char>(0));
|
||||
|
||||
@@ -311,9 +311,9 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
|
||||
|
||||
dummyTransactions[1].vout.resize(2);
|
||||
dummyTransactions[1].vout[0].nValue = 21*CENT;
|
||||
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(key[2].GetPubKey().GetID());
|
||||
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(PKHash(key[2].GetPubKey()));
|
||||
dummyTransactions[1].vout[1].nValue = 22*CENT;
|
||||
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(key[3].GetPubKey().GetID());
|
||||
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(PKHash(key[3].GetPubKey()));
|
||||
AddCoins(coinsRet, CTransaction(dummyTransactions[1]), 0);
|
||||
|
||||
return dummyTransactions;
|
||||
@@ -562,8 +562,8 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
||||
CheckWithFlag(output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false);
|
||||
|
||||
// P2SH pay-to-compressed-pubkey.
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(scriptPubkey1)), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(scriptPubkey2)), output2, input2);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(scriptPubkey1)), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(scriptPubkey2)), output2, input2);
|
||||
ReplaceRedeemScript(input2.vin[0].scriptSig, scriptPubkey1);
|
||||
CheckWithFlag(output1, input1, 0, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true);
|
||||
@@ -587,8 +587,8 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
||||
CheckWithFlag(output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false);
|
||||
|
||||
// P2SH witness pay-to-compressed-pubkey (v0).
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(GetScriptForWitness(scriptPubkey1))), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(GetScriptForWitness(scriptPubkey2))), output2, input2);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey1))), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey2))), output2, input2);
|
||||
ReplaceRedeemScript(input2.vin[0].scriptSig, GetScriptForWitness(scriptPubkey1));
|
||||
CheckWithFlag(output1, input1, 0, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true);
|
||||
@@ -612,8 +612,8 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
||||
CheckWithFlag(output1, input2, STANDARD_SCRIPT_VERIFY_FLAGS, false);
|
||||
|
||||
// P2SH pay-to-uncompressed-pubkey.
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(scriptPubkey1L)), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(scriptPubkey2L)), output2, input2);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(scriptPubkey1L)), output1, input1);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(scriptPubkey2L)), output2, input2);
|
||||
ReplaceRedeemScript(input2.vin[0].scriptSig, scriptPubkey1L);
|
||||
CheckWithFlag(output1, input1, 0, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true);
|
||||
@@ -629,8 +629,8 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
||||
CreateCreditAndSpend(keystore, GetScriptForWitness(scriptPubkey2L), output2, input2, false);
|
||||
|
||||
// Signing disabled for P2SH witness pay-to-uncompressed-pubkey (v1).
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(GetScriptForWitness(scriptPubkey1L))), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(GetScriptForWitness(scriptPubkey2L))), output2, input2, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey1L))), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptPubkey2L))), output2, input2, false);
|
||||
|
||||
// Normal 2-of-2 multisig
|
||||
CreateCreditAndSpend(keystore, scriptMulti, output1, input1, false);
|
||||
@@ -642,10 +642,10 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
||||
CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true);
|
||||
|
||||
// P2SH 2-of-2 multisig
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(scriptMulti)), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(scriptMulti)), output1, input1, false);
|
||||
CheckWithFlag(output1, input1, 0, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForDestination(CScriptID(scriptMulti)), output2, input2, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForDestination(ScriptHash(scriptMulti)), output2, input2, false);
|
||||
CheckWithFlag(output2, input2, 0, true);
|
||||
CheckWithFlag(output2, input2, SCRIPT_VERIFY_P2SH, false);
|
||||
BOOST_CHECK(*output1 == *output2);
|
||||
@@ -666,10 +666,10 @@ BOOST_AUTO_TEST_CASE(test_witness)
|
||||
CheckWithFlag(output1, input1, STANDARD_SCRIPT_VERIFY_FLAGS, true);
|
||||
|
||||
// P2SH witness 2-of-2 multisig
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(CScriptID(GetScriptForWitness(scriptMulti))), output1, input1, false);
|
||||
CreateCreditAndSpend(keystore, GetScriptForDestination(ScriptHash(GetScriptForWitness(scriptMulti))), output1, input1, false);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH, true);
|
||||
CheckWithFlag(output1, input1, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForDestination(CScriptID(GetScriptForWitness(scriptMulti))), output2, input2, false);
|
||||
CreateCreditAndSpend(keystore2, GetScriptForDestination(ScriptHash(GetScriptForWitness(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);
|
||||
@@ -695,7 +695,7 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
||||
t.vout[0].nValue = 90*CENT;
|
||||
CKey key;
|
||||
key.MakeNewKey(true);
|
||||
t.vout[0].scriptPubKey = GetScriptForDestination(key.GetPubKey().GetID());
|
||||
t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
|
||||
|
||||
std::string reason;
|
||||
BOOST_CHECK(IsStandardTx(CTransaction(t), reason));
|
||||
|
||||
@@ -56,7 +56,7 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
|
||||
|
||||
// Check that new transactions in new blocks make it into the index.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
CScript coinbase_script_pub_key = GetScriptForDestination(coinbaseKey.GetPubKey().GetID());
|
||||
CScript coinbase_script_pub_key = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
|
||||
std::vector<CMutableTransaction> no_txns;
|
||||
const CBlock& block = CreateAndProcessBlock(no_txns, coinbase_script_pub_key);
|
||||
const CTransaction& txn = *block.vtx[0];
|
||||
|
||||
@@ -151,8 +151,8 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
|
||||
}
|
||||
|
||||
CScript p2pk_scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
|
||||
CScript p2sh_scriptPubKey = GetScriptForDestination(CScriptID(p2pk_scriptPubKey));
|
||||
CScript p2pkh_scriptPubKey = GetScriptForDestination(coinbaseKey.GetPubKey().GetID());
|
||||
CScript p2sh_scriptPubKey = GetScriptForDestination(ScriptHash(p2pk_scriptPubKey));
|
||||
CScript p2pkh_scriptPubKey = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
|
||||
CScript p2wpkh_scriptPubKey = GetScriptForWitness(p2pkh_scriptPubKey);
|
||||
|
||||
CBasicKeyStore keystore;
|
||||
|
||||
Reference in New Issue
Block a user