Skip to content

Commit

Permalink
Support wasm (still blocking)
Browse files Browse the repository at this point in the history
  • Loading branch information
Restioson committed Mar 12, 2024
1 parent 7bb4b65 commit caba716
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 11 additions & 3 deletions p2pd-oracle-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ license-file = "../LICENSE"
name = "p2pd-oracle-client"
repository = "https://github.com/p2pderivatives/rust-dlc/tree/master/p2pd-oracle-client"
version = "0.1.0"
edition = "2021"

[dependencies]
chrono = {version = "0.4.19", features = ["serde"]}
dlc-manager = {path = "../dlc-manager"}
dlc-messages = {path = "../dlc-messages", features = ["use-serde"]}
reqwest = {version = "0.11", features = ["blocking", "json"]}
dlc-manager = { version = "0.4.0" }
dlc-messages = { version = "0.4.0", features = ["use-serde"]}
reqwest = {version = "0.11", features = ["json"]}
secp256k1-zkp = {version = "0.7.0" }
serde = {version = "*", features = ["derive"]}

[dev-dependencies]
mockito = "0.31.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
pollster = "0.3.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
reqwest = {version = "0.11", features = ["blocking", "json"]}

14 changes: 14 additions & 0 deletions p2pd-oracle-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ struct AttestationResponse {
values: Vec<String>,
}

#[cfg(target_arch = "wasm32")]
fn get<T>(path: &str) -> Result<T, DlcManagerError>
where
T: serde::de::DeserializeOwned,
{
pollster::block_on(pollster::block_on(reqwest::get(path))
.map_err(|x| {
dlc_manager::error::Error::IOError(std::io::Error::new(std::io::ErrorKind::Other, x))
})?
.json::<T>())
.map_err(|e| dlc_manager::error::Error::OracleError(e.to_string()))
}

#[cfg(not(target_arch = "wasm32"))]
fn get<T>(path: &str) -> Result<T, DlcManagerError>
where
T: serde::de::DeserializeOwned,
Expand Down

0 comments on commit caba716

Please sign in to comment.