Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
merge up to main
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed Oct 1, 2024
2 parents c97a400 + d83bd7c commit 9d3846d
Show file tree
Hide file tree
Showing 55 changed files with 347 additions and 389 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy_static = "1.5.0"
serde = { version = "1.0.193", features = ["derive", "rc"] }
serde_json = "1.0.108"
thiserror = "1.0.50"
http-std = { git = "https://github.com/TBD54566975/web5-rs", rev = "005bd3c04574039ad7c3e41eeefae877b9895104" }
web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "005bd3c04574039ad7c3e41eeefae877b9895104" }
web5_uniffi_wrapper = { git = "https://github.com/TBD54566975/web5-rs", rev = "005bd3c04574039ad7c3e41eeefae877b9895104" }
http-std = { git = "https://github.com/TBD54566975/web5-rs", rev = "ef1a31970411686ed3a2fd502f5952048cc39876" }
web5 = { git = "https://github.com/TBD54566975/web5-rs", rev = "ef1a31970411686ed3a2fd502f5952048cc39876" }
web5_uniffi_wrapper = { git = "https://github.com/TBD54566975/web5-rs", rev = "ef1a31970411686ed3a2fd502f5952048cc39876" }

1 change: 1 addition & 0 deletions bindings/tbdex_uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license-file.workspace = true
[dependencies]
serde_json = { workspace = true }
tbdex = { path = "../../crates/tbdex" }
tokio = { version = "1.38.0", features = ["full"] }
thiserror = { workspace = true }
uniffi = { version = "0.27.1", features = ["cli"] }
web5 = { workspace = true }
Expand Down
9 changes: 6 additions & 3 deletions bindings/tbdex_uniffi/src/http_client/balances.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::{errors::Result, resources::balance::Balance};
use crate::{errors::Result, get_rt, resources::balance::Balance};
use std::sync::{Arc, RwLock};
use web5_uniffi_wrapper::dids::bearer_did::BearerDid;

pub fn get_balances(pfi_did_uri: String, bearer_did: Arc<BearerDid>) -> Result<Vec<Arc<Balance>>> {
let inner_balances =
tbdex::http_client::balances::get_balances(&pfi_did_uri, &bearer_did.0.clone())?;
let rt = get_rt()?;
let inner_balances = rt.block_on(tbdex::http_client::balances::get_balances(
&pfi_did_uri,
&bearer_did.0.clone(),
))?;

let balances = inner_balances
.into_iter()
Expand Down
27 changes: 20 additions & 7 deletions bindings/tbdex_uniffi/src/http_client/exchanges.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
errors::Result,
get_rt,
messages::{
cancel::Cancel, close::Close, order::Order, order_instructions::OrderInstructions,
order_status::OrderStatus, quote::Quote, rfq::Rfq,
Expand Down Expand Up @@ -48,17 +49,27 @@ impl Exchange {
}

pub fn create_exchange(rfq: Arc<Rfq>, reply_to: Option<String>) -> Result<()> {
tbdex::http_client::exchanges::create_exchange(&rfq.to_inner()?, reply_to)?;
let rt = get_rt()?;
rt.block_on(tbdex::http_client::exchanges::create_exchange(
&rfq.to_inner()?,
reply_to,
))?;
Ok(())
}

pub fn submit_order(order: Arc<Order>) -> Result<()> {
tbdex::http_client::exchanges::submit_order(&order.get_data()?)?;
let rt = get_rt()?;
rt.block_on(tbdex::http_client::exchanges::submit_order(
&order.get_data()?,
))?;
Ok(())
}

pub fn submit_cancel(cancel: Arc<Cancel>) -> Result<()> {
tbdex::http_client::exchanges::submit_cancel(&cancel.get_data()?)?;
let rt = get_rt()?;
rt.block_on(tbdex::http_client::exchanges::submit_cancel(
&cancel.get_data()?,
))?;
Ok(())
}

Expand All @@ -67,11 +78,12 @@ pub fn get_exchange(
bearer_did: Arc<BearerDid>,
exchange_id: String,
) -> Result<Exchange> {
let inner_exchange = tbdex::http_client::exchanges::get_exchange(
let rt = get_rt()?;
let inner_exchange = rt.block_on(tbdex::http_client::exchanges::get_exchange(
&pfi_did_uri,
&bearer_did.0.clone(),
&exchange_id,
)?;
))?;

Ok(Exchange::from_inner(inner_exchange))
}
Expand All @@ -81,10 +93,11 @@ pub fn get_exchange_ids(
bearer_did: Arc<BearerDid>,
query_params: Option<GetExchangeIdsQueryParams>,
) -> Result<Vec<String>> {
let exchange_ids = tbdex::http_client::exchanges::get_exchange_ids(
let rt = get_rt()?;
let exchange_ids = rt.block_on(tbdex::http_client::exchanges::get_exchange_ids(
&pfi_did_uri,
&bearer_did.0.clone(),
query_params,
)?;
))?;
Ok(exchange_ids)
}
6 changes: 4 additions & 2 deletions bindings/tbdex_uniffi/src/http_client/offerings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{errors::Result, resources::offering::Offering};
use crate::{errors::Result, get_rt, resources::offering::Offering};
use std::sync::{Arc, RwLock};

pub fn get_offerings(pfi_did_uri: String) -> Result<Vec<Arc<Offering>>> {
let inner_offerings = tbdex::http_client::offerings::get_offerings(&pfi_did_uri)?;
let rt = get_rt()?;
let inner_offerings =
rt.block_on(tbdex::http_client::offerings::get_offerings(&pfi_did_uri))?;

let offerings = inner_offerings
.into_iter()
Expand Down
12 changes: 12 additions & 0 deletions bindings/tbdex_uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use crate::{
offering::{data::Offering as OfferingData, Offering},
},
};
use errors::Result;
use tbdex::{
http::{ErrorDetail as ErrorDetailData, ErrorResponseBody as ErrorResponseBodyData},
http_client::exchanges::GetExchangeIdsQueryParams as GetExchangeIdsQueryParamsData,
Expand All @@ -64,6 +65,7 @@ use tbdex::{
ResourceKind, ResourceMetadata as ResourceMetadataData,
},
};
use tokio::runtime::Runtime;
use web5::{
crypto::jwk::Jwk as JwkData,
dids::{
Expand All @@ -81,4 +83,14 @@ use web5_uniffi_wrapper::{
errors::Web5Error,
};

pub fn get_rt() -> Result<Runtime> {
let rt = Runtime::new().map_err(|e| {
tbdex::errors::TbdexError::AsyncRuntime(format!(
"unable to instantiate tokio runtime {}",
e
))
})?;
Ok(rt)
}

uniffi::include_scaffolding!("tbdex");
9 changes: 6 additions & 3 deletions bindings/tbdex_uniffi/src/messages/cancel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -48,7 +51,7 @@ impl Cancel {

pub fn verify(&self) -> Result<()> {
let cancel = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(cancel.verify()?)
let rt = get_rt()?;
Ok(rt.block_on(cancel.verify())?)
}
}
9 changes: 6 additions & 3 deletions bindings/tbdex_uniffi/src/messages/close.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -48,7 +51,7 @@ impl Close {

pub fn verify(&self) -> Result<()> {
let close = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(close.verify()?)
let rt = get_rt()?;
Ok(rt.block_on(close.verify())?)
}
}
9 changes: 6 additions & 3 deletions bindings/tbdex_uniffi/src/messages/order.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -47,7 +50,7 @@ impl Order {

pub fn verify(&self) -> Result<()> {
let order = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(order.verify()?)
let rt = get_rt()?;
Ok(rt.block_on(order.verify())?)
}
}
9 changes: 6 additions & 3 deletions bindings/tbdex_uniffi/src/messages/order_instructions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -51,7 +54,7 @@ impl OrderInstructions {

pub fn verify(&self) -> Result<()> {
let order_instructions = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(order_instructions.verify()?)
let rt = get_rt()?;
Ok(rt.block_on(order_instructions.verify())?)
}
}
9 changes: 6 additions & 3 deletions bindings/tbdex_uniffi/src/messages/order_status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -49,7 +52,7 @@ impl OrderStatus {

pub fn verify(&self) -> Result<()> {
let order_status = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(order_status.verify()?)
let rt = get_rt()?;
Ok(rt.block_on(order_status.verify())?)
}
}
9 changes: 6 additions & 3 deletions bindings/tbdex_uniffi/src/messages/quote.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -48,7 +51,7 @@ impl Quote {

pub fn verify(&self) -> Result<()> {
let quote = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(quote.verify()?)
let rt = get_rt()?;
Ok(rt.block_on(quote.verify())?)
}
}
9 changes: 5 additions & 4 deletions bindings/tbdex_uniffi/src/messages/rfq.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
errors::{Result, TbdexError},
get_rt,
resources::offering::Offering,
};
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -72,14 +73,14 @@ impl Rfq {

pub fn verify(&self) -> Result<()> {
let rfq = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(rfq.verify()?)
let rt = get_rt()?;
Ok(rt.block_on(rfq.verify())?)
}

pub fn verify_offering_requirements(&self, offering: Arc<Offering>) -> Result<()> {
let rfq = self.0.read().map_err(TbdexError::from_poison_error)?;

Ok(rfq.verify_offering_requirements(&offering.to_inner()?)?)
let rt = get_rt()?;
Ok(rt.block_on(rfq.verify_offering_requirements(&offering.to_inner()?))?)
}

pub fn verify_all_private_data(&self) -> Result<()> {
Expand Down
8 changes: 6 additions & 2 deletions bindings/tbdex_uniffi/src/resources/balance.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -49,7 +52,8 @@ impl Balance {

pub fn verify(&self) -> Result<()> {
let inner_balance = self.0.read().map_err(TbdexError::from_poison_error)?;
inner_balance.verify()?;
let rt = get_rt()?;
rt.block_on(inner_balance.verify())?;
Ok(())
}
}
8 changes: 6 additions & 2 deletions bindings/tbdex_uniffi/src/resources/offering.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::errors::{Result, TbdexError};
use crate::{
errors::{Result, TbdexError},
get_rt,
};
use std::sync::{Arc, RwLock};
use tbdex::{
json::{FromJson, ToJson},
Expand Down Expand Up @@ -57,7 +60,8 @@ impl Offering {

pub fn verify(&self) -> Result<()> {
let inner_offering = self.0.read().map_err(TbdexError::from_poison_error)?;
inner_offering.verify()?;
let rt = get_rt()?;
rt.block_on(inner_offering.verify())?;
Ok(())
}
}
Expand Down
2 changes: 2 additions & 0 deletions bindings/tbdex_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository.workspace = true
license-file.workspace = true

[dependencies]
async-trait = "0.1.83"
http-std = { workspace = true }
js-sys = "0.3.70"
lazy_static = { workspace = true }
Expand All @@ -15,6 +16,7 @@ serde_json = { workspace = true }
serde-wasm-bindgen = "0.6.5"
tbdex = { path = "../../crates/tbdex" }
wasm-bindgen = "0.2.93"
wasm-bindgen-futures = "0.4.43"
web5 = { workspace = true }
web-sys = { version = "0.3.70", features = ["console"] }

Expand Down
5 changes: 5 additions & 0 deletions bindings/tbdex_wasm/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use http_std::Error as HttpStdError;
use serde::Serialize;
use serde_wasm_bindgen::to_value;
use tbdex::errors::TbdexError;
Expand Down Expand Up @@ -48,3 +49,7 @@ pub fn map_err(err: TbdexError) -> JsValue {
pub fn map_web5_err(err: Web5Error) -> JsValue {
map_err(TbdexError::Web5Error(err))
}

pub fn map_http_std_err(err: HttpStdError) -> JsValue {
map_err(TbdexError::HttpStdError(err))
}
Loading

0 comments on commit 9d3846d

Please sign in to comment.