Skip to content

Commit

Permalink
Merge pull request #800 from h4sh3d/feat/config-swap-finality
Browse files Browse the repository at this point in the history
Config: expose swap finality parameters
  • Loading branch information
Lederstrumpf authored Dec 13, 2022
2 parents 2fe9a32 + fed4f7a commit 9499015
Show file tree
Hide file tree
Showing 14 changed files with 508 additions and 109 deletions.
18 changes: 18 additions & 0 deletions farcasterd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ bitcoin_cookie_path = "~/.bitcoin/testnet3/.cookie"
# the wallet should have spendable funds
monero_rpc_wallet = "http://localhost:38084"

# Swap parameter for the Bitcoin blockchain
[swap.bitcoin.testnet]
# Avoid broadcasting a transaction if a race can happen in # blocks
#
# E.g. if the safety is set to 3 and the the cancel transaction becomes
# broadcastable in 4 blocks we are safe and we do publish buy, if it becomes
# broadcastable in 3 blocks or less we do not publish the buy as the safety is
# not respected.
safety = 3
# Number of confirmations required to consider a transaction final. Must be
# smaller than safety.
finality = 1

# Swap parameter for the Monero blockchain
[swap.monero.testnet]
# Number of confirmations required to consider a transaction final
finality = 1

# Defines grpc options
[grpc]
# Set this to true to enable the grpc daemon
Expand Down
17 changes: 1 addition & 16 deletions src/bin/swapd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,8 @@ fn main() {
debug!("MSG RPC socket {}", &service_config.msg_endpoint);
debug!("CTL RPC socket {}", &service_config.ctl_endpoint);

/*
use self::internal::ResultExt;
let (config_from_file, _) =
internal::Config::custom_args_and_optional_files(std::iter::empty::<
&str,
>())
.unwrap_or_exit();
*/

debug!("Starting runtime ...");
swapd::run(
service_config,
opts.swap_id,
opts.public_offer,
opts.trade_role,
)
.expect("Error running swapd runtime");
swapd::run(service_config, opts).expect("Error running swapd runtime");

unreachable!()
}
113 changes: 113 additions & 0 deletions src/chains.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//! This module defines the currently supported blockchains in the node for the arbitrating and
//! the accordant roles. The types defined here are convertible with core `Blockchain` type.
use std::convert::TryFrom;
use std::str::FromStr;

use farcaster_core::{blockchain::Blockchain, consensus};
use strict_encoding::{StrictDecode, StrictEncode};

/// A list of supported arbitrating blockchain
#[derive(
Debug,
Clone,
Copy,
Hash,
PartialEq,
Eq,
Parser,
Display,
Serialize,
Deserialize,
StrictEncode,
StrictDecode,
)]
#[serde(crate = "serde_crate")]
#[display(Debug)]
pub enum ArbitratingBlockchain {
/// The Bitcoin (BTC) blockchain.
Bitcoin,
}

impl FromStr for ArbitratingBlockchain {
type Err = consensus::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Bitcoin" | "bitcoin" | "btc" | "BTC" => Ok(ArbitratingBlockchain::Bitcoin),
_ => Err(consensus::Error::UnknownType),
}
}
}

impl Into<Blockchain> for ArbitratingBlockchain {
fn into(self) -> Blockchain {
match self {
ArbitratingBlockchain::Bitcoin => Blockchain::Bitcoin,
}
}
}

impl TryFrom<Blockchain> for ArbitratingBlockchain {
type Error = consensus::Error;

fn try_from(blockchain: Blockchain) -> Result<Self, Self::Error> {
match blockchain {
Blockchain::Bitcoin => Ok(ArbitratingBlockchain::Bitcoin),
_ => Err(consensus::Error::TypeMismatch),
}
}
}

/// A list of supported accordant blockchain
#[derive(
Debug,
Clone,
Copy,
Hash,
PartialEq,
Eq,
Parser,
Display,
Serialize,
Deserialize,
StrictEncode,
StrictDecode,
)]
#[serde(crate = "serde_crate")]
#[display(Debug)]
pub enum AccordantBlockchain {
/// The Monero (XMR) blockchain.
Monero,
// NOTE: we could in theory add Bitcoin here, but currently the node does not support it
}

impl FromStr for AccordantBlockchain {
type Err = consensus::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Monero" | "monero" | "xmr" | "XMR" => Ok(AccordantBlockchain::Monero),
_ => Err(consensus::Error::UnknownType),
}
}
}

impl Into<Blockchain> for AccordantBlockchain {
fn into(self) -> Blockchain {
match self {
AccordantBlockchain::Monero => Blockchain::Monero,
}
}
}

impl TryFrom<Blockchain> for AccordantBlockchain {
type Error = consensus::Error;

fn try_from(blockchain: Blockchain) -> Result<Self, Self::Error> {
match blockchain {
Blockchain::Monero => Ok(AccordantBlockchain::Monero),
_ => Err(consensus::Error::TypeMismatch),
}
}
}
Loading

0 comments on commit 9499015

Please sign in to comment.