-
Notifications
You must be signed in to change notification settings - Fork 296
/
rosetta_client.rs
52 lines (50 loc) · 1.54 KB
/
rosetta_client.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use ic_rosetta_api::models::{
Block, BlockRequest, BlockResponse, NetworkIdentifier, PartialBlockIdentifier,
};
use rosetta_core::request_types::MetadataRequest;
use rosetta_core::response_types::NetworkListResponse;
use url::Url;
pub struct RosettaClient {
pub url: Url,
}
impl RosettaClient {
pub async fn network_list(&self) -> Result<Vec<NetworkIdentifier>, reqwest::Error> {
let request = MetadataRequest::new();
let client = reqwest::Client::new();
let response = client
.post(self.url.join("/network/list").unwrap())
.json(&request)
.send()
.await?
.json::<NetworkListResponse>()
.await?;
Ok(response
.network_identifiers
.into_iter()
.map(NetworkIdentifier)
.collect::<Vec<NetworkIdentifier>>())
}
pub async fn block(
&self,
network_identifier: NetworkIdentifier,
index: u64,
) -> Result<Option<Block>, reqwest::Error> {
let block_identifier = PartialBlockIdentifier {
index: Some(index),
hash: None,
};
let request = BlockRequest {
network_identifier: network_identifier.into(),
block_identifier,
};
let client = reqwest::Client::new();
let response = client
.post(self.url.join("/block").unwrap())
.json(&request)
.send()
.await?
.json::<BlockResponse>()
.await?;
Ok(response.block)
}
}