Skip to content

Commit 33be281

Browse files
committed
Update fee queries to pull whole object.
1 parent f2f646b commit 33be281

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

include/bitcoin/database/impl/query/validate.ipp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,23 @@ code CLASS::get_block_state(const header_link& link) const NOEXCEPT
124124
}
125125

126126
TEMPLATE
127-
code CLASS::get_block_state(uint64_t& fees,
128-
const header_link& link) const NOEXCEPT
127+
uint64_t CLASS::get_block_fees(const header_link& link) const NOEXCEPT
129128
{
130-
table::validated_bk::slab valid{};
131-
if (!store_.validated_bk.at(to_validated_bk(link), valid))
132-
return is_associated(link) ? error::unvalidated : error::unassociated;
129+
// TODO: optimize.
130+
const auto block = get_block(link, false);
131+
return block && populate_without_metadata(*block) ? block->fees() :
132+
max_uint64;
133+
}
133134

134-
// TODO: Fees only valid if block_valid is the current state (iterate for valid).
135-
fees = valid.fees;
135+
TEMPLATE
136+
uint64_t CLASS::get_tx_fee(const tx_link& link) const NOEXCEPT
137+
{
138+
// TODO: optimize.
139+
const auto tx = get_transaction(link, false);
140+
if (is_coinbase(link))
141+
return {};
136142

137-
return to_block_code(valid.code);
143+
return tx && populate_without_metadata(*tx) ? tx->fee() : max_uint64;
138144
}
139145

140146
TEMPLATE

include/bitcoin/database/query.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,10 @@ class query
473473
/// -----------------------------------------------------------------------
474474

475475
/// States.
476-
code get_header_state(const header_link& link) const NOEXCEPT;
476+
uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT;
477+
uint64_t get_block_fees(const header_link& link) const NOEXCEPT;
477478
code get_block_state(const header_link& link) const NOEXCEPT;
478-
code get_block_state(uint64_t& fees, const header_link& link) const NOEXCEPT;
479+
code get_header_state(const header_link& link) const NOEXCEPT;
479480
code get_tx_state(const tx_link& link, const context& ctx) const NOEXCEPT;
480481
code get_tx_state(uint64_t& fee, size_t& sigops, const tx_link& link,
481482
const context& ctx) const NOEXCEPT;

test/query/validate.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__invalid_link__unassociated
167167
uint64_t fees{};
168168
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
169169
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unassociated);
170-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unassociated);
171170
BOOST_REQUIRE_EQUAL(fees, 0u);
172171
}
173172

@@ -185,7 +184,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unassociated_link__unassoc
185184
uint64_t fees{};
186185
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
187186
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unassociated);
188-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unassociated);
189187
BOOST_REQUIRE_EQUAL(fees, 0u);
190188
}
191189

@@ -202,7 +200,6 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unvalidated_link__unvalida
202200
uint64_t fees{};
203201
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::unvalidated);
204202
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::unvalidated);
205-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::unvalidated);
206203
BOOST_REQUIRE_EQUAL(fees, 0u);
207204
}
208205

@@ -219,13 +216,11 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__confirmable__block_confirm
219216
uint64_t fees{};
220217
BOOST_REQUIRE_EQUAL(query.get_header_state(0), error::unvalidated);
221218
BOOST_REQUIRE_EQUAL(query.get_block_state(0), error::unvalidated);
222-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 0), error::unvalidated);
223219
BOOST_REQUIRE_EQUAL(fees, 0u);
224220

225221
BOOST_REQUIRE(query.set_block_confirmable(1));
226222
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_confirmable);
227223
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_confirmable);
228-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_confirmable);
229224
BOOST_REQUIRE_EQUAL(fees, 0u);
230225
}
231226

@@ -239,12 +234,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__valid__block_valid)
239234
BOOST_REQUIRE(query.initialize(test::genesis));
240235
BOOST_REQUIRE(query.set(test::block1, context{}, false, false));
241236

242-
uint64_t fees{};
243237
BOOST_REQUIRE(query.set_block_valid(1, 42));
244238
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_valid);
245239
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_valid);
246-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_valid);
247-
BOOST_REQUIRE_EQUAL(fees, 42u);
248240
}
249241

250242
BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unconfirmable__block_unconfirmable)
@@ -257,12 +249,9 @@ BOOST_AUTO_TEST_CASE(query_validate__get_block_state__unconfirmable__block_uncon
257249
BOOST_REQUIRE(query.initialize(test::genesis));
258250
BOOST_REQUIRE(query.set(test::block1, context{}, false, false));
259251

260-
uint64_t fees{};
261252
BOOST_REQUIRE(query.set_block_unconfirmable(1));
262253
BOOST_REQUIRE_EQUAL(query.get_header_state(1), error::block_unconfirmable);
263254
BOOST_REQUIRE_EQUAL(query.get_block_state(1), error::block_unconfirmable);
264-
BOOST_REQUIRE_EQUAL(query.get_block_state(fees, 1), error::block_unconfirmable);
265-
BOOST_REQUIRE_EQUAL(fees, 0u);
266255
}
267256

268257
BOOST_AUTO_TEST_CASE(query_validate__get_tx_state__invalid_link__unvalidated)

0 commit comments

Comments
 (0)