end_to_end/
end_to_end.rs

1use std::str::FromStr;
2
3use shadow_drive_sdk::{models::ShadowFile, Byte, Keypair, Pubkey, ShadowDriveClient};
4use solana_sdk::signature::read_keypair_file;
5
6const SOLANA_MAINNET_RPC: &'static str = "https://api.mainnet-beta.solana.com";
7
8#[tokio::main]
9async fn main() {
10    // Get keypair
11    let keypair_file: String = std::env::args()
12        .skip(1)
13        .next()
14        .expect("no keypair file provided");
15    let keypair: Keypair = read_keypair_file(keypair_file).expect("failed to read keypair file");
16    println!("loaded keypair");
17
18    // Initialize client
19    let client = ShadowDriveClient::new(keypair, SOLANA_MAINNET_RPC);
20    println!("initialized client");
21
22    // Create account
23    let response = client
24        .create_storage_account(
25            "test",
26            Byte::from_bytes(2_u128.pow(20)),
27            shadow_drive_sdk::StorageAccountVersion::V2,
28        )
29        .await
30        .expect("failed to create storage account");
31    let account = Pubkey::from_str(&response.shdw_bucket.unwrap()).unwrap();
32    println!("created storage account");
33
34    // Upload files
35    let files: Vec<ShadowFile> = vec![
36        ShadowFile::file("alpha.txt".to_string(), "./examples/files/alpha.txt"),
37        ShadowFile::file(
38            "not_alpha.txt".to_string(),
39            "./examples/files/not_alpha.txt",
40        ),
41    ];
42    let response = client
43        .store_files(&account, files.clone())
44        .await
45        .expect("failed to upload files");
46    println!("uploaded files");
47    for url in &response.finalized_locations {
48        println!("    {url}")
49    }
50    // Try editing
51    for file in files {
52        let response = client
53            .edit_file(&account, file)
54            .await
55            .expect("failed to upload files");
56        assert!(!response.finalized_location.is_empty(), "failed edit");
57        println!("edited file: {}", response.finalized_location);
58    }
59
60    // Delete files
61    for url in response.finalized_locations {
62        client
63            .delete_file(&account, url)
64            .await
65            .expect("failed to delete files");
66    }
67    println!("deleted files");
68
69    // Delete account
70    client
71        .delete_storage_account(&account)
72        .await
73        .expect("failed to delete storage account");
74    println!("deleted account");
75}