Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 2.25 KB

File metadata and controls

54 lines (40 loc) · 2.25 KB

Data

The Data API enables storage of arbitrarily sized blobs on the Autonomi Network by leveraging the Chunk native data type. Under the hood, data is self-encrypted, splitting the payload into multiple encrypted chunks that are dispersed across the network. A DataMap, which contains the addresses of these chunks, is generated to facilitate data retrieval and decryption. Depending on the desired access control, the DataMap can be kept private for confidential data storage or published as a chunk, thereby making the data publicly available via the DataMap’s address.

  • Immutable: Permanent Immutable/Incorruptible storage
  • Size: The data can be of any size
  • Access Control: Data can be private or public

Client Methods

  • data_cost
    Estimates the storage cost for a piece of data.

Client Methods for Private Data (the default on the Network)

  • data_get
    Retrieves bytes from the network using a data map.
  • data_put
    Uploads bytes to the network and returns the price along with the data map to access the data. (This data map is to be kept secret)

Client Methods for Public Data

  • data_get_public
    Retrieves bytes from the network using an address.
  • data_put_public
    Uploads bytes to the network and returns the price along with the address to access the data. (This address can be published so that others can access the data)

Example

use autonomi::{Client, Bytes};
use autonomi::client::payment::PaymentOption;
use eyre::Result;

async fn data_example() -> Result<()> {
    // initialize a local client and test wallet
    let client = Client::init_local().await?;
    let wallet = get_funded_wallet();
    // initialize a local client and test wallet
    let client = Client::init_local().await?;
    let wallet = get_funded_wallet();

    let data = autonomi::Bytes::from("Hello, World!");
    let cost = client.data_cost(data.clone()).await?;
    println!("cost estimate of uploading data: {cost}");

    let (cost, addr) = client.data_put_public(data.clone(), wallet.into()).await?;
    println!("public data put for: {cost} at address: {addr}");

    let data_fetched = client.data_get_public(&addr).await?;
    assert_eq!(data, data_fetched, "data fetched should match data put");
    Ok(())
}