Skip to content

Commit

Permalink
rust crates refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed Jan 29, 2024
1 parent 826db1b commit 86214b8
Show file tree
Hide file tree
Showing 51 changed files with 267 additions and 234 deletions.
34 changes: 22 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
[workspace]
resolver = "2"

members = [
"Rust/tesseract",
"Rust/transports",
"Rust/utils"
]
members = [ "Rust/sdk", "Rust/transport", "Rust/utils", "Rust/framework" ]

[workspace.package]
authors = ["Tesseract Systems, Inc. <[email protected]>"]
authors = ["Daniel Leping", "Yehor Popovych", "Tesseract Systems, Inc."]
edition = "2021"
version = "0.1.0"
version = "0.5.6"
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/tesseract-one/Tesseract.swift"
documentation = "https://github.com/tesseract-one/Tesseract.swift"
homepage = "https://github.com/tesseract-one/"
categories = ["api-bindings", "authentication", "network-programming"]
keywords = ["blockchain", "dApp", "wallet", "mobile", "bridge"]

[workspace.dependencies]
async-trait = "0.1"
cbindgen = "0.26"
errorcon = "0.1"
log = "0.4"
tesseract = { git = "https://github.com/tesseract-one/Tesseract.rs.git", branch = "master" }
tesseract-protocol-test = { git = "https://github.com/tesseract-one/Tesseract.rs.git", branch = "master" }
tesseract-protocol-substrate = { git = "https://github.com/tesseract-one/Tesseract.rs.git", branch = "master" }

#build deps (C-interop)
cbindgen = "0.26"

#tesseract
tesseract-one = "0.5"

#protocols
tesseract-protocol-test = "0.5"
tesseract-protocol-substrate = "0.5"

#local
tesseract-swift-utils = { path = "Rust/utils", version = "0.5.6"}
tesseract-swift-transport = { path = "Rust/transport", version = "0.5.6"}
tesseract-swift = { path = "Rust/sdk", version = "0.5.6"}

[profile.release]
strip = true
Expand Down
14 changes: 5 additions & 9 deletions Examples/Rust/Rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
[workspace]

resolver = "2"

members = [
"app",
"wallet"
]

[workspace.dependencies]
tesseract = { git = "https://github.com/tesseract-one/Tesseract.rs.git", branch = "dapp-fixes" }
tesseract-protocol-test = { git = "https://github.com/tesseract-one/Tesseract.rs.git", branch = "dapp-fixes" }
#tesseract = { path = "../../../../Tesseract.rs/tesseract", features = ["client"] }
#tesseract-protocol-test = { path = "../../../../Tesseract.rs/protocols/test", features = ["client"] }
tesseract-one = "0.5"
tesseract-protocol-test = "0.5"

tesseract-swift = { path = "../../../Rust/sdk" }

tesseract-swift-utils = { path = "../../../Rust/utils" }
tesseract-swift-transports = { path = "../../../Rust/transports" }
async-trait = "0.1"
errorcon = "0.1"
log = "0.4"
log-panics = { version = "2", features = ["with-backtrace"]}
log-panics = { version = "2", features = ["with-backtrace"] }
stderrlog = "0.5"
cbindgen = "0.26"

Expand Down
9 changes: 4 additions & 5 deletions Examples/Rust/Rust/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ name = "app"
version = "0.0.1"
authors = ["Tesseract Systems, Inc. <[email protected]>"]
license = "Apache-2.0"
description = "Cardano bindings for C."
keywords = [ "Tesseract", "Cardano", "C" ]
description = "Tesseract SDK Client Example"
edition = "2021"

[dependencies]
tesseract-swift-utils.workspace = true
tesseract-swift-transports = { workspace = true, features = ["client"]}
tesseract-swift = { workspace = true, features = ["client"] }

tesseract = { workspace = true, features = ["client"] }
tesseract-one = { workspace = true, features = ["client"] }
tesseract-protocol-test = { workspace = true, features = ["client"] }

async-trait.workspace = true
errorcon.workspace = true
log.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion Examples/Rust/Rust/app/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ prefix_with_name = true

[parse]
parse_deps = true
include = ["tesseract-swift-utils", "tesseract-swift-client"]
include = ["tesseract-swift", "tesseract-swift-utils", "tesseract-swift-transport"]

[export]
exclude = [
Expand Down
4 changes: 2 additions & 2 deletions Examples/Rust/Rust/app/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{collections::HashMap, sync::Arc};

use async_trait::async_trait;

use tesseract::client::{transport::Status, Delegate};
use tesseract_swift_utils::{ptr::CAnyDropPtr, string::CString, string::CStringRef, traits::AsCRef};
use tesseract_one::client::{transport::Status, Delegate};
use tesseract_swift::utils::{ptr::CAnyDropPtr, string::CString, string::CStringRef, traits::AsCRef};

#[repr(C)]
pub struct AlertProvider {
Expand Down
26 changes: 8 additions & 18 deletions Examples/Rust/Rust/app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
#![feature(async_closure)]

extern crate async_trait;
extern crate tesseract;
extern crate tesseract_protocol_test;
extern crate tesseract_swift_transports;
extern crate tesseract_swift_utils;
extern crate errorcon;

pub mod delegate;

use delegate::{AlertProvider, TransportDelegate};
use stderrlog::LogLevelNum;
use tesseract::client::Tesseract;
use tesseract_one::client::Tesseract;
use errorcon::convertible::ErrorContext;

pub use tesseract_swift_transports::client::*;
use tesseract_protocol_test::TestService;
use tesseract_swift_transports::error::TesseractSwiftError;
use tesseract_swift_utils::future_impls::CFutureString;
use tesseract_swift_utils::response::CMoveResponse;
use tesseract_swift_utils::string::CStringRef;
use tesseract_swift_utils::traits::TryAsRef;
use tesseract_swift_utils::ptr::SyncPtr;
use tesseract_swift_utils::error::CError;
pub use tesseract_swift_utils::*;
use tesseract_swift::error::TesseractSwiftError;
use tesseract_swift::client::transport::ClientTransport;
use tesseract_swift::utils::{
future_impls::CFutureString, response::CMoveResponse, string::CStringRef,
traits::TryAsRef, ptr::SyncPtr, error::CError, Void
};

use std::mem::ManuallyDrop;
use std::sync::Arc;
Expand All @@ -46,7 +36,7 @@ impl AppContextPtr {
}

struct AppContext {
service: Arc<dyn tesseract::client::Service<Protocol = tesseract_protocol_test::Test>>,
service: Arc<dyn tesseract_one::client::Service<Protocol = tesseract_protocol_test::Test>>,
}

#[no_mangle]
Expand Down
10 changes: 5 additions & 5 deletions Examples/Rust/Rust/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name = "wallet"
version = "0.0.1"
authors = ["Tesseract Systems, Inc. <[email protected]>"]
license = "Apache-2.0"
description = "Cardano bindings for C."
keywords = [ "Tesseract", "Cardano", "C" ]
description = "Tesseract SDK Service Example"
edition = "2021"

[dependencies]
tesseract-swift-utils.workspace = true
tesseract-swift-transports = { workspace = true, features = ["service"]}
tesseract = { workspace = true, features = ["service"] }
tesseract-swift = { workspace = true, features = ["service"] }

tesseract-one = { workspace = true, features = ["service"] }
tesseract-protocol-test = { workspace = true, features = ["service"] }

async-trait.workspace = true
errorcon.workspace = true
log.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion Examples/Rust/Rust/wallet/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ prefix_with_name = true

[parse]
parse_deps = true
include = ["tesseract-swift-utils", "tesseract-swift-service"]
include = ["tesseract-swift", "tesseract-swift-utils", "tesseract-swift-transport"]

[export]
exclude = [
Expand Down
2 changes: 1 addition & 1 deletion Examples/Rust/Rust/wallet/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::atomic::{AtomicBool, Ordering};
use stderrlog::LogLevelNum;
use tesseract_swift_transports::error::TesseractSwiftError;
use tesseract_swift::error::TesseractSwiftError;

static INITIALIZED: AtomicBool = AtomicBool::new(false);

Expand Down
35 changes: 13 additions & 22 deletions Examples/Rust/Rust/wallet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
#![feature(async_closure)]

extern crate async_trait;
extern crate errorcon;
extern crate tesseract;
extern crate tesseract_protocol_test;
extern crate tesseract_swift_transports;
extern crate tesseract_swift_utils;

use async_trait::async_trait;
use errorcon::convertible::ErrorContext;
use stderrlog::LogLevelNum;
use tesseract_swift_transports::error::TesseractSwiftError;
use tesseract_swift::error::TesseractSwiftError;
use std::mem::ManuallyDrop;
use std::sync::Arc;
use tesseract::service::Tesseract;
use tesseract_swift_transports::service::ServiceTransport;
use tesseract_swift_utils::error::CError;
use tesseract_swift_utils::future_impls::CFutureBool;
use tesseract_swift_utils::ptr::{CAnyDropPtr, SyncPtr};
use tesseract_swift_utils::response::CMoveResponse;
use tesseract_swift_utils::string::{CString, CStringRef};
use tesseract_swift_utils::traits::{TryAsRef, AsCRef};
use tesseract_swift_utils::Void;
use tesseract_one::service::Tesseract;
use tesseract_swift::service::transport::ServiceTransport;
use tesseract_swift::utils::{
error::CError, future_impls::CFutureBool, ptr::{CAnyDropPtr, SyncPtr},
response::CMoveResponse, string::{CString, CStringRef}, traits::{TryAsRef, AsCRef},
Void
};

mod init;

Expand Down Expand Up @@ -55,21 +46,21 @@ impl TestService {
}
}

impl tesseract::service::Service for TestService {
impl tesseract_one::service::Service for TestService {
type Protocol = tesseract_protocol_test::Test;

fn protocol(&self) -> &tesseract_protocol_test::Test {
&tesseract_protocol_test::Test::Protocol
}

fn to_executor(self) -> Box<dyn tesseract::service::Executor + Send + Sync> {
fn to_executor(self) -> Box<dyn tesseract_one::service::Executor + Send + Sync> {
Box::new(tesseract_protocol_test::service::TestExecutor::from_service(self))
}
}

#[async_trait]
impl tesseract_protocol_test::TestService for TestService {
async fn sign_transaction(self: Arc<Self>, req: &str) -> tesseract::Result<String> {
async fn sign_transaction(self: Arc<Self>, req: &str) -> tesseract_one::Result<String> {
let cstr: CString = req.into();
let future = unsafe {
ManuallyDrop::into_inner((self.ui.approve_tx)(&self.ui, cstr.as_cref()))
Expand All @@ -79,12 +70,12 @@ impl tesseract_protocol_test::TestService for TestService {

if allow {
if req == "make_error" {
Err(tesseract::Error::described(tesseract::ErrorKind::Weird, "intentional error for test").into())
Err(tesseract_one::Error::described(tesseract_one::ErrorKind::Weird, "intentional error for test").into())
} else {
Ok(format!("{}{}", req, self.signature))
}
} else {
Err(tesseract::Error::kinded(tesseract::ErrorKind::Cancelled).into())
Err(tesseract_one::Error::kinded(tesseract_one::ErrorKind::Cancelled).into())
}
}).await
}
Expand Down
44 changes: 44 additions & 0 deletions Rust/framework/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "tesseract-swift-framework"
description = "Tesseract framework to be embedded into prebuilt Swift artifacts. Don't use directly."
version.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
documentation.workspace = true
readme.workspace = true
authors.workspace = true
categories.workspace = true
keywords.workspace = true

[dependencies]
async-trait.workspace = true
errorcon.workspace = true
log.workspace = true

log-panics = { version = "2", features = ["with-backtrace"] }
stderrlog = "0.5"

tesseract-swift.workspace = true

tesseract-one.workspace = true
tesseract-protocol-test = { workspace = true, optional = true, features = ["client", "service"] }
tesseract-protocol-substrate = { workspace = true, optional = true, features = ["client", "service"] }

[build-dependencies]
cbindgen.workspace = true

[features]
default = ["client", "service", "protocol-all"]

client = ["tesseract-swift/client", "tesseract-one/client"]
service = ["tesseract-swift/service", "tesseract-one/service"]

protocol-test = ["dep:tesseract-protocol-test"]
protocol-substrate = ["dep:tesseract-protocol-substrate"]
protocol-all = ["protocol-test", "protocol-substrate"]

[lib]
crate-type = ["staticlib"]

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ prefix_with_name = true

[parse]
parse_deps = true
include = ["tesseract-swift-utils", "tesseract-swift-transports"]
include = ["tesseract-swift", "tesseract-swift-utils", "tesseract-swift-transport"]

[export]
exclude = [
Expand Down
20 changes: 9 additions & 11 deletions Rust/tesseract/src/client.rs → Rust/framework/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ use std::sync::Arc;
use std::{mem::ManuallyDrop, collections::HashMap};

use async_trait::async_trait;
use tesseract::Protocol;
use tesseract::client::{Transport, Tesseract, Service, Delegate, transport,};
use tesseract::serialize::Serializer as TSerializer;
use tesseract_swift_transports::client::{ClientTransport, ClientStatus};
use tesseract_swift_transports::error::TesseractSwiftError;
use tesseract_swift_utils::array::CArray;
use tesseract_swift_utils::future_impls::CFutureString;
use tesseract_swift_utils::traits::AsCRef;
use tesseract_swift_utils::{
ptr::{SyncPtr, CAnyDropPtr}, Void, array::CArrayRef,
map::CKeyValue, string::CString
use tesseract_one::Protocol;
use tesseract_one::client::{Transport, Tesseract, Service, Delegate, transport};
use tesseract_one::serialize::Serializer as TSerializer;

use tesseract_swift::client::transport::{ClientTransport, ClientStatus};
use tesseract_swift::error::TesseractSwiftError;
use tesseract_swift::utils::{
array::{CArray, CArrayRef}, future_impls::CFutureString, traits::AsCRef,
ptr::{SyncPtr, CAnyDropPtr}, map::CKeyValue, string::CString, Void
};

pub type ClientTransportsStatusRef<'a> = CArrayRef<'a, CKeyValue<CString, ClientStatus>>;
Expand Down
5 changes: 3 additions & 2 deletions Rust/tesseract/src/init.rs → Rust/framework/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::mem::ManuallyDrop;
use errorcon::convertible::ErrorContext;
use stderrlog::LogLevelNum;
use tesseract_swift_utils::{response::CVoidResponse, error::CError};
use tesseract_swift_transports::error::TesseractSwiftError;

use tesseract_swift::error::TesseractSwiftError;
use tesseract_swift::utils::{response::CVoidResponse, error::CError};

#[repr(C)]
pub enum LogLevel {
Expand Down
4 changes: 0 additions & 4 deletions Rust/tesseract/src/lib.rs → Rust/framework/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#![feature(async_closure)]

extern crate errorcon;
extern crate tesseract_swift_utils;
extern crate tesseract_swift_transports;

#[cfg(feature = "client")]
pub mod client;

Expand Down
5 changes: 5 additions & 0 deletions Rust/framework/src/protocols/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(feature = "protocol-test")]
pub mod test;

#[cfg(feature="protocol-substrate")]
pub mod substrate;
Loading

0 comments on commit 86214b8

Please sign in to comment.