Skip to content

Commit

Permalink
feat: https support in endpoint config (#556)
Browse files Browse the repository at this point in the history
Previously only http was supported.
  • Loading branch information
varun-doshi authored Dec 2, 2024
1 parent 8329a77 commit 54095db
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- Added `GetAccountProofs` endpoint (#506).
- Support Https in endpoint configuration (#556).

### Changes

Expand Down
9 changes: 6 additions & 3 deletions bin/node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl NodeConfig {
mod tests {
use figment::Jail;
use miden_node_store::config::StoreConfig;
use miden_node_utils::config::{load_config, Endpoint};
use miden_node_utils::config::{load_config, Endpoint, Protocol};

use super::NodeConfig;
use crate::{
Expand All @@ -93,10 +93,10 @@ mod tests {
verify_tx_proofs = true
[rpc]
endpoint = { host = "127.0.0.1", port = 8080 }
endpoint = { host = "127.0.0.1", port = 8080, protocol = "Http" }
[store]
endpoint = { host = "127.0.0.1", port = 8080 }
endpoint = { host = "127.0.0.1", port = 8080, protocol = "Https" }
database_filepath = "local.sqlite3"
genesis_filepath = "genesis.dat"
blockstore_dir = "blocks"
Expand All @@ -112,19 +112,22 @@ mod tests {
endpoint: Endpoint {
host: "127.0.0.1".to_string(),
port: 8080,
protocol: Protocol::default()
},
verify_tx_proofs: true
},
rpc: NormalizedRpcConfig {
endpoint: Endpoint {
host: "127.0.0.1".to_string(),
port: 8080,
protocol: Protocol::Http
},
},
store: StoreConfig {
endpoint: Endpoint {
host: "127.0.0.1".to_string(),
port: 8080,
protocol: Protocol::Https
},
database_filepath: "local.sqlite3".into(),
genesis_filepath: "genesis.dat".into(),
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{Display, Formatter};

use miden_node_utils::config::{
Endpoint, DEFAULT_BLOCK_PRODUCER_PORT, DEFAULT_NODE_RPC_PORT, DEFAULT_STORE_PORT,
Endpoint, Protocol, DEFAULT_BLOCK_PRODUCER_PORT, DEFAULT_NODE_RPC_PORT, DEFAULT_STORE_PORT,
};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -39,6 +39,7 @@ impl Default for RpcConfig {
endpoint: Endpoint {
host: "0.0.0.0".to_string(),
port: DEFAULT_NODE_RPC_PORT,
protocol: Protocol::default(),
},
store_url: Endpoint::localhost(DEFAULT_STORE_PORT).to_string(),
block_producer_url: Endpoint::localhost(DEFAULT_BLOCK_PRODUCER_PORT).to_string(),
Expand Down
27 changes: 25 additions & 2 deletions crates/utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,31 @@ pub const DEFAULT_BLOCK_PRODUCER_PORT: u16 = 48046;
pub const DEFAULT_STORE_PORT: u16 = 28943;
pub const DEFAULT_FAUCET_SERVER_PORT: u16 = 8080;

#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize, Default)]
pub enum Protocol {
#[default]
Http,
Https,
}
/// The `(host, port)` pair for the server's listening socket.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct Endpoint {
/// Host used by the store.
pub host: String,
/// Port number used by the store.
pub port: u16,
/// Protocol type: http or https.
#[serde(default)]
pub protocol: Protocol,
}

impl Endpoint {
pub fn localhost(port: u16) -> Self {
Endpoint { host: "localhost".to_string(), port }
Endpoint {
host: "localhost".to_string(),
port,
protocol: Protocol::default(),
}
}
}

Expand All @@ -41,7 +54,17 @@ impl ToSocketAddrs for Endpoint {

impl Display for Endpoint {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("http://{}:{}", self.host, self.port))
let Endpoint { protocol, host, port } = self;
f.write_fmt(format_args!("{protocol}://{host}:{port}"))
}
}

impl Display for Protocol {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Protocol::Http => f.write_str("http"),
Protocol::Https => f.write_str("https"),
}
}
}

Expand Down

0 comments on commit 54095db

Please sign in to comment.