|
1 | | -use super::Error; |
2 | | -use crate::service::DynBitcoinCoreApi; |
| 1 | +use crate::{serialize, BitcoinCoreApi, DynBitcoinCoreApi, Error as BitcoinError}; |
3 | 2 | use async_trait::async_trait; |
4 | | -use bitcoin::{serialize, BitcoinCoreApi, Error as BitcoinError}; |
5 | 3 |
|
6 | 4 | #[async_trait] |
7 | 5 | pub trait Backing { |
8 | 6 | /// Returns the height of the longest chain |
9 | | - async fn get_block_count(&self) -> Result<u32, Error>; |
| 7 | + async fn get_block_count(&self) -> Result<u32, BitcoinError>; |
10 | 8 |
|
11 | 9 | /// Returns the raw header of a block in storage |
12 | 10 | /// |
13 | 11 | /// # Arguments |
14 | 12 | /// |
15 | 13 | /// * `height` - The height of the block to fetch |
16 | | - async fn get_block_header(&self, height: u32) -> Result<Option<Vec<u8>>, Error>; |
| 14 | + async fn get_block_header(&self, height: u32) -> Result<Option<Vec<u8>>, BitcoinError>; |
17 | 15 |
|
18 | 16 | /// Returns the (little endian) hash of a block |
19 | 17 | /// |
20 | 18 | /// # Arguments |
21 | 19 | /// |
22 | 20 | /// * `height` - The height of the block to fetch |
23 | | - async fn get_block_hash(&self, height: u32) -> Result<Vec<u8>, Error>; |
| 21 | + async fn get_block_hash(&self, height: u32) -> Result<Vec<u8>, BitcoinError>; |
24 | 22 | } |
25 | 23 |
|
26 | 24 | #[async_trait] |
27 | 25 | impl Backing for DynBitcoinCoreApi { |
28 | | - async fn get_block_count(&self) -> Result<u32, Error> { |
| 26 | + async fn get_block_count(&self) -> Result<u32, BitcoinError> { |
29 | 27 | let count = BitcoinCoreApi::get_block_count(&**self).await?; |
30 | 28 | return Ok(count as u32); |
31 | 29 | } |
32 | 30 |
|
33 | | - async fn get_block_header(&self, height: u32) -> Result<Option<Vec<u8>>, Error> { |
| 31 | + async fn get_block_header(&self, height: u32) -> Result<Option<Vec<u8>>, BitcoinError> { |
34 | 32 | let block_hash = match BitcoinCoreApi::get_block_hash(&**self, height).await { |
35 | 33 | Ok(h) => h, |
36 | 34 | Err(BitcoinError::InvalidBitcoinHeight) => { |
37 | 35 | return Ok(None); |
38 | 36 | } |
39 | | - Err(err) => return Err(err.into()), |
| 37 | + Err(err) => return Err(err), |
40 | 38 | }; |
41 | 39 | let block_header = BitcoinCoreApi::get_block_header(&**self, &block_hash).await?; |
42 | 40 | Ok(Some(serialize(&block_header))) |
43 | 41 | } |
44 | 42 |
|
45 | | - async fn get_block_hash(&self, height: u32) -> Result<Vec<u8>, Error> { |
| 43 | + async fn get_block_hash(&self, height: u32) -> Result<Vec<u8>, BitcoinError> { |
46 | 44 | let block_hash = BitcoinCoreApi::get_block_hash(&**self, height) |
47 | 45 | .await |
48 | 46 | .map(|hash| serialize(&hash))?; |
|
0 commit comments