-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
81 changed files
with
1,234 additions
and
1,015 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[package] | ||
name = "xmtp_common" | ||
edition = "2021" | ||
version.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
web-time.workspace = true | ||
tracing.workspace = true | ||
tokio = { workspace = true, features = ["time"] } | ||
rand = "0.8" | ||
futures.workspace = true | ||
xmtp_cryptography.workspace = true | ||
|
||
parking_lot = { workspace = true, optional = true } | ||
tracing-subscriber = { workspace = true, features = ["fmt", "env-filter", "ansi", "json"], optional = true } | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
getrandom = { workspace = true, features = ["js"] } | ||
gloo-timers = { workspace = true, features = ["futures"] } | ||
tracing-wasm = { version = "0.2", optional = true } | ||
console_error_panic_hook = { version = "0.1", optional = true } | ||
js-sys.workspace = true | ||
web-sys = { workspace = true, features = ["Window"] } | ||
wasm-bindgen-futures.workspace = true | ||
|
||
[dev-dependencies] | ||
thiserror.workspace = true | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies] | ||
tokio = { workspace = true, features = ["time", "macros", "rt", "sync"]} | ||
wasm-bindgen-test.workspace = true | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] | ||
tokio = { workspace = true, features = ["time", "macros", "rt-multi-thread", "sync"]} | ||
|
||
[features] | ||
test-utils = ["dep:parking_lot", "dep:tracing-subscriber", "dep:tracing-wasm", "dep:console_error_panic_hook"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Common types shared among all XMTP Crates | ||
mod macros; | ||
|
||
#[cfg(feature = "test-utils")] | ||
mod test; | ||
#[cfg(feature = "test-utils")] | ||
pub use test::*; | ||
|
||
pub mod retry; | ||
pub use retry::*; | ||
|
||
/// Global Marker trait for WebAssembly | ||
#[cfg(target_arch = "wasm32")] | ||
pub trait Wasm {} | ||
#[cfg(target_arch = "wasm32")] | ||
impl<T> Wasm for T {} | ||
|
||
pub mod time; | ||
|
||
use rand::{ | ||
distributions::{Alphanumeric, DistString}, | ||
RngCore, | ||
}; | ||
use xmtp_cryptography::utils as crypto_utils; | ||
|
||
pub fn rand_string<const N: usize>() -> String { | ||
Alphanumeric.sample_string(&mut crypto_utils::rng(), N) | ||
} | ||
|
||
pub fn rand_array<const N: usize>() -> [u8; N] { | ||
let mut buffer = [0u8; N]; | ||
crypto_utils::rng().fill_bytes(&mut buffer); | ||
buffer | ||
} | ||
|
||
/// Yield back control to the async runtime | ||
#[cfg(not(target_arch = "wasm32"))] | ||
pub async fn yield_() { | ||
tokio::task::yield_now().await | ||
} | ||
|
||
/// Yield back control to the async runtime | ||
#[cfg(target_arch = "wasm32")] | ||
pub async fn yield_() { | ||
time::sleep(crate::time::Duration::from_millis(1)).await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// Turn the `Result<T, E>` into an `Option<T>`, logging the error with `tracing::error` and | ||
/// returning `None` if the value matches on Result::Err(). | ||
/// Optionally pass a message as the second argument. | ||
#[macro_export] | ||
macro_rules! optify { | ||
( $e: expr ) => { | ||
match $e { | ||
Ok(v) => Some(v), | ||
Err(e) => { | ||
tracing::error!("{}", e); | ||
None | ||
} | ||
} | ||
}; | ||
( $e: expr, $msg: tt ) => { | ||
match $e { | ||
Ok(v) => Some(v), | ||
Err(e) => { | ||
tracing::error!("{}: {:?}", $msg, e); | ||
None | ||
} | ||
} | ||
}; | ||
} |
Oops, something went wrong.