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.into_values().map(BlobV1).collect();
23 Self { blobs }
24 }
25}
26
27impl From<BlobsV1> for IndexMap<Hash, Vec<u8>> {
28 fn from(value: BlobsV1) -> Self {
29 let mut blobs = IndexMap::default();
30 for blob in value.blobs {
31 let content = blob.0;
32 blobs.insert(hash(&content), content);
33 }
34 blobs
35 }
36}
37
38impl TransactionPartialPrepare for BlobsV1 {
39 type Prepared = PreparedBlobsV1;
40}
41
42#[derive(Debug, Clone, Eq, PartialEq)]
43pub struct PreparedBlobsV1 {
44 pub blobs_by_hash: IndexMap<Hash, Vec<u8>>,
45 pub summary: Summary,
46}
47
48impl_has_summary!(PreparedBlobsV1);
49
50#[allow(deprecated)]
51impl TransactionPreparableFromValue for PreparedBlobsV1 {
52 fn prepare_from_value(decoder: &mut TransactionDecoder) -> Result<Self, PrepareError> {
53 let max_blobs = decoder.settings().max_blobs;
54 let (blobs, summary) = ConcatenatedDigest::prepare_from_sbor_array_full_value::<
55 Vec<SummarizedRawValueBodyRawBytes>,
56 >(decoder, ValueType::Blob, max_blobs)?;
57
58 let mut blobs_by_hash = index_map_with_capacity(blobs.len());
59 for blob in blobs {
60 blobs_by_hash.insert(blob.summary.hash, blob.inner);
61 }
62
63 Ok(PreparedBlobsV1 {
64 blobs_by_hash,
65 summary,
66 })
67 }
68}