[][src]Struct safe_api::Safe

pub struct Safe {
    pub xorurl_base: String,
    // some fields omitted
}

Fields

xorurl_base: String

Methods

impl Safe[src]

pub fn auth_app(
    &mut self,
    app_id: &str,
    app_name: &str,
    app_vendor: &str,
    port: Option<u16>
) -> ResultReturn<String>
[src]

pub fn connect(
    &mut self,
    app_id: &str,
    auth_credentials: Option<&str>
) -> ResultReturn<()>
[src]

impl Safe[src]

pub fn fetch(&self, url: &str) -> ResultReturn<SafeData>[src]

Retrieve data from a safe:// URL

Examples

Fetch FilesContainer relative path file

let (xorurl, _, _) = unwrap!(safe.files_container_create("testdata/", None, true, false));

let safe_data = unwrap!( safe.fetch( &format!( "{}/test.md", &xorurl.replace("?v=0", "") ) ) );
let data_string = match safe_data {
	SafeData::PublishedImmutableData { data, .. } => {
		match String::from_utf8(data) {
			Ok(string) => string,
			Err(e) => panic!("Invalid UTF-8 sequence: {}", e),
		}
	}
	other => panic!(
		"Content type '{:?}' should not have been found. This should be immutable data.",
		other
	)
};

assert!(data_string.starts_with("hello tests!"));

impl Safe[src]

pub fn files_container_create(
    &mut self,
    location: &str,
    dest: Option<&str>,
    recursive: bool,
    dry_run: bool
) -> ResultReturn<(XorUrl, ProcessedFiles, FilesMap)>
[src]

Create a FilesContainer.

Example

let (xorurl, _processed_files, _files_map) = safe.files_container_create("testdata", None, true, false).unwrap();
assert!(xorurl.contains("safe://"))

pub fn files_container_get(&self, url: &str) -> ResultReturn<(u64, FilesMap)>[src]

Fetch an existing FilesContainer.

Example

let (xorurl, _processed_files, _files_map) = safe.files_container_create("testdata", None, true, false).unwrap();
let (version, files_map) = safe.files_container_get(&xorurl).unwrap();
println!("FilesContainer fetched is at version: {}", version);
println!("FilesMap of fetched version is: {:?}", files_map);

pub fn files_container_sync(
    &mut self,
    location: &str,
    url: &str,
    recursive: bool,
    delete: bool,
    update_nrs: bool,
    dry_run: bool
) -> ResultReturn<(u64, ProcessedFiles, FilesMap)>
[src]

Sync up local folder with the content on a FilesContainer.

Example

let (xorurl, _processed_files, _files_map) = safe.files_container_create("testdata", None, true, false).unwrap();
let (version, new_processed_files, new_files_map) = safe.files_container_sync("testdata", &xorurl, true, false, false, false).unwrap();
println!("FilesContainer synced up is at version: {}", version);
println!("The local files that were synced up are: {:?}", new_processed_files);
println!("The FilesMap of the updated FilesContainer now is: {:?}", new_files_map);

pub fn files_container_add(
    &mut self,
    source_file: &str,
    url: &str,
    force: bool,
    update_nrs: bool,
    dry_run: bool
) -> ResultReturn<(u64, ProcessedFiles, FilesMap)>
[src]

Add a file, either a local path or a published file, on an existing FilesContainer.

Example

let (xorurl, _processed_files, _files_map) = safe.files_container_create("testdata", None, true, false).unwrap();
let new_file_name = format!("{}/new_name_test.md", xorurl);
let (version, new_processed_files, new_files_map) = safe.files_container_add("testdata/test.md", &new_file_name, false, false, false).unwrap();
println!("FilesContainer is now at version: {}", version);
println!("The local files that were synced up are: {:?}", new_processed_files);
println!("The FilesMap of the updated FilesContainer now is: {:?}", new_files_map);

pub fn files_container_add_from_raw(
    &mut self,
    data: &[u8],
    url: &str,
    force: bool,
    update_nrs: bool,
    dry_run: bool
) -> ResultReturn<(u64, ProcessedFiles, FilesMap)>
[src]

Add a file, from raw bytes, on an existing FilesContainer.

Example

let (xorurl, _processed_files, _files_map) = safe.files_container_create("testdata", None, true, false).unwrap();
let new_file_name = format!("{}/new_name_test.md", xorurl);
let (version, new_processed_files, new_files_map) = safe.files_container_add_from_raw(b"0123456789", &new_file_name, false, false, false).unwrap();
println!("FilesContainer is now at version: {}", version);
println!("The local files that were synced up are: {:?}", new_processed_files);
println!("The FilesMap of the updated FilesContainer now is: {:?}", new_files_map);

pub fn files_put_published_immutable(
    &mut self,
    data: &[u8],
    media_type: Option<&str>
) -> ResultReturn<XorUrl>
[src]

Put Published ImmutableData

Put data blobs onto the network.

Example

let data = b"Something super good";
let xorurl = safe.files_put_published_immutable(data, Some("text/plain")).unwrap();

pub fn files_get_published_immutable(&self, url: &str) -> ResultReturn<Vec<u8>>[src]

Get Published ImmutableData

Put data blobs onto the network.

Example

let xorurl = safe.files_put_published_immutable(data, None).unwrap();
let received_data = safe.files_get_published_immutable(&xorurl).unwrap();

impl Safe[src]

pub fn keypair(&self) -> ResultReturn<BlsKeyPair>[src]

pub fn keys_create(
    &mut self,
    from: Option<String>,
    preload_amount: Option<String>,
    pk: Option<String>
) -> ResultReturn<(XorUrl, Option<BlsKeyPair>)>
[src]

pub fn keys_create_preload_test_coins(
    &mut self,
    preload_amount: &str
) -> ResultReturn<(XorUrl, Option<BlsKeyPair>)>
[src]

pub fn keys_balance_from_sk(&self, sk: &str) -> ResultReturn<String>[src]

pub fn keys_balance_from_url(&self, url: &str, sk: &str) -> ResultReturn<String>[src]

pub fn validate_sk_for_url(&self, sk: &str, url: &str) -> ResultReturn<String>[src]

pub fn keys_transfer(
    &mut self,
    amount: &str,
    from_sk: Option<String>,
    to_url: &str,
    tx_id: Option<u64>
) -> ResultReturn<u64>
[src]

Transfer safecoins from one SafeKey to another, or to a Wallet

Using a secret key you can send safecoins to a Wallet or to a SafeKey.

Example

let mut safe = Safe::new("base32z");
let (key1_xorurl, key_pair1) = unwrap!(safe.keys_create_preload_test_coins("14"));
let (key2_xorurl, key_pair2) = unwrap!(safe.keys_create_preload_test_coins("1"));
let current_balance = unwrap!(safe.keys_balance_from_sk(&key_pair1.clone().unwrap().sk));
assert_eq!("14.000000000", current_balance);

unwrap!(safe.keys_transfer( "10", Some(key_pair1.clone().unwrap().sk), &key2_xorurl, None ));
let from_balance = unwrap!(safe.keys_balance_from_url( &key1_xorurl, &key_pair1.unwrap().sk ));
assert_eq!("4.000000000", from_balance);
let to_balance = unwrap!(safe.keys_balance_from_url( &key2_xorurl, &key_pair2.unwrap().sk ));
assert_eq!("11.000000000", to_balance);

impl Safe[src]

pub fn parse_url(url: &str) -> ResultReturn<XorUrlEncoder>[src]

pub fn parse_and_resolve_url(
    &self,
    url: &str
) -> ResultReturn<(XorUrlEncoder, bool)>
[src]

pub fn nrs_map_container_add(
    &mut self,
    name: &str,
    link: &str,
    default: bool,
    hard_link: bool,
    dry_run: bool
) -> ResultReturn<(u64, XorUrl, BTreeMap<String, (String, String)>, NrsMap)>
[src]

pub fn nrs_map_container_create(
    &mut self,
    name: &str,
    link: &str,
    default: bool,
    hard_link: bool,
    dry_run: bool
) -> ResultReturn<(XorUrl, BTreeMap<String, (String, String)>, NrsMap)>
[src]

Create a NrsMapContainer.

Example

let rand_string: String = thread_rng().sample_iter(&Alphanumeric).take(15).collect();
let file_xorurl = safe.files_put_published_immutable(&vec![], None).unwrap();
let (xorurl, _processed_entries, nrs_map_container) = safe.nrs_map_container_create(&rand_string, &file_xorurl, true, false, false).unwrap();
assert!(xorurl.contains("safe://"))

pub fn nrs_map_container_remove(
    &mut self,
    name: &str,
    dry_run: bool
) -> ResultReturn<(u64, XorUrl, BTreeMap<String, (String, String)>, NrsMap)>
[src]

pub fn nrs_map_container_get(&self, url: &str) -> ResultReturn<(u64, NrsMap)>[src]

Fetch an existing NrsMapContainer.

Example

let rand_string: String = thread_rng().sample_iter(&Alphanumeric).take(15).collect();
let file_xorurl = safe.files_put_published_immutable(&vec![], Some("text/plain")).unwrap();
let (xorurl, _processed_entries, _nrs_map) = safe.nrs_map_container_create(&rand_string, &file_xorurl, true, false, false).unwrap();
let (version, nrs_map_container) = safe.nrs_map_container_get(&xorurl).unwrap();
assert_eq!(version, 0);
assert_eq!(nrs_map_container.get_default_link().unwrap(), file_xorurl);

impl Safe[src]

pub fn wallet_create(&mut self) -> ResultReturn<XorUrl>[src]

pub fn wallet_insert(
    &mut self,
    url: &str,
    name: Option<String>,
    default: bool,
    sk: &str
) -> ResultReturn<String>
[src]

pub fn wallet_balance(&mut self, url: &str) -> ResultReturn<String>[src]

pub fn wallet_get_default_balance(
    &self,
    url: &str
) -> ResultReturn<(WalletSpendableBalance, u64)>
[src]

pub fn wallet_transfer(
    &mut self,
    amount: &str,
    from_url: Option<String>,
    to_url: &str,
    tx_id: Option<u64>
) -> ResultReturn<u64>
[src]

Transfer safecoins from one Wallet to another

Using established Wallet and SpendableBalances you can send safecoins between Wallets.

Example

let mut safe = Safe::new("base32z");
let wallet_xorurl = unwrap!(safe.wallet_create());
let wallet_xorurl2 = unwrap!(safe.wallet_create());
let (key1_xorurl, key_pair1) = unwrap!(safe.keys_create_preload_test_coins("14"));
let (key2_xorurl, key_pair2) = unwrap!(safe.keys_create_preload_test_coins("1"));
unwrap!(safe.wallet_insert(
    &wallet_xorurl,
    Some("frombalance".to_string()),
    true,
    &key_pair1.clone().unwrap().sk,
));
let current_balance = unwrap!(safe.wallet_balance(&wallet_xorurl));
assert_eq!("14.000000000", current_balance);

unwrap!(safe.wallet_insert(
    &wallet_xorurl2,
    Some("tobalance".to_string()),
    true,
    &key_pair2.clone().unwrap().sk,
));


unwrap!(safe.wallet_transfer( "10", Some(wallet_xorurl), &wallet_xorurl2, None ));
let from_balance = unwrap!(safe.keys_balance_from_url( &key1_xorurl, &key_pair1.unwrap().sk ));
assert_eq!("4.000000000", from_balance);
let to_balance = unwrap!(safe.keys_balance_from_url( &key2_xorurl, &key_pair2.unwrap().sk ));
assert_eq!("11.000000000", to_balance);

pub fn wallet_get(&self, url: &str) -> ResultReturn<WalletSpendableBalances>[src]

impl Safe[src]

pub fn new(xorurl_base: &str) -> Self[src]

Auto Trait Implementations

impl Send for Safe

impl Unpin for Safe

impl Sync for Safe

impl !UnwindSafe for Safe

impl !RefUnwindSafe for Safe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Err = <U as TryFrom<T>>::Err

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> UnsafeAny for T where
    T: Any