Struct shadow_drive_rust::ShadowDriveClient
source · [−]pub struct ShadowDriveClient<T> where
T: Signer, { /* private fields */ }Expand description
Client that allows a user to interact with the Shadow Drive.
Implementations
sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn add_storage(
&self,
storage_account_key: &Pubkey,
size: Byte
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn add_storage(
&self,
storage_account_key: &Pubkey,
size: Byte
) -> ShadowDriveResult<ShdwDriveResponse>
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn cancel_delete_file(
&self,
storage_account_key: &Pubkey,
url: String
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn cancel_delete_file(
&self,
storage_account_key: &Pubkey,
url: String
) -> ShadowDriveResult<ShdwDriveResponse>
Unmarks a file for deletion from the Shadow Drive.
To prevent deletion, this method must be called before the end of the Solana epoch in which delete_file is called.
storage_account_key- The public key of theStorageAccountthat contains the file.url- The Shadow Drive url of the file you want to unmark for deletion.
Example
let cancel_delete_file_response = shdw_drive_client
.cancel_delete_file(&storage_account_key, url)
.await?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn create_storage_account(
&self,
name: &str,
size: Byte
) -> ShadowDriveResult<CreateStorageAccountResponse>
pub async fn create_storage_account(
&self,
name: &str,
size: Byte
) -> 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.
sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn delete_file(
&self,
storage_account_key: &Pubkey,
url: String
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn delete_file(
&self,
storage_account_key: &Pubkey,
url: String
) -> ShadowDriveResult<ShdwDriveResponse>
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn edit_file(
&self,
storage_account_key: &Pubkey,
url: &str,
data: ShadowFile
) -> ShadowDriveResult<ShadowUploadResponse>
pub async fn edit_file(
&self,
storage_account_key: &Pubkey,
url: &str,
data: ShadowFile
) -> ShadowDriveResult<ShadowUploadResponse>
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn get_storage_account(
&self,
key: &Pubkey
) -> ShadowDriveResult<StorageAccount>
pub async fn get_storage_account(
&self,
key: &Pubkey
) -> ShadowDriveResult<StorageAccount>
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<StorageAccount>>
pub async fn get_storage_accounts(
&self,
owner: &Pubkey
) -> ShadowDriveResult<Vec<StorageAccount>>
Returns all StorageAccounts associated with the public key provided by a user.
owner- The public key that is the owner of all the returnedStorageAccounts.
Example
let storage_accounts = shdw_drive_client
.get_storage_accounts(&user_pubkey)
.await
.expect("failed to get storage account");sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn make_storage_immutable(
&self,
storage_account_key: &Pubkey
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn make_storage_immutable(
&self,
storage_account_key: &Pubkey
) -> ShadowDriveResult<ShdwDriveResponse>
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn reduce_storage(
&self,
storage_account_key: &Pubkey,
size: Byte
) -> ShadowDriveResult<ShdwDriveResponse>
pub async fn reduce_storage(
&self,
storage_account_key: &Pubkey,
size: Byte
) -> ShadowDriveResult<ShdwDriveResponse>
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?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn upload_file<'a>(
&self,
storage_account_key: &Pubkey,
data: ShadowFile
) -> ShadowDriveResult<ShadowUploadResponse>
pub async fn upload_file<'a>(
&self,
storage_account_key: &Pubkey,
data: ShadowFile
) -> ShadowDriveResult<ShadowUploadResponse>
Uploads a ShadowFile to the Shadow Drive, using the specified StorageAccount.
storage_account_key- The public key of theStorageAccountthat will hold the file.data- TheShadowFileto be uploaded.
Example
let upload_file_response = shdw_drive_client
.upload_file(&storage_account_key, file)
.await?;sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
sourcepub async fn upload_multiple_files(
&self,
storage_account_key: &Pubkey,
data: Vec<ShadowFile>
) -> ShadowDriveResult<Vec<ShadowBatchUploadResponse>>
pub async fn upload_multiple_files(
&self,
storage_account_key: &Pubkey,
data: Vec<ShadowFile>
) -> ShadowDriveResult<Vec<ShadowBatchUploadResponse>>
upload_multiple_files uploads a vector of ShadowFiles to Shadow Drive.
The multiple upload process is done in 4 steps:
- Validate & prepare all files into
UploadingData. If a file there are validation errors, the process is aborted. - Filter files that have the same name as a previously uploaded file. Uploads are not attempted for duplicates.
- Divide files to be uploaded into batches of 5 or less to reduce calls but keep transaction size below the limit.
- For each batch: a. confirm file account seed b. derive file account pubkey for each file c. construct & partial sign transaction d. submit transaction and files to Shadow Drive as multipart form data
storage_account_key- The public key of theStorageAccountthat will hold the files.data- A vector ofShadowFiles to be uploaded.
Example
let upload_results = shdw_drive_client
.upload_multiple_files(&storage_account_key, files)
.await
.expect("failed to upload files");sourceimpl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
impl<T> ShadowDriveClient<T> where
T: Signer + Send + Sync,
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 Finalized.
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");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);Auto Trait Implementations
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
impl<T> AbiExample for T
impl<T> AbiExample for T
default fn example() -> T
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more