fuel_core_chain_config/config/
blob.rs1use crate::{
2 serialization::HexIfHumanReadable,
3 TableEntry,
4};
5use fuel_core_types::{
6 fuel_types::BlobId,
7 fuel_vm::{
8 BlobBytes,
9 BlobData,
10 },
11};
12use serde::{
13 Deserialize,
14 Serialize,
15};
16use serde_with::serde_as;
17
18#[serde_as]
19#[derive(Default, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
20pub struct BlobConfig {
21 pub blob_id: BlobId,
22 #[serde_as(as = "HexIfHumanReadable")]
23 pub payload: Vec<u8>,
24}
25
26#[cfg(feature = "test-helpers")]
27impl crate::Randomize for BlobConfig {
28 fn randomize(mut rng: impl ::rand::Rng) -> Self {
29 use fuel_core_types::fuel_tx::BlobIdExt;
30
31 let payload_len = rng.gen_range(32..128);
32 let mut payload = vec![0; payload_len as usize];
33 rng.fill_bytes(&mut payload);
34
35 let blob_id = BlobId::compute(&payload);
36
37 Self { blob_id, payload }
38 }
39}
40
41impl From<TableEntry<BlobData>> for BlobConfig {
42 fn from(value: TableEntry<BlobData>) -> Self {
43 BlobConfig {
44 blob_id: value.key,
45 payload: value.value.0.to_vec(),
46 }
47 }
48}
49
50impl From<BlobConfig> for TableEntry<BlobData> {
51 fn from(config: BlobConfig) -> Self {
52 Self {
53 key: config.blob_id,
54 value: BlobBytes(config.payload),
55 }
56 }
57}