From 2967b24d2d1fb6067edfcc5cafcf859a220d6153 Mon Sep 17 00:00:00 2001 From: Nathan Iheanyi Date: Sat, 28 Mar 2026 21:40:24 +0100 Subject: [PATCH] feat: implement Network::passphrase() for Stellar network passphrases --- crates/core/src/network/config.rs | 2 +- crates/core/src/types/config.rs | 58 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/crates/core/src/network/config.rs b/crates/core/src/network/config.rs index 1203fc4e..e644cfc2 100644 --- a/crates/core/src/network/config.rs +++ b/crates/core/src/network/config.rs @@ -3,7 +3,7 @@ //! Manages RPC endpoints, archive URLs, network passphrases for //! mainnet/testnet/futurenet/standalone networks. -use crate::types::config::{Network, NetworkConfig}; +use crate::types::config::NetworkConfig; /// Resolve a network name string to a `NetworkConfig`. /// diff --git a/crates/core/src/types/config.rs b/crates/core/src/types/config.rs index 08635185..ae9a2b12 100644 --- a/crates/core/src/types/config.rs +++ b/crates/core/src/types/config.rs @@ -19,6 +19,64 @@ impl Default for Network { } } +impl Network { + /// Return the canonical network passphrase for this network. + /// + /// These strings are used when signing and verifying Stellar transactions — + /// they must match exactly what the network nodes expect. + pub fn passphrase(&self) -> &'static str { + match self { + Self::Mainnet => "Public Global Stellar Network ; September 2015", + Self::Testnet => "Test SDF Network ; September 2015", + Self::Futurenet => "Test SDF Future Network ; October 2022", + Self::Standalone => "Standalone Network ; February 2017", + Self::Custom => "", + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn passphrase_mainnet() { + assert_eq!( + Network::Mainnet.passphrase(), + "Public Global Stellar Network ; September 2015" + ); + } + + #[test] + fn passphrase_testnet() { + assert_eq!( + Network::Testnet.passphrase(), + "Test SDF Network ; September 2015" + ); + } + + #[test] + fn passphrase_futurenet() { + assert_eq!( + Network::Futurenet.passphrase(), + "Test SDF Future Network ; October 2022" + ); + } + + #[test] + fn passphrase_standalone() { + assert_eq!( + Network::Standalone.passphrase(), + "Standalone Network ; February 2017" + ); + } + + #[test] + fn passphrase_custom_is_empty() { + assert_eq!(Network::Custom.passphrase(), ""); + } +} + /// Configuration for connecting to a Stellar network. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct NetworkConfig {