mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
Replace CScript _hex_v_u8 appends with _hex
This will skip vector conversion before serializing to the prevector in CScript.
This commit is contained in:
parent
cac846c2fb
commit
5e190cd11f
5 changed files with 22 additions and 15 deletions
|
@ -73,7 +73,7 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi
|
||||||
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
|
static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
|
||||||
{
|
{
|
||||||
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
|
const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
|
||||||
const CScript genesisOutputScript = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex_v_u8 << OP_CHECKSIG;
|
const CScript genesisOutputScript = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
|
||||||
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
|
return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ public:
|
||||||
m_assumed_chain_state_size = 0;
|
m_assumed_chain_state_size = 0;
|
||||||
|
|
||||||
const char* testnet4_genesis_msg = "03/May/2024 000000000000000000001ebd58c244970b3aa9d783bb001011fbe8ea8e98e00e";
|
const char* testnet4_genesis_msg = "03/May/2024 000000000000000000001ebd58c244970b3aa9d783bb001011fbe8ea8e98e00e";
|
||||||
const CScript testnet4_genesis_script = CScript() << "000000000000000000000000000000000000000000000000000000000000000000"_hex_v_u8 << OP_CHECKSIG;
|
const CScript testnet4_genesis_script = CScript() << "000000000000000000000000000000000000000000000000000000000000000000"_hex << OP_CHECKSIG;
|
||||||
genesis = CreateGenesisBlock(testnet4_genesis_msg,
|
genesis = CreateGenesisBlock(testnet4_genesis_msg,
|
||||||
testnet4_genesis_script,
|
testnet4_genesis_script,
|
||||||
1714777860,
|
1714777860,
|
||||||
|
|
|
@ -608,7 +608,7 @@ void MinerTestingSetup::TestPrioritisedMining(const CScript& scriptPubKey, const
|
||||||
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||||
{
|
{
|
||||||
// Note that by default, these tests run with size accounting enabled.
|
// Note that by default, these tests run with size accounting enabled.
|
||||||
CScript scriptPubKey = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex_v_u8 << OP_CHECKSIG;
|
CScript scriptPubKey = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
|
||||||
std::unique_ptr<CBlockTemplate> pblocktemplate;
|
std::unique_ptr<CBlockTemplate> pblocktemplate;
|
||||||
|
|
||||||
CTxMemPool& tx_mempool{*m_node.mempool};
|
CTxMemPool& tx_mempool{*m_node.mempool};
|
||||||
|
|
|
@ -1368,6 +1368,13 @@ static CScript ScriptFromHex(const std::string& str)
|
||||||
return ToScript(*Assert(TryParseHex(str)));
|
return ToScript(*Assert(TryParseHex(str)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(script_byte_array_u8_vector_equivalence)
|
||||||
|
{
|
||||||
|
const CScript scriptPubKey1 = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex_v_u8 << OP_CHECKSIG;
|
||||||
|
const CScript scriptPubKey2 = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
|
||||||
|
BOOST_CHECK(scriptPubKey1 == scriptPubKey2);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(script_FindAndDelete)
|
BOOST_AUTO_TEST_CASE(script_FindAndDelete)
|
||||||
{
|
{
|
||||||
// Exercise the FindAndDelete functionality
|
// Exercise the FindAndDelete functionality
|
||||||
|
@ -1421,7 +1428,7 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
|
||||||
// prefix, leaving 02ff03 which is push-two-bytes:
|
// prefix, leaving 02ff03 which is push-two-bytes:
|
||||||
s = ToScript("0302ff030302ff03"_hex);
|
s = ToScript("0302ff030302ff03"_hex);
|
||||||
d = ToScript("03"_hex);
|
d = ToScript("03"_hex);
|
||||||
expect = CScript() << "ff03"_hex_v_u8 << "ff03"_hex_v_u8;
|
expect = CScript() << "ff03"_hex << "ff03"_hex;
|
||||||
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
|
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
|
||||||
BOOST_CHECK(s == expect);
|
BOOST_CHECK(s == expect);
|
||||||
|
|
||||||
|
|
|
@ -852,24 +852,24 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
||||||
CheckIsNotStandard(t, "scriptpubkey");
|
CheckIsNotStandard(t, "scriptpubkey");
|
||||||
|
|
||||||
// MAX_OP_RETURN_RELAY-byte TxoutType::NULL_DATA (standard)
|
// MAX_OP_RETURN_RELAY-byte TxoutType::NULL_DATA (standard)
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
|
||||||
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY, t.vout[0].scriptPubKey.size());
|
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY, t.vout[0].scriptPubKey.size());
|
||||||
CheckIsStandard(t);
|
CheckIsStandard(t);
|
||||||
|
|
||||||
// MAX_OP_RETURN_RELAY+1-byte TxoutType::NULL_DATA (non-standard)
|
// MAX_OP_RETURN_RELAY+1-byte TxoutType::NULL_DATA (non-standard)
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800"_hex_v_u8;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800"_hex;
|
||||||
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY + 1, t.vout[0].scriptPubKey.size());
|
BOOST_CHECK_EQUAL(MAX_OP_RETURN_RELAY + 1, t.vout[0].scriptPubKey.size());
|
||||||
CheckIsNotStandard(t, "scriptpubkey");
|
CheckIsNotStandard(t, "scriptpubkey");
|
||||||
|
|
||||||
// Data payload can be encoded in any way...
|
// Data payload can be encoded in any way...
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ""_hex_v_u8;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << ""_hex;
|
||||||
CheckIsStandard(t);
|
CheckIsStandard(t);
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "00"_hex_v_u8 << "01"_hex_v_u8;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "00"_hex << "01"_hex;
|
||||||
CheckIsStandard(t);
|
CheckIsStandard(t);
|
||||||
// OP_RESERVED *is* considered to be a PUSHDATA type opcode by IsPushOnly()!
|
// OP_RESERVED *is* considered to be a PUSHDATA type opcode by IsPushOnly()!
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RESERVED << -1 << 0 << "01"_hex_v_u8 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << OP_RESERVED << -1 << 0 << "01"_hex << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16;
|
||||||
CheckIsStandard(t);
|
CheckIsStandard(t);
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << 0 << "01"_hex_v_u8 << 2 << "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"_hex_v_u8;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << 0 << "01"_hex << 2 << "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"_hex;
|
||||||
CheckIsStandard(t);
|
CheckIsStandard(t);
|
||||||
|
|
||||||
// ...so long as it only contains PUSHDATA's
|
// ...so long as it only contains PUSHDATA's
|
||||||
|
@ -883,13 +883,13 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
|
||||||
|
|
||||||
// Only one TxoutType::NULL_DATA permitted in all cases
|
// Only one TxoutType::NULL_DATA permitted in all cases
|
||||||
t.vout.resize(2);
|
t.vout.resize(2);
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
|
||||||
t.vout[0].nValue = 0;
|
t.vout[0].nValue = 0;
|
||||||
t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
|
t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
|
||||||
t.vout[1].nValue = 0;
|
t.vout[1].nValue = 0;
|
||||||
CheckIsNotStandard(t, "multi-op-return");
|
CheckIsNotStandard(t, "multi-op-return");
|
||||||
|
|
||||||
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex_v_u8;
|
t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
|
||||||
t.vout[1].scriptPubKey = CScript() << OP_RETURN;
|
t.vout[1].scriptPubKey = CScript() << OP_RETURN;
|
||||||
CheckIsNotStandard(t, "multi-op-return");
|
CheckIsNotStandard(t, "multi-op-return");
|
||||||
|
|
||||||
|
|
|
@ -684,7 +684,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
|
||||||
scriptPubKey.clear();
|
scriptPubKey.clear();
|
||||||
scriptPubKey << OP_0 << "aabb"_hex_v_u8;
|
scriptPubKey << OP_0 << "aabb"_hex;
|
||||||
|
|
||||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
|
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
|
||||||
BOOST_CHECK_EQUAL(result, ISMINE_NO);
|
BOOST_CHECK_EQUAL(result, ISMINE_NO);
|
||||||
|
@ -699,7 +699,7 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0]));
|
||||||
|
|
||||||
scriptPubKey.clear();
|
scriptPubKey.clear();
|
||||||
scriptPubKey << OP_16 << "aabb"_hex_v_u8;
|
scriptPubKey << OP_16 << "aabb"_hex;
|
||||||
|
|
||||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
|
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey);
|
||||||
BOOST_CHECK_EQUAL(result, ISMINE_NO);
|
BOOST_CHECK_EQUAL(result, ISMINE_NO);
|
||||||
|
|
Loading…
Add table
Reference in a new issue