-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy paths3.rs
More file actions
42 lines (35 loc) · 1.09 KB
/
s3.rs
File metadata and controls
42 lines (35 loc) · 1.09 KB
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
use aligned_sdk::core::types::VerificationData;
#[derive(Debug)]
pub enum GetBatchProofsError {
Fetching,
Deserialization,
EmptyBody,
StatusFailed,
ReqwestClientFailed,
}
// needed to make S3 bucket work
const DEFAULT_USER_AGENT: &str = "proof-aggregator/aligned-layer";
pub async fn get_aligned_batch_from_s3(
url: String,
) -> Result<Vec<VerificationData>, GetBatchProofsError> {
let client = reqwest::Client::builder()
.user_agent(DEFAULT_USER_AGENT)
.build()
.map_err(|_| GetBatchProofsError::ReqwestClientFailed)?;
let response = client
.get(url)
.send()
.await
.map_err(|_| GetBatchProofsError::Fetching)?;
if !response.status().is_success() {
return Err(GetBatchProofsError::StatusFailed);
}
let bytes = response
.bytes()
.await
.map_err(|_| GetBatchProofsError::EmptyBody)?;
let bytes: &[u8] = bytes.iter().as_slice();
let data: Vec<VerificationData> =
ciborium::from_reader(bytes).map_err(|_| GetBatchProofsError::Deserialization)?;
Ok(data)
}