pub struct ShadowDriveClient<T>where
T: Signer,{ /* private fields */ }Expand description
Client that allows a user to interact with the Shadow Drive.
Implementations§
Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn add_immutable_storage(
&self,
storage_account_key: &Pubkey,
size: Byte,
) -> ShadowDriveResult<StorageResponse>
pub async fn add_immutable_storage( &self, storage_account_key: &Pubkey, size: Byte, ) -> ShadowDriveResult<StorageResponse>
Adds storage capacity to the specified immutable StorageAccount.
This will fail if the StorageAccount is not immutable.
storage_account_key- The public key of the immutableStorageAccount.size- The additional amount of storage you want to add. E.g if you have an existingStorageAccountwith 1MB of storage but you need 2MB total,sizeshould equal 1MB. When specifying size, only KB, MB, and GB storage units are currently supported.
§Example
let add_immutable_storage_response = shdw_drive_client
.add_immutable_storage(storage_account_key, Byte::from_str("1MB").expect("invalid byte string"))
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn add_storage(
&self,
storage_account_key: &Pubkey,
size: Byte,
) -> ShadowDriveResult<StorageResponse>
pub async fn add_storage( &self, storage_account_key: &Pubkey, size: Byte, ) -> ShadowDriveResult<StorageResponse>
Adds storage capacity to the specified StorageAccount.
storage_account_key- The public key of theStorageAccount.size- The additional amount of storage you want to add. E.g if you have an existingStorageAccountwith 1MB of storage but you need 2MB total,sizeshould equal 1MB. When specifying size, only KB, MB, and GB storage units are currently supported.
§Example
let add_storage_response = shdw_drive_client
.add_storage(&storage_account_key, added_bytes)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn cancel_delete_storage_account(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn cancel_delete_storage_account( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<ShdwDriveResponse>
Unmarks a StorageAccount for deletion from the Shadow Drive.
To prevent deletion, this method must be called before the end of the Solana epoch in which delete_storage_account is called.
storage_account_key- The public key of theStorageAccountthat you want to unmark for deletion.
§Example
let cancel_delete_storage_account_response = shdw_drive_client
.cancel_delete_storage_account(&storage_account_key)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn claim_stake(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn claim_stake( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<ShdwDriveResponse>
Claims any available stake as a result of the reduce_storage command.
After reducing storage amount, users must wait until the end of the epoch to successfully claim their stake.
storage_account_key- The public key of theStorageAccountthat you want to claim excess stake from.
§Example
let claim_stake = shdw_drive_client
.claim_stake(&storage_account_key)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn create_storage_account(
&self,
name: &str,
size: Byte,
version: StorageAccountVersion,
) -> ShadowDriveResult<CreateStorageAccountResponse>
pub async fn create_storage_account( &self, name: &str, size: Byte, version: StorageAccountVersion, ) -> ShadowDriveResult<CreateStorageAccountResponse>
Creates a StorageAccount on the Shadow Drive.
[StorageAccount]’s can hold multiple files, and are paid for using the SHDW token.
name- The name of theStorageAccount. Does not need to be unique.size- The amount of storage theStorageAccountshould be initialized with. When specifying size, only KB, MB, and GB storage units are currently supported.
Examples found in repository?
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}Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn delete_file(
&self,
storage_account_key: &Pubkey,
url: String,
) -> ShadowDriveResult<DeleteFileResponse>
pub async fn delete_file( &self, storage_account_key: &Pubkey, url: String, ) -> ShadowDriveResult<DeleteFileResponse>
Marks a file for deletion from the Shadow Drive.
Files marked for deletion are deleted at the end of each Solana epoch.
Marking a file for deletion can be undone with cancel_delete_file,
but this must be done before the end of the Solana epoch.
storage_account_key- The public key of theStorageAccountthat contains the file.url- The Shadow Drive url of the file you want to mark for deletion.
§Example
let delete_file_response = shdw_drive_client
.delete_file(&storage_account_key, url)
.await?;Examples found in repository?
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}Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn delete_storage_account(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn delete_storage_account( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<ShdwDriveResponse>
Marks a StorageAccount for deletion from the Shadow Drive.
If an account is marked for deletion, all files within the account will be deleted as well.
Any stake remaining in the StorageAccount will be refunded to the creator.
Accounts marked for deletion are deleted at the end of each Solana epoch.
Marking a StorageAccount for deletion can be undone with cancel_delete_storage_account,
but this must be done before the end of the Solana epoch.
storage_account_key- The public key of theStorageAccountthat you want to mark for deletion.
§Example
let delete_storage_account_response = shdw_drive_client
.delete_storage_account(&storage_account_key)
.await?;Examples found in repository?
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}Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn edit_file(
&self,
storage_account_key: &Pubkey,
data: ShadowFile,
) -> ShadowDriveResult<ShadowEditResponse>
pub async fn edit_file( &self, storage_account_key: &Pubkey, data: ShadowFile, ) -> ShadowDriveResult<ShadowEditResponse>
Replace an existing file on the Shadow Drive with the given updated file.
storage_account_key- The public key of theStorageAccountthat contains the file.url- The Shadow Drive url of the file you want to replace.data- The updatedShadowFile.
§Example
let edit_file_response = shdw_drive_client
.edit_file(&storage_account_key, url, file)
.await?;Examples found in repository?
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}Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn get_storage_account(
&self,
key: &Pubkey,
) -> ShadowDriveResult<StorageAcct>
pub async fn get_storage_account( &self, key: &Pubkey, ) -> ShadowDriveResult<StorageAcct>
Returns the StorageAccount associated with the pubkey provided by a user.
key- The public key of theStorageAccount.
§Example
let storage_account = shdw_drive_client
.get_storage_account(&storage_account_key)
.await
.expect("failed to get storage account");Sourcepub async fn get_storage_accounts(
&self,
owner: &Pubkey,
) -> ShadowDriveResult<Vec<StorageAcct>>
pub async fn get_storage_accounts( &self, owner: &Pubkey, ) -> ShadowDriveResult<Vec<StorageAcct>>
Returns all [StorageAccount]s associated with the public key provided by a user.
owner- The public key that is the owner of all the returned [StorageAccount]s.
§Example
let storage_accounts = shdw_drive_client
.get_storage_accounts(&user_pubkey)
.await
.expect("failed to get storage account");Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn list_objects(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<Vec<String>>
pub async fn list_objects( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<Vec<String>>
Gets a list of all files associated with a storage account. The output contains all of the file names as strings.
storage_account_key- The public key of theStorageAccountthat owns the files.
§Example
let files = shdw_drive_client
.list_objects(&storage_account_key)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn make_storage_immutable(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<StorageResponse>
pub async fn make_storage_immutable( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<StorageResponse>
Permanently locks a StorageAccount and all contained files. After a StorageAccount
has been locked, a user will no longer be able to delete/edit files, add/reduce storage amount,
or delete the StorageAccount.
storage_account_key- The public key of theStorageAccountthat will be made immutable.
§Example
let make_immutable_response = shdw_drive_client
.make_storage_immutable(&storage_account_key)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn migrate(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<(ShdwDriveResponse, ShdwDriveResponse)>
pub async fn migrate( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<(ShdwDriveResponse, ShdwDriveResponse)>
Migrates a v1 StorageAccount to v2.
This requires two separate transactions to reuse the original pubkey. To minimize chance of failure, it is recommended to call this method with a commitment level of Finalized
storage_account_key- The public key of theStorageAccountto be migrated.
§Example
let migrate_response = shdw_drive_client
.migrate(&storage_account_key)
.await?;Sourcepub async fn migrate_step_1(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn migrate_step_1( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<ShdwDriveResponse>
First transaction step that migrates a v1 StorageAccount to v2.
Consists of copying the existing account’s data into an intermediate account, and deleting the v1 storage account
Sourcepub async fn migrate_step_2(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn migrate_step_2( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<ShdwDriveResponse>
Second transaction step that migrates a v1 StorageAccount to v2.
Consists of recreating the storage account using the original pubkey, and deleting the intermediate account
Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn redeem_rent(
&self,
storage_account_key: &Pubkey,
file_account_key: &Pubkey,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn redeem_rent( &self, storage_account_key: &Pubkey, file_account_key: &Pubkey, ) -> ShadowDriveResult<ShdwDriveResponse>
Reclaims the Solana rent from any on-chain file accounts. Older versions of the Shadow Drive used to create accounts for uploaded files.
storage_account_key- The public key of theStorageAccountthat contained the deleted file.file_account_key- The public key of the File account to be closed.
§Example
let redeem_rent_response = shdw_drive_client
.redeem_rent(&storage_account_key, &file_account_key)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn reduce_storage(
&self,
storage_account_key: &Pubkey,
size: Byte,
) -> ShadowDriveResult<StorageResponse>
pub async fn reduce_storage( &self, storage_account_key: &Pubkey, size: Byte, ) -> ShadowDriveResult<StorageResponse>
Reduces the amount of total storage available for the given storage account.
storage_account_key- The public key of theStorageAccountwhose storage will be reduced.size- The amount of storage you want to remove. E.g if you have an existingStorageAccountwith 3MB of storage but you want 2MB total,sizeshould equal 1MB. When specifying size, only KB, MB, and GB storage units are currently supported.
§Example
let reduce_storage_response = shdw_drive_client
.reduce_storage(&storage_account_key, reduced_bytes)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn refresh_stake(
&self,
storage_account_key: &Pubkey,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn refresh_stake( &self, storage_account_key: &Pubkey, ) -> ShadowDriveResult<ShdwDriveResponse>
Allows user to refresh stake account, and unmarks deletion.
storage_account_key- The public key of theStorageAccountthat you want to top up stake for.
§Example
let refresh_stake = shdw_drive_client
.refresh_stake(&storage_account_key)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn store_files(
&self,
storage_account_key: &Pubkey,
data: Vec<ShadowFile>,
) -> ShadowDriveResult<ShadowUploadResponse>
pub async fn store_files( &self, storage_account_key: &Pubkey, data: Vec<ShadowFile>, ) -> ShadowDriveResult<ShadowUploadResponse>
Examples found in repository?
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}Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub async fn top_up(
&self,
storage_account_key: &Pubkey,
amount: u64,
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn top_up( &self, storage_account_key: &Pubkey, amount: u64, ) -> ShadowDriveResult<ShdwDriveResponse>
Allows user to top up stake account, transfering some amount of $SHDW.
storage_account_key- The public key of theStorageAccountthat you want to top up stake for.amount- The amount of $SHDW to transfer into stake account
§Example
let top_up = shdw_drive_client
.top_up(&storage_account_key, top_up_amount)
.await?;Source§impl<T> ShadowDriveClient<T>where
T: Signer,
impl<T> ShadowDriveClient<T>where
T: Signer,
Sourcepub fn new<U: ToString>(wallet: T, rpc_url: U) -> Self
pub fn new<U: ToString>(wallet: T, rpc_url: U) -> Self
Creates a new ShadowDriveClient from the given Signer and URL.
wallet- ASignerthat for signs all transactions generated by the client. Typically this is a user’s keypair.rpc_url- An HTTP URL of a Solana RPC provider.
The underlying Solana RPC client is configured with 120s timeout and a commitment level of confirmed.
To customize RpcClient settings see new_with_rpc.
§Example
use solana_sdk::signer::keypair::Keypair;
let wallet = Keypair::generate();
let shdw_drive = ShadowDriveClient::new(wallet, "https://ssc-dao.genesysgo.net");Examples found in repository?
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}Sourcepub fn new_with_rpc(wallet: T, rpc_client: RpcClient) -> Self
pub fn new_with_rpc(wallet: T, rpc_client: RpcClient) -> Self
Creates a new ShadowDriveClient from the given Signer and RpcClient.
wallet- ASignerthat for signs all transactions generated by the client. Typically this is a user’s keypair.rpc_client- A SolanaRpcClientthat handles sending transactions and reading accounts from the blockchain.
Providng the RpcClient allows customization of timeout and committment level.
§Example
use solana_client::rpc_client::RpcClient;
use solana_sdk::signer::keypair::Keypair;
use solana_sdk::commitment_config::CommitmentConfig;
let wallet = Keypair::generate();
let solana_rpc = RpcClient::new_with_commitment("https://ssc-dao.genesysgo.net", CommitmentConfig::confirmed());
let shdw_drive = ShadowDriveClient::new_with_rpc(wallet, solana_rpc);pub async fn get_object_data( &self, location: &str, ) -> ShadowDriveResult<FileDataResponse>
pub async fn get_storage_account_size( &self, storage_account_key: &str, ) -> ShadowDriveResult<GetBucketSizeResponse>
Auto Trait Implementations§
impl<T> !Freeze for ShadowDriveClient<T>
impl<T> !RefUnwindSafe for ShadowDriveClient<T>
impl<T> Send for ShadowDriveClient<T>where
T: Send,
impl<T> Sync for ShadowDriveClient<T>where
T: Sync,
impl<T> Unpin for ShadowDriveClient<T>where
T: Unpin,
impl<T> !UnwindSafe for ShadowDriveClient<T>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more