Skip to content

Commit 5f865e3

Browse files
committed
Add block.spends computed count of non-null inputs.
1 parent bebfa0e commit 5f865e3

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

include/bitcoin/system/chain/block.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class BC_API block
9090
hashes transaction_hashes(bool witness) const NOEXCEPT;
9191

9292
/// Computed properties.
93+
size_t spends() const NOEXCEPT;
9394
size_t weight() const NOEXCEPT;
9495
uint64_t fees() const NOEXCEPT;
9596
uint64_t claim() const NOEXCEPT;

src/chain/block.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ hashes block::transaction_hashes(bool witness) const NOEXCEPT
251251
return out;
252252
}
253253

254+
// computed
255+
size_t block::spends() const NOEXCEPT
256+
{
257+
if (txs_->empty())
258+
return zero;
259+
260+
// Overflow returns max_size_t.
261+
const auto ins = [](size_t total, const auto& tx) NOEXCEPT
262+
{
263+
return ceilinged_add(total, tx->inputs());
264+
};
265+
266+
return std::accumulate(std::next(txs_->begin()), txs_->end(), zero, ins);
267+
}
268+
254269
// computed
255270
hash_digest block::hash() const NOEXCEPT
256271
{

0 commit comments

Comments
 (0)