Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config: expose swap finality parameters #800

Merged
merged 19 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 arbitraing 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 add in theory 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