autonomi/lib.rs
1// Copyright 2024 MaidSafe.net limited.
2//
3// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
4// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
5// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
6// KIND, either express or implied. Please review the Licences for the specific language governing
7// permissions and limitations relating to use of the SAFE Network Software.
8
9//! Connect to and build on the Autonomi network.
10//!
11//! # Example
12//!
13//! ```no_run
14//! use autonomi::{Bytes, Client, Wallet};
15//! use autonomi::client::payment::PaymentOption;
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
19//! let client = Client::init().await?;
20//!
21//! // Default wallet of testnet.
22//! let key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
23//! let wallet = Wallet::new_from_private_key(Default::default(), key)?;
24//! let payment = PaymentOption::Wallet(wallet);
25//!
26//! // Put and fetch data.
27//! let (cost, data_addr) = client.data_put_public(Bytes::from("Hello, World"), payment.clone()).await?;
28//! let _data_fetched = client.data_get_public(&data_addr).await?;
29//!
30//! // Put and fetch directory from local file system.
31//! let (cost, dir_addr) = client.dir_upload_public("files/to/upload".into(), payment).await?;
32//! client.dir_download_public(&dir_addr, "files/downloaded".into()).await?;
33//!
34//! Ok(())
35//! }
36//! ```
37//!
38//! # Data types
39//!
40//! This API gives access to the four fundamental types on the network: [`Chunk`], [`Pointer`], [`Scratchpad`] and [`GraphEntry`].
41//!
42//! When we upload data, it's split into chunks using self-encryption, yielding
43//! a 'datamap' allowing us to reconstruct the data again. Any two people that
44//! upload the exact same data will get the same datamap, as all chunks are
45//! content-addressed and self-encryption is deterministic.
46//!
47//! # Features
48//!
49//! - `loud`: Print debug information to stdout
50
51// docs.rs generation will enable unstable `doc_cfg` feature
52#![cfg_attr(docsrs, feature(doc_cfg))]
53#![allow(clippy::large_enum_variant)]
54#![allow(clippy::result_large_err)]
55// Allow expect/panic and wrong_self_convention temporarily
56#![allow(clippy::expect_used)]
57#![allow(clippy::panic)]
58#![allow(clippy::wrong_self_convention)]
59
60#[macro_use]
61extern crate tracing;
62
63pub mod client;
64pub mod networking;
65pub mod self_encryption;
66
67// The Network data types
68pub use client::data_types::chunk;
69pub use client::data_types::graph;
70pub use client::data_types::pointer;
71pub use client::data_types::scratchpad;
72
73// The high-level data types
74pub use client::data;
75pub use client::files;
76pub use client::register;
77pub use client::vault;
78
79// Re-exports of the evm types
80pub use ant_evm::EvmNetwork as Network;
81pub use ant_evm::EvmWallet as Wallet;
82pub use ant_evm::QuoteHash;
83pub use ant_evm::RewardsAddress;
84pub use ant_evm::utils::{Error as EvmUtilError, get_evm_network};
85pub use ant_evm::{Amount, AttoTokens};
86pub use ant_evm::{MaxFeePerGas, TransactionConfig};
87
88// Re-exports of address related types
89pub use ant_protocol::storage::AddressParseError;
90pub use xor_name::XorName;
91
92// Re-exports protocol version
93pub use ant_protocol::version;
94
95// Re-exports of the bls types
96pub use bls::{PublicKey, SecretKey, Signature};
97
98#[doc(no_inline)] // Place this under 'Re-exports' in the docs.
99pub use bytes::Bytes;
100#[doc(no_inline)] // Place this under 'Re-exports' in the docs.
101pub use libp2p::Multiaddr;
102
103// private helper modules
104pub(crate) mod utils;
105
106#[doc(inline)]
107pub use client::{
108 // Client
109 Client,
110 // Client Configs
111 config::Bootstrap,
112 config::BootstrapConfig,
113 config::BootstrapError,
114 config::ClientConfig,
115 config::ClientOperatingStrategy,
116 config::InitialPeersConfig,
117 // Native data types
118 data_types::chunk::Chunk,
119 data_types::chunk::ChunkAddress,
120 data_types::graph::GraphEntry,
121 data_types::graph::GraphEntryAddress,
122 data_types::pointer::Pointer,
123 data_types::pointer::PointerAddress,
124 data_types::scratchpad::Scratchpad,
125 data_types::scratchpad::ScratchpadAddress,
126 // Payment
127 quote::PaymentMode,
128};
129
130#[cfg(feature = "extension-module")]
131mod python;