3030namespace libbitcoin {
3131namespace database {
3232
33- // fee estimate
34- // ----------------------------------------------------------------------------
33+ TEMPLATE
34+ bool CLASS::get_tx_fees (fee_rate& out, const tx_link& link) const NOEXCEPT
35+ {
36+ const auto tx = get_transaction (link, false );
37+ if (!tx || !populate_without_metadata (*tx))
38+ return false ;
3539
36- // protected
40+ out.bytes = tx->virtual_size ();
41+ out.fee = tx->fee ();
42+ return true ;
43+ }
44+
3745TEMPLATE
3846bool CLASS::get_block_fees (fee_rates& out,
3947 const header_link& link) const NOEXCEPT
@@ -58,9 +66,8 @@ bool CLASS::get_block_fees(fee_rates& out,
5866 return true ;
5967}
6068
61- // public
6269TEMPLATE
63- bool CLASS::get_block_fees (std::atomic_bool& cancel, fee_rate_sets& out,
70+ bool CLASS::get_branch_fees (std::atomic_bool& cancel, fee_rate_sets& out,
6471 size_t top, size_t count) const NOEXCEPT
6572{
6673 out.clear ();
@@ -78,31 +85,22 @@ bool CLASS::get_block_fees(std::atomic_bool& cancel, fee_rate_sets& out,
7885 std::vector<size_t > offsets (count);
7986 std::iota (offsets.begin (), offsets.end (), zero);
8087
81- std::atomic_bool failure {};
88+ std::atomic_bool fail {};
8289 constexpr auto relaxed = std::memory_order_relaxed;
8390 std::for_each (poolstl::execution::par, offsets.begin (), offsets.end (),
8491 [&](const size_t & offset) NOEXCEPT
8592 {
86- if (failure.load (relaxed))
87- return ;
88-
89- if (cancel.load (relaxed))
90- {
91- failure.store (true , relaxed);
93+ if (fail.load (relaxed))
9294 return ;
93- }
9495
95- const auto link = to_confirmed (start + offset);
96- if (!get_block_fees (out.at (offset), link))
97- {
98- failure.store (false , relaxed);
99- return ;
100- }
96+ if (cancel.load (relaxed) || !get_block_fees (out.at (offset),
97+ to_confirmed (start + offset)))
98+ fail.store (true , relaxed);
10199 });
102100
103- const auto failed = failure .load (relaxed);
101+ const auto failed = fail .load (relaxed);
104102 if (failed) out.clear ();
105- return failed;
103+ return ! failed;
106104}
107105
108106} // namespace database
0 commit comments