Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

* [FEATURE][rust] Added `NodeRpcClient::endpoint` and `Client::rpc_endpoint`, exposing the configured node endpoint URL without a network round-trip. ([#2291](https://github.com/0xMiden/miden-client/pull/2291))

### Fixes

* [FIX][rust] RPC endpoint parsing now rejects endpoint strings that omit either the protocol or host. ([#2266](https://github.com/0xMiden/miden-client/pull/2266))
Expand Down
6 changes: 6 additions & 0 deletions crates/rust-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ impl<AUTH> Client<AUTH> {
self.store.identifier()
}

/// Returns the node endpoint URL the client's RPC transport is configured to talk to, if the
/// transport tracks one.
pub fn rpc_endpoint(&self) -> Option<&str> {
self.rpc_api.endpoint()
}

/// Registers a [`transaction::TransactionObserver`]. Per-observer failures are logged.
pub fn with_transaction_observer(
&mut self,
Expand Down
8 changes: 8 additions & 0 deletions crates/rust-client/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ pub trait NodeRpcClient: Send + Sync {
/// Returns the genesis commitment if it has been set, without fetching from the node.
fn has_genesis_commitment(&self) -> Option<Word>;

/// Returns the node endpoint URL this client is configured to talk to, if it tracks one.
///
/// Defaults to `None` for implementations that don't track an endpoint (e.g. test mocks); real
/// transports return their configured URL.
Comment on lines +140 to +141

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could avoid returning Option<> (mock implementations can provide mocked endpoints). Also I think I would avoid mentioning mock implementations specifically on the docs.

fn endpoint(&self) -> Option<&str> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go this route, I think we should make this return a more strict type than &str, to ensure validity by construction. For example, it could be Endpoint.

None
}

/// Given a Proven Transaction, send it to the node for it to be included in a future block
/// using the `/SubmitProvenTransaction` RPC endpoint.
///
Expand Down
11 changes: 11 additions & 0 deletions crates/rust-client/src/rpc/tonic_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ impl NodeRpcClient for GrpcClient {
*self.genesis_commitment.read()
}

fn endpoint(&self) -> Option<&str> {
Some(&self.endpoint)
}

async fn set_genesis_commitment(&self, commitment: Word) -> Result<(), RpcError> {
// Check if already set before doing anything else
if self.genesis_commitment.read().is_some() {
Expand Down Expand Up @@ -1177,6 +1181,13 @@ mod tests {
tokio::task::spawn(async move { dyn_trait_send_fut(client).await });
}

#[test]
fn endpoint_returns_the_configured_url() {
let endpoint = Endpoint::devnet();
let client = GrpcClient::new(&endpoint, 10000);
assert_eq!(client.endpoint(), Some(endpoint.to_string().as_str()));
}

#[tokio::test]
async fn set_genesis_commitment_sets_the_commitment_when_its_not_already_set() {
let endpoint = &Endpoint::devnet();
Expand Down
Loading