Skip to content

Commit 0f3d6ea

Browse files
committed
Change get_spent() to return outpoint (with spend value).
1 parent 24c2cda commit 0f3d6ea

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,25 +305,32 @@ typename CLASS::output::cptr CLASS::get_output(
305305
}
306306

307307
TEMPLATE
308-
typename CLASS::point CLASS::get_spent(const output_link& link) const NOEXCEPT
308+
typename CLASS::outpoint CLASS::get_spent(
309+
const output_link& link) const NOEXCEPT
309310
{
310-
if (const auto tx = to_output_tx(link); !tx.is_terminal())
311-
if (const auto index = to_output_index(tx, link);
312-
index != point::null_index)
313-
return { get_tx_key(tx), index };
311+
table::output::get_parent_value out{};
312+
if (!store_.output.get(link, out))
313+
return {};
314+
315+
const auto index = to_output_index(out.parent_fk, link);
316+
if (index == point::null_index)
317+
return {};
314318

315-
return {};
319+
return { { get_tx_key(out.parent_fk), index }, out.value };
316320
}
317321

318322
TEMPLATE
319323
typename CLASS::point CLASS::get_spender(const point_link& link) const NOEXCEPT
320324
{
321-
if (const auto tx = to_spending_tx(link); !tx.is_terminal())
322-
if (const auto index = to_input_index(tx, link);
323-
index != point::null_index)
324-
return { get_tx_key(tx), index };
325+
const auto tx = to_spending_tx(link);
326+
if (tx.is_terminal())
327+
return {};
328+
329+
const auto index = to_input_index(tx, link);
330+
if (index == point::null_index)
331+
return {};
325332

326-
return {};
333+
return { get_tx_key(tx), index };
327334
}
328335

329336
TEMPLATE

include/bitcoin/database/query.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class query
6666
using point = system::chain::point;
6767
using input = system::chain::input;
6868
using output = system::chain::output;
69+
using outpoint = system::chain::outpoint;
6970
using header = system::chain::header;
7071
using script = system::chain::script;
7172
using witness = system::chain::witness;
@@ -395,8 +396,8 @@ class query
395396
input::cptr get_input(const tx_link& link, uint32_t index,
396397
bool witness) const NOEXCEPT;
397398

398-
point get_spent(const output_link& link) const NOEXCEPT;
399399
point get_spender(const point_link& link) const NOEXCEPT;
400+
outpoint get_spent(const output_link& link) const NOEXCEPT;
400401
script::cptr get_output_script(const output_link& link) const NOEXCEPT;
401402
output::cptr get_output(const output_link& link) const NOEXCEPT;
402403
output::cptr get_output(const tx_link& link, uint32_t index) const NOEXCEPT;

include/bitcoin/database/tables/archives/output.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ struct output
133133
system::chain::script::cptr script{};
134134
};
135135

136+
struct get_parent_value
137+
: public schema::output
138+
{
139+
link count() const NOEXCEPT
140+
{
141+
BC_ASSERT(false);
142+
return {};
143+
}
144+
145+
inline bool from_data(reader& source) NOEXCEPT
146+
{
147+
parent_fk = source.read_little_endian<tx::integer, tx::size>();
148+
value = source.read_variable();
149+
return source;
150+
}
151+
152+
tx::integer parent_fk{};
153+
uint64_t value{};
154+
};
155+
136156
struct get_parent
137157
: public schema::output
138158
{

0 commit comments

Comments
 (0)