-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathhelpers.rs
More file actions
41 lines (38 loc) · 1.48 KB
/
helpers.rs
File metadata and controls
41 lines (38 loc) · 1.48 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
use crate::{db::Receipt, server::types::GetReceiptsResponse};
pub(super) fn format_merkle_paths(paths: Vec<Receipt>) -> Result<Vec<GetReceiptsResponse>, String> {
paths
.into_iter()
.map(|receipt| {
if let Some(merkle_path) = &receipt.merkle_path {
if merkle_path.is_empty() {
return Ok(GetReceiptsResponse {
status: receipt.status,
merkle_path: Vec::new(),
nonce: receipt.nonce,
address: receipt.address,
});
}
if merkle_path.len() % 32 != 0 {
return Err("merkle path length is not a multiple of 32 bytes".into());
}
let formatted_merkle_path = merkle_path
.chunks(32)
.map(|chunk| format!("0x{}", hex::encode(chunk)))
.collect();
Ok(GetReceiptsResponse {
status: receipt.status,
merkle_path: formatted_merkle_path,
nonce: receipt.nonce,
address: receipt.address,
})
} else {
Ok(GetReceiptsResponse {
status: receipt.status,
merkle_path: Vec::new(),
nonce: receipt.nonce,
address: receipt.address,
})
}
})
.collect()
}