From 825847940782dfe644c20910fb291d262c3f99ac Mon Sep 17 00:00:00 2001 From: mario4tier Date: Mon, 12 Dec 2022 23:25:59 -0500 Subject: [PATCH] Reformating (cargo fmt) --- crates/dtp-dev-app/src/main.rs | 7 +- crates/dtp-sdk/src/lib.rs | 117 +++++++++++++++++---------------- 2 files changed, 65 insertions(+), 59 deletions(-) diff --git a/crates/dtp-dev-app/src/main.rs b/crates/dtp-dev-app/src/main.rs index 6b17df8..d03d206 100644 --- a/crates/dtp-dev-app/src/main.rs +++ b/crates/dtp-dev-app/src/main.rs @@ -2,11 +2,10 @@ use std::str::FromStr; use sui_sdk::types::base_types::SuiAddress; use sui_sdk::SuiClient; -use dtp_sdk::{ DTP, ConnectionApi, PeerNodeHandle, OwnNodeHandle }; +use dtp_sdk::{ConnectionApi, OwnNodeHandle, PeerNodeHandle, DTP}; #[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - +async fn main() -> Result<(), anyhow::Error> { // Test localnet with the pre-funded wallet. let sui = SuiClient::new("http://0.0.0.0:9000", None, None).await?; let address = SuiAddress::from_str("0xcfed50a652b8fce7a7917a8a736a7c2b1d646ba2")?; @@ -24,7 +23,7 @@ async fn main() -> Result<(), anyhow::Error> { let peer_node: PeerNodeHandle = con_api.get_peer_node_by_address(peer_address).await?; let own_node: OwnNodeHandle = con_api.get_own_node_by_address(own_address).await?; - println!("Ping result is {:?}", con_api.ping( &own_node, &peer_node ) ); + println!("Ping result is {:?}", con_api.ping(&own_node, &peer_node)); Ok(()) } diff --git a/crates/dtp-sdk/src/lib.rs b/crates/dtp-sdk/src/lib.rs index 51df854..1ca71bf 100644 --- a/crates/dtp-sdk/src/lib.rs +++ b/crates/dtp-sdk/src/lib.rs @@ -1,6 +1,6 @@ // For now, just focusing on getting the SDKs dependencies right, code is meaningless. -use sui_sdk::types::base_types::{ObjectID, SuiAddress}; use std::str::FromStr; +use sui_sdk::types::base_types::{ObjectID, SuiAddress}; // High-Level Design (very rough for now, likely to evolve): // @@ -24,79 +24,86 @@ use std::str::FromStr; #[derive(Debug)] pub struct PeerNodeHandle { - pub id : ObjectID, + pub id: ObjectID, } pub struct OwnNodeHandle { - pub id : ObjectID, + pub id: ObjectID, } // Provides all the DTP SDK APIs. pub struct DTP { - connection_api: ConnectionApi, + connection_api: ConnectionApi, } impl DTP { - pub fn new( - ) -> Result { - let connection_api: ConnectionApi = ConnectionApi{ v: 1 }; + pub fn new() -> Result { + let connection_api = ConnectionApi; - Ok(DTP{ connection_api }) - } + Ok(DTP { connection_api }) + } - pub fn connection_api(&self) -> &ConnectionApi { - &self.connection_api - } + pub fn connection_api(&self) -> &ConnectionApi { + &self.connection_api + } } -pub struct ConnectionApi{ v: u32 } +pub struct ConnectionApi; impl ConnectionApi { - // Get an handle of a DTP Node own by a peer on the network. - // - // The handle is used for doing operations such as ping the node, create connections, - // block the node with the firewall etc... - // - pub async fn get_peer_node_by_address( - &self, - _address: SuiAddress - ) -> Result - { - // TODO Mocking for now, but calling into Sui SDK for conversion. - Ok(PeerNodeHandle{ id: ObjectID::from_str("0x6205fc058b205227d7b7bd5b4e7802f0055157c6")? }) - } - - // Get an handle of a DTP Node that you own and that is expected to already - // be on the network. - pub async fn get_own_node_by_address( - &self, - _address: SuiAddress - ) -> Result - { - // TODO Mocking for now, but calling into Sui SDK for conversion. - Ok(OwnNodeHandle{ id: ObjectID::from_str("0x6205fc058b205227d7b7bd5b4e7802f0055157c6")? }) - } - - // Create a new DTP Node on the network that - // you will own. - pub async fn create_node(&self) -> Result - { // TODO Mocking for now, but calling into Sui SDK for conversion. - Ok(OwnNodeHandle{ id: ObjectID::from_str("0x6205fc058b205227d7b7bd5b4e7802f0055157c6")? }) - } - - pub fn ping( - &self, - _own_node: &OwnNodeHandle, - _peer_node: &PeerNodeHandle, - ) -> Result - { - Ok(true) - } + // Get an handle of a DTP Node own by a peer on the network. + // + // The handle is used for doing operations such as ping the node, create connections, + // block the node with the firewall etc... + // + pub async fn get_peer_node_by_address( + &self, + _address: SuiAddress, + ) -> Result { + // TODO Mocking for now, but calling into Sui SDK for conversion. + Ok(PeerNodeHandle { + id: ObjectID::from_str("0x6205fc058b205227d7b7bd5b4e7802f0055157c6")?, + }) + } + + // Get an handle of a DTP Node that you own and that is expected to already + // be on the network. + pub async fn get_own_node_by_address( + &self, + _address: SuiAddress, + ) -> Result { + // TODO Mocking for now, but calling into Sui SDK for conversion. + Ok(OwnNodeHandle { + id: ObjectID::from_str("0x6205fc058b205227d7b7bd5b4e7802f0055157c6")?, + }) + } + // Create a new DTP Node on the network that + // you will own. + pub async fn create_node(&self) -> Result { + // TODO Mocking for now, but calling into Sui SDK for conversion. + Ok(OwnNodeHandle { + id: ObjectID::from_str("0x6205fc058b205227d7b7bd5b4e7802f0055157c6")?, + }) + } + + pub fn ping( + &self, + _own_node: &OwnNodeHandle, + _peer_node: &PeerNodeHandle, + ) -> Result { + Ok(true) + } } #[cfg(test)] mod tests { - //use super::*; + use super::*; + + #[test] + fn test_dtp_instantiation() -> Result<(), anyhow::Error> { + let _dtp = DTP::new()?; + Ok(()) + } #[test] fn node_call() { @@ -105,7 +112,7 @@ mod tests { // Use it to create a DTP Node Object. // Mock a ping to that object. - + //assert_eq!(result, 4); } }