partner_chains_dolos_data_sources/client/
api.rs1use async_trait::async_trait;
2use blockfrost_openapi::models::{
3 address_transactions_content_inner::AddressTransactionsContentInner,
4 address_utxo_content_inner::AddressUtxoContentInner,
5 asset_addresses_inner::AssetAddressesInner, asset_transactions_inner::AssetTransactionsInner,
6 block_content::BlockContent, epoch_param_content::EpochParamContent,
7 epoch_stake_pool_content_inner::EpochStakePoolContentInner, genesis_content::GenesisContent,
8 pool_history_inner::PoolHistoryInner, pool_list_extended_inner::PoolListExtendedInner,
9 tx_content::TxContent, tx_content_utxo::TxContentUtxo,
10};
11use sidechain_domain::*;
12
13use crate::DataSourceError;
14
15pub struct McBlockId(String);
17
18impl From<McBlockHash> for McBlockId {
19 fn from(value: McBlockHash) -> Self {
20 McBlockId(value.to_string())
21 }
22}
23
24impl From<McBlockNumber> for McBlockId {
25 fn from(value: McBlockNumber) -> Self {
26 McBlockId(value.to_string())
27 }
28}
29
30impl From<String> for McBlockId {
31 fn from(value: String) -> Self {
32 McBlockId(value)
33 }
34}
35
36impl std::fmt::Display for McBlockId {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 self.0.fmt(f)
39 }
40}
41
42pub struct McPoolId(String);
44
45impl From<MainchainKeyHash> for McPoolId {
46 fn from(value: MainchainKeyHash) -> Self {
47 let pool_id =
48 bech32::encode::<bech32::Bech32>(bech32::Hrp::parse_unchecked("pool"), &value.0)
49 .expect("MainchainKeyHash is valid");
50 McPoolId(pool_id)
51 }
52}
53
54impl From<String> for McPoolId {
55 fn from(value: String) -> Self {
56 McPoolId(value)
57 }
58}
59
60impl std::fmt::Display for McPoolId {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 self.0.fmt(f)
63 }
64}
65
66#[async_trait]
67pub trait MiniBFApi {
69 async fn addresses_utxos(
71 &self,
72 address: MainchainAddress,
73 ) -> Result<Vec<AddressUtxoContentInner>, DataSourceError>;
74 async fn addresses_transactions(
76 &self,
77 address: MainchainAddress,
78 ) -> Result<Vec<AddressTransactionsContentInner>, DataSourceError>;
79
80 async fn assets_transactions(
82 &self,
83 asset_id: AssetId,
84 ) -> Result<Vec<AssetTransactionsInner>, DataSourceError>;
85 async fn assets_addresses(
87 &self,
88 asset_id: AssetId,
89 ) -> Result<Vec<AssetAddressesInner>, DataSourceError>;
90
91 async fn blocks_latest(&self) -> Result<BlockContent, DataSourceError>;
93 async fn blocks_by_id(
95 &self,
96 id: impl Into<McBlockId> + Send,
97 ) -> Result<BlockContent, DataSourceError>;
98 async fn blocks_slot(&self, slot_number: McSlotNumber)
100 -> Result<BlockContent, DataSourceError>;
101 async fn blocks_next(
103 &self,
104 hash: impl Into<McBlockId> + Send,
105 ) -> Result<Vec<BlockContent>, DataSourceError>;
106 async fn blocks_txs(
108 &self,
109 id: impl Into<McBlockId> + Send,
110 ) -> Result<Vec<String>, DataSourceError>;
111
112 async fn epochs_blocks(
114 &self,
115 epoch_number: McEpochNumber,
116 ) -> Result<Vec<String>, DataSourceError>;
117 async fn epochs_parameters(
119 &self,
120 epoch_number: McEpochNumber,
121 ) -> Result<EpochParamContent, DataSourceError>;
122 async fn epochs_stakes_by_pool(
124 &self,
125 epoch_number: McEpochNumber,
126 pool_id: impl Into<McPoolId> + Send,
127 ) -> Result<Vec<EpochStakePoolContentInner>, DataSourceError>;
128
129 async fn pools_history(
131 &self,
132 pool_id: impl Into<McPoolId> + Send,
133 ) -> Result<Vec<PoolHistoryInner>, DataSourceError>;
134 async fn pools_extended(&self) -> Result<Vec<PoolListExtendedInner>, DataSourceError>;
136
137 async fn scripts_datum_hash(
139 &self,
140 datum_hash: &str,
141 ) -> Result<Vec<serde_json::Value>, DataSourceError>;
142
143 async fn transaction_by_hash(&self, tx_hash: McTxHash) -> Result<TxContent, DataSourceError>;
145 async fn transactions_utxos(&self, tx_hash: McTxHash)
147 -> Result<TxContentUtxo, DataSourceError>;
148
149 async fn genesis(&self) -> Result<GenesisContent, DataSourceError>;
151}