Skip to content

Commit

Permalink
Reformating (cargo fmt)
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Dec 13, 2022
1 parent 71c68e6 commit 8258479
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 59 deletions.
7 changes: 3 additions & 4 deletions crates/dtp-dev-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
Expand All @@ -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(())
}
117 changes: 62 additions & 55 deletions crates/dtp-sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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):
//
Expand All @@ -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<Self, anyhow::Error> {
let connection_api: ConnectionApi = ConnectionApi{ v: 1 };
pub fn new() -> Result<Self, anyhow::Error> {
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<PeerNodeHandle, anyhow::Error>
{
// 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<OwnNodeHandle, anyhow::Error>
{
// 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<OwnNodeHandle, anyhow::Error>
{ // 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<bool, anyhow::Error>
{
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<PeerNodeHandle, anyhow::Error> {
// 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<OwnNodeHandle, anyhow::Error> {
// 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<OwnNodeHandle, anyhow::Error> {
// 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<bool, anyhow::Error> {
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() {
Expand All @@ -105,7 +112,7 @@ mod tests {
// Use it to create a DTP Node Object.

// Mock a ping to that object.

//assert_eq!(result, 4);
}
}

0 comments on commit 8258479

Please sign in to comment.