[][src]Struct safe_api::Safe

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

Fields

xorurl_base: XorUrlBase

Methods

impl Safe[src]

pub async fn auth_app<'_, '_, '_, '_>(
    app_id: &'_ str,
    app_name: &'_ str,
    app_vendor: &'_ str,
    endpoint: Option<&'_ str>
) -> Result<String>
[src]

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

impl Safe[src]

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

pub async fn keys_create<'_, '_, '_, '_>(
    &'_ mut self,
    from: Option<&'_ str>,
    preload_amount: Option<&'_ str>,
    pk: Option<&'_ str>
) -> Result<(XorUrl, Option<BlsKeyPair>)>
[src]

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

pub async fn keys_balance_from_sk<'_, '_>(
    &'_ self,
    sk: &'_ str
) -> Result<String>
[src]

pub async fn keys_balance_from_url<'_, '_, '_>(
    &'_ self,
    url: &'_ str,
    sk: &'_ str
) -> Result<String>
[src]

pub async fn validate_sk_for_url<'_, '_, '_>(
    &'_ self,
    sk: &'_ str,
    url: &'_ str
) -> Result<String>
[src]

pub async fn keys_transfer<'_, '_, '_, '_>(
    &'_ mut self,
    amount: &'_ str,
    from_sk: Option<&'_ str>,
    to_url: &'_ str,
    tx_id: Option<u64>
) -> Result<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::default();
    let (key1_xorurl, key_pair1) = safe.keys_create_preload_test_coins("14").await.unwrap();
    let (key2_xorurl, key_pair2) = safe.keys_create_preload_test_coins("1").await.unwrap();
    let current_balance = safe.keys_balance_from_sk(&key_pair1.clone().unwrap().sk).await.unwrap();
    assert_eq!("14.000000000", current_balance);

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

impl Safe[src]

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

pub async fn parse_and_resolve_url<'_, '_>(
    &'_ self,
    url: &'_ str
) -> Result<(XorUrlEncoder, Option<XorUrlEncoder>)>
[src]

pub async fn nrs_map_container_add<'_, '_, '_>(
    &'_ mut self,
    name: &'_ str,
    link: &'_ str,
    default: bool,
    hard_link: bool,
    dry_run: bool
) -> Result<(u64, XorUrl, ProcessedEntries, NrsMap)>
[src]

pub async fn nrs_map_container_create<'_, '_, '_>(
    &'_ mut self,
    name: &'_ str,
    link: &'_ str,
    default: bool,
    hard_link: bool,
    dry_run: bool
) -> Result<(XorUrl, ProcessedEntries, 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, false).await.unwrap();
    let (xorurl, _processed_entries, nrs_map_container) = safe.nrs_map_container_create(&rand_string, &file_xorurl, true, false, false).await.unwrap();
    assert!(xorurl.contains("safe://"))

pub async fn nrs_map_container_remove<'_, '_>(
    &'_ mut self,
    name: &'_ str,
    dry_run: bool
) -> Result<(u64, XorUrl, ProcessedEntries, NrsMap)>
[src]

pub async fn nrs_map_container_get<'_, '_>(
    &'_ self,
    url: &'_ str
) -> Result<(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"), false).await.unwrap();
    let (xorurl, _processed_entries, _nrs_map) = safe.nrs_map_container_create(&rand_string, &file_xorurl, true, false, false).await.unwrap();
    let (version, nrs_map_container) = safe.nrs_map_container_get(&xorurl).await.unwrap();
    assert_eq!(version, 0);
    assert_eq!(nrs_map_container.get_default_link().unwrap(), file_xorurl);

impl Safe[src]

pub async fn fetch<'_, '_>(
    &'_ self,
    url: &'_ str,
    range: Range
) -> Result<SafeData>
[src]

Retrieve data from a safe:// URL

Examples

Fetch FilesContainer relative path file

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

    let safe_data = safe.fetch( &format!( "{}/test.md", &xorurl.replace("?v=0", "") ), None ).await.unwrap();
    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!"));

pub async fn inspect<'_, '_>(&'_ self, url: &'_ str) -> Result<SafeData>[src]

Inspect a safe:// URL and retrieve metadata information but the actual target content

As opposed to 'fetch' function, the actual target content won't be fetched, and only

the URL will be inspected resolving it as necessary to find the target location.

This is helpful if you are interested in knowing about the target content rather than

trying to revieve the actual content.

Examples

Inspect FilesContainer relative path file

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

    let safe_data = safe.inspect( &format!( "{}/test.md", &xorurl.replace("?v=0", "") ) ).await.unwrap();
    let data_string = match safe_data {
        SafeData::PublishedImmutableData { data, media_type, .. } => {
            assert_eq!(media_type, Some("text/markdown".to_string()));
            assert!(data.is_empty());
        }
        other => panic!(
            "Content type '{:?}' should not have been found. This should be immutable data.",
            other
        )
    };

impl Safe[src]

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

Create a FilesContainer.

Example

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

pub async fn files_container_get<'_, '_>(
    &'_ self,
    url: &'_ str
) -> Result<(u64, FilesMap)>
[src]

Fetch an existing FilesContainer.

Example

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

pub async fn files_container_sync<'_, '_, '_>(
    &'_ mut self,
    location: &'_ str,
    url: &'_ str,
    recursive: bool,
    delete: bool,
    update_nrs: bool,
    dry_run: bool
) -> Result<(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(Some("../testdata"), None, true, false).await.unwrap();
    let (version, new_processed_files, new_files_map) = safe.files_container_sync("../testdata", &xorurl, true, false, false, false).await.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 async fn files_container_add<'_, '_, '_>(
    &'_ mut self,
    source_file: &'_ str,
    url: &'_ str,
    force: bool,
    update_nrs: bool,
    dry_run: bool
) -> Result<(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(Some("../testdata"), None, true, false).await.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).await.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 async fn files_container_add_from_raw<'_, '_, '_>(
    &'_ mut self,
    data: &'_ [u8],
    url: &'_ str,
    force: bool,
    update_nrs: bool,
    dry_run: bool
) -> Result<(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(Some("../testdata"), None, true, false).await.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).await.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 async fn files_container_remove_path<'_, '_>(
    &'_ mut self,
    url: &'_ str,
    recursive: bool,
    update_nrs: bool,
    dry_run: bool
) -> Result<(u64, ProcessedFiles, FilesMap)>
[src]

Remove a file from an existing FilesContainer.

Example

    let (xorurl, processed_files, files_map) = safe.files_container_create(Some("../testdata/"), None, true, false).await.unwrap();
    let remote_file_path = format!("{}/test.md", xorurl);
    let (version, new_processed_files, new_files_map) = safe.files_container_remove_path(&remote_file_path, false, false, false).await.unwrap();
    println!("FilesContainer is now at version: {}", version);
    println!("The files that were removed: {:?}", new_processed_files);
    println!("The FilesMap of the updated FilesContainer now is: {:?}", new_files_map);

pub async fn files_put_published_immutable<'_, '_, '_>(
    &'_ mut self,
    data: &'_ [u8],
    media_type: Option<&'_ str>,
    dry_run: bool
) -> Result<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"), false).await.unwrap();
    let received_data = safe.files_get_published_immutable(&xorurl, None).await.unwrap();
    assert_eq!(received_data, data);

pub async fn files_get_published_immutable<'_, '_>(
    &'_ self,
    url: &'_ str,
    range: Range
) -> Result<Vec<u8>>
[src]

Get Published ImmutableData

Put data blobs onto the network.

Example

    let data = b"Something super good";
    let xorurl = safe.files_put_published_immutable(data, None, false).await.unwrap();
    let received_data = safe.files_get_published_immutable(&xorurl, None).await.unwrap();
    assert_eq!(received_data, data);

impl Safe[src]

pub async fn wallet_create<'_>(&'_ mut self) -> Result<XorUrl>[src]

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

pub async fn wallet_balance<'_, '_>(
    &'_ mut self,
    url: &'_ str
) -> Result<String>
[src]

pub async fn wallet_get_default_balance<'_, '_>(
    &'_ self,
    url: &'_ str
) -> Result<(WalletSpendableBalance, u64)>
[src]

pub async fn wallet_transfer<'_, '_, '_, '_>(
    &'_ mut self,
    amount: &'_ str,
    from_url: Option<&'_ str>,
    to_url: &'_ str,
    tx_id: Option<u64>
) -> Result<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::default();
    let wallet_xorurl = safe.wallet_create().await.unwrap();
    let wallet_xorurl2 = safe.wallet_create().await.unwrap();
    let (key1_xorurl, key_pair1) = safe.keys_create_preload_test_coins("14").await.unwrap();
    let (key2_xorurl, key_pair2) = safe.keys_create_preload_test_coins("1").await.unwrap();
    safe.wallet_insert(
        &wallet_xorurl,
        Some("frombalance"),
        true,
        &key_pair1.clone().unwrap().sk,
    ).await.unwrap();
    let current_balance = safe.wallet_balance(&wallet_xorurl).await.unwrap();
    assert_eq!("14.000000000", current_balance);

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


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

pub async fn wallet_get<'_, '_>(
    &'_ self,
    url: &'_ str
) -> Result<WalletSpendableBalances>
[src]

impl Safe[src]

pub fn new(xorurl_base: Option<XorUrlBase>) -> Self[src]

Trait Implementations

impl Default for Safe[src]

Auto Trait Implementations

impl !RefUnwindSafe for Safe

impl Send for Safe

impl Sync for Safe

impl Unpin for Safe

impl !UnwindSafe for Safe

Blanket Implementations

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

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

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

impl<T> Clear for T where
    T: InitializableFromZeroed + ?Sized

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

impl<T> InitializableFromZeroed for T where
    T: Default

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,