Skip to content

Commit 717ad9d

Browse files
authored
Merge pull request #688 from evoskuil/master
Add to_transaction(header_link, position).
2 parents a78a85a + 7d74ffd commit 717ad9d

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,33 +411,44 @@ output_links CLASS::to_block_prevouts(const header_link& link) const NOEXCEPT
411411
// ----------------------------------------------------------------------------
412412

413413
TEMPLATE
414-
tx_link CLASS::to_coinbase(const header_link& link) const NOEXCEPT
414+
tx_links CLASS::to_transactions(const header_link& link) const NOEXCEPT
415415
{
416-
table::txs::get_coinbase txs{};
416+
table::txs::get_txs txs{};
417417
if (!store_.txs.at(to_txs(link), txs))
418418
return {};
419419

420-
return txs.coinbase_fk;
420+
return std::move(txs.tx_fks);
421421
}
422422

423423
TEMPLATE
424-
tx_links CLASS::to_transactions(const header_link& link) const NOEXCEPT
424+
tx_links CLASS::to_spending_txs(const header_link& link) const NOEXCEPT
425425
{
426-
table::txs::get_txs txs{};
426+
table::txs::get_spending_txs txs{};
427427
if (!store_.txs.at(to_txs(link), txs))
428428
return {};
429429

430430
return std::move(txs.tx_fks);
431431
}
432432

433433
TEMPLATE
434-
tx_links CLASS::to_spending_txs(const header_link& link) const NOEXCEPT
434+
tx_link CLASS::to_coinbase(const header_link& link) const NOEXCEPT
435435
{
436-
table::txs::get_spending_txs txs{};
436+
table::txs::get_coinbase txs{};
437437
if (!store_.txs.at(to_txs(link), txs))
438438
return {};
439439

440-
return std::move(txs.tx_fks);
440+
return txs.coinbase_fk;
441+
}
442+
443+
TEMPLATE
444+
tx_link CLASS::to_transaction(const header_link& link,
445+
size_t position) const NOEXCEPT
446+
{
447+
table::txs::get_tx txs{ {}, position };
448+
if (!store_.txs.at(to_txs(link), txs))
449+
return {};
450+
451+
return txs.tx_fk;
441452
}
442453

443454
// header to arraymap tables (guard domain transitions)

include/bitcoin/database/query.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,11 @@ class query
314314
output_links to_block_prevouts(const header_link& link) const NOEXCEPT;
315315

316316
/// block to txs (forward navigation)
317-
tx_link to_coinbase(const header_link& link) const NOEXCEPT;
318317
tx_links to_transactions(const header_link& link) const NOEXCEPT;
319318
tx_links to_spending_txs(const header_link& link) const NOEXCEPT;
319+
tx_link to_coinbase(const header_link& link) const NOEXCEPT;
320+
tx_link to_transaction(const header_link& link,
321+
size_t position) const NOEXCEPT;
320322

321323
/// header to arraymap tables (guard domain transitions)
322324
constexpr size_t to_validated_bk(const header_link& link) const NOEXCEPT;

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,34 @@ struct txs
171171
tx::integer coinbase_fk{};
172172
};
173173

174+
struct get_tx
175+
: public schema::txs
176+
{
177+
link count() const NOEXCEPT
178+
{
179+
BC_ASSERT(false);
180+
return {};
181+
}
182+
183+
inline bool from_data(reader& source) NOEXCEPT
184+
{
185+
const auto number = source.read_little_endian<ct::integer, ct::size>();
186+
source.skip_bytes(bytes::size);
187+
if (number > position)
188+
{
189+
source.skip_bytes(position * tx::size);
190+
tx_fk = source.read_little_endian<tx::integer, tx::size>();
191+
return source;
192+
}
193+
194+
source.invalidate();
195+
return source;
196+
}
197+
198+
const size_t position{};
199+
tx::integer tx_fk{};
200+
};
201+
174202
struct get_block_size
175203
: public schema::txs
176204
{

0 commit comments

Comments
 (0)