mirror of
https://github.com/mimblewimble/mwixnet.git
synced 2025-01-21 03:21:09 +03:00
Resolve socket addresses from config file
This commit is contained in:
parent
ef3dd40b2a
commit
2bdf1256df
3 changed files with 20 additions and 14 deletions
|
@ -30,11 +30,11 @@ pub struct ServerConfig {
|
||||||
/// socket address the server listener should bind to
|
/// socket address the server listener should bind to
|
||||||
pub addr: SocketAddr,
|
pub addr: SocketAddr,
|
||||||
/// foreign api address of the grin node
|
/// foreign api address of the grin node
|
||||||
pub grin_node_url: SocketAddr,
|
pub grin_node_url: String,
|
||||||
/// path to file containing api secret for the grin node
|
/// path to file containing api secret for the grin node
|
||||||
pub grin_node_secret_path: Option<String>,
|
pub grin_node_secret_path: Option<String>,
|
||||||
/// owner api address of the grin wallet
|
/// owner api address of the grin wallet
|
||||||
pub wallet_owner_url: SocketAddr,
|
pub wallet_owner_url: String,
|
||||||
/// path to file containing secret for the grin wallet's owner api
|
/// path to file containing secret for the grin wallet's owner api
|
||||||
pub wallet_owner_secret_path: Option<String>,
|
pub wallet_owner_secret_path: Option<String>,
|
||||||
/// public key of the previous mix/swap server (e.g. N_1 if this is N_2)
|
/// public key of the previous mix/swap server (e.g. N_1 if this is N_2)
|
||||||
|
@ -180,9 +180,9 @@ struct RawConfig {
|
||||||
nonce: String,
|
nonce: String,
|
||||||
interval_s: u32,
|
interval_s: u32,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
grin_node_url: SocketAddr,
|
grin_node_url: String,
|
||||||
grin_node_secret_path: Option<String>,
|
grin_node_secret_path: Option<String>,
|
||||||
wallet_owner_url: SocketAddr,
|
wallet_owner_url: String,
|
||||||
wallet_owner_secret_path: Option<String>,
|
wallet_owner_secret_path: Option<String>,
|
||||||
#[serde(with = "grin_onion::crypto::dalek::option_dalek_pubkey_serde", default)]
|
#[serde(with = "grin_onion::crypto::dalek::option_dalek_pubkey_serde", default)]
|
||||||
prev_server: Option<DalekPublicKey>,
|
prev_server: Option<DalekPublicKey>,
|
||||||
|
@ -204,9 +204,9 @@ pub fn write_config(
|
||||||
nonce: encrypted.nonce,
|
nonce: encrypted.nonce,
|
||||||
interval_s: server_config.interval_s,
|
interval_s: server_config.interval_s,
|
||||||
addr: server_config.addr,
|
addr: server_config.addr,
|
||||||
grin_node_url: server_config.grin_node_url,
|
grin_node_url: server_config.grin_node_url.clone(),
|
||||||
grin_node_secret_path: server_config.grin_node_secret_path.clone(),
|
grin_node_secret_path: server_config.grin_node_secret_path.clone(),
|
||||||
wallet_owner_url: server_config.wallet_owner_url,
|
wallet_owner_url: server_config.wallet_owner_url.clone(),
|
||||||
wallet_owner_secret_path: server_config.wallet_owner_secret_path.clone(),
|
wallet_owner_secret_path: server_config.wallet_owner_secret_path.clone(),
|
||||||
prev_server: server_config.prev_server.clone(),
|
prev_server: server_config.prev_server.clone(),
|
||||||
next_server: server_config.next_server.clone(),
|
next_server: server_config.next_server.clone(),
|
||||||
|
@ -268,16 +268,16 @@ pub fn wallet_owner_secret_path(chain_type: &ChainTypes) -> PathBuf {
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grin_node_url(chain_type: &ChainTypes) -> SocketAddr {
|
pub fn grin_node_url(chain_type: &ChainTypes) -> String {
|
||||||
if *chain_type == ChainTypes::Testnet {
|
if *chain_type == ChainTypes::Testnet {
|
||||||
"127.0.0.1:13413".parse().unwrap()
|
"127.0.0.1:13413".into()
|
||||||
} else {
|
} else {
|
||||||
"127.0.0.1:3413".parse().unwrap()
|
"127.0.0.1:3413".into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wallet_owner_url(_chain_type: &ChainTypes) -> SocketAddr {
|
pub fn wallet_owner_url(_chain_type: &ChainTypes) -> String {
|
||||||
"127.0.0.1:3420".parse().unwrap()
|
"127.0.0.1:3420".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
use std::net::ToSocketAddrs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
@ -142,9 +143,11 @@ pub struct HttpGrinNode {
|
||||||
const ENDPOINT: &str = "/v2/foreign";
|
const ENDPOINT: &str = "/v2/foreign";
|
||||||
|
|
||||||
impl HttpGrinNode {
|
impl HttpGrinNode {
|
||||||
pub fn new(node_url: &SocketAddr, node_api_secret: &Option<String>) -> HttpGrinNode {
|
pub fn new(node_url: &str, node_api_secret: &Option<String>) -> HttpGrinNode {
|
||||||
|
let mut addrs_iter = node_url.to_socket_addrs().unwrap();
|
||||||
|
let node_url = addrs_iter.next().unwrap();
|
||||||
HttpGrinNode {
|
HttpGrinNode {
|
||||||
node_url: node_url.to_owned(),
|
node_url,
|
||||||
node_api_secret: node_api_secret.to_owned(),
|
node_api_secret: node_api_secret.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
use std::net::ToSocketAddrs;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use grin_core::core::Output;
|
use grin_core::core::Output;
|
||||||
|
@ -54,11 +55,13 @@ pub struct ECDHPubkey {
|
||||||
impl HttpWallet {
|
impl HttpWallet {
|
||||||
/// Calls the 'open_wallet' using the RPC API.
|
/// Calls the 'open_wallet' using the RPC API.
|
||||||
pub async fn async_open_wallet(
|
pub async fn async_open_wallet(
|
||||||
wallet_owner_url: &SocketAddr,
|
wallet_owner_url: &str,
|
||||||
wallet_owner_secret: &Option<String>,
|
wallet_owner_secret: &Option<String>,
|
||||||
wallet_pass: &ZeroingString,
|
wallet_pass: &ZeroingString,
|
||||||
) -> Result<HttpWallet, WalletError> {
|
) -> Result<HttpWallet, WalletError> {
|
||||||
info!("Opening wallet at {}", wallet_owner_url);
|
info!("Opening wallet at {}", wallet_owner_url);
|
||||||
|
let mut addrs_iter = wallet_owner_url.to_socket_addrs().unwrap();
|
||||||
|
let wallet_owner_url = addrs_iter.next().unwrap();
|
||||||
let shared_key =
|
let shared_key =
|
||||||
HttpWallet::async_init_secure_api(&wallet_owner_url, &wallet_owner_secret).await?;
|
HttpWallet::async_init_secure_api(&wallet_owner_url, &wallet_owner_secret).await?;
|
||||||
let open_wallet_params = json!({
|
let open_wallet_params = json!({
|
||||||
|
|
Loading…
Reference in a new issue