pub struct ShadowDriveClient<T> where
    T: Signer
{ /* private fields */ }
Expand description

Client that allows a user to interact with the Shadow Drive.

Implementations

Adds storage capacity to the specified StorageAccount.

  • storage_account_key - The public key of the StorageAccount.
  • size - The additional amount of storage you want to add. E.g if you have an existing StorageAccount with 1MB of storage but you need 2MB total, size should 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?;

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 the StorageAccount that 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?;

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 the StorageAccount that you want to unmark for deletion.
Example
let cancel_delete_storage_account_response = shdw_drive_client
    .cancel_delete_storage_account(&storage_account_key)
    .await?;

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 the StorageAccount that you want to claim excess stake from.
Example
let claim_stake = shdw_drive_client
    .claim_stake(&storage_account_key)
    .await?;

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 the StorageAccount. Does not need to be unique.
  • size - The amount of storage the StorageAccount should be initialized with. When specifying size, only KB, MB, and GB storage units are currently supported.

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 the StorageAccount that 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?;

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 the StorageAccount that you want to mark for deletion.
Example
let delete_storage_account_response = shdw_drive_client
    .delete_storage_account(&storage_account_key)
    .await?;

Replace an existing file on the Shadow Drive with the given updated file.

  • storage_account_key - The public key of the StorageAccount that contains the file.
  • url - The Shadow Drive url of the file you want to replace.
  • data - The updated ShadowFile.
Example
let edit_file_response = shdw_drive_client
    .edit_file(&storage_account_key, url, file)
    .await?;

Returns the StorageAccount associated with the pubkey provided by a user.

Example
let storage_account = shdw_drive_client
    .get_storage_account(&storage_account_key)
    .await
    .expect("failed to get storage account");

Returns all StorageAccounts associated with the public key provided by a user.

  • owner - The public key that is the owner of all the returned StorageAccounts.
Example
let storage_accounts = shdw_drive_client
    .get_storage_accounts(&user_pubkey)
    .await
    .expect("failed to get storage account");

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 the StorageAccount that owns the files.
Example
let files = shdw_drive_client
    .list_objects(&storage_account_key)
    .await?;

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 the StorageAccount that will be made immutable.
Example
let make_immutable_response = shdw_drive_client
    .make_storage_immutable(&storage_account_key)
    .await?;

Reduces the amount of total storage available for the given storage account.

  • storage_account_key - The public key of the StorageAccount whose storage will be reduced.
  • size - The amount of storage you want to remove. E.g if you have an existing StorageAccount with 3MB of storage but you want 2MB total, size should 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?;

Uploads a ShadowFile to the Shadow Drive, using the specified StorageAccount.

  • storage_account_key - The public key of the StorageAccount that will hold the file.
  • data - The ShadowFile to be uploaded.
Example
let upload_file_response = shdw_drive_client
    .upload_file(&storage_account_key, file)
    .await?;

upload_multiple_files uploads a vector of ShadowFiles to Shadow Drive. The multiple upload process is done in 4 steps:

  1. Validate & prepare all files into UploadingData. If a file there are validation errors, the process is aborted.
  2. Filter files that have the same name as a previously uploaded file. Uploads are not attempted for duplicates.
  3. Divide files to be uploaded into batches of 5 or less to reduce calls but keep transaction size below the limit.
  4. 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 the StorageAccount that will hold the files.
  • data - A vector of ShadowFiles to be uploaded.
Example

 let upload_results = shdw_drive_client
    .upload_multiple_files(&storage_account_key, files)
    .await
    .expect("failed to upload files");

Creates a new ShadowDriveClient from the given Signer and URL.

  • wallet - A Signer that 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");

Creates a new ShadowDriveClient from the given Signer and RpcClient.

  • wallet - A Signer that for signs all transactions generated by the client. Typically this is a user’s keypair.
  • rpc_client - A Solana RpcClient that 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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more