Struct sn_client::client::Client [−][src]
pub struct Client { /* fields omitted */ }
Client object
Implementations
impl Client
[src]
impl Client
[src]pub async fn read_blob(
&self,
address: BlobAddress,
position: Option<usize>,
len: Option<usize>
) -> Result<Vec<u8>, Error> where
Self: Sized,
[src]
pub async fn read_blob(
&self,
address: BlobAddress,
position: Option<usize>,
len: Option<usize>
) -> Result<Vec<u8>, Error> where
Self: Sized,
[src]Read the contents of a blob from the network. The contents might be spread across different blobs in the network. This function invokes the self-encryptor and returns the data that was initially stored.
Takes position
and len
arguments which specify the start position
and the length of bytes to be read. Passing None
to position reads the data from the beginning.
Passing None
to length reads the full length of the data.
Examples
Get data
use sn_client::Client; use sn_data_types::BlobAddress; use xor_name::XorName; let target_blob = BlobAddress::Public(XorName::random()); let client = Client::new(None, None, bootstrap_contacts).await?; // grab the random blob from the network let _data = client.read_blob(target_blob, None, None).await?;
pub async fn store_public_blob(&self, data: &[u8]) -> Result<BlobAddress, Error>
[src]
pub async fn store_public_blob(&self, data: &[u8]) -> Result<BlobAddress, Error>
[src]Store data in public blobs on the network.
This performs self encrypt on the data itself and returns a single address using which the data can be read. It performs data storage as well as all necessary payment validation and checks against the client’s AT2 actor.
Examples
Store data
use sn_client::Client; use sn_data_types::Token; use std::str::FromStr; // Let's use an existing client, with a pre-existing balance to be used for write payments. let mut client = Client::new(None, None, bootstrap_contacts).await?; let data = b"some data".to_vec(); // grab the random blob from the network let _address = client.store_public_blob(&data).await?;
pub async fn store_private_blob(
&self,
data: &[u8]
) -> Result<BlobAddress, Error>
[src]
pub async fn store_private_blob(
&self,
data: &[u8]
) -> Result<BlobAddress, Error>
[src]Store data in private blobs on the network.
This performs self encrypt on the data itself and returns a single address using which the data can be read. It performs data storage as well as all necessary payment validation and checks against the client’s AT2 actor.
Examples
Store data
use sn_client::Client; use sn_data_types::Token; use std::str::FromStr; // Let's use an existing client, with a pre-existing balance to be used for write payments. let mut client = Client::new(None, None, bootstrap_contacts).await?; let data = b"some data".to_vec(); // grab the random blob from the network let fetched_data = client.store_private_blob(&data).await?; println!( "{:?}", fetched_data ); // prints "some data"
pub async fn delete_blob(&self, address: BlobAddress) -> Result<(), Error>
[src]
pub async fn delete_blob(&self, address: BlobAddress) -> Result<(), Error>
[src]Delete blob can only be performed on Private Blobs. But on those private blobs this will remove the data from the network.
Examples
Remove data
use sn_client::Client; use sn_data_types::Token; use std::str::FromStr; // Let's use an existing client, with a pre-existing balance to be used for write payments. let mut client = Client::new(None, None, bootstrap_contacts).await?; let data = b"some private data".to_vec(); let address = client.store_private_blob(&data).await?; let _ = client.delete_blob(address).await?; // Now when we attempt to retrieve the blob, we should get an error match client.read_blob(address, None, None).await { Err(error) => eprintln!("Expected error getting blob {:?}", error), _ => return Err(anyhow::anyhow!("Should not have been able to retrieve this blob")) };
impl Client
[src]
impl Client
[src]pub async fn store_seq_map(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
entries: Option<MapSeqEntries>,
permissions: Option<BTreeMap<PublicKey, MapPermissionSet>>
) -> Result<MapAddress, Error>
[src]
pub async fn store_seq_map(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
entries: Option<MapSeqEntries>,
permissions: Option<BTreeMap<PublicKey, MapPermissionSet>>
) -> Result<MapAddress, Error>
[src]Store a new sequenced Map
Examples
use sn_client::Client; use sn_data_types::{ Keypair, Token, MapAction, MapPermissionSet, MapSeqValue, MapSeqEntries}; use rand::rngs::OsRng; use std::collections::BTreeMap; use xor_name::XorName; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 15001; let mut entries = MapSeqEntries::default(); let mut permissions = BTreeMap::default(); let permission_set = MapPermissionSet::new().allow(MapAction::Read); let _ = permissions.insert(client.public_key().await, permission_set); let _ = entries.insert(b"key".to_vec(), MapSeqValue { data: b"value".to_vec(), version: 0 }); let owner = client.public_key().await; let _ = client.store_seq_map(name, tag, owner, Some(entries), Some(permissions)).await?;
pub async fn store_unseq_map(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
entries: Option<MapUnseqEntries>,
permissions: Option<BTreeMap<PublicKey, MapPermissionSet>>
) -> Result<MapAddress, Error>
[src]
pub async fn store_unseq_map(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
entries: Option<MapUnseqEntries>,
permissions: Option<BTreeMap<PublicKey, MapPermissionSet>>
) -> Result<MapAddress, Error>
[src]Store a new unsequenced Map
Examples
use sn_client::Client; use sn_data_types::{ Keypair, Token, MapAction, MapPermissionSet, MapUnseqEntries}; use rand::rngs::OsRng; use std::collections::BTreeMap; use xor_name::XorName; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 15001; let mut entries = MapUnseqEntries::default(); let mut permissions = BTreeMap::default(); let permission_set = MapPermissionSet::new().allow(MapAction::Read); let _ = permissions.insert(client.public_key().await, permission_set); let _ = entries.insert(b"key".to_vec(), b"value".to_vec()); let owner = client.public_key().await; let _ = client.store_unseq_map(name, tag, owner, Some(entries), Some(permissions)).await?;
pub async fn delete_map(&self, address: MapAddress) -> Result<(), Error>
[src]
pub async fn delete_map(&self, address: MapAddress) -> Result<(), Error>
[src]Delete Map
Examples
use sn_client::Client; use sn_data_types::{ Keypair, Token, MapAction, MapPermissionSet, MapUnseqEntries}; use rand::rngs::OsRng; use std::collections::BTreeMap; use xor_name::XorName; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 15001; let mut entries = MapUnseqEntries::default(); let mut permissions = BTreeMap::default(); let permission_set = MapPermissionSet::new().allow(MapAction::Read); let _ = permissions.insert(client.public_key().await, permission_set); let _ = entries.insert(b"key".to_vec(), b"value".to_vec()); let owner = client.public_key().await; let address = client.store_unseq_map(name, tag, owner, Some(entries.clone()), Some(permissions)).await?; let _ = client.delete_map(address).await?;
pub async fn delete_map_user_perms(
&self,
address: MapAddress,
user: PublicKey,
version: u64
) -> Result<(), Error>
[src]
pub async fn delete_map_user_perms(
&self,
address: MapAddress,
user: PublicKey,
version: u64
) -> Result<(), Error>
[src]Delete map user permission
pub async fn set_map_user_perms(
&self,
address: MapAddress,
user: PublicKey,
permissions: MapPermissionSet,
version: u64
) -> Result<(), Error>
[src]
pub async fn set_map_user_perms(
&self,
address: MapAddress,
user: PublicKey,
permissions: MapPermissionSet,
version: u64
) -> Result<(), Error>
[src]Set map user permissions
pub async fn edit_map_entries(
&self,
address: MapAddress,
changes: MapEntryActions
) -> Result<(), Error>
[src]
pub async fn edit_map_entries(
&self,
address: MapAddress,
changes: MapEntryActions
) -> Result<(), Error>
[src]Mutate map user entries
pub async fn get_map(&self, address: MapAddress) -> Result<Map, Error> where
Self: Sized,
[src]
pub async fn get_map(&self, address: MapAddress) -> Result<Map, Error> where
Self: Sized,
[src]Fetch map data from the network
Examples
use sn_client::Client; use sn_data_types::{ Keypair, Token, MapAction, MapPermissionSet, MapUnseqEntries}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 15001; let mut entries = MapUnseqEntries::default(); let mut permissions = BTreeMap::default(); let permission_set = MapPermissionSet::new().allow(MapAction::Read); let _ = permissions.insert(client.public_key().await, permission_set); let _ = entries.insert(b"key".to_vec(), b"value".to_vec()); let owner = client.public_key().await; let address = client.store_unseq_map(name, tag, owner, Some(entries.clone()), Some(permissions)).await?; let _ = client.get_map(address).await?;
pub async fn get_map_value(
&self,
address: MapAddress,
key: Vec<u8>
) -> Result<MapValue, Error> where
Self: Sized,
[src]
pub async fn get_map_value(
&self,
address: MapAddress,
key: Vec<u8>
) -> Result<MapValue, Error> where
Self: Sized,
[src]Fetch the value for a given key in a map
Examples
use sn_client::Client; use sn_data_types::{ Keypair, Token, MapAction, MapValue, MapPermissionSet, MapUnseqEntries}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 15001; let mut entries = MapUnseqEntries::default(); let _ = entries.insert(b"beep".to_vec(), b"boop".to_vec() ); let mut permissions = BTreeMap::default(); let permission_set = MapPermissionSet::new().allow(MapAction::Read); let _ = permissions.insert(client.public_key().await, permission_set); let _ = entries.insert(b"key".to_vec(), b"value".to_vec()); let owner = client.public_key().await; let address = client.store_unseq_map(name, tag, owner, Some(entries.clone()), Some(permissions)).await?; let received_value = match client.get_map_value(address, b"beep".to_vec()).await? { MapValue::Unseq(value) => value, _ => panic!("Exptected an unsequenced map") }; assert_eq!(received_value, b"boop".to_vec());
pub async fn get_map_shell(&self, address: MapAddress) -> Result<Map, Error> where
Self: Sized,
[src]
pub async fn get_map_shell(&self, address: MapAddress) -> Result<Map, Error> where
Self: Sized,
[src]Get a shell (bare bones) version of Map
from the network.
pub async fn get_map_version(&self, address: MapAddress) -> Result<u64, Error> where
Self: Sized,
[src]
pub async fn get_map_version(&self, address: MapAddress) -> Result<u64, Error> where
Self: Sized,
[src]Get a current version of Map
from the network.
Examples
use sn_client::Client; use sn_data_types::{ Keypair, Token, MapAction, MapPermissionSet, MapUnseqEntries}; use rand::rngs::OsRng; use std::collections::BTreeMap; use xor_name::XorName; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 15001; let mut entries = MapUnseqEntries::default(); let _ = entries.insert(b"beep".to_vec(), b"boop".to_vec() ); let mut permissions = BTreeMap::default(); let permission_set = MapPermissionSet::new().allow(MapAction::Read); let _ = permissions.insert(client.public_key().await, permission_set); let _ = entries.insert(b"key".to_vec(), b"value".to_vec()); let owner = client.public_key().await; let address = client.store_unseq_map(name, tag, owner, Some(entries.clone()), Some(permissions)).await?; let version = client.get_map_version(address).await?; assert_eq!(version, 0);
pub async fn mutate_seq_map_entries(
&self,
name: XorName,
tag: u64,
actions: MapSeqEntryActions
) -> Result<(), Error> where
Self: Sized,
[src]
pub async fn mutate_seq_map_entries(
&self,
name: XorName,
tag: u64,
actions: MapSeqEntryActions
) -> Result<(), Error> where
Self: Sized,
[src]Mutates sequenced Map
entries in bulk
pub async fn mutate_unseq_map_entries(
&self,
name: XorName,
tag: u64,
actions: MapUnseqEntryActions
) -> Result<(), Error> where
Self: Sized,
[src]
pub async fn mutate_unseq_map_entries(
&self,
name: XorName,
tag: u64,
actions: MapUnseqEntryActions
) -> Result<(), Error> where
Self: Sized,
[src]Mutates unsequenced Map
entries in bulk
pub async fn list_unseq_map_entries(
&self,
name: XorName,
tag: u64
) -> Result<BTreeMap<Vec<u8>, Vec<u8>>, Error> where
Self: Sized,
[src]
pub async fn list_unseq_map_entries(
&self,
name: XorName,
tag: u64
) -> Result<BTreeMap<Vec<u8>, Vec<u8>>, Error> where
Self: Sized,
[src]Return a complete list of entries in Map
.
pub async fn list_seq_map_entries(
&self,
name: XorName,
tag: u64
) -> Result<MapSeqEntries, Error> where
Self: Sized,
[src]
pub async fn list_seq_map_entries(
&self,
name: XorName,
tag: u64
) -> Result<MapSeqEntries, Error> where
Self: Sized,
[src]Return a complete list of entries in Map
.
pub async fn list_map_keys(
&self,
address: MapAddress
) -> Result<BTreeSet<Vec<u8>>, Error> where
Self: Sized,
[src]
pub async fn list_map_keys(
&self,
address: MapAddress
) -> Result<BTreeSet<Vec<u8>>, Error> where
Self: Sized,
[src]Return a list of keys in Map
stored on the network.
pub async fn list_seq_map_values(
&self,
name: XorName,
tag: u64
) -> Result<Vec<MapSeqValue>, Error> where
Self: Sized,
[src]
pub async fn list_seq_map_values(
&self,
name: XorName,
tag: u64
) -> Result<Vec<MapSeqValue>, Error> where
Self: Sized,
[src]Return a list of values in a Sequenced Mutable Data
pub async fn list_unseq_map_values(
&self,
name: XorName,
tag: u64
) -> Result<Vec<Vec<u8>>, Error> where
Self: Sized,
[src]
pub async fn list_unseq_map_values(
&self,
name: XorName,
tag: u64
) -> Result<Vec<Vec<u8>>, Error> where
Self: Sized,
[src]Returns a list of values in an Unsequenced Mutable Data
pub async fn list_map_user_permissions(
&self,
address: MapAddress,
user: PublicKey
) -> Result<MapPermissionSet, Error> where
Self: Sized,
[src]
pub async fn list_map_user_permissions(
&self,
address: MapAddress,
user: PublicKey
) -> Result<MapPermissionSet, Error> where
Self: Sized,
[src]Return the permissions set for a particular user
pub async fn list_map_permissions(
&self,
address: MapAddress
) -> Result<BTreeMap<PublicKey, MapPermissionSet>, Error> where
Self: Sized,
[src]
pub async fn list_map_permissions(
&self,
address: MapAddress
) -> Result<BTreeMap<PublicKey, MapPermissionSet>, Error> where
Self: Sized,
[src]Return a list of permissions in Map
stored on the network.
pub async fn set_map_user_permissions(
&self,
address: MapAddress,
user: PublicKey,
permissions: MapPermissionSet,
version: u64
) -> Result<(), Error> where
Self: Sized,
[src]
pub async fn set_map_user_permissions(
&self,
address: MapAddress,
user: PublicKey,
permissions: MapPermissionSet,
version: u64
) -> Result<(), Error> where
Self: Sized,
[src]Updates or inserts a permissions set for a user
pub async fn del_map_user_permissions(
&self,
address: MapAddress,
user: PublicKey,
version: u64
) -> Result<(), Error> where
Self: Sized,
[src]
pub async fn del_map_user_permissions(
&self,
address: MapAddress,
user: PublicKey,
version: u64
) -> Result<(), Error> where
Self: Sized,
[src]Updates or inserts a permissions set for a user
impl Client
[src]
impl Client
[src]pub async fn store_private_register(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<PublicKey, PrivatePermissions>
) -> Result<Address, Error>
[src]
pub async fn store_private_register(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<PublicKey, PrivatePermissions>
) -> Result<Address, Error>
[src]Create a Private Register onto the Network
Creates a private Register on the network which can then be written to. Private data can be removed from the network at a later date.
A tag must be supplied. A xorname must be supplied, this can be random or deterministic as per your apps needs.
pub async fn store_public_register(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<User, PublicPermissions>
) -> Result<Address, Error>
[src]
pub async fn store_public_register(
&self,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<User, PublicPermissions>
) -> Result<Address, Error>
[src]Create a Public Register onto the Network
Creates a public Register on the network which can then be written to. Public data can not be removed from the network at a later date.
A tag must be supplied. A xorname must be supplied, this can be random or deterministic as per your apps needs.
pub async fn delete_register(&self, address: Address) -> Result<(), Error>
[src]
pub async fn delete_register(&self, address: Address) -> Result<(), Error>
[src]Delete Register
You’re only able to delete a PrivateRegister. Public data can no be removed from the network.
pub async fn write_to_register(
&self,
address: Address,
entry: Entry,
parents: BTreeSet<EntryHash>
) -> Result<EntryHash, Error>
[src]
pub async fn write_to_register(
&self,
address: Address,
entry: Entry,
parents: BTreeSet<EntryHash>
) -> Result<EntryHash, Error>
[src]Write to Register
Public or private isn’t important for writing, though the data you write will be Public or Private according to the type of the targeted Register.
pub async fn get_register(&self, address: Address) -> Result<Register, Error>
[src]
pub async fn get_register(&self, address: Address) -> Result<Register, Error>
[src]Get a Register from the Network
pub async fn read_register(
&self,
address: Address
) -> Result<BTreeSet<(EntryHash, Entry)>, Error>
[src]
pub async fn read_register(
&self,
address: Address
) -> Result<BTreeSet<(EntryHash, Entry)>, Error>
[src]Get the last data entry from a Register data.
pub async fn get_register_entry(
&self,
address: Address,
hash: EntryHash
) -> Result<Entry, Error>
[src]
pub async fn get_register_entry(
&self,
address: Address,
hash: EntryHash
) -> Result<Entry, Error>
[src]Get an entry from a Register on the Network by its hash
pub async fn get_register_owner(
&self,
address: Address
) -> Result<PublicKey, Error>
[src]
pub async fn get_register_owner(
&self,
address: Address
) -> Result<PublicKey, Error>
[src]Get the owner of a Register.
pub async fn get_register_permissions_for_user(
&self,
address: Address,
user: PublicKey
) -> Result<Permissions, Error>
[src]
pub async fn get_register_permissions_for_user(
&self,
address: Address,
user: PublicKey
) -> Result<Permissions, Error>
[src]Get the set of Permissions in a Register for a specific user.
impl Client
[src]
impl Client
[src]pub async fn store_private_sequence(
&self,
sequence: Option<SequenceEntries>,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<PublicKey, SequencePrivatePermissions>
) -> Result<SequenceAddress, Error>
[src]
pub async fn store_private_sequence(
&self,
sequence: Option<SequenceEntries>,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<PublicKey, SequencePrivatePermissions>
) -> Result<SequenceAddress, Error>
[src]Create Private Sequence Data on to the Network
Creates a private sequence on the network which can be appended to. Private data can be removed from the network at a later date.
A tag must be supplied. A xorname must be supplied, this can be random or deterministic as per your apps needs.
Examples
Store data
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let _address = client.store_private_sequence(None, name, tag, owner, perms).await?;
pub async fn store_public_sequence(
&self,
sequence: Option<SequenceEntries>,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<SequenceUser, SequencePublicPermissions>
) -> Result<SequenceAddress, Error>
[src]
pub async fn store_public_sequence(
&self,
sequence: Option<SequenceEntries>,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<SequenceUser, SequencePublicPermissions>
) -> Result<SequenceAddress, Error>
[src]Create Public Sequence Data into the Network
Creates a public sequence on the network which can be appended to. Public data can not be removed from the network at a later date.
A tag must be supplied. A xorname must be supplied, this can be random or deterministic as per your apps needs.
Examples
Store data
use sn_client::Client; use sn_data_types::{Keypair, SequenceUser, Token, SequencePublicPermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<SequenceUser, SequencePublicPermissions>::new(); // Set the access permissions let _ = perms.insert( SequenceUser::Key(owner), SequencePublicPermissions::new(true), ); // The returned address can then be used to `append` data to. let _address = client.store_public_sequence(None, name, tag, owner, perms).await?;
pub async fn delete_sequence(
&self,
address: SequenceAddress
) -> Result<(), Error>
[src]
pub async fn delete_sequence(
&self,
address: SequenceAddress
) -> Result<(), Error>
[src]Delete sequence
You’re only able to delete a PrivateSequence. Public data can no be removed from the network.
Examples
Delete data
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; client.delete_sequence(address).await?;
pub async fn append_to_sequence(
&self,
address: SequenceAddress,
entry: SequenceEntry
) -> Result<(), Error>
[src]
pub async fn append_to_sequence(
&self,
address: SequenceAddress,
entry: SequenceEntry
) -> Result<(), Error>
[src]Append to Sequence
Public or private isn’t important for append. You can append to either (though the data you append will be Public or Private).
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; client.append_to_sequence(address, b"New Entry Value".to_vec()).await?;
pub async fn get_sequence(
&self,
address: SequenceAddress
) -> Result<Sequence, Error>
[src]
pub async fn get_sequence(
&self,
address: SequenceAddress
) -> Result<Sequence, Error>
[src]Get Sequence Data from the Network
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; let _data = client.get_sequence(address).await?;
pub async fn get_sequence_last_entry(
&self,
address: SequenceAddress
) -> Result<(u64, SequenceEntry), Error>
[src]
pub async fn get_sequence_last_entry(
&self,
address: SequenceAddress
) -> Result<(u64, SequenceEntry), Error>
[src]Get the last data entry from a Sequence Data.
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; client.append_to_sequence(address, b"New Entry Value".to_vec()).await?; client.append_to_sequence(address, b"Another New Entry Value".to_vec()).await?; // Now we can retrieve the alst entry in the sequence: let (_position, last_entry) = client.get_sequence_last_entry(address).await?; assert_eq!(last_entry, b"Another New Entry Value".to_vec());
pub async fn get_sequence_entry(
&self,
address: SequenceAddress,
index_from_start: u64
) -> Result<SequenceEntry, Error>
[src]
pub async fn get_sequence_entry(
&self,
address: SequenceAddress,
index_from_start: u64
) -> Result<SequenceEntry, Error>
[src]Get Sequence Data from the Network at a specific version
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; client.append_to_sequence(address, b"New Entry Value".to_vec()).await?; client.append_to_sequence(address, b"Another New Entry Value".to_vec()).await?; // Now we can retrieve the alst entry in the sequence: let entry_v1 = client.get_sequence_entry(address, 1).await?; assert_eq!(entry_v1, b"Another New Entry Value".to_vec());
pub async fn get_sequence_range(
&self,
address: SequenceAddress,
range: (SequenceIndex, SequenceIndex)
) -> Result<SequenceEntries, Error>
[src]
pub async fn get_sequence_range(
&self,
address: SequenceAddress,
range: (SequenceIndex, SequenceIndex)
) -> Result<SequenceEntries, Error>
[src]Get a set of Entries for the requested range from a Sequence.
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions, SequenceIndex}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; client.append_to_sequence(address, b"New Entry Value".to_vec()).await?; client.append_to_sequence(address, b"Another New Entry Value".to_vec()).await?; client.append_to_sequence(address, b"Third Entry Value".to_vec()).await?; // Now we can retrieve the alst entry in the sequence: let entries = client.get_sequence_range(address, (SequenceIndex::FromStart(1), SequenceIndex::FromEnd(0) )).await?; assert_eq!(entries[0], b"Another New Entry Value".to_vec()); assert_eq!(entries[1], b"Third Entry Value".to_vec());
pub async fn get_sequence_owner(
&self,
address: SequenceAddress
) -> Result<PublicKey, Error>
[src]
pub async fn get_sequence_owner(
&self,
address: SequenceAddress
) -> Result<PublicKey, Error>
[src]Get the owner of a Sequence.
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; let seq_owner = client.get_sequence_owner(address).await?; assert_eq!(seq_owner, owner);
pub async fn get_sequence_public_permissions_for_user(
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePublicPermissions, Error>
[src]
pub async fn get_sequence_public_permissions_for_user(
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePublicPermissions, Error>
[src]Get the set of Permissions of a Public Sequence.
Examples
use sn_client::Client; use sn_data_types::{Keypair, Token, SequenceUser,SequencePublicPermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<SequenceUser, SequencePublicPermissions>::new(); // Set the access permissions let _ = perms.insert( SequenceUser::Key(owner), SequencePublicPermissions::new(true), ); // The returned address can then be used to `append` data to. let address = client.store_public_sequence(None, name, tag, owner, perms).await?; let _permissions = client.get_sequence_public_permissions_for_user(address, owner).await?;
pub async fn get_sequence_private_permissions_for_user(
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePrivatePermissions, Error>
[src]
pub async fn get_sequence_private_permissions_for_user(
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePrivatePermissions, Error>
[src]Get the set of Permissions of a Private Sequence.
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; let _permissions = client.get_sequence_private_permissions_for_user(address, owner).await?;
pub async fn get_sequence_permissions(
&self,
address: SequenceAddress,
user: SequenceUser
) -> Result<SequencePermissions, Error>
[src]
pub async fn get_sequence_permissions(
&self,
address: SequenceAddress,
user: SequenceUser
) -> Result<SequencePermissions, Error>
[src]Get the set of Permissions for a specific user in a Sequence.
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, Token, SequencePrivatePermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; // Let's use an existing client, with a pre-existing balance to be used for write payments. let id = Keypair::new_ed25519(&mut OsRng); let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let name = XorName::random(); let tag = 10; let owner = client.public_key().await; let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, true), ); // The returned address can then be used to `append` data to. let address = client.store_private_sequence(None, name, tag, owner, perms).await?; let _permissions = client.get_sequence_public_permissions_for_user(address, owner).await?;
impl Client
[src]
impl Client
[src]Handle all token transfers and Write API requests for a given ClientId.
pub async fn get_local_balance(&self) -> Token
[src]
pub async fn get_local_balance(&self) -> Token
[src]Get the current known account balance from the local actor. (ie. Without querying the network)
Examples
Create a random client
use sn_client::Client; use std::str::FromStr; use sn_data_types::Token; let client = Client::new(None, None, bootstrap_contacts).await?; // now we check the local balance let some_balance = client.get_local_balance().await; assert_eq!(some_balance, Token::from_str("0")?);
pub async fn send_tokens(
&self,
to: PublicKey,
amount: Token
) -> Result<(u64, PublicKey), Error>
[src]
pub async fn send_tokens(
&self,
to: PublicKey,
amount: Token
) -> Result<(u64, PublicKey), Error>
[src]Send token to another PublicKey.
If the PublicKey does not exist as a balance on the network it will be created with the send amount.
Examples
Send token to a PublickKey. (This test uses “simulated payouts” to generate test token. This of course would not be avaiable on a live network.)
use sn_client::Client; use sn_data_types::{PublicKey, Token}; use std::str::FromStr; // A random sk, to send token to let sk = threshold_crypto::SecretKey::random(); let pk = PublicKey::from(sk.public_key()); // Next we create a random client. let mut client = Client::new(None, None, bootstrap_contacts).await?; let target_balance = Token::from_str("100")?; // And trigger a simulated payout to our client's PublicKey, so we have token to send. let _ = client.trigger_simulated_farming_payout(target_balance).await?; // Now we have 100 token at our balance, we can send it elsewhere: let (count, sending_pk) = client.send_tokens( pk, target_balance ).await?; // Finally, we can see that the token has arrived: let received_balance = client.get_balance_for(pk).await?; assert_eq!(1, count); assert_ne!(pk, sending_pk); assert_eq!(received_balance, target_balance);
impl Client
[src]
impl Client
[src]Handle all token transfers and Write API requests for a given ClientId.
pub async fn trigger_simulated_farming_payout(
&mut self,
amount: Token
) -> Result<(), Error>
[src]
pub async fn trigger_simulated_farming_payout(
&mut self,
amount: Token
) -> Result<(), Error>
[src]Simulate a farming payout & add a balance to the client’s PublicKey.
Useful for testing to generate initial balances needed for sending transfer requests, which is in turn required for performing write operations.
This also keeps the client transfer actor up to date.
Examples
Add 100 token to a client
use sn_client::Client; use sn_data_types::{Keypair, Token}; use std::str::FromStr; use rand::rngs::OsRng; let id = Keypair::new_ed25519(&mut OsRng); // Start our client let mut client = Client::new(Some(id), None, bootstrap_contacts).await?; let target_balance = Token::from_str("100")?; let _ = client.trigger_simulated_farming_payout(target_balance).await?; let balance = client.get_balance().await?; assert_eq!(balance, target_balance);
impl Client
[src]
impl Client
[src]pub async fn get_balance(&self) -> Result<Token, Error> where
Self: Sized,
[src]
pub async fn get_balance(&self) -> Result<Token, Error> where
Self: Sized,
[src]Get the client’s current coin balance from the network
Examples
Retrieve an existing balance
use sn_client::Client; use sn_data_types::{Keypair, Token}; use rand::rngs::OsRng; use std::str::FromStr; // Let's check the balance of a client with a random id. // (It should have 0 balance) let id = Keypair::new_ed25519(&mut OsRng); let client = Client::new(Some(id), None, bootstrap_contacts).await?; let initial_balance = Token::from_str("0")?; let balance = client.get_balance().await?; assert_eq!(balance, initial_balance);
pub async fn get_balance_for(
&self,
public_key: PublicKey
) -> Result<Token, Error> where
Self: Sized,
[src]
pub async fn get_balance_for(
&self,
public_key: PublicKey
) -> Result<Token, Error> where
Self: Sized,
[src]Get balance for a Public Key on the network.
Examples
Retrieve an existing balance
use sn_client::Client; use sn_data_types::{Keypair, Token}; use std::str::FromStr; use rand::rngs::OsRng; // Let's check the balance of a client with a random id. let id = Keypair::new_ed25519(&mut OsRng); let pk = id.public_key(); // And we use a random client to do this let client = Client::new(None, None, bootstrap_contacts).await?; let initial_balance = Token::from_str("0")?; let balance = client.get_balance_for(pk).await?; assert_eq!(balance, initial_balance);
pub async fn get_history(&self) -> Result<(), Error>
[src]
pub async fn get_history(&self) -> Result<(), Error>
[src]Retrieve the history of the account from the network and apply to our local client’s AT2 actor.
Examples
Retrieving an existing balance history
use sn_client::Client; use sn_data_types::Keypair; use rand::rngs::OsRng; // Let's check the balance of a random client. // And we use a random client id to do this let id = Keypair::new_ed25519(&mut OsRng); let client = Client::new(Some(id), None, bootstrap_contacts).await?; // Upon calling, history is retrieved and applied to the local AT2 actor. let _ = client.get_history().await?;
impl Client
[src]
impl Client
[src]Easily manage connections to/from The Safe Network with the client and its APIs. Use a random client for read-only or one-time operations. Supply an existing, SecretKey which holds a SafeCoin balance to be able to perform write operations.
pub async fn new(
optional_keypair: Option<Keypair>,
config_file_path: Option<&Path>,
bootstrap_config: Option<HashSet<SocketAddr>>
) -> Result<Self, Error>
[src]
pub async fn new(
optional_keypair: Option<Keypair>,
config_file_path: Option<&Path>,
bootstrap_config: Option<HashSet<SocketAddr>>
) -> Result<Self, Error>
[src]Create a Safe Network client instance. Either for an existing SecretKey (in which case) the client will attempt to retrieve the history of the key’s balance in order to be ready for any token operations. Or if no SecreteKey is passed, a random keypair will be used, which provides a client that can only perform Read operations (at least until the client’s SecretKey receives some token).
Examples
Create a random client
use sn_client::Client; let client = Client::new(None, None, bootstrap_contacts).await?; // Now for example you can perform read operations: let _some_balance = client.get_balance().await?;
pub async fn keypair(&self) -> Keypair
[src]
pub async fn keypair(&self) -> Keypair
[src]Return the client’s FullId.
Useful for retrieving the PublicKey or KeyPair in the event you need to sign something
Examples
use sn_client::Client; let client = Client::new(None, None, bootstrap_contacts).await?; let _keypair = client.keypair().await;
pub async fn public_key(&self) -> PublicKey
[src]
pub async fn public_key(&self) -> PublicKey
[src]Return the client’s PublicKey.
Examples
use sn_client::Client; let client = Client::new(None, None, bootstrap_contacts).await?; let _pk = client.public_key().await;
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,