Introduce convenience type CTransactionRef
This commit is contained in:
@@ -26,21 +26,21 @@ static CBlock BuildBlockTestCase() {
|
||||
tx.vout[0].nValue = 42;
|
||||
|
||||
block.vtx.resize(3);
|
||||
block.vtx[0] = std::make_shared<const CTransaction>(tx);
|
||||
block.vtx[0] = MakeTransactionRef(tx);
|
||||
block.nVersion = 42;
|
||||
block.hashPrevBlock = GetRandHash();
|
||||
block.nBits = 0x207fffff;
|
||||
|
||||
tx.vin[0].prevout.hash = GetRandHash();
|
||||
tx.vin[0].prevout.n = 0;
|
||||
block.vtx[1] = std::make_shared<const CTransaction>(tx);
|
||||
block.vtx[1] = MakeTransactionRef(tx);
|
||||
|
||||
tx.vin.resize(10);
|
||||
for (size_t i = 0; i < tx.vin.size(); i++) {
|
||||
tx.vin[i].prevout.hash = GetRandHash();
|
||||
tx.vin[i].prevout.n = 0;
|
||||
}
|
||||
block.vtx[2] = std::make_shared<const CTransaction>(tx);
|
||||
block.vtx[2] = MakeTransactionRef(tx);
|
||||
|
||||
bool mutated;
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block, &mutated);
|
||||
@@ -80,12 +80,12 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest)
|
||||
|
||||
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1);
|
||||
|
||||
std::vector<std::shared_ptr<const CTransaction>> removed;
|
||||
std::vector<CTransactionRef> removed;
|
||||
pool.removeRecursive(*block.vtx[2], &removed);
|
||||
BOOST_CHECK_EQUAL(removed.size(), 1);
|
||||
|
||||
CBlock block2;
|
||||
std::vector<std::shared_ptr<const CTransaction>> vtx_missing;
|
||||
std::vector<CTransactionRef> vtx_missing;
|
||||
BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing) == READ_STATUS_INVALID); // No transactions
|
||||
|
||||
vtx_missing.push_back(block.vtx[2]); // Wrong transaction
|
||||
@@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
|
||||
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[2]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1);
|
||||
|
||||
CBlock block2;
|
||||
std::vector<std::shared_ptr<const CTransaction>> vtx_missing;
|
||||
std::vector<CTransactionRef> vtx_missing;
|
||||
BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing) == READ_STATUS_INVALID); // No transactions
|
||||
|
||||
vtx_missing.push_back(block.vtx[1]); // Wrong transaction
|
||||
@@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
|
||||
BOOST_CHECK_EQUAL(pool.mapTx.find(block.vtx[1]->GetHash())->GetSharedTx().use_count(), SHARED_TX_OFFSET + 1);
|
||||
|
||||
CBlock block2;
|
||||
std::vector<std::shared_ptr<const CTransaction>> vtx_missing;
|
||||
std::vector<CTransactionRef> vtx_missing;
|
||||
BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing) == READ_STATUS_OK);
|
||||
BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString());
|
||||
bool mutated;
|
||||
@@ -266,7 +266,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest)
|
||||
|
||||
CBlock block;
|
||||
block.vtx.resize(1);
|
||||
block.vtx[0] = std::make_shared<const CTransaction>(std::move(coinbase));
|
||||
block.vtx[0] = MakeTransactionRef(std::move(coinbase));
|
||||
block.nVersion = 42;
|
||||
block.hashPrevBlock = GetRandHash();
|
||||
block.nBits = 0x207fffff;
|
||||
@@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest)
|
||||
BOOST_CHECK(partialBlock.IsTxAvailable(0));
|
||||
|
||||
CBlock block2;
|
||||
std::vector<std::shared_ptr<const CTransaction>> vtx_missing;
|
||||
std::vector<CTransactionRef> vtx_missing;
|
||||
BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing) == READ_STATUS_OK);
|
||||
BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString());
|
||||
BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block2, &mutated).ToString());
|
||||
|
||||
@@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(MempoolRemoveTest)
|
||||
|
||||
|
||||
CTxMemPool testPool(CFeeRate(0));
|
||||
std::vector<std::shared_ptr<const CTransaction>> removed;
|
||||
std::vector<CTransactionRef> removed;
|
||||
|
||||
// Nothing in pool, remove should do nothing:
|
||||
testPool.removeRecursive(txParent, &removed);
|
||||
@@ -410,8 +410,8 @@ BOOST_AUTO_TEST_CASE(MempoolAncestorIndexingTest)
|
||||
CheckSort<ancestor_score>(pool, sortedOrder);
|
||||
|
||||
/* after tx6 is mined, tx7 should move up in the sort */
|
||||
std::vector<std::shared_ptr<const CTransaction>> vtx;
|
||||
vtx.push_back(std::make_shared<const CTransaction>(tx6));
|
||||
std::vector<CTransactionRef> vtx;
|
||||
vtx.push_back(MakeTransactionRef(tx6));
|
||||
pool.removeForBlock(vtx, 1, NULL, false);
|
||||
|
||||
sortedOrder.erase(sortedOrder.begin()+1);
|
||||
@@ -546,7 +546,7 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest)
|
||||
pool.addUnchecked(tx5.GetHash(), entry.Fee(1000LL).FromTx(tx5, &pool));
|
||||
pool.addUnchecked(tx7.GetHash(), entry.Fee(9000LL).FromTx(tx7, &pool));
|
||||
|
||||
std::vector<std::shared_ptr<const CTransaction>> vtx;
|
||||
std::vector<CTransactionRef> vtx;
|
||||
SetMockTime(42);
|
||||
SetMockTime(42 + CTxMemPool::ROLLING_FEE_HALFLIFE);
|
||||
BOOST_CHECK_EQUAL(pool.GetMinFee(1).GetFeePerK(), maxFeeRateRemoved.GetFeePerK() + 1000);
|
||||
|
||||
@@ -15,7 +15,7 @@ static uint256 BlockBuildMerkleTree(const CBlock& block, bool* fMutated, std::ve
|
||||
{
|
||||
vMerkleTree.clear();
|
||||
vMerkleTree.reserve(block.vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes.
|
||||
for (std::vector<std::shared_ptr<const CTransaction>>::const_iterator it(block.vtx.begin()); it != block.vtx.end(); ++it)
|
||||
for (std::vector<CTransactionRef>::const_iterator it(block.vtx.begin()); it != block.vtx.end(); ++it)
|
||||
vMerkleTree.push_back((*it)->GetHash());
|
||||
int j = 0;
|
||||
bool mutated = false;
|
||||
@@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(merkle_test)
|
||||
for (int j = 0; j < ntx; j++) {
|
||||
CMutableTransaction mtx;
|
||||
mtx.nLockTime = j;
|
||||
block.vtx[j] = std::make_shared<const CTransaction>(mtx);
|
||||
block.vtx[j] = MakeTransactionRef(std::move(mtx));
|
||||
}
|
||||
// Compute the root of the block before mutating it.
|
||||
bool unmutatedMutated = false;
|
||||
|
||||
@@ -77,7 +77,7 @@ bool TestSequenceLocks(const CTransaction &tx, int flags)
|
||||
// Implemented as an additional function, rather than a separate test case,
|
||||
// to allow reusing the blockchain created in CreateNewBlock_validity.
|
||||
// Note that this test assumes blockprioritysize is 0.
|
||||
void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey, std::vector<std::shared_ptr<const CTransaction>>& txFirst)
|
||||
void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey, std::vector<CTransactionRef>& txFirst)
|
||||
{
|
||||
// Test the ancestor feerate transaction selection.
|
||||
TestMemPoolEntryHelper entry;
|
||||
@@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
// We can't make transactions until we have inputs
|
||||
// Therefore, load 100 blocks :)
|
||||
int baseheight = 0;
|
||||
std::vector<std::shared_ptr<const CTransaction>> txFirst;
|
||||
std::vector<CTransactionRef> txFirst;
|
||||
for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i)
|
||||
{
|
||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||
@@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
txCoinbase.vin[0].scriptSig.push_back(blockinfo[i].extranonce);
|
||||
txCoinbase.vin[0].scriptSig.push_back(chainActive.Height());
|
||||
txCoinbase.vout[0].scriptPubKey = CScript();
|
||||
pblock->vtx[0] = std::make_shared<const CTransaction>(std::move(txCoinbase));
|
||||
pblock->vtx[0] = MakeTransactionRef(std::move(txCoinbase));
|
||||
if (txFirst.size() == 0)
|
||||
baseheight = chainActive.Height();
|
||||
if (txFirst.size() < 4)
|
||||
|
||||
@@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(pmt_test1)
|
||||
for (unsigned int j=0; j<nTx; j++) {
|
||||
CMutableTransaction tx;
|
||||
tx.nLockTime = j; // actual transaction data doesn't matter; just make the nLockTime's unique
|
||||
block.vtx.push_back(std::make_shared<const CTransaction>(tx));
|
||||
block.vtx.push_back(MakeTransactionRef(std::move(tx)));
|
||||
}
|
||||
|
||||
// calculate actual merkle root and height
|
||||
|
||||
@@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
||||
CFeeRate baseRate(basefee, GetVirtualTransactionSize(tx));
|
||||
|
||||
// Create a fake block
|
||||
std::vector<std::shared_ptr<const CTransaction>> block;
|
||||
std::vector<CTransactionRef> block;
|
||||
int blocknum = 0;
|
||||
|
||||
// Loop through 200 blocks
|
||||
@@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
||||
// 9/10 blocks add 2nd highest and so on until ...
|
||||
// 1/10 blocks add lowest fee transactions
|
||||
while (txHashes[9-h].size()) {
|
||||
std::shared_ptr<const CTransaction> ptx = mpool.get(txHashes[9-h].back());
|
||||
CTransactionRef ptx = mpool.get(txHashes[9-h].back());
|
||||
if (ptx)
|
||||
block.push_back(ptx);
|
||||
txHashes[9-h].pop_back();
|
||||
@@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
||||
// Estimates should still not be below original
|
||||
for (int j = 0; j < 10; j++) {
|
||||
while(txHashes[j].size()) {
|
||||
std::shared_ptr<const CTransaction> ptx = mpool.get(txHashes[j].back());
|
||||
CTransactionRef ptx = mpool.get(txHashes[j].back());
|
||||
if (ptx)
|
||||
block.push_back(ptx);
|
||||
txHashes[j].pop_back();
|
||||
@@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
|
||||
tx.vin[0].prevout.n = 10000*blocknum+100*j+k;
|
||||
uint256 hash = tx.GetHash();
|
||||
mpool.addUnchecked(hash, entry.Fee(feeV[j]).Time(GetTime()).Priority(0).Height(blocknum).FromTx(tx, &mpool));
|
||||
std::shared_ptr<const CTransaction> ptx = mpool.get(hash);
|
||||
CTransactionRef ptx = mpool.get(hash);
|
||||
if (ptx)
|
||||
block.push_back(ptx);
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>&
|
||||
// Replace mempool-selected txns with just coinbase plus passed-in txns:
|
||||
block.vtx.resize(1);
|
||||
BOOST_FOREACH(const CMutableTransaction& tx, txns)
|
||||
block.vtx.push_back(std::make_shared<const CTransaction>(tx));
|
||||
block.vtx.push_back(MakeTransactionRef(tx));
|
||||
// IncrementExtraNonce creates a valid coinbase and merkleRoot
|
||||
unsigned int extraNonce = 0;
|
||||
IncrementExtraNonce(&block, chainActive.Tip(), extraNonce);
|
||||
|
||||
Reference in New Issue
Block a user