use ant_protocol::storage::DataTypes;
use autonomi::{Client, Wallet, data::DataAddress, self_encryption::encrypt};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::init_local().await?;
let wallet = Wallet::new_from_private_key(
client.evm_network().clone(),
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
)?;
let (data_map, chunks) = encrypt("Hello, World!".into())?;
let mut all_chunks = vec![&data_map];
all_chunks.extend(chunks.iter());
let quote = client
.get_store_quotes(
DataTypes::Chunk,
all_chunks
.iter()
.map(|chunk| (*chunk.address().xorname(), chunk.size())),
)
.await?;
wallet
.pay_for_quotes(quote.payments())
.await
.map_err(|err| err.0)?;
let receipt = autonomi::client::payment::receipt_from_store_quotes(quote);
client.chunk_batch_upload(all_chunks, &receipt).await?;
let addr = DataAddress::new(*data_map.address().xorname());
let data = client.data_get_public(&addr).await?;
println!("{}", String::from_utf8_lossy(&data));
Ok(())
}