@@ -128,20 +128,7 @@ use std::{
128128} ;
129129
130130use libbitcoinkernel_sys:: {
131- btck_Block, btck_BlockHash, btck_BlockHeader, btck_BlockSpentOutputs, btck_Coin,
132- btck_TransactionSpentOutputs, btck_block_copy, btck_block_count_transactions,
133- btck_block_create, btck_block_destroy, btck_block_get_hash, btck_block_get_header,
134- btck_block_get_transaction_at, btck_block_hash_copy, btck_block_hash_create,
135- btck_block_hash_destroy, btck_block_hash_equals, btck_block_hash_to_bytes,
136- btck_block_header_copy, btck_block_header_create, btck_block_header_destroy,
137- btck_block_header_get_bits, btck_block_header_get_hash, btck_block_header_get_nonce,
138- btck_block_header_get_prev_hash, btck_block_header_get_timestamp,
139- btck_block_header_get_version, btck_block_spent_outputs_copy, btck_block_spent_outputs_count,
140- btck_block_spent_outputs_destroy, btck_block_spent_outputs_get_transaction_spent_outputs_at,
141- btck_block_to_bytes, btck_coin_confirmation_height, btck_coin_copy, btck_coin_destroy,
142- btck_coin_get_output, btck_coin_is_coinbase, btck_transaction_spent_outputs_copy,
143- btck_transaction_spent_outputs_count, btck_transaction_spent_outputs_destroy,
144- btck_transaction_spent_outputs_get_coin_at,
131+ btck_Block, btck_BlockHash, btck_BlockHeader, btck_BlockSpentOutputs, btck_Coin, btck_TransactionSpentOutputs, btck_block_copy, btck_block_count_transactions, btck_block_create, btck_block_destroy, btck_block_get_hash, btck_block_get_header, btck_block_get_transaction_at, btck_block_hash_copy, btck_block_hash_create, btck_block_hash_destroy, btck_block_hash_equals, btck_block_hash_to_bytes, btck_block_header_copy, btck_block_header_create, btck_block_header_destroy, btck_block_header_get_bits, btck_block_header_get_hash, btck_block_header_get_nonce, btck_block_header_get_prev_hash, btck_block_header_get_timestamp, btck_block_header_get_version, btck_block_spent_outputs_copy, btck_block_spent_outputs_count, btck_block_spent_outputs_create, btck_block_spent_outputs_destroy, btck_block_spent_outputs_get_transaction_spent_outputs_at, btck_block_to_bytes, btck_coin_confirmation_height, btck_coin_copy, btck_coin_create, btck_coin_destroy, btck_coin_get_output, btck_coin_is_coinbase, btck_transaction_spent_outputs_copy, btck_transaction_spent_outputs_count, btck_transaction_spent_outputs_destroy, btck_transaction_spent_outputs_get_coin_at
145132} ;
146133
147134use crate :: {
@@ -150,7 +137,7 @@ use crate::{
150137 c_helpers:: present,
151138 sealed:: { AsPtr , FromMutPtr , FromPtr } ,
152139 } ,
153- KernelError ,
140+ KernelError , TxOut ,
154141} ;
155142
156143use super :: transaction:: { TransactionRef , TxOutRef } ;
@@ -1155,6 +1142,36 @@ impl BlockSpentOutputs {
11551142 pub fn as_ref ( & self ) -> BlockSpentOutputsRef < ' _ > {
11561143 unsafe { BlockSpentOutputsRef :: from_ptr ( self . inner as * const _ ) }
11571144 }
1145+
1146+ pub fn new ( coins : & [ Vec < Coin > ] ) -> Self {
1147+ struct CallbackContext < ' a > {
1148+ coins : & ' a [ Vec < Coin > ] ,
1149+ }
1150+
1151+ extern "C" fn coin_getter (
1152+ context : * mut c_void ,
1153+ tx_index : usize ,
1154+ coin_index : usize ,
1155+ ) -> * const btck_Coin {
1156+ let ctx = unsafe { & * ( context as * const CallbackContext ) } ;
1157+ ctx. coins [ tx_index] [ coin_index] . as_ptr ( )
1158+ }
1159+
1160+ extern "C" fn count_getter ( context : * mut c_void , tx_index : usize ) -> usize {
1161+ let ctx = unsafe { & * ( context as * const CallbackContext ) } ;
1162+ ctx. coins [ tx_index] . len ( )
1163+ }
1164+
1165+ let context = CallbackContext { coins } ;
1166+ unsafe {
1167+ BlockSpentOutputs :: from_ptr ( btck_block_spent_outputs_create (
1168+ & context as * const CallbackContext as * mut c_void ,
1169+ Some ( coin_getter) ,
1170+ Some ( count_getter) ,
1171+ coins. len ( ) ,
1172+ ) )
1173+ }
1174+ }
11581175}
11591176
11601177impl FromMutPtr < btck_BlockSpentOutputs > for BlockSpentOutputs {
@@ -1710,6 +1727,10 @@ unsafe impl Send for Coin {}
17101727unsafe impl Sync for Coin { }
17111728
17121729impl Coin {
1730+ pub fn new ( output : & TxOut ) -> Coin {
1731+ unsafe { Coin :: from_ptr ( btck_coin_create ( output. as_ptr ( ) , 0 , 0 ) ) }
1732+ }
1733+
17131734 /// Creates a borrowed reference to this coin.
17141735 ///
17151736 /// This allows converting from owned [`Coin`] to [`CoinRef`] without
0 commit comments