Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ test_libbitcoin_database_test_SOURCES = \
test/query/confirm.cpp \
test/query/consensus.cpp \
test/query/context.cpp \
test/query/estimate.cpp \
test/query/extent.cpp \
test/query/fees.cpp \
test/query/height.cpp \
test/query/initialize.cpp \
test/query/merkle.cpp \
Expand Down Expand Up @@ -182,8 +182,8 @@ include_bitcoin_database_impl_query_HEADERS = \
include/bitcoin/database/impl/query/confirm.ipp \
include/bitcoin/database/impl/query/consensus.ipp \
include/bitcoin/database/impl/query/context.ipp \
include/bitcoin/database/impl/query/estimate.ipp \
include/bitcoin/database/impl/query/extent.ipp \
include/bitcoin/database/impl/query/fees.ipp \
include/bitcoin/database/impl/query/height.ipp \
include/bitcoin/database/impl/query/initialize.ipp \
include/bitcoin/database/impl/query/merkle.ipp \
Expand Down
2 changes: 1 addition & 1 deletion builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ if (with-tests)
"../../test/query/confirm.cpp"
"../../test/query/consensus.cpp"
"../../test/query/context.cpp"
"../../test/query/estimate.cpp"
"../../test/query/extent.cpp"
"../../test/query/fees.cpp"
"../../test/query/height.cpp"
"../../test/query/initialize.cpp"
"../../test/query/merkle.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
<ClCompile Include="..\..\..\..\test\query\confirm.cpp" />
<ClCompile Include="..\..\..\..\test\query\consensus.cpp" />
<ClCompile Include="..\..\..\..\test\query\context.cpp" />
<ClCompile Include="..\..\..\..\test\query\estimate.cpp" />
<ClCompile Include="..\..\..\..\test\query\extent.cpp" />
<ClCompile Include="..\..\..\..\test\query\fees.cpp" />
<ClCompile Include="..\..\..\..\test\query\height.cpp">
<ObjectFileName>$(IntDir)test_query_height.obj</ObjectFileName>
</ClCompile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@
<ClCompile Include="..\..\..\..\test\query\context.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\estimate.cpp">
<ClCompile Include="..\..\..\..\test\query\extent.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\extent.cpp">
<ClCompile Include="..\..\..\..\test\query\fees.cpp">
<Filter>src\query</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\query\height.cpp">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@
<None Include="..\..\..\..\include\bitcoin\database\impl\query\confirm.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\consensus.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\context.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\estimate.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\extent.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\fees.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\height.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\initialize.ipp" />
<None Include="..\..\..\..\include\bitcoin\database\impl\query\merkle.ipp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@
<None Include="..\..\..\..\include\bitcoin\database\impl\query\context.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\estimate.ipp">
<None Include="..\..\..\..\include\bitcoin\database\impl\query\extent.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\extent.ipp">
<None Include="..\..\..\..\include\bitcoin\database\impl\query\fees.ipp">
<Filter>include\bitcoin\database\impl\query</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\database\impl\query\height.ipp">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,35 @@

namespace libbitcoin {
namespace database {


// TODO: optimize.

TEMPLATE
uint64_t CLASS::get_tx_fee(const tx_link& link) const NOEXCEPT
{
const auto tx = get_transaction(link, false);
if (!tx)
return max_uint64;

if (tx->is_coinbase())
return zero;

return populate_without_metadata(*tx) ? tx->fee() : max_uint64;
}

TEMPLATE
uint64_t CLASS::get_block_fee(const header_link& link) const NOEXCEPT
{
const auto block = get_block(link, false);
return block && populate_without_metadata(*block) ? block->fees() :
max_uint64;
}

TEMPLATE
bool CLASS::get_tx_fees(fee_rate& out, const tx_link& link) const NOEXCEPT
{
const auto tx = get_transaction(link, false);
if (!tx || !populate_without_metadata(*tx))
if (!tx || tx->is_coinbase() || !populate_without_metadata(*tx))
return false;

out.bytes = tx->virtual_size();
Expand Down Expand Up @@ -68,17 +91,17 @@ bool CLASS::get_block_fees(fee_rates& out,

TEMPLATE
bool CLASS::get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out,
size_t top, size_t count) const NOEXCEPT
size_t start, size_t count) const NOEXCEPT
{
out.clear();
if (is_zero(count))
return true;

if (top > get_top_confirmed())
if (system::is_add_overflow(start, sub1(count)))
return false;

const auto start = top - sub1(count);
if (system::is_subtract_overflow(top, sub1(count)))
const auto last = start + sub1(count);
if (last > get_top_confirmed())
return false;

out.resize(count);
Expand Down
20 changes: 0 additions & 20 deletions include/bitcoin/database/impl/query/validate.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,6 @@ code CLASS::get_block_state(const header_link& link) const NOEXCEPT
return to_block_code(valid.code);
}

TEMPLATE
uint64_t CLASS::get_block_fee(const header_link& link) const NOEXCEPT
{
// TODO: optimize.
const auto block = get_block(link, false);
return block && populate_without_metadata(*block) ? block->fees() :
max_uint64;
}

TEMPLATE
uint64_t CLASS::get_tx_fee(const tx_link& link) const NOEXCEPT
{
// TODO: optimize.
const auto tx = get_transaction(link, false);
if (is_coinbase(link))
return {};

return tx && populate_without_metadata(*tx) ? tx->fee() : max_uint64;
}

TEMPLATE
inline bool CLASS::is_validated(const header_link& link) const NOEXCEPT
{
Expand Down
12 changes: 8 additions & 4 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,21 @@ class query
bool populate_without_metadata(const block& block) const NOEXCEPT;
bool populate_without_metadata(const transaction& tx) const NOEXCEPT;

/// Services.
/// Fees.
/// -----------------------------------------------------------------------

/// Total fee value by tx or block.
uint64_t get_tx_fee(const tx_link& link) const NOEXCEPT;
uint64_t get_block_fee(const header_link& link) const NOEXCEPT;

/// Gether fee rate tuples by tx, block or branch.
/// Fee rate tuples by tx, block or branch.
bool get_tx_fees(fee_rate& out, const tx_link& link) const NOEXCEPT;
bool get_block_fees(fee_rates& out, const header_link& link) const NOEXCEPT;
bool get_branch_fees(std::atomic_bool& cancel, fee_rate_sets& out,
size_t top, size_t count) const NOEXCEPT;
size_t start, size_t count) const NOEXCEPT;

/// Merkle.
/// -----------------------------------------------------------------------

/// Merkle computations over the index of confirmed headers.
hash_digest get_merkle_root(size_t height) const NOEXCEPT;
Expand Down Expand Up @@ -786,13 +790,13 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
#include <bitcoin/database/impl/query/consensus.ipp>
#include <bitcoin/database/impl/query/context.ipp>
#include <bitcoin/database/impl/query/extent.ipp>
#include <bitcoin/database/impl/query/fees.ipp>
#include <bitcoin/database/impl/query/height.ipp>
#include <bitcoin/database/impl/query/initialize.ipp>
#include <bitcoin/database/impl/query/network.ipp>
#include <bitcoin/database/impl/query/objects.ipp>
#include <bitcoin/database/impl/query/optional.ipp>
#include <bitcoin/database/impl/query/merkle.ipp>
#include <bitcoin/database/impl/query/estimate.ipp>
#include <bitcoin/database/impl/query/translate.ipp>
#include <bitcoin/database/impl/query/validate.ipp>

Expand Down
109 changes: 109 additions & 0 deletions test/mocks/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,115 @@ const block block_spend_internal_2b
}
}
};
const block block_missing_prevout_2b
{
header
{
0x31323334, // version
block1b.hash(), // previous_block_hash
system::one_hash, // merkle_root
0x41424344, // timestamp
0x51525354, // bits
0x61626364 // nonce
},
transactions
{
tx2b,
transaction
{
0xb2,
inputs
{
input
{
// missing prevout index.
point{ tx2b.hash(false), 0x01 },
script{ { { opcode::checkmultisig }, { opcode::size } } },
witness{},
0xb2
}
},
outputs
{
output
{
0xb0, // fee will be 0x01
script{ { { opcode::pick } } }
}
},
0xb2
}
}
};
const block block_valid_spend_internal_2b
{
header
{
0x31323334, // version
block1b.hash(), // previous_block_hash
system::one_hash, // merkle_root
0x41424344, // timestamp
0x51525354, // bits
0x61626364 // nonce
},
transactions
{
tx2b,
transaction
{
0xb2,
inputs
{
input
{
point{ tx2b.hash(false), 0x00 },
script{ { { opcode::checkmultisig }, { opcode::size } } },
witness{},
0xb2
}
},
outputs
{
output
{
0xb0, // fee will be 0x01
script{ { { opcode::pick } } }
}
},
0xb2
},
transaction
{
0xb2,
inputs
{
input
{
point{ block1b.transactions_ptr()->front()->hash(false), 0x00 },
script{ { { opcode::checkmultisig }, { opcode::size } } },
witness{},
0xb2
},
input
{
point{ block1b.transactions_ptr()->front()->hash(false), 0x01 },
script{ { { opcode::checkmultisig } } },
witness{},
0xb2
}
},
outputs
{
output
{
0xb2, // fee will be 0xb1 + 0xb1 - 0xb2 = 0xb0
script{ { { opcode::pick }, { opcode::roll }, { opcode::pick } } }
}
},
0xb2
}
}
};

} // namespace test

Expand Down
33 changes: 0 additions & 33 deletions test/query/estimate.cpp

This file was deleted.

Loading
Loading