use crate::client::Client;
use crate::crypto::shared_secretbox;
use crate::immutable_data;
use crate::nfs::NfsError;
use bincode::{deserialize, serialize};
use safe_nd::IDataAddress;
use self_encryption::DataMap;
use xor_name::XorName;
pub async fn get(
client: &(impl Client + 'static),
address: IDataAddress,
encryption_key: Option<shared_secretbox::Key>,
) -> Result<DataMap, NfsError> {
let content = immutable_data::get_value(client, address, None, None, encryption_key).await?;
deserialize(&content).map_err(From::from)
}
pub async fn put(
client: &(impl Client + 'static),
data_map: &DataMap,
published: bool,
encryption_key: Option<shared_secretbox::Key>,
) -> Result<XorName, NfsError> {
let client = client.clone();
let client2 = client.clone();
let encoded = serialize(&data_map)?;
let data = immutable_data::create(&client, &encoded, published, encryption_key).await?;
let name = *data.name();
client2.put_idata(data).await?;
Ok(name)
}