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

feat(node-bindings): add methods for returning instance urls #359

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/node-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde_json.workspace = true
tempfile.workspace = true
thiserror.workspace = true
tracing.workspace = true
url.workspace = true

[dev-dependencies]
rand.workspace = true
11 changes: 11 additions & 0 deletions crates/node-bindings/src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
time::{Duration, Instant},
};
use thiserror::Error;
use url::Url;

/// How long we will wait for anvil to indicate that it is ready.
const ANVIL_STARTUP_TIMEOUT_MILLIS: u64 = 10_000;
Expand Down Expand Up @@ -68,6 +69,16 @@ impl AnvilInstance {
pub fn ws_endpoint(&self) -> String {
format!("ws://localhost:{}", self.port)
}

/// Returns the HTTP endpoint url of this instance
pub fn endpoint_url(&self) -> Url {
Url::parse(&self.endpoint()).unwrap()
}

/// Returns the Websocket endpoint url of this instance
pub fn ws_endpoint_url(&self) -> Url {
Url::parse(&self.ws_endpoint()).unwrap()
}
}

impl Drop for AnvilInstance {
Expand Down
11 changes: 11 additions & 0 deletions crates/node-bindings/src/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::{
};
use tempfile::tempdir;
use thiserror::Error;
use url::Url;

/// How long we will wait for geth to indicate that it is ready.
const GETH_STARTUP_TIMEOUT: Duration = Duration::from_secs(10);
Expand Down Expand Up @@ -76,6 +77,16 @@ impl GethInstance {
format!("ws://localhost:{}", self.port)
}

/// Returns the HTTP endpoint url of this instance
pub fn endpoint_url(&self) -> Url {
Url::parse(&self.endpoint()).unwrap()
}

/// Returns the Websocket endpoint url of this instance
pub fn ws_endpoint_url(&self) -> Url {
Url::parse(&self.ws_endpoint()).unwrap()
}

/// Returns the path to this instances' IPC socket
pub fn ipc_path(&self) -> &Option<PathBuf> {
&self.ipc
Expand Down
Loading