2021-01-08 01:04:48 +00:00
|
|
|
pub mod seed;
|
|
|
|
|
2021-01-07 23:41:25 +00:00
|
|
|
use crate::bitcoin::Timelock;
|
2020-12-01 23:00:00 +00:00
|
|
|
use conquer_once::Lazy;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct Config {
|
|
|
|
pub bob_time_to_act: Duration,
|
|
|
|
pub bitcoin_finality_confirmations: u32,
|
|
|
|
pub bitcoin_avg_block_time: Duration,
|
2021-01-05 06:09:55 +00:00
|
|
|
pub monero_finality_confirmations: u32,
|
2020-12-23 05:04:06 +00:00
|
|
|
pub bitcoin_cancel_timelock: Timelock,
|
|
|
|
pub bitcoin_punish_timelock: Timelock,
|
2021-01-07 23:41:25 +00:00
|
|
|
pub bitcoin_network: bitcoin::Network,
|
|
|
|
pub monero_network: monero::Network,
|
2020-12-01 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 06:03:52 +00:00
|
|
|
pub trait GetConfig {
|
|
|
|
fn get_config() -> Config;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct Mainnet;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct Testnet;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
pub struct Regtest;
|
|
|
|
|
|
|
|
impl GetConfig for Mainnet {
|
|
|
|
fn get_config() -> Config {
|
|
|
|
Config {
|
2020-12-01 23:00:00 +00:00
|
|
|
bob_time_to_act: *mainnet::BOB_TIME_TO_ACT,
|
|
|
|
bitcoin_finality_confirmations: mainnet::BITCOIN_FINALITY_CONFIRMATIONS,
|
|
|
|
bitcoin_avg_block_time: *mainnet::BITCOIN_AVG_BLOCK_TIME,
|
2021-01-05 06:09:55 +00:00
|
|
|
monero_finality_confirmations: mainnet::MONERO_FINALITY_CONFIRMATIONS,
|
2020-12-22 04:47:09 +00:00
|
|
|
bitcoin_cancel_timelock: mainnet::BITCOIN_CANCEL_TIMELOCK,
|
2020-12-10 03:43:17 +00:00
|
|
|
bitcoin_punish_timelock: mainnet::BITCOIN_PUNISH_TIMELOCK,
|
2021-01-07 23:41:25 +00:00
|
|
|
bitcoin_network: bitcoin::Network::Bitcoin,
|
|
|
|
monero_network: monero::Network::Mainnet,
|
2021-01-04 09:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-27 06:03:52 +00:00
|
|
|
}
|
2021-01-04 09:29:11 +00:00
|
|
|
|
2021-01-27 06:03:52 +00:00
|
|
|
impl GetConfig for Testnet {
|
|
|
|
fn get_config() -> Config {
|
|
|
|
Config {
|
2021-01-05 00:26:00 +00:00
|
|
|
bob_time_to_act: *testnet::BOB_TIME_TO_ACT,
|
|
|
|
bitcoin_finality_confirmations: testnet::BITCOIN_FINALITY_CONFIRMATIONS,
|
|
|
|
bitcoin_avg_block_time: *testnet::BITCOIN_AVG_BLOCK_TIME,
|
2021-01-05 06:09:55 +00:00
|
|
|
monero_finality_confirmations: testnet::MONERO_FINALITY_CONFIRMATIONS,
|
2021-01-05 00:26:00 +00:00
|
|
|
bitcoin_cancel_timelock: testnet::BITCOIN_CANCEL_TIMELOCK,
|
|
|
|
bitcoin_punish_timelock: testnet::BITCOIN_PUNISH_TIMELOCK,
|
2021-01-07 23:41:25 +00:00
|
|
|
bitcoin_network: bitcoin::Network::Testnet,
|
|
|
|
monero_network: monero::Network::Stagenet,
|
2020-12-01 23:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-27 06:03:52 +00:00
|
|
|
}
|
2020-12-01 23:00:00 +00:00
|
|
|
|
2021-01-27 06:03:52 +00:00
|
|
|
impl GetConfig for Regtest {
|
|
|
|
fn get_config() -> Config {
|
|
|
|
Config {
|
2020-12-01 23:00:00 +00:00
|
|
|
bob_time_to_act: *regtest::BOB_TIME_TO_ACT,
|
|
|
|
bitcoin_finality_confirmations: regtest::BITCOIN_FINALITY_CONFIRMATIONS,
|
|
|
|
bitcoin_avg_block_time: *regtest::BITCOIN_AVG_BLOCK_TIME,
|
2021-01-05 06:09:55 +00:00
|
|
|
monero_finality_confirmations: regtest::MONERO_FINALITY_CONFIRMATIONS,
|
2020-12-22 04:47:09 +00:00
|
|
|
bitcoin_cancel_timelock: regtest::BITCOIN_CANCEL_TIMELOCK,
|
2020-12-10 03:43:17 +00:00
|
|
|
bitcoin_punish_timelock: regtest::BITCOIN_PUNISH_TIMELOCK,
|
2021-01-07 23:41:25 +00:00
|
|
|
bitcoin_network: bitcoin::Network::Regtest,
|
|
|
|
monero_network: monero::Network::default(),
|
2020-12-01 23:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod mainnet {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
// For each step, we are giving Bob 10 minutes to act.
|
|
|
|
pub static BOB_TIME_TO_ACT: Lazy<Duration> = Lazy::new(|| Duration::from_secs(10 * 60));
|
|
|
|
|
|
|
|
pub static BITCOIN_FINALITY_CONFIRMATIONS: u32 = 3;
|
|
|
|
|
|
|
|
pub static BITCOIN_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(10 * 60));
|
2020-12-02 01:36:47 +00:00
|
|
|
|
2020-12-09 03:45:09 +00:00
|
|
|
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 15;
|
2020-12-07 02:43:23 +00:00
|
|
|
|
2020-12-10 03:43:17 +00:00
|
|
|
// Set to 12 hours, arbitrary value to be reviewed properly
|
2020-12-23 05:04:06 +00:00
|
|
|
pub static BITCOIN_CANCEL_TIMELOCK: Timelock = Timelock::new(72);
|
|
|
|
pub static BITCOIN_PUNISH_TIMELOCK: Timelock = Timelock::new(72);
|
2020-12-01 23:00:00 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 00:26:00 +00:00
|
|
|
mod testnet {
|
|
|
|
use super::*;
|
|
|
|
|
2021-01-07 00:46:58 +00:00
|
|
|
pub static BOB_TIME_TO_ACT: Lazy<Duration> = Lazy::new(|| Duration::from_secs(60 * 60));
|
2021-01-05 00:26:00 +00:00
|
|
|
|
|
|
|
// This does not reflect recommended values for mainnet!
|
|
|
|
pub static BITCOIN_FINALITY_CONFIRMATIONS: u32 = 1;
|
|
|
|
|
|
|
|
pub static BITCOIN_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(5 * 60));
|
|
|
|
|
|
|
|
// This does not reflect recommended values for mainnet!
|
|
|
|
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 5;
|
|
|
|
|
|
|
|
// This does not reflect recommended values for mainnet!
|
2021-01-07 02:19:22 +00:00
|
|
|
pub static BITCOIN_CANCEL_TIMELOCK: Timelock = Timelock::new(12);
|
2021-01-05 00:26:00 +00:00
|
|
|
pub static BITCOIN_PUNISH_TIMELOCK: Timelock = Timelock::new(6);
|
|
|
|
}
|
|
|
|
|
2020-12-01 23:00:00 +00:00
|
|
|
mod regtest {
|
|
|
|
use super::*;
|
|
|
|
|
2020-12-07 02:43:23 +00:00
|
|
|
// In test, we set a shorter time to fail fast
|
2020-12-02 01:36:47 +00:00
|
|
|
pub static BOB_TIME_TO_ACT: Lazy<Duration> = Lazy::new(|| Duration::from_secs(30));
|
2020-12-01 23:00:00 +00:00
|
|
|
|
|
|
|
pub static BITCOIN_FINALITY_CONFIRMATIONS: u32 = 1;
|
|
|
|
|
2020-12-04 01:54:48 +00:00
|
|
|
pub static BITCOIN_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(5));
|
2020-12-02 01:36:47 +00:00
|
|
|
|
2020-12-07 02:43:23 +00:00
|
|
|
pub static MONERO_FINALITY_CONFIRMATIONS: u32 = 1;
|
|
|
|
|
2021-01-25 01:54:33 +00:00
|
|
|
pub static BITCOIN_CANCEL_TIMELOCK: Timelock = Timelock::new(100);
|
2020-12-10 03:43:17 +00:00
|
|
|
|
2020-12-23 05:04:06 +00:00
|
|
|
pub static BITCOIN_PUNISH_TIMELOCK: Timelock = Timelock::new(50);
|
2020-12-01 23:00:00 +00:00
|
|
|
}
|