Rust crate for interaction with the FairOS API.
Sign up with mnemonic:
let mut fairos = Client::new();
let mut rng = ChaCha20Rng::from_entropy();
let mnemonic = Client::generate_mnemonic(&mut rng);
let (address, _) = fairos.signup("username", "password", Some(&mnemonic)).await.unwrap();
Sign up without mnemonic:
let mut fairos = Client::new();
let (address, mnemonic) = fairos.signup("username", "password", None).await.unwrap();
Log in:
fairos.login("username", "password").await.unwrap();
Import account with address:
let address = fairos.import_with_address("username", "password", "0x...").await.unwrap();
Import account with mnemonic:
let mnemonic = "brick salad slogan group happy exact wash way keen park amount concert";
let address = fairos.import_with_mnemonic("username", "password", mnemonic).await.unwrap();
Delete user:
fairos.delete_user("username", "password").await.unwrap();
Log out:
fairos.logout("username").await.unwrap();
Export user:
let export = fairos.export_user("username").await.unwrap();
println!("{:?}", export.username);
println!("{:?}", export.address);
Create pod:
fairos.create_pod("username", "cat-photos", "password").await.unwrap();
Open pod:
fairos.open_pod("username", "cat-photos", "password").await.unwrap();
Sync pod:
fairos.sync_pod("username", "cat-photos").await.unwrap();
Close pod:
fairos.close_pod("username", "cat-photos").await.unwrap();
Share pod:
let reference = fairos.share_pod("username", "cat-photos", "password").await.unwrap();
Receive shared pod:
fairos.receive_shared_pod("second-user", &reference).await.unwrap();
Delete pod:
fairos.delete_pod("username", "cat-photos", "password").await.unwrap();
List pods:
let (pods, shared_pods) = fairos.list_pods("username").await.unwrap();
println!("{:?}", pods);
Make directory:
fairos.open_pod("username", "cat-photos", "password").await.unwrap();
fairos.mkdir("username", "cat-photos", "/Photos").await.unwrap();
Remove directory:
fairos.rmdir("username", "cat-photos", "/Photos").await.unwrap();
List directory:
let (dirs, files) = fairos.ls("username", "cat-photos", "/Photos").await.unwrap();
println!("{:?}", dirs);
println!("{:?}", files);
Upload file:
fairos
.upload_file(
"username",
"cat-photos",
"/Photos",
"/home/user/Pictures/my-cute-cat.jpeg",
BlockSize::Megabytes(2),
Some(Compression::Gzip),
)
.await
.unwrap();
Upload buffer:
fairos
.upload_buffer(
"username",
"cat-photos",
"/",
"cat-names.txt",
"Peanut Butter, Cleo, Oreo, Smokey".as_bytes(),
mime::TEXT_PLAIN,
BlockSize::Kilobytes(1),
Some(Compression::Gzip),
)
.await
.unwrap();
Download file:
fairos
.download_file(
"username",
"cat-photos",
"/Photos/my-cute-cat.jpeg",
"/home/user/Downloads/cat-pic.jpeg"
)
.await
.unwrap();
Download buffer:
let bytes = fairos
.download_buffer(
"username",
"cat-photos",
"/Photos/my-cute-cat.jpeg",
)
.await
.unwrap();
Remove file:
let reference = fairos.rm("username", "cat-photos", "/Photos/my-cute-cat.jpeg").await.unwrap();
Share and receive file:
let reference = fairos.share_file("username", "cat-photos", "/Photos/my-cute-cat.jpeg").await.unwrap();
let file_path = fairos.receive_shared_file("second-user", "my-files", &reference, "/Documents/images").await.unwrap();
println!("{:?}", file_path); // "/Documents/images/my-cute-cat.jpeg"
Create key value store:
fairos.open_pod("username", "cat-data", "password").await.unwrap();
fairos.create_kv_store("username", "cat-data", "cat-breeds", IndexType::Str).await.unwrap();
Open key value store:
fairos.open_kv_store("username", "cat-data", "cat-breeds").await.unwrap();
Delete key value store:
fairos.delete_kv_store("username", "cat-data", "cat-breeds").await.unwrap();
List key value stores:
let stores = fairos.list_kv_stores("username", "cat-data").await.unwrap();
println!("{:?}", stores);
Put key value pair in store:
#[derive(Debug, Deserialize, Serialize)]
struct CatBreed<'a> {
pub weight: (u32, u32),
pub coat_colors: &'a [&'a str],
pub life_expectancy: (u32, u32),
}
let siamese_facts = CatBreed {
weight: (5, 12),
coat_colors: &["Chocolate", "Seal", "Lilac", "Blue", "Red", "Cream", "Fawn", "Cinnamon"],
life_expectancy: (8, 12),
};
fairos.put_kv_pair("username", "cat-data", "cat-breeds", "Siamese", siamese_facts).await.unwrap();
Get key value pair from store:
let facts: CatBreed = fairos.get_kv_pair("username", "cat-data", "cat-breeds", "Siamese").await.unwrap();
Delete key value pair from store:
fairos.delete_kv_pair("username", "cat-data", "cat-breeds", "Siamese").await.unwrap();
Count key value pairs in store:
let count = fairos.count_kv_pairs("username", "cat-data", "cat-breeds").await.unwrap();
println!("{:?}", count);
Create document database:
fairos.open_pod("username", "cat-data", "password").await.unwrap();
fairos
.create_doc_database(
"username",
"cat-data",
"my-cats",
&[("name", FieldType::Str), ("age", FieldType::Number), ("breed", FieldType::Str)],
true,
)
.await
.unwrap();
Open document database:
fairos.open_doc_database("username", "cat-data", "my-cats").await.unwrap();
Delete document database:
fairos.delete_doc_database("username", "cat-data", "my-cats").await.unwrap();
List document databases:
let databases = fairos.list_doc_databases("username", "cat-data").await.unwrap();
println!("{:?}", databases);
Put document in database:
#[derive(Debug, Deserialize, Serialize)]
struct Cat<'a> {
pub name: &'a str,
pub age: u32,
pub breed: &'a str,
}
let cat = Cat {
name: "Bandit",
age: 7,
breed: "Tabby",
};
let id = fairos.put_document("username", "cat-data", "my-cats", cat).await.unwrap();
Get document in database:
let cat: Cat = fairos.get_document("username", "cat-data", "my-cats", &id).await.unwrap();
Find documents in database:
let cats: Vec<Cat> = fairos
.find_documents(
"username",
"cat-data",
"my-cats",
Expr::Eq("name", ExprValue::Str("Tabby".into())),
Some(1)
)
.await
.unwrap();
Delete document in database:
fairos.delete_document("username", "cat-data", "my-cats", &id).await.unwrap();
Count documents in database:
let count = fairos.count_documents("username", "cat-data", "my-cats", Expr::All).await.unwrap();
println!("{:?}", count);