Skip to content

Commit ee9d3b9

Browse files
committed
add client for dolos minibf
1 parent d68e868 commit ee9d3b9

File tree

9 files changed

+459
-2
lines changed

9 files changed

+459
-2
lines changed

Cargo.lock

Lines changed: 97 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ ed25519-zebra = { version = "4.0.3" }
118118
ed25519 = { version = "2.2.2" }
119119
figment = { version = "0.10.19", features = ["env", "test"] }
120120
fraction = { version = "0.15.3", default-features = false }
121-
futures = { version = "0.3.30", features = ["thread-pool"] }
121+
futures = { version = "0.3.31", features = ["thread-pool"] }
122122
hex = { version = "0.4.3", features = ["alloc"], default-features = false }
123123
hex-literal = "1.0.0"
124124
itertools = "0.14.0"
@@ -185,6 +185,9 @@ derive-where = { version = "1.2.7", default-features = false }
185185
once_cell = { version = "1.21.3", default-features = false }
186186
paste = { version = "1.0.15" }
187187
fork-tree = { version = "13.0.1" }
188+
ureq = { version = "3.1.2", default-features = false }
189+
url = { version = "2.5.7", default-features = false }
190+
blockfrost-openapi = { version = "0.1.75", default-features = false }
188191

189192
# substrate dependencies
190193
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2509" }

toolkit/data-sources/dolos/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ sp-block-participation = { workspace = true, features = [
2727
sp-partner-chains-bridge = { workspace = true, optional = true, features = [
2828
"std",
2929
] }
30+
serde = { workspace = true }
31+
serde_json = { workspace = true }
32+
log = { workspace = true }
33+
blockfrost-openapi = { workspace = true }
34+
ureq = { workspace = true, features = ["json"] }
35+
url = { workspace = true }
36+
thiserror = { workspace = true }
37+
partner-chains-plutus-data = { workspace = true }
38+
futures = { workspace = true }
39+
cardano-serialization-lib = { workspace = true }
40+
itertools = { workspace = true }
3041

3142
[features]
3243
default = []
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
use async_trait::async_trait;
2+
use 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,
8+
pool_history_inner::PoolHistoryInner, pool_list_extended_inner::PoolListExtendedInner,
9+
tx_content::TxContent, tx_content_utxo::TxContentUtxo,
10+
};
11+
use sidechain_domain::*;
12+
13+
pub enum McBlockId {
14+
McBlockHash(McBlockHash),
15+
McBlockNumber(McBlockNumber),
16+
Raw(String), // makes you think
17+
}
18+
19+
impl From<McBlockHash> for McBlockId {
20+
fn from(value: McBlockHash) -> Self {
21+
McBlockId::McBlockHash(value)
22+
}
23+
}
24+
25+
impl From<McBlockNumber> for McBlockId {
26+
fn from(value: McBlockNumber) -> Self {
27+
McBlockId::McBlockNumber(value)
28+
}
29+
}
30+
31+
impl From<String> for McBlockId {
32+
fn from(value: String) -> Self {
33+
McBlockId::Raw(value)
34+
}
35+
}
36+
37+
impl std::fmt::Display for McBlockId {
38+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39+
match self {
40+
McBlockId::McBlockHash(mc_block_hash) => mc_block_hash.fmt(f),
41+
McBlockId::McBlockNumber(mc_block_number) => mc_block_number.fmt(f),
42+
McBlockId::Raw(str) => str.fmt(f),
43+
}
44+
}
45+
}
46+
47+
#[async_trait]
48+
pub trait MiniBFApi {
49+
async fn addresses_utxos(
50+
&self,
51+
address: MainchainAddress,
52+
) -> Result<Vec<AddressUtxoContentInner>, String>;
53+
async fn addresses_transactions(
54+
&self,
55+
address: MainchainAddress,
56+
) -> Result<Vec<AddressTransactionsContentInner>, String>;
57+
58+
async fn assets_transactions(
59+
&self,
60+
asset_id: AssetId,
61+
) -> Result<Vec<AssetTransactionsInner>, String>;
62+
async fn assets_addresses(&self, asset_id: AssetId)
63+
-> Result<Vec<AssetAddressesInner>, String>;
64+
65+
async fn blocks_latest(&self) -> Result<BlockContent, String>;
66+
async fn blocks_by_id(&self, id: impl Into<McBlockId> + Send) -> Result<BlockContent, String>;
67+
async fn blocks_slot(&self, slot_number: McSlotNumber) -> Result<BlockContent, String>;
68+
async fn blocks_next(
69+
&self,
70+
hash: impl Into<McBlockId> + Send,
71+
) -> Result<Vec<BlockContent>, String>;
72+
async fn blocks_txs(&self, id: impl Into<McBlockId> + Send) -> Result<Vec<String>, String>;
73+
74+
async fn epochs_blocks(&self, epoch_number: McEpochNumber) -> Result<Vec<String>, String>;
75+
async fn epochs_parameters(
76+
&self,
77+
epoch_number: McEpochNumber,
78+
) -> Result<EpochParamContent, String>;
79+
async fn epochs_stakes_by_pool(
80+
&self,
81+
epoch_number: McEpochNumber,
82+
pool_id: &str,
83+
) -> Result<Vec<EpochStakePoolContentInner>, String>;
84+
85+
async fn pools_history(&self, pool_id: &str) -> Result<Vec<PoolHistoryInner>, String>;
86+
async fn pools_extended(&self) -> Result<Vec<PoolListExtendedInner>, String>;
87+
88+
async fn scripts_datum_hash(&self, datum_hash: &str) -> Result<Vec<serde_json::Value>, String>;
89+
90+
async fn transaction_by_hash(&self, tx_hash: McTxHash) -> Result<TxContent, String>;
91+
async fn transactions_utxos(&self, tx_hash: McTxHash) -> Result<TxContentUtxo, String>;
92+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use blockfrost_openapi::models::block_content::BlockContent;
2+
use sidechain_domain::*;
3+
4+
pub fn from_block_content(value: BlockContent) -> Result<MainchainBlock, String> {
5+
Ok(MainchainBlock {
6+
number: value
7+
.height
8+
.map(|n| sidechain_domain::McBlockNumber(n as u32))
9+
.ok_or("number missing")?,
10+
hash: McBlockHash::decode_hex(&value.hash)?,
11+
epoch: value
12+
.epoch
13+
.map(|n| sidechain_domain::McEpochNumber(n as u32))
14+
.ok_or("epoch missing")?,
15+
slot: value
16+
.slot
17+
.map(|n| sidechain_domain::McSlotNumber(n as u64))
18+
.ok_or("slot missing")?,
19+
timestamp: value.time as u64,
20+
})
21+
}

0 commit comments

Comments
 (0)