Introduce own de-/serializable monero::Network

This commit is contained in:
Daniel Karzel 2021-05-11 18:03:33 +10:00
parent 69cf12620d
commit 9ac5b635d7
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
4 changed files with 32 additions and 4 deletions

View File

@ -151,7 +151,7 @@ async fn main() -> Result<()> {
let seed = Seed::from_file_or_generate(data_dir.as_path())
.context("Failed to read in seed file")?;
if monero_receive_address.network != env_config.monero_network {
if monero_receive_address.network != env_config.monero_network.into() {
bail!("The given monero address is on network {:?}, expected address of network {:?}.", monero_receive_address.network, env_config.monero_network)
}
@ -294,7 +294,7 @@ async fn init_monero_wallet(
let monero_wallet_rpc = monero::WalletRpc::new(data_dir.join("monero")).await?;
let monero_wallet_rpc_process = monero_wallet_rpc
.run(network, monero_daemon_address.as_str())
.run(network.into(), monero_daemon_address.as_str())
.await?;
let monero_wallet = monero::Wallet::open_or_create(

View File

@ -1,4 +1,5 @@
use crate::bitcoin::{CancelTimelock, PunishTimelock};
use crate::monero;
use std::cmp::max;
use std::time::Duration;
use time::NumericalStdDurationShort;

View File

@ -1,7 +1,7 @@
pub mod wallet;
mod wallet_rpc;
pub use ::monero::{Address, Network, PrivateKey, PublicKey};
pub use ::monero::{Address, PrivateKey, PublicKey};
pub use curve25519_dalek::scalar::Scalar;
pub use wallet::Wallet;
pub use wallet_rpc::{WalletRpc, WalletRpcProcess};
@ -19,6 +19,33 @@ use std::str::FromStr;
pub const PICONERO_OFFSET: u64 = 1_000_000_000_000;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Serialize, Deserialize)]
pub enum Network {
Mainnet,
Stagenet,
Testnet,
}
impl From<monero::Network> for Network {
fn from(network: monero::Network) -> Self {
match network {
monero::Network::Mainnet => Self::Mainnet,
monero::Network::Stagenet => Self::Stagenet,
monero::Network::Testnet => Self::Testnet,
}
}
}
impl From<Network> for monero::Network {
fn from(network: Network) -> Self {
match network {
Network::Mainnet => monero::Network::Mainnet,
Network::Stagenet => monero::Network::Stagenet,
Network::Testnet => monero::Network::Testnet,
}
}
}
pub fn private_key_from_secp256k1_scalar(scalar: bitcoin::Scalar) -> PrivateKey {
let mut bytes = scalar.to_bytes();

View File

@ -47,7 +47,7 @@ impl Wallet {
monero::Address::from_str(client.get_address(0).await?.address.as_str())?;
Ok(Self {
inner: Mutex::new(client),
network: env_config.monero_network,
network: env_config.monero_network.into(),
name,
main_address,
sync_interval: env_config.monero_sync_interval(),