[−][src]Struct safe_api::Safe
Fields
xorurl_base: XorUrlBase
Methods
impl Safe
[src]
pub fn auth_app(
app_id: &str,
app_name: &str,
app_vendor: &str,
endpoint: Option<&str>
) -> Result<String>
[src]
app_id: &str,
app_name: &str,
app_vendor: &str,
endpoint: Option<&str>
) -> Result<String>
pub fn connect(
&mut self,
app_id: &str,
auth_credentials: Option<&str>
) -> Result<()>
[src]
&mut self,
app_id: &str,
auth_credentials: Option<&str>
) -> Result<()>
impl Safe
[src]
pub fn fetch(&self, url: &str) -> Result<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!"));
pub 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, _, _) = unwrap!(safe.files_container_create("../testdata/", None, true, false)); let safe_data = unwrap!( safe.inspect( &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
) -> Result<(XorUrl, ProcessedFiles, FilesMap)>
[src]
&mut self,
location: &str,
dest: Option<&str>,
recursive: bool,
dry_run: bool
) -> Result<(XorUrl, ProcessedFiles, FilesMap)>
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) -> Result<(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
) -> Result<(u64, ProcessedFiles, FilesMap)>
[src]
&mut self,
location: &str,
url: &str,
recursive: bool,
delete: bool,
update_nrs: bool,
dry_run: bool
) -> Result<(u64, ProcessedFiles, FilesMap)>
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
) -> Result<(u64, ProcessedFiles, FilesMap)>
[src]
&mut self,
source_file: &str,
url: &str,
force: bool,
update_nrs: bool,
dry_run: bool
) -> Result<(u64, ProcessedFiles, FilesMap)>
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
) -> Result<(u64, ProcessedFiles, FilesMap)>
[src]
&mut self,
data: &[u8],
url: &str,
force: bool,
update_nrs: bool,
dry_run: bool
) -> Result<(u64, ProcessedFiles, FilesMap)>
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>,
dry_run: bool
) -> Result<XorUrl>
[src]
&mut self,
data: &[u8],
media_type: Option<&str>,
dry_run: bool
) -> Result<XorUrl>
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).unwrap();
pub fn files_get_published_immutable(&self, url: &str) -> Result<Vec<u8>>
[src]
Get Published ImmutableData
Put data blobs onto the network.
Example
let xorurl = safe.files_put_published_immutable(data, None, false).unwrap(); let received_data = safe.files_get_published_immutable(&xorurl).unwrap();
impl Safe
[src]
pub fn keypair(&self) -> Result<BlsKeyPair>
[src]
pub fn keys_create(
&mut self,
from: Option<&str>,
preload_amount: Option<&str>,
pk: Option<&str>
) -> Result<(XorUrl, Option<BlsKeyPair>)>
[src]
&mut self,
from: Option<&str>,
preload_amount: Option<&str>,
pk: Option<&str>
) -> Result<(XorUrl, Option<BlsKeyPair>)>
pub fn keys_create_preload_test_coins(
&mut self,
preload_amount: &str
) -> Result<(XorUrl, Option<BlsKeyPair>)>
[src]
&mut self,
preload_amount: &str
) -> Result<(XorUrl, Option<BlsKeyPair>)>
pub fn keys_balance_from_sk(&self, sk: &str) -> Result<String>
[src]
pub fn keys_balance_from_url(&self, url: &str, sk: &str) -> Result<String>
[src]
pub fn validate_sk_for_url(&self, sk: &str, url: &str) -> Result<String>
[src]
pub fn keys_transfer(
&mut self,
amount: &str,
from_sk: Option<&str>,
to_url: &str,
tx_id: Option<u64>
) -> Result<u64>
[src]
&mut self,
amount: &str,
from_sk: Option<&str>,
to_url: &str,
tx_id: Option<u64>
) -> Result<u64>
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) = 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) -> Result<XorUrlEncoder>
[src]
pub fn parse_and_resolve_url(
&self,
url: &str
) -> Result<(XorUrlEncoder, Option<XorUrlEncoder>)>
[src]
&self,
url: &str
) -> Result<(XorUrlEncoder, Option<XorUrlEncoder>)>
pub 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]
&mut self,
name: &str,
link: &str,
default: bool,
hard_link: bool,
dry_run: bool
) -> Result<(u64, XorUrl, ProcessedEntries, NrsMap)>
pub fn nrs_map_container_create(
&mut self,
name: &str,
link: &str,
default: bool,
hard_link: bool,
dry_run: bool
) -> Result<(XorUrl, ProcessedEntries, NrsMap)>
[src]
&mut self,
name: &str,
link: &str,
default: bool,
hard_link: bool,
dry_run: bool
) -> Result<(XorUrl, ProcessedEntries, NrsMap)>
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).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
) -> Result<(u64, XorUrl, ProcessedEntries, NrsMap)>
[src]
&mut self,
name: &str,
dry_run: bool
) -> Result<(u64, XorUrl, ProcessedEntries, NrsMap)>
pub 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).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) -> Result<XorUrl>
[src]
pub fn wallet_insert(
&mut self,
url: &str,
name: Option<&str>,
default: bool,
sk: &str
) -> Result<String>
[src]
&mut self,
url: &str,
name: Option<&str>,
default: bool,
sk: &str
) -> Result<String>
pub fn wallet_balance(&mut self, url: &str) -> Result<String>
[src]
pub fn wallet_get_default_balance(
&self,
url: &str
) -> Result<(WalletSpendableBalance, u64)>
[src]
&self,
url: &str
) -> Result<(WalletSpendableBalance, u64)>
pub fn wallet_transfer(
&mut self,
amount: &str,
from_url: Option<&str>,
to_url: &str,
tx_id: Option<u64>
) -> Result<u64>
[src]
&mut self,
amount: &str,
from_url: Option<&str>,
to_url: &str,
tx_id: Option<u64>
) -> Result<u64>
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 = 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"), 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"), 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) -> Result<WalletSpendableBalances>
[src]
impl Safe
[src]
pub fn new(xorurl_base: Option<XorUrlBase>) -> Self
[src]
Trait Implementations
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]
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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Clear for T where
T: InitializableFromZeroed + ?Sized,
T: InitializableFromZeroed + ?Sized,
fn clear(&mut self)
impl<T> From<T> for T
[src]
impl<T> InitializableFromZeroed for T where
T: Default,
T: Default,
unsafe fn initialize(place: *mut T)
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, 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.
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.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> UnsafeAny for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,