snap_coin/
blockchain_data_provider.rs1use serde::{Deserialize, Serialize};
2use thiserror::Error;
3
4use crate::{api::requests::RequestResponseError, core::{block::Block, blockchain::BlockchainError, transaction::{TransactionId, TransactionOutput}}, crypto::{Hash, keys::Public}};
5
6#[derive(Error, Debug, Serialize, Deserialize)]
8pub enum BlockchainDataProviderError {
9 #[error("Failed to access data")]
10 AccessError,
11
12 #[error("Blockchain error: {0}")]
13 BlockchainError(#[from] BlockchainError),
14
15 #[error("Request / response error")]
16 RequestResponseError(#[from] RequestResponseError)
17}
18
19#[async_trait::async_trait]
20pub trait BlockchainDataProvider {
21 async fn get_height(&self) -> Result<usize, BlockchainDataProviderError>;
23
24 async fn get_reward(&self) -> Result<u64, BlockchainDataProviderError>;
26
27 async fn get_block_by_height(&self, height: usize) -> Result<Option<Block>, BlockchainDataProviderError>;
30
31 async fn get_block_by_hash(&self, hash: Hash) -> Result<Option<Block>, BlockchainDataProviderError>;
34
35 async fn get_height_by_hash(&self, hash: Hash) -> Result<Option<usize>, BlockchainDataProviderError>;
38
39 async fn get_block_hash_by_height(&self, height: usize) -> Result<Option<Hash>, BlockchainDataProviderError>;
42
43 async fn get_transaction_difficulty(&self) -> Result<[u8; 32], BlockchainDataProviderError>;
45
46 async fn get_block_difficulty(&self) -> Result<[u8; 32], BlockchainDataProviderError>;
48
49 async fn get_available_transaction_outputs(&self, address: Public) -> Result<Vec<(TransactionId, TransactionOutput, usize)>, BlockchainDataProviderError>;
52}