77
88#include < kernel/bitcoinkernel.h>
99
10+ #include < array>
1011#include < functional>
1112#include < memory>
1213#include < optional>
@@ -473,7 +474,7 @@ class TransactionApi
473474
474475 auto Outputs () const
475476 {
476- return Range<Transaction , &TransactionApi::CountOutputs, &TransactionApi::GetOutput>{*static_cast <const Derived*>(this )};
477+ return Range<Derived , &TransactionApi<Derived> ::CountOutputs, &TransactionApi<Derived> ::GetOutput>{*static_cast <const Derived*>(this )};
477478 }
478479
479480 std::vector<std::byte> ToBytes () const
@@ -527,10 +528,20 @@ bool ScriptPubkeyApi<Derived>::Verify(int64_t amount,
527528 return result == 1 ;
528529}
529530
530- struct BlockHashDeleter {
531- void operator ()(btck_BlockHash* ptr) const
531+ class BlockHash : public Handle <btck_BlockHash, btck_block_hash_copy, btck_block_hash_destroy>
532+ {
533+ public:
534+ explicit BlockHash (const std::array<std::byte, 32 >& hash)
535+ : Handle{btck_block_hash_create (reinterpret_cast <const unsigned char *>(hash.data ()))} {}
536+
537+ explicit BlockHash (btck_BlockHash* hash)
538+ : Handle{hash} {}
539+
540+ std::array<std::byte, 32 > Bytes () const
532541 {
533- btck_block_hash_destroy (ptr);
542+ std::array<std::byte, 32 > hash;
543+ btck_block_hash_to_bytes (get (), reinterpret_cast <unsigned char *>(hash.data ()));
544+ return hash;
534545 }
535546};
536547
@@ -559,9 +570,9 @@ class Block : public Handle<btck_Block, btck_block_copy, btck_block_destroy>
559570 return Range<Block, &Block::CountTransactions, &Block::GetTransaction>{*this };
560571 }
561572
562- std::unique_ptr<btck_BlockHash, BlockHashDeleter> GetHash () const
573+ BlockHash GetHash () const
563574 {
564- return std::unique_ptr<btck_BlockHash, BlockHashDeleter>( btck_block_get_hash (get ())) ;
575+ return BlockHash{ btck_block_get_hash (get ())} ;
565576 }
566577
567578 std::vector<std::byte> ToBytes () const
@@ -631,9 +642,9 @@ class BlockTreeEntry : public View<btck_BlockTreeEntry>
631642 return btck_block_tree_entry_get_height (get ());
632643 }
633644
634- std::unique_ptr<btck_BlockHash, BlockHashDeleter> GetHash () const
645+ BlockHash GetHash () const
635646 {
636- return std::unique_ptr<btck_BlockHash, BlockHashDeleter>( btck_block_tree_entry_get_block_hash (get ())) ;
647+ return BlockHash{ btck_block_tree_entry_get_block_hash (get ())} ;
637648 }
638649
639650 friend class ChainMan ;
@@ -761,6 +772,10 @@ class Context : public Handle<btck_Context, btck_context_copy, btck_context_dest
761772 Context ()
762773 : Handle{check (btck_context_create (ContextOptions{}.get ()))} {}
763774
775+ bool interrupt () {
776+ return btck_context_interrupt (get ()) == 0 ;
777+ }
778+
764779 friend class ChainstateManagerOptions ;
765780};
766781
@@ -848,7 +863,7 @@ class CoinApi
848863public:
849864 uint32_t GetConfirmationHeight () const { return btck_coin_confirmation_height (impl ()); }
850865
851- bool IsCoinbase () const { return btck_coin_is_coinbase (impl ()); }
866+ bool IsCoinbase () const { return btck_coin_is_coinbase (impl ()) == 1 ; }
852867
853868 TransactionOutputView GetOutput () const
854869 {
@@ -866,6 +881,8 @@ class Coin : Handle<btck_Coin, btck_coin_copy, btck_coin_destroy>, public CoinAp
866881{
867882public:
868883 Coin (btck_Coin* coin) : Handle{check (coin)} {}
884+
885+ Coin (const CoinView& view) : Handle{view} {}
869886};
870887
871888template <typename Derived>
@@ -908,6 +925,8 @@ class TransactionSpentOutputs : Handle<btck_TransactionSpentOutputs, btck_transa
908925{
909926public:
910927 TransactionSpentOutputs (btck_TransactionSpentOutputs* transaction_spent_outputs) : Handle{check (transaction_spent_outputs)} {}
928+
929+ TransactionSpentOutputs (const TransactionSpentOutputsView& view) : Handle{view} {}
911930};
912931
913932class BlockSpentOutputs : Handle<btck_BlockSpentOutputs, btck_block_spent_outputs_copy, btck_block_spent_outputs_destroy>
@@ -969,12 +988,12 @@ class ChainMan : UniqueHandle<btck_ChainstateManager, btck_chainstate_manager_de
969988 return ChainView{btck_chainstate_manager_get_active_chain (get ())};
970989 }
971990
972- BlockTreeEntry GetBlockTreeEntry (btck_BlockHash* block_hash) const
991+ BlockTreeEntry GetBlockTreeEntry (const btck_BlockHash* block_hash) const
973992 {
974993 return btck_chainstate_manager_get_block_tree_entry_by_hash (get (), block_hash);
975994 }
976995
977- std::optional<Block> ReadBlock (BlockTreeEntry& entry) const
996+ std::optional<Block> ReadBlock (const BlockTreeEntry& entry) const
978997 {
979998 auto block{btck_block_read (get (), entry.get ())};
980999 if (!block) return std::nullopt ;
0 commit comments