Struct sn_client::client::Client [−][src]
Client object
Implementations
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]
&self,
name: XorName,
tag: u64,
owner: PublicKey,
entries: Option<MapSeqEntries>,
permissions: Option<BTreeMap<PublicKey, MapPermissionSet>>
) -> Result<MapAddress, Error>
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]
&self,
name: XorName,
tag: u64,
owner: PublicKey,
entries: Option<MapUnseqEntries>,
permissions: Option<BTreeMap<PublicKey, MapPermissionSet>>
) -> Result<MapAddress, Error>
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]
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]
&self,
address: MapAddress,
user: PublicKey,
version: u64
) -> Result<(), Error>
Delete map user permission
pub async fn set_map_user_perms(
&self,
address: MapAddress,
user: PublicKey,
permissions: MapPermissionSet,
version: u64
) -> Result<(), Error>
[src]
&self,
address: MapAddress,
user: PublicKey,
permissions: MapPermissionSet,
version: u64
) -> Result<(), Error>
Set map user permissions
pub async fn edit_map_entries(
&self,
address: MapAddress,
changes: MapEntryActions
) -> Result<(), Error>
[src]
&self,
address: MapAddress,
changes: MapEntryActions
) -> Result<(), Error>
Mutate map user entries
pub async fn get_map(&self, address: MapAddress) -> Result<Map, Error> where
Self: Sized,
[src]
Self: Sized,
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]
&self,
address: MapAddress,
key: Vec<u8>
) -> Result<MapValue, Error> where
Self: Sized,
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]
Self: Sized,
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]
Self: Sized,
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]
&self,
name: XorName,
tag: u64,
actions: MapSeqEntryActions
) -> Result<(), Error> where
Self: Sized,
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]
&self,
name: XorName,
tag: u64,
actions: MapUnseqEntryActions
) -> Result<(), Error> where
Self: Sized,
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]
&self,
name: XorName,
tag: u64
) -> Result<BTreeMap<Vec<u8>, Vec<u8>>, Error> where
Self: Sized,
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]
&self,
name: XorName,
tag: u64
) -> Result<MapSeqEntries, Error> where
Self: Sized,
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]
&self,
address: MapAddress
) -> Result<BTreeSet<Vec<u8>>, Error> where
Self: Sized,
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]
&self,
name: XorName,
tag: u64
) -> Result<Vec<MapSeqValue>, Error> where
Self: Sized,
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]
&self,
name: XorName,
tag: u64
) -> Result<Vec<Vec<u8>>, Error> where
Self: Sized,
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]
&self,
address: MapAddress,
user: PublicKey
) -> Result<MapPermissionSet, Error> where
Self: Sized,
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]
&self,
address: MapAddress
) -> Result<BTreeMap<PublicKey, MapPermissionSet>, Error> where
Self: Sized,
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]
&self,
address: MapAddress,
user: PublicKey,
permissions: MapPermissionSet,
version: u64
) -> Result<(), Error> where
Self: Sized,
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]
&self,
address: MapAddress,
user: PublicKey,
version: u64
) -> Result<(), Error> where
Self: Sized,
Updates or inserts a permissions set for a user
pub fn change_map_owner(
&self,
_name: XorName,
_tag: u64,
_new_owner: PublicKey,
_version: u64
) -> Result<(), Error>
[src]
&self,
_name: XorName,
_tag: u64,
_new_owner: PublicKey,
_version: u64
) -> Result<(), Error>
Sends an ownership transfer request.
impl Client
[src]
pub async fn read_blob(
&self,
address: BlobAddress,
position: Option<u64>,
len: Option<u64>
) -> Result<Vec<u8>, Error> where
Self: Sized,
[src]
&self,
address: BlobAddress,
position: Option<u64>,
len: Option<u64>
) -> Result<Vec<u8>, Error> where
Self: Sized,
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]
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]
&self,
data: &[u8]
) -> Result<BlobAddress, Error>
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]
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")) };
pub async fn generate_data_map(&self, the_blob: &Blob) -> Result<DataMap, Error>
[src]
Uses self_encryption to generated an encrypted blob serialized data map, without writing to the network
impl Client
[src]
Handle all token transfers and Write API requests for a given ClientId.
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]
&self,
to: PublicKey,
amount: Token
) -> Result<(u64, PublicKey), Error>
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]
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]
&mut self,
amount: Token
) -> Result<(), Error>
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]
pub async fn get_balance(&self) -> Result<Token, Error> where
Self: Sized,
[src]
Self: Sized,
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]
&self,
public_key: PublicKey
) -> Result<Token, Error> where
Self: Sized,
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]
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?;
pub async fn get_store_cost(&self, bytes: u64) -> Result<Token, Error>
[src]
Fetch latest StoreCost for given number of bytes from the network.
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]
&self,
sequence: Option<SequenceEntries>,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<PublicKey, SequencePrivatePermissions>
) -> Result<SequenceAddress, Error>
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, 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]
&self,
sequence: Option<SequenceEntries>,
name: XorName,
tag: u64,
owner: PublicKey,
permissions: BTreeMap<SequenceUser, SequencePublicPermissions>
) -> Result<SequenceAddress, Error>
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, 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]
&self,
address: SequenceAddress
) -> Result<(), Error>
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, 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]
&self,
address: SequenceAddress,
entry: SequenceEntry
) -> Result<(), Error>
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, 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]
&self,
address: SequenceAddress
) -> Result<Sequence, Error>
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, 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]
&self,
address: SequenceAddress
) -> Result<(u64, SequenceEntry), Error>
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, 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]
&self,
address: SequenceAddress,
index_from_start: u64
) -> Result<SequenceEntry, Error>
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, 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]
&self,
address: SequenceAddress,
range: (SequenceIndex, SequenceIndex)
) -> Result<SequenceEntries, Error>
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, 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]
&self,
address: SequenceAddress
) -> Result<PublicKey, Error>
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, 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 set_private_sequence_owner(
&self,
address: SequenceAddress,
owner: PublicKey
) -> Result<(), Error>
[src]
&self,
address: SequenceAddress,
owner: PublicKey
) -> Result<(), Error>
Set the new owner of a Sequence Data Update sequence data owners
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; use threshold_crypto::SecretKey; // 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 new_owner = PublicKey::from( SecretKey::random().public_key() ); let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, 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 _ = client.set_private_sequence_owner(address, new_owner).await?;
pub async fn get_sequence_pub_permissions_for_user(
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePublicPermissions, Error>
[src]
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePublicPermissions, Error>
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, 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_pub_permissions_for_user(address, owner).await?;
pub async fn get_sequence_private_permissions_for_user(
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePrivatePermissions, Error>
[src]
&self,
address: SequenceAddress,
user: PublicKey
) -> Result<SequencePrivatePermissions, Error>
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, 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]
&self,
address: SequenceAddress,
user: SequenceUser
) -> Result<SequencePermissions, Error>
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, 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_pub_permissions_for_user(address, owner).await?;
pub async fn sequence_set_public_permissions(
&self,
address: SequenceAddress,
permissions: BTreeMap<SequenceUser, SequencePublicPermissions>
) -> Result<(), Error>
[src]
&self,
address: SequenceAddress,
permissions: BTreeMap<SequenceUser, SequencePublicPermissions>
) -> Result<(), Error>
Set permissions for a PublicKey on a Public Sequence
Examples
use sn_client::Client; use sn_data_types::{Keypair, PublicKey, SequenceUser, Token, SequencePublicPermissions}; use std::collections::BTreeMap; use xor_name::XorName; use rand::rngs::OsRng; use threshold_crypto::SecretKey; // 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 another_key = PublicKey::from( SecretKey::random().public_key() ); let mut perms = BTreeMap::<SequenceUser, SequencePublicPermissions>::new(); // Set the access permissions let _ = perms.insert( SequenceUser::Key(owner), SequencePublicPermissions::new(true, 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 mut perms2 = BTreeMap::<SequenceUser, SequencePublicPermissions>::new(); let _ = perms2.insert( SequenceUser::Key(another_key), SequencePublicPermissions::new(false, false), ); let _ = client.sequence_set_public_permissions(address, perms2).await?;
pub async fn sequence_set_private_permissions(
&self,
address: SequenceAddress,
permissions: BTreeMap<PublicKey, SequencePrivatePermissions>
) -> Result<(), Error>
[src]
&self,
address: SequenceAddress,
permissions: BTreeMap<PublicKey, SequencePrivatePermissions>
) -> Result<(), Error>
Set permissions for a PublicKey on 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; use threshold_crypto::SecretKey; // 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 another_key = PublicKey::from( SecretKey::random().public_key() ); let mut perms = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); // Set the access permissions let _ = perms.insert( owner, SequencePrivatePermissions::new(true, 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 mut perms2 = BTreeMap::<PublicKey, SequencePrivatePermissions>::new(); let _ = perms2.insert( another_key, SequencePrivatePermissions::new(false, false, false), ); let _ = client.sequence_set_private_permissions(address, perms2).await?;
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]
optional_keypair: Option<Keypair>,
config_file_path: Option<&Path>,
bootstrap_config: Option<HashSet<SocketAddr>>
) -> Result<Self, Error>
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]
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]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,