File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use std::collections::HashMap;
1111use bdk_wallet:: bitcoin:: address:: NetworkChecked ;
1212use bdk_wallet:: bitcoin:: address:: NetworkUnchecked ;
1313use bdk_wallet:: bitcoin:: address:: { Address as BdkAddress , AddressData as BdkAddressData } ;
14+ use bdk_wallet:: bitcoin:: blockdata:: block:: Block as BdkBlock ;
1415use bdk_wallet:: bitcoin:: blockdata:: block:: Header as BdkHeader ;
1516use bdk_wallet:: bitcoin:: consensus:: encode:: deserialize;
1617use bdk_wallet:: bitcoin:: consensus:: encode:: serialize;
@@ -299,6 +300,27 @@ impl From<BdkHeader> for Header {
299300 }
300301}
301302
303+ /// Bitcoin block.
304+ /// A collection of transactions with an attached proof of work.
305+ #[ derive( uniffi:: Record ) ]
306+ pub struct Block {
307+ pub header : Header ,
308+ pub txdata : Vec < Arc < Transaction > > ,
309+ }
310+
311+ impl From < BdkBlock > for Block {
312+ fn from ( bdk_block : BdkBlock ) -> Self {
313+ Block {
314+ header : bdk_block. header . into ( ) ,
315+ txdata : bdk_block
316+ . txdata
317+ . into_iter ( )
318+ . map ( |tx| Arc :: new ( tx. into ( ) ) )
319+ . collect ( ) ,
320+ }
321+ }
322+ }
323+
302324/// The type of address.
303325#[ derive( Debug , uniffi:: Enum ) ]
304326pub enum AddressData {
Original file line number Diff line number Diff line change 11use crate :: bitcoin:: Address ;
2+ use crate :: bitcoin:: Block ;
23use crate :: bitcoin:: BlockHash ;
34use crate :: bitcoin:: Header ;
45use crate :: bitcoin:: Transaction ;
@@ -178,6 +179,17 @@ impl EsploraClient {
178179 . map_err ( EsploraError :: from)
179180 }
180181
182+ /// Get a Block given a particular BlockHash.
183+ pub fn get_block_by_hash (
184+ & self ,
185+ block_hash : Arc < BlockHash > ,
186+ ) -> Result < Option < Block > , EsploraError > {
187+ self . 0
188+ . get_block_by_hash ( & block_hash. 0 )
189+ . map ( |block| block. map ( |block| block. into ( ) ) )
190+ . map_err ( EsploraError :: from)
191+ }
192+
181193 /// Get a `Txid` of a transaction given its index in a block with a given hash.
182194 pub fn get_txid_at_block_index (
183195 & self ,
You can’t perform that action at this time.
0 commit comments