Crates.io | shadow-drive-rust |
lib.rs | shadow-drive-rust |
version | 0.4.0 |
source | src |
created_at | 2022-06-10 06:03:04.521177 |
updated_at | 2022-09-27 23:05:25.873426 |
description | Rust SDK for GenesysGo's Shadow Drive. |
homepage | |
repository | https://github.com/VegetarianOrc/shadow-drive-rust |
max_upload_size | |
id | 603351 |
size | 146,816 |
Rust SDK for GenesysGo's Shadow Drive, a decentralized storage network.
Available on crates.io.
Add the crate to your Cargo.toml
.
shadow-drive-rust = "0.4.0"
//init tracing.rs subscriber
tracing_subscriber::fmt()
.with_env_filter("off,shadow_drive_rust=debug")
.init();
//load keypair from file
let keypair = read_keypair_file(KEYPAIR_PATH).expect("failed to load keypair at path");
//create shdw drive client
let shdw_drive_client = ShadowDriveClient::new(keypair, "https://ssc-dao.genesysgo.net");
//derive the storage account pubkey
let pubkey = keypair.pubkey();
let (storage_account_key, _) =
shadow_drive_rust::derived_addresses::storage_account(&pubkey, 0);
// read files in directory
let dir = tokio::fs::read_dir("multiple_uploads")
.await
.expect("failed to read multiple uploads dir");
// create Vec of ShadowFile structs for upload
let mut files = tokio_stream::wrappers::ReadDirStream::new(dir)
.filter(Result::is_ok)
.and_then(|entry| async move {
Ok(ShadowFile::file(
entry
.file_name()
.into_string()
.expect("failed to convert os string to regular string"),
entry.path(),
))
})
.collect::<Result<Vec<_>, _>>()
.await
.expect("failed to create shdw files for dir");
// Bytes are also supported
files.push(ShadowFile::bytes(
String::from("buf.txt"),
&b"this is a buf test"[..],
));
// kick off upload
let upload_results = shdw_drive_client
.upload_multiple_files(&storage_account_key, files)
.await
.expect("failed to upload files");
//profit
println!("upload results: {:#?}", upload_results);
More examples can be found in the example
directory.