Skip to content

Commit

Permalink
feat: add config for swap parameters such as finality arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
h4sh3d committed Dec 2, 2022
1 parent 9238401 commit ba4d741
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions farcasterd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ bitcoin_cookie_path = "~/.bitcoin/testnet3/.cookie"
# the wallet should have spendable funds
monero_rpc_wallet = "http://localhost:38084"

[swap.bitcoin]
race_threshold = 3
confirmations_required = 1

[swap.monero]
confirmations_required = 1

# Defines grpc options
[grpc]
# Set this to true to enable the grpc daemon
Expand Down
28 changes: 28 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub const GRPC_BIND_IP_ADDRESS: &str = "127.0.0.1";
pub struct Config {
/// Farcasterd configuration
pub farcasterd: Option<FarcasterdConfig>,
/// Swap configuration, applies to all swaps launched by this node
pub swap: Option<SwapConfig>,
/// Sets the grpc server port, if none is given, no grpc server is run
pub grpc: Option<GrpcConfig>,
/// Syncer configuration
Expand Down Expand Up @@ -107,6 +109,7 @@ impl Default for Config {
fn default() -> Self {
Config {
farcasterd: None,
swap: None,
grpc: None,
syncers: Some(SyncersConfig::default()),
}
Expand All @@ -120,6 +123,31 @@ pub struct FarcasterdConfig {
pub auto_funding: Option<AutoFundingConfig>,
}

#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(crate = "serde_crate")]
pub struct SwapConfig {
/// Swap parameters for the Bitcoin blockchain
pub bitcoin: BitcoinConfig,
/// Swap parameters for the Monero blockchain
pub monero: MoneroConfig,
}

#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(crate = "serde_crate")]
pub struct BitcoinConfig {
/// Avoid broadcasting a transaction if a race can happen in # blocks
pub race_threshold: u8,
/// Number of confirmations required to consider a transaction final
pub confirmations_required: u8,
}

#[derive(Deserialize, Serialize, Debug, Clone, Default)]
#[serde(crate = "serde_crate")]
pub struct MoneroConfig {
/// Number of confirmations required to consider a transaction final
pub confirmations_required: u8,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(crate = "serde_crate")]
pub struct GrpcConfig {
Expand Down
4 changes: 2 additions & 2 deletions src/swapd/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ pub fn run(
SwapRole::Alice => State::Alice(AliceState::StartA { local_trade_role }),
SwapRole::Bob => State::Bob(BobState::StartB { local_trade_role }),
};
let sweep_monero_thr = 10;
info!(
"{}: {}",
"Starting swap".to_string().bright_green_bold(),
Expand All @@ -105,7 +104,8 @@ pub fn run(
btc_finality_thr: 1,
race_thr: 3,
xmr_finality_thr: 1,
sweep_monero_thr,
// this is a constant
sweep_monero_thr: 10,
};

temporal_safety.valid_params()?;
Expand Down

0 comments on commit ba4d741

Please sign in to comment.