mutant_lib/storage/
mod.rs1mod init;
2mod network;
3
4use crate::error::Error;
5use autonomi::{Client, ScratchpadAddress, SecretKey, Wallet};
6
7use network::create_scratchpad_static;
8
9pub(crate) use network::fetch_scratchpad_internal_static;
10pub(crate) use network::storage_save_mis_from_arc_static;
11pub(crate) use network::update_scratchpad_internal_static;
12
13#[repr(u64)]
14pub(super) enum ContentType {
15 MasterIndex = 1,
16}
17
18#[derive(Clone)]
19pub struct Storage {
20 wallet: Wallet,
21 client: Client,
22 master_index_address: ScratchpadAddress,
23 master_index_key: SecretKey,
24}
25
26pub use init::new;
27
28impl Storage {
29 pub(crate) async fn create_scratchpad_internal_raw(
30 &self,
31 initial_data: &[u8],
32 content_type: u64,
33 ) -> Result<(ScratchpadAddress, SecretKey), Error> {
34 let owner_key = SecretKey::random();
35 let payment_option = autonomi::client::payment::PaymentOption::from(&self.wallet);
36
37 let address = create_scratchpad_static(
38 &self.client,
39 &owner_key,
40 initial_data,
41 content_type,
42 payment_option,
43 )
44 .await?;
45
46 Ok((address, owner_key))
47 }
48
49 pub(crate) fn client(&self) -> &Client {
50 &self.client
51 }
52
53 pub(crate) fn get_master_index_info(&self) -> (ScratchpadAddress, SecretKey) {
54 (self.master_index_address, self.master_index_key.clone())
55 }
56}