From 5ab083703ef6831410c3ffdc778913c0cac30b63 Mon Sep 17 00:00:00 2001 From: chris-belcher Date: Tue, 11 Jan 2022 15:41:57 +0000 Subject: [PATCH] Use an enum not a string as param to run_maker() --- src/lib.rs | 13 +++++-------- src/main.rs | 7 ++++++- tests/test_standard_coinswap.rs | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index de8feaef..a836eddb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,8 +19,10 @@ use wallet_sync::{Wallet, WalletSyncAddressAmount}; pub mod contracts; use contracts::{read_locktime_from_contract, SwapCoin}; -pub mod error; pub mod maker_protocol; +use maker_protocol::MakerBehavior; + +pub mod error; pub mod messages; pub mod offerbook_sync; pub mod taker_protocol; @@ -315,7 +317,7 @@ pub fn run_maker( wallet_file_name: &PathBuf, sync_amount: WalletSyncAddressAmount, port: u16, - special_behavior: Option, + maker_behavior: MakerBehavior, kill_flag: Option>>, ) { let rpc = match get_bitcoin_rpc() { @@ -340,12 +342,7 @@ pub fn run_maker( port, rpc_ping_interval: 30, watchtower_ping_interval: 300, - maker_behavior: match special_behavior.unwrap_or(String::new()).as_str() { - "closeonsignsenderscontracttx" => { - maker_protocol::MakerBehavior::CloseOnSignSendersContractTx - } - _ => maker_protocol::MakerBehavior::Normal, - }, + maker_behavior, kill_flag: if kill_flag.is_none() { Arc::new(RwLock::new(false)) } else { diff --git a/src/main.rs b/src/main.rs index 421ed3dc..f2550309 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use structopt::StructOpt; use teleport; +use teleport::maker_protocol::MakerBehavior; use teleport::wallet_sync::WalletSyncAddressAmount; use teleport::watchtower_client::ContractInfo; @@ -95,11 +96,15 @@ fn main() -> Result<(), Box> { port, special_behavior, } => { + let maker_special_behavior = match special_behavior.unwrap_or(String::new()).as_str() { + "closeonsignsenderscontracttx" => MakerBehavior::CloseOnSignSendersContractTx, + _ => MakerBehavior::Normal, + }; teleport::run_maker( &args.wallet_file_name, WalletSyncAddressAmount::Normal, port.unwrap_or(6102), - special_behavior, + maker_special_behavior, None, ); } diff --git a/tests/test_standard_coinswap.rs b/tests/test_standard_coinswap.rs index 24bb3038..b0907590 100644 --- a/tests/test_standard_coinswap.rs +++ b/tests/test_standard_coinswap.rs @@ -2,6 +2,7 @@ use bitcoin::util::amount::Amount; use bitcoin_wallet::mnemonic; use bitcoincore_rpc::{Client, RpcApi}; +use teleport::maker_protocol::MakerBehavior; use teleport::wallet_sync::{Wallet, WalletSyncAddressAmount}; use serde_json::Value; @@ -151,7 +152,7 @@ async fn test_standard_coinswap() { &PathBuf::from_str(MAKER1).unwrap(), WalletSyncAddressAmount::Testing, 6102, - None, + MakerBehavior::Normal, Some(kill_flag_maker1), ); }); @@ -162,7 +163,7 @@ async fn test_standard_coinswap() { &PathBuf::from_str(MAKER2).unwrap(), WalletSyncAddressAmount::Testing, 16102, - None, + MakerBehavior::Normal, Some(kill_flag_maker2), ); });