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
104 changes: 67 additions & 37 deletions include/bitcoin/database/impl/query/objects.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,6 @@ typename CLASS::transaction::cptr CLASS::get_transaction(const tx_link& link,
return ptr;
}

TEMPLATE
typename CLASS::output::cptr CLASS::get_output(
const output_link& link) const NOEXCEPT
{
table::output::only out{};
if (!store_.output.get(link, out))
return {};

return out.output;
}

// static/protected
TEMPLATE
typename CLASS::point::cptr CLASS::make_point(hash_digest&& hash,
Expand All @@ -216,6 +205,50 @@ typename CLASS::point::cptr CLASS::make_point(hash_digest&& hash,
return system::to_shared<point>(std::move(hash), index);
}

TEMPLATE
typename CLASS::point CLASS::get_point(
const point_link& link) const NOEXCEPT
{
table::point::record point{};
if (!store_.point.get(link, point))
return {};

return { point.hash, point.index };
}

TEMPLATE
typename CLASS::witness::cptr CLASS::get_witness(
const point_link& link) const NOEXCEPT
{
table::input::get_witness in{};
table::ins::get_input ins{};
if (!store_.ins.get(link, ins) ||
!store_.input.get(ins.input_fk, in))
return {};

return in.witness;
}

TEMPLATE
typename CLASS::script::cptr CLASS::get_input_script(
const point_link& link) const NOEXCEPT
{
table::input::get_script in{};
table::ins::get_input ins{};
if (!store_.ins.get(link, ins) ||
!store_.input.get(ins.input_fk, in))
return {};

return in.script;
}

TEMPLATE
typename CLASS::input::cptr CLASS::get_input(const tx_link& link,
uint32_t index, bool witness) const NOEXCEPT
{
return get_input(to_point(link, index), witness);
}

TEMPLATE
typename CLASS::input::cptr CLASS::get_input(const point_link& link,
bool witness) const NOEXCEPT
Expand Down Expand Up @@ -243,14 +276,32 @@ typename CLASS::input::cptr CLASS::get_input(const point_link& link,
}

TEMPLATE
typename CLASS::point CLASS::get_point(
const point_link& link) const NOEXCEPT
typename CLASS::script::cptr CLASS::get_output_script(
const output_link& link) const NOEXCEPT
{
table::point::record point{};
if (!store_.point.get(link, point))
table::output::get_script out{};
if (!store_.output.get(link, out))
return {};

return { point.hash, point.index };
return out.script;
}

TEMPLATE
typename CLASS::output::cptr CLASS::get_output(const tx_link& link,
uint32_t index) const NOEXCEPT
{
return get_output(to_output(link, index));
}

TEMPLATE
typename CLASS::output::cptr CLASS::get_output(
const output_link& link) const NOEXCEPT
{
table::output::only out{};
if (!store_.output.get(link, out))
return {};

return out.output;
}

TEMPLATE
Expand All @@ -270,27 +321,6 @@ typename CLASS::inputs_ptr CLASS::get_spenders(
return inputs;
}

TEMPLATE
typename CLASS::input::cptr CLASS::get_input(const tx_link& link,
uint32_t input_index, bool witness) const NOEXCEPT
{
return get_input(to_point(link, input_index), witness);
}

TEMPLATE
typename CLASS::output::cptr CLASS::get_output(const tx_link& link,
uint32_t output_index) const NOEXCEPT
{
return get_output(to_output(link, output_index));
}

TEMPLATE
typename CLASS::inputs_ptr CLASS::get_spenders_index(const tx_link& link,
uint32_t output_index, bool witness) const NOEXCEPT
{
return get_spenders(to_output(link, output_index), witness);
}

// Populate prevout objects.
// ----------------------------------------------------------------------------

Expand Down
23 changes: 13 additions & 10 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ class query
using block = system::chain::block;
using point = system::chain::point;
using input = system::chain::input;
using script = system::chain::script;
using output = system::chain::output;
using header = system::chain::header;
using script = system::chain::script;
using witness = system::chain::witness;
using headers = system::chain::header_cptrs;
using transaction = system::chain::transaction;
using transactions = system::chain::transaction_cptrs;
Expand Down Expand Up @@ -379,20 +380,22 @@ class query

header::cptr get_header(const header_link& link) const NOEXCEPT;
block::cptr get_block(const header_link& link, bool witness) const NOEXCEPT;
transaction::cptr get_transaction(const tx_link& link, bool witness) const NOEXCEPT;
transaction::cptr get_transaction(const tx_link& link,
bool witness) const NOEXCEPT;

point get_point(const point_link& link) const NOEXCEPT;
witness::cptr get_witness(const point_link& link) const NOEXCEPT;
script::cptr get_input_script(const point_link& link) const NOEXCEPT;
input::cptr get_input(const point_link& link, bool witness) const NOEXCEPT;
input::cptr get_input(const tx_link& link, uint32_t index,
bool witness) const NOEXCEPT;

script::cptr get_output_script(const output_link& link) const NOEXCEPT;
output::cptr get_output(const output_link& link) const NOEXCEPT;
output::cptr get_output(const tx_link& link, uint32_t index) const NOEXCEPT;
inputs_ptr get_spenders(const output_link& link,
bool witness) const NOEXCEPT;

input::cptr get_input(const tx_link& link,
uint32_t input_index, bool witness) const NOEXCEPT;
output::cptr get_output(const tx_link& link,
uint32_t output_index) const NOEXCEPT;
point get_point(const point_link& link) const NOEXCEPT;
inputs_ptr get_spenders_index(const tx_link& link,
uint32_t output_index, bool witness) const NOEXCEPT;

/// False implies missing prevouts, node input.metadata is populated.
bool populate_with_metadata(const input& input) const NOEXCEPT;
bool populate_with_metadata(const block& block) const NOEXCEPT;
Expand Down
39 changes: 39 additions & 0 deletions include/bitcoin/database/tables/archives/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,45 @@ struct input
system::chain::witness::cptr witness{};
};

struct get_script
: public schema::input
{
link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
}

inline bool from_data(reader& source) NOEXCEPT
{
using namespace system;
script = std::make_shared<const chain::script>(source, true);
return source;
}

system::chain::script::cptr script{};
};

struct get_witness
: public schema::input
{
link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
}

inline bool from_data(reader& source) NOEXCEPT
{
using namespace system;
source.skip_bytes(source.read_size());
witness = std::make_shared<const chain::witness>(source, true);
return source;
}

system::chain::witness::cptr witness{};
};

struct put_ref
: public schema::input
{
Expand Down
21 changes: 21 additions & 0 deletions include/bitcoin/database/tables/archives/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ struct output
system::chain::output::cptr output{};
};

struct get_script
: public schema::output
{
link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
}

inline bool from_data(reader& source) NOEXCEPT
{
using namespace system;
source.skip_bytes(tx::size);
source.skip_variable();
script = std::make_shared<const chain::script>(source, true);
return source;
}

system::chain::script::cptr script{};
};

struct get_parent
: public schema::output
{
Expand Down
Loading
Loading