Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AsyncWebsocketClient #70

Merged
merged 19 commits into from
Aug 28, 2023
Merged
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --release --no-default-features --features core,models
args: --release --no-default-features --features core,models,net,tungstenite
- uses: actions-rs/cargo@v1
with:
command: test
args: --all-features
- uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features core,models
args: --no-default-features --features core,models,net,tungstenite
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Examples
- Wallet from seed
- New wallet generation
- `AsyncWebsocketClient` requests
- make `new` methods of models public
- add `AsyncWebsocketClient`
- update dependencies

## [[v0.2.0-beta]]
### Added
Expand Down
49 changes: 40 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ ed25519-dalek = "1.0.1"
secp256k1 = { version = "0.27.0", default-features = false, features = [
"alloc",
] }
bs58 = { version = "0.4.0", default-features = false, features = [
bs58 = { version = "0.5.0", default-features = false, features = [
"check",
"alloc",
] }
indexmap = { version = "1.7.0", features = ["serde"] }
indexmap = { version = "2.0.0", features = ["serde"] }
regex = { version = "1.5.4", default-features = false }
strum = { version = "0.24.1", default-features = false }
strum_macros = { version = "0.24.2", default-features = false }
strum = { version = "0.25.0", default-features = false }
strum_macros = { version = "0.25.2", default-features = false }
crypto-bigint = { version = "0.5.1" }
rust_decimal = { version = "1.17.0", default-features = false, features = [
"serde",
Expand All @@ -51,33 +51,64 @@ serde = { version = "1.0.130", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.68", default-features = false, features = [
"alloc",
] }
serde_with = "2.3.1"
serde_with = "3.2.0"
serde_repr = "0.1"
zeroize = "1.5.7"
hashbrown = { version = "0.13.2", default-features = false, features = ["serde"] }
hashbrown = { version = "0.14.0", default-features = false, features = ["serde"] }
fnv = { version = "1.0.7", default-features = false }
derive-new = { version = "0.5.9", default-features = false }
thiserror-no-std = "2.0.2"
anyhow = { version ="1.0.69", default-features = false }
tokio = { version = "1.28.0", default-features = false, optional = true }
url = { version = "2.2.2", default-features = false, optional = true }
futures = { version = "0.3.28", default-features = false, optional = true }
rand_core = { version = "0.6.4", default-features = false }
tokio-tungstenite = { version = "0.20.0", optional = true }

[dependencies.embedded-websocket]
# git version needed to use `framer_async`
git = "https://github.com/ninjasource/embedded-websocket"
version = "0.9.2"
rev = "8d87d46f46fa0c75e099ca8aad37e8d00c8854f8"
default-features = false
optional = true

[dev-dependencies]
criterion = "0.4.0"
criterion = "0.5.1"
cargo-husky = { version = "1.5.0", default-features = false, features = [
"user-hooks",
] }
tokio-util = { version = "0.7.7", features = ["codec"] }
bytes = { version = "1.4.0", default-features = false }

[[bench]]
name = "benchmarks"
harness = false

[features]
default = ["std", "core", "models", "utils"]
default = ["std", "core", "models", "utils", "net", "tungstenite", "embedded-websocket"]
models = ["core", "transactions", "requests", "ledger"]
transactions = ["core", "amounts", "currencies"]
requests = ["core", "amounts", "currencies"]
ledger = ["core", "amounts", "currencies"]
amounts = ["core"]
currencies = ["core"]
net = ["dep:url", "dep:futures"]
tungstenite = ["tokio/full", "tokio-tungstenite/native-tls"]
embedded-websocket = ["dep:embedded-websocket"]
core = ["utils"]
utils = []
std = ["rand/std", "regex/std", "chrono/std", "rand/std_rng", "hex/std", "rust_decimal/std", "bs58/std", "serde/std", "indexmap/std", "secp256k1/std"]
std = [
"embedded-websocket/std",
"futures/std",
"rand/std",
"regex/std",
"chrono/std",
"rand/std_rng",
"hex/std",
"rust_decimal/std",
"bs58/std",
"serde/std",
"indexmap/std",
"secp256k1/std",
]
32 changes: 30 additions & 2 deletions examples/std/src/bin/tokio/net/send_request.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
use xrpl::asynch::client::{AsyncWebsocketClientTungstenite, TungsteniteMessage};
use xrpl::models::requests::AccountInfo;

// TODO: add as soon as `AsyncWebsocketClient` is implemented
LimpidCrypto marked this conversation as resolved.
Show resolved Hide resolved
fn main() {
todo!()
#[tokio::main]
async fn main() {
let websocket =
AsyncWebsocketClientTungstenite::open("wss://xrplcluster.com/".parse().unwrap())
.await
.unwrap();
assert!(websocket.is_open());

let account_info = AccountInfo::new(
"rJumr5e1HwiuV543H7bqixhtFreChWTaHH",
None,
None,
None,
None,
None,
None,
);

websocket.send(&account_info).await.unwrap();

while let Ok(Some(TungsteniteMessage::Text(response))) = websocket.try_next().await {
let account_info_echo: AccountInfo = serde_json::from_str(response.as_str()).unwrap();
println!("account_info_echo: {:?}", account_info_echo);

websocket.close().await.unwrap();
break;
}
}
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
LimpidCrypto marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/_anyhow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#[macro_export]
macro_rules! Err {
($err:expr $(,)?) => {{
use alloc::string::ToString;

let error = $err.to_string().replace("\"", "");
let boxed_error = ::alloc::boxed::Box::new(error);
let leaked_error: &'static str = ::alloc::boxed::Box::leak(boxed_error);
Expand Down
Loading
Loading