partner_chains_dolos_data_sources/client/
api.rs

1use 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
15/// Mainchain block id, either a block hash or a block number
16pub 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
42/// Mainchain pool id as a bech32 string
43pub 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]
67/// Mini Blockfrost API interface
68pub trait MiniBFApi {
69	/// UTXOs of the address.
70	async fn addresses_utxos(
71		&self,
72		address: MainchainAddress,
73	) -> Result<Vec<AddressUtxoContentInner>, DataSourceError>;
74	/// Transactions on the address.
75	async fn addresses_transactions(
76		&self,
77		address: MainchainAddress,
78	) -> Result<Vec<AddressTransactionsContentInner>, DataSourceError>;
79
80	/// List of specific asset transactions.
81	async fn assets_transactions(
82		&self,
83		asset_id: AssetId,
84	) -> Result<Vec<AssetTransactionsInner>, DataSourceError>;
85	/// List of addresses containing a specific asset.
86	async fn assets_addresses(
87		&self,
88		asset_id: AssetId,
89	) -> Result<Vec<AssetAddressesInner>, DataSourceError>;
90
91	/// Return the latest block available to the backends, also known as the tip of the blockchain.
92	async fn blocks_latest(&self) -> Result<BlockContent, DataSourceError>;
93	/// Return the content of a requested block.
94	async fn blocks_by_id(
95		&self,
96		id: impl Into<McBlockId> + Send,
97	) -> Result<BlockContent, DataSourceError>;
98	/// Return the content of a requested block for a specific slot.
99	async fn blocks_slot(&self, slot_number: McSlotNumber)
100	-> Result<BlockContent, DataSourceError>;
101	/// Return the list of blocks following a specific block.
102	async fn blocks_next(
103		&self,
104		hash: impl Into<McBlockId> + Send,
105	) -> Result<Vec<BlockContent>, DataSourceError>;
106	/// Return the transactions within the block.
107	async fn blocks_txs(
108		&self,
109		id: impl Into<McBlockId> + Send,
110	) -> Result<Vec<String>, DataSourceError>;
111
112	/// Return the blocks minted for the epoch specified.
113	async fn epochs_blocks(
114		&self,
115		epoch_number: McEpochNumber,
116	) -> Result<Vec<String>, DataSourceError>;
117	/// Return the protocol parameters for the epoch specified.
118	async fn epochs_parameters(
119		&self,
120		epoch_number: McEpochNumber,
121	) -> Result<EpochParamContent, DataSourceError>;
122	/// Return the active stake distribution for the epoch specified by stake pool.
123	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	/// History of stake pool parameters over epochs.
130	async fn pools_history(
131		&self,
132		pool_id: impl Into<McPoolId> + Send,
133	) -> Result<Vec<PoolHistoryInner>, DataSourceError>;
134	/// List of registered stake pools with additional information.
135	async fn pools_extended(&self) -> Result<Vec<PoolListExtendedInner>, DataSourceError>;
136
137	/// Query JSON value of a datum by its hash.
138	async fn scripts_datum_hash(
139		&self,
140		datum_hash: &str,
141	) -> Result<Vec<serde_json::Value>, DataSourceError>;
142
143	/// Return content of the requested transaction.
144	async fn transaction_by_hash(&self, tx_hash: McTxHash) -> Result<TxContent, DataSourceError>;
145	/// Return the inputs and UTXOs of the specific transaction.
146	async fn transactions_utxos(&self, tx_hash: McTxHash)
147	-> Result<TxContentUtxo, DataSourceError>;
148
149	/// Return the information about blockchain genesis.
150	async fn genesis(&self) -> Result<GenesisContent, DataSourceError>;
151}