MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MakeTransactionBulkedTo

Function MakeTransactionBulkedTo

src/bench/txorphanage.cpp:30–47  ·  view source on GitHub ↗

Creates a transaction with num_inputs inputs and 1 output, padded to target_weight. Use this function to maximize m_outpoint_to_orphan_it operations. If num_inputs is 0, we maximize the number of inputs.

Source from the content-addressed store, hash-verified

28// Creates a transaction with num_inputs inputs and 1 output, padded to target_weight. Use this function to maximize m_outpoint_to_orphan_it operations.
29// If num_inputs is 0, we maximize the number of inputs.
30static CTransactionRef MakeTransactionBulkedTo(unsigned int num_inputs, int64_t target_weight, FastRandomContext& det_rand)
31{
32 CMutableTransaction tx;
33 assert(target_weight >= 40 + APPROX_WEIGHT_PER_INPUT);
34 if (!num_inputs) num_inputs = (target_weight - 40) / APPROX_WEIGHT_PER_INPUT;
35 for (unsigned int i = 0; i < num_inputs; ++i) {
36 tx.vin.emplace_back(Txid::FromUint256(det_rand.rand256()), 0);
37 }
38 assert(GetTransactionWeight(*MakeTransactionRef(tx)) <= target_weight);
39
40 tx.vout.resize(1);
41
42 // If necessary, pad the transaction to the target weight.
43 if (GetTransactionWeight(*MakeTransactionRef(tx)) < target_weight - 4) {
44 BulkTransaction(tx, target_weight);
45 }
46 return MakeTransactionRef(tx);
47}
48
49// Constructs a transaction using a subset of inputs[start_input : start_input + num_inputs] up to the weight_limit.
50static CTransactionRef MakeTransactionSpendingUpTo(const std::vector<CTxIn>& inputs, unsigned int start_input, unsigned int num_inputs, int64_t weight_limit)

Callers 3

OrphanageEraseAllFunction · 0.85

Calls 6

GetTransactionWeightFunction · 0.85
MakeTransactionRefFunction · 0.85
BulkTransactionFunction · 0.85
rand256Method · 0.80
emplace_backMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected