1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2021 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

//! The Safe Network Client.
//!
//! In order to connect to The Safe Network you'll need to send messages back and forth to network nodes.
//! The [Client] has everything needed to perform this communication, with APIs to enable
//! working with data.
//!
//! With these APIs you can easily:
//! - Connect to The Safe Network
//! - Read Public data from the network
//! - Write data to the network (assuming you have a SafeCoin balance)
//!
//! ## Basic Usage
//!
//! Setting up a random client for read only access:
//!
//! ```no_run
//! # // The Safe Client is an sync library so will need some kind of runtime. Here we use tokio.
//! # extern crate tokio; use anyhow::Result;
//! # use safe_network::client::utils::test_utils::read_network_conn_info;
//! use safe_network::client::Client;
//! # #[tokio::main] async fn main() { let _: Result<()> = futures::executor::block_on( async {
//! # let bootstrap_contacts = Some(read_network_conn_info()?);
//! let client = Client::new(None, None, bootstrap_contacts).await?;
//! // Now for example you can perform read operations:
//! let _some_balance = client.get_balance().await?;
//! # Ok(()) } ); }
//! ```
//!
//! Or use a pre-existing SecretKey which has a SafeCoin balance to be able to write to the network:
//!
//! ```no_run
//! # // The Safe Client is an sync library so will need some kind of runtime. Here we use tokio.
//! # extern crate tokio; use anyhow::Result;
//! # use safe_network::client::utils::test_utils::read_network_conn_info;
//! use safe_network::client::Client;
//! use rand::rngs::OsRng;
//! use safe_network::types::Keypair;
//! # #[tokio::main] async fn main() { let _: Result<()> = futures::executor::block_on( async {
//! let id = Keypair::new_ed25519(&mut OsRng);
//! # let bootstrap_contacts = Some(read_network_conn_info()?);
//! let client = Client::new(Some(id), None, bootstrap_contacts).await?;
//! // Now for example you can perform read operations:
//! let _some_balance = client.get_balance().await?;
//! # Ok(()) } ); }
//! ```

mod connections;
mod errors;

// Export public API.

pub use client_api::Client;
pub use errors::{Error, ErrorMessage, TransfersError};
pub use qp2p::Config as QuicP2pConfig;

/// Client trait and related constants.
pub mod client_api;
/// Config file handling.
pub mod config_handler;

/// Utility functions.
pub mod utils;