radix_transactions/model/v1/
blobs.rs1use super::*;
2use crate::internal_prelude::*;
3
4#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
5#[sbor(transparent)]
6pub struct BlobV1(pub Vec<u8>);
7
8#[derive(Default, Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
9#[sbor(transparent)]
10pub struct BlobsV1 {
11 pub blobs: Vec<BlobV1>,
12}
13
14impl BlobsV1 {
15 pub fn none() -> Self {
16 Self { blobs: Vec::new() }
17 }
18}
19
20impl From<IndexMap<Hash, Vec<u8>>> for BlobsV1 {
21 fn from(blobs: IndexMap<Hash, Vec<u8>>) -> Self {
22 let blobs = blobs
23 .into_values()
24 .into_iter()
25 .map(|blob| BlobV1(blob))
26 .collect();
27 Self { blobs }
28 }
29}
30
31impl From<BlobsV1> for IndexMap<Hash, Vec<u8>> {
32 fn from(value: BlobsV1) -> Self {
33 let mut blobs = IndexMap::default();
34 for blob in value.blobs {
35 let content = blob.0;
36 blobs.insert(hash(&content), content);
37 }
38 blobs
39 }
40}
41
42impl TransactionPartialPrepare for BlobsV1 {
43 type Prepared = PreparedBlobsV1;
44}
45
46#[derive(Debug, Clone, Eq, PartialEq)]
47pub struct PreparedBlobsV1 {
48 pub blobs_by_hash: IndexMap<Hash, Vec<u8>>,
49 pub summary: Summary,
50}
51
52impl_has_summary!(PreparedBlobsV1);
53
54#[allow(deprecated)]
55impl TransactionPreparableFromValue for PreparedBlobsV1 {
56 fn prepare_from_value(decoder: &mut TransactionDecoder) -> Result<Self, PrepareError> {
57 let max_blobs = decoder.settings().max_blobs;
58 let (blobs, summary) = ConcatenatedDigest::prepare_from_sbor_array_full_value::<
59 Vec<SummarizedRawValueBodyRawBytes>,
60 >(decoder, ValueType::Blob, max_blobs)?;
61
62 let mut blobs_by_hash = index_map_with_capacity(blobs.len());
63 for blob in blobs {
64 blobs_by_hash.insert(blob.summary.hash, blob.inner);
65 }
66
67 Ok(PreparedBlobsV1 {
68 blobs_by_hash,
69 summary,
70 })
71 }
72}