@@ -289,25 +289,12 @@ transaction::sizes transaction::serialized_size(const input_cptrs& inputs,
289
289
{
290
290
sizes size{ zero, zero };
291
291
292
- // Keep the condition outside of the loop.
293
- if (segregated)
292
+ std::for_each (inputs.begin (), inputs.end (), [&](const auto & in) NOEXCEPT
294
293
{
295
- std::for_each (inputs.begin (), inputs.end (), [&](const auto & in) NOEXCEPT
296
- {
297
- size.nominal = ceilinged_add (size.nominal , in->nominal_size ());
294
+ size.nominal = ceilinged_add (size.nominal , in->nominal_size ());
295
+ if (segregated)
298
296
size.witnessed = ceilinged_add (size.witnessed , in->witnessed_size ());
299
- });
300
- }
301
- else
302
- {
303
- // Witness must be zeroed because witnesses have nonzero size when they
304
- // are zero-valued, so they can be archived easily. Also it would be
305
- // wasteful to to count mutiple zero sizes, so exclude them here.
306
- std::for_each (inputs.begin (), inputs.end (), [&](const auto & in) NOEXCEPT
307
- {
308
- size.nominal = ceilinged_add (size.nominal , in->nominal_size ());
309
- });
310
- }
297
+ });
311
298
312
299
const auto outs = [](size_t total, const auto & output) NOEXCEPT
313
300
{
@@ -316,20 +303,20 @@ transaction::sizes transaction::serialized_size(const input_cptrs& inputs,
316
303
317
304
constexpr auto base_const_size = ceilinged_add (sizeof (version_),
318
305
sizeof (locktime_));
319
-
320
306
constexpr auto witness_const_size = ceilinged_add (sizeof (witness_marker),
321
307
sizeof (witness_enabled));
322
308
323
309
const auto base_size = ceilinged_add (ceilinged_add (ceilinged_add (
324
310
base_const_size, variable_size (inputs.size ())),
325
311
variable_size (outputs.size ())),
326
312
std::accumulate (outputs.begin (), outputs.end (), zero, outs));
327
-
328
313
const auto nominal_size = ceilinged_add (base_size, size.nominal );
329
- const auto witnessed_size = ceilinged_add (ceilinged_add (base_size,
330
- witness_const_size),
331
- size.witnessed );
332
314
315
+ // witnessed_size is nominal_size for non-segregated transactions.
316
+ const auto witnessed_size = segregated ? ceilinged_add (ceilinged_add (
317
+ base_size, witness_const_size), size.witnessed ) : nominal_size;
318
+
319
+ // Values are the same for non-segregated transactions.
333
320
return { nominal_size, witnessed_size };
334
321
}
335
322
0 commit comments