From 54095db301390347efab9d4f9412a55656783d12 Mon Sep 17 00:00:00 2001 From: Varun Doshi <61531351+varun-doshi@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:54:46 +0530 Subject: [PATCH] feat: https support in endpoint config (#556) Previously only http was supported. --- CHANGELOG.md | 1 + bin/node/src/config.rs | 9 ++++++--- crates/rpc/src/config.rs | 3 ++- crates/utils/src/config.rs | 27 +++++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed4c12a1b..ccb6505c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Enhancements - Added `GetAccountProofs` endpoint (#506). +- Support Https in endpoint configuration (#556). ### Changes diff --git a/bin/node/src/config.rs b/bin/node/src/config.rs index 173496764..8e44ad064 100644 --- a/bin/node/src/config.rs +++ b/bin/node/src/config.rs @@ -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::{ @@ -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" @@ -112,6 +112,7 @@ mod tests { endpoint: Endpoint { host: "127.0.0.1".to_string(), port: 8080, + protocol: Protocol::default() }, verify_tx_proofs: true }, @@ -119,12 +120,14 @@ mod tests { 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(), diff --git a/crates/rpc/src/config.rs b/crates/rpc/src/config.rs index 7cd6e6448..07dac0778 100644 --- a/crates/rpc/src/config.rs +++ b/crates/rpc/src/config.rs @@ -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}; @@ -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(), diff --git a/crates/utils/src/config.rs b/crates/utils/src/config.rs index c350fd36b..5c70315df 100644 --- a/crates/utils/src/config.rs +++ b/crates/utils/src/config.rs @@ -17,6 +17,12 @@ 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 { @@ -24,11 +30,18 @@ pub struct Endpoint { 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(), + } } } @@ -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"), + } } }