diff --git a/.github/workflows/cross-platform.yml b/.github/workflows/cross-platform.yml index e82110b67e..103b9af8fd 100644 --- a/.github/workflows/cross-platform.yml +++ b/.github/workflows/cross-platform.yml @@ -36,7 +36,7 @@ jobs: - name: Cargo check for WASM # Allow clippy lints (these can be pedantic on WASM), but deny regular Rust warnings - run: cargo clippy --target=wasm32-unknown-unknown --package=autonomi --all-targets -- --allow=clippy::all --deny=warnings + run: cargo clippy --target=wasm32-unknown-unknown --package=autonomi --lib --tests -- --allow=clippy::all --deny=warnings timeout-minutes: 30 websocket: diff --git a/autonomi/README.md b/autonomi/README.md index 10936d324b..a5ce30a3d1 100644 --- a/autonomi/README.md +++ b/autonomi/README.md @@ -9,9 +9,47 @@ Connect to and build on the Autonomi network. Add the autonomi crate to your `Cargo.toml`: -```toml -[dependencies] -autonomi = { path = "../autonomi", version = "0.1.0" } +```sh +# `cargo add` adds dependencies to your Cargo.toml manifest file +cargo add autonomi +``` + +### Example + +```rust +use autonomi::{Bytes, Client, Wallet}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + // Default wallet of testnet. + let key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + + let client = Client::connect(&["/ip4/127.0.0.1/udp/1234/quic-v1".parse()?]).await?; + let wallet = Wallet::new_from_private_key(Default::default(), key)?; + + // Put and fetch data. + let data_addr = client + .data_put(Bytes::from("Hello, World"), (&wallet).into()) + .await?; + let _data_fetched = client.data_get(data_addr).await?; + + // Put and fetch directory from local file system. + let dir_addr = client.dir_upload("files/to/upload".into(), &wallet).await?; + client + .dir_download(dir_addr, "files/downloaded".into()) + .await?; + + Ok(()) +} +``` + +In the above example the wallet is setup to use the default EVM network (Arbitrum One). Instead we can use a different network: +```rust +use autonomi::{EvmNetwork, Wallet}; +// Arbitrum Sepolia +let wallet = Wallet::new_from_private_key(EvmNetwork::ArbitrumSepolia, key)?; +// Custom (e.g. local testnet) +let wallet = Wallet::new_from_private_key(EvmNetwork::new_custom("", "", ""), key)?; ``` ## Running tests diff --git a/autonomi/examples/put_and_dir_upload.rs b/autonomi/examples/put_and_dir_upload.rs new file mode 100644 index 0000000000..f90480d101 --- /dev/null +++ b/autonomi/examples/put_and_dir_upload.rs @@ -0,0 +1,24 @@ +use autonomi::{Bytes, Client, Wallet}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + // Default wallet of testnet. + let key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; + + let client = Client::connect(&["/ip4/127.0.0.1/udp/1234/quic-v1".parse()?]).await?; + let wallet = Wallet::new_from_private_key(Default::default(), key)?; + + // Put and fetch data. + let data_addr = client + .data_put(Bytes::from("Hello, World"), (&wallet).into()) + .await?; + let _data_fetched = client.data_get(data_addr).await?; + + // Put and fetch directory from local file system. + let dir_addr = client.dir_upload("files/to/upload".into(), &wallet).await?; + client + .dir_download(dir_addr, "files/downloaded".into()) + .await?; + + Ok(()) +}