Skip to content

Commit

Permalink
Merge pull request #891 from TheCharlatan/rmBoolean
Browse files Browse the repository at this point in the history
Syncer: Remove Boolean type and replace with raw type
  • Loading branch information
TheCharlatan authored Dec 28, 2022
2 parents eb8483d + a95aae3 commit 624bc1b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 71 deletions.
16 changes: 8 additions & 8 deletions src/swapd/swap_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{
swap_key_manager::{HandleBuyProcedureSignatureRes, HandleRefundProcedureSignaturesRes},
syncer_client::{log_tx_created, log_tx_seen},
},
syncerd::{Abort, Boolean, SweepSuccess, Task, TaskTarget, TransactionConfirmations},
syncerd::{Abort, SweepSuccess, Task, TaskTarget, TransactionConfirmations},
Endpoints, Error,
};
use crate::{
Expand Down Expand Up @@ -1355,7 +1355,7 @@ fn try_bob_cancel_final_to_swap_end(
Some(&TxLabel::Refund) => {
let abort_all = Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::False,
respond: false,
});
event.send_sync_service(
runtime.syncer_state.monero_syncer(),
Expand All @@ -1376,7 +1376,7 @@ fn try_bob_cancel_final_to_swap_end(
Some(&TxLabel::Punish) => {
let abort_all = Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::False,
respond: false,
});
event.send_sync_service(
runtime.syncer_state.monero_syncer(),
Expand Down Expand Up @@ -1901,7 +1901,7 @@ fn try_alice_buy_procedure_signature_to_swap_end(
{
let abort_all = Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::False,
respond: false,
});
event.send_sync_service(
runtime.syncer_state.monero_syncer(),
Expand Down Expand Up @@ -1972,7 +1972,7 @@ fn try_alice_canceled_to_alice_refund_or_alice_punish(
{
let abort_all = Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::False,
respond: false,
});
event.send_sync_service(
runtime.syncer_state.monero_syncer(),
Expand Down Expand Up @@ -2080,7 +2080,7 @@ fn try_alice_canceled_to_alice_refund_or_alice_punish(
}
let abort_all = Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::False,
respond: false,
});
event.send_sync_service(
runtime.syncer_state.monero_syncer(),
Expand Down Expand Up @@ -2153,7 +2153,7 @@ fn try_alice_refund_sweeping_to_swap_end(
}
let abort_all = Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::False,
respond: false,
});
event.send_sync_service(
runtime.syncer_state.monero_syncer(),
Expand Down Expand Up @@ -2194,7 +2194,7 @@ fn try_bob_buy_sweeping_to_swap_end(
}
let abort_all = Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::False,
respond: false,
});
event.send_sync_service(
runtime.syncer_state.monero_syncer(),
Expand Down
10 changes: 5 additions & 5 deletions src/swapd/syncer_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
bus::ServiceBus,
service::{Endpoints, LogStyle},
syncerd::{
Abort, AddressAddendum, Boolean, BroadcastTransaction, BtcAddressAddendum, GetTx,
SweepAddress, SweepAddressAddendum, SweepBitcoinAddress, SweepMoneroAddress, TaskTarget,
Abort, AddressAddendum, BroadcastTransaction, BtcAddressAddendum, GetTx, SweepAddress,
SweepAddressAddendum, SweepBitcoinAddress, SweepMoneroAddress, TaskTarget,
TransactionBroadcasted, TxFilter, Txid, WatchAddress, WatchEstimateFee, WatchHeight,
WatchTransaction, XmrAddressAddendum,
},
Expand Down Expand Up @@ -97,7 +97,7 @@ impl SyncerState {
pub fn abort_task(&mut self, id: TaskId) -> Task {
Task::Abort(Abort {
task_target: TaskTarget::TaskId(id),
respond: Boolean::False,
respond: false,
})
}

Expand Down Expand Up @@ -200,7 +200,7 @@ impl SyncerState {
id,
lifetime: self.task_lifetime(Blockchain::Bitcoin),
addendum: AddressAddendum::Bitcoin(addendum),
include_tx: Boolean::True,
include_tx: true,
filter,
});
self.tasks.tasks.insert(id, task.clone());
Expand Down Expand Up @@ -258,7 +258,7 @@ impl SyncerState {
id,
lifetime: self.task_lifetime(Blockchain::Monero),
addendum: AddressAddendum::Monero(addendum),
include_tx: Boolean::False,
include_tx: false,
filter: TxFilter::Incoming,
};
let task = Task::WatchAddress(watch_addr);
Expand Down
8 changes: 2 additions & 6 deletions src/syncerd/bitcoin_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::syncerd::runtime::SyncerdTask;
use crate::syncerd::runtime::Synclet;
use crate::syncerd::syncer_state::{AddressTx, BalanceServiceIdPair, TransactionServiceIdPair};
use crate::syncerd::syncer_state::{GetTxServiceIdPair, SyncerState};
use crate::syncerd::types::{AddressAddendum, Boolean, SweepAddressAddendum, Task};
use crate::syncerd::types::{AddressAddendum, SweepAddressAddendum, Task};
use crate::syncerd::BtcAddressAddendum;
use crate::syncerd::Event;
use crate::syncerd::FeeEstimations;
Expand Down Expand Up @@ -650,12 +650,8 @@ async fn run_syncerd_task_receiver(
},
Task::Abort(task) => {
let mut state_guard = state.lock().await;
let respond = match task.respond {
Boolean::True => true,
Boolean::False => false,
};
state_guard
.abort(task.task_target, syncerd_task.source, respond)
.abort(task.task_target, syncerd_task.source, task.respond)
.await;
drop(state_guard);
}
Expand Down
8 changes: 2 additions & 6 deletions src/syncerd/monero_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::syncerd::runtime::Synclet;
use crate::syncerd::syncer_state::create_set;
use crate::syncerd::syncer_state::AddressTx;
use crate::syncerd::syncer_state::SyncerState;
use crate::syncerd::types::{AddressAddendum, Boolean, SweepAddressAddendum, Task};
use crate::syncerd::types::{AddressAddendum, SweepAddressAddendum, Task};
use crate::syncerd::TaskTarget;
use crate::syncerd::TransactionBroadcasted;
use crate::syncerd::XmrAddressAddendum;
Expand Down Expand Up @@ -485,12 +485,8 @@ async fn run_syncerd_task_receiver(
},
Task::Abort(task) => {
let mut state_guard = state.lock().await;
let respond = match task.respond {
Boolean::True => true,
Boolean::False => false,
};
state_guard
.abort(task.task_target, syncerd_task.source, respond)
.abort(task.task_target, syncerd_task.source, task.respond)
.await;
}
Task::BroadcastTransaction(task) => {
Expand Down
4 changes: 2 additions & 2 deletions src/syncerd/syncer_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,14 @@ async fn syncer_state_addresses() {
id: TaskId(0),
lifetime: 1,
addendum: addendum.clone(),
include_tx: Boolean::False,
include_tx: false,
filter: TxFilter::All,
};
let address_task_two = WatchAddress {
id: TaskId(0),
lifetime: 1,
addendum: addendum.clone(),
include_tx: Boolean::False,
include_tx: false,
filter: TxFilter::All,
};
let source1 = ServiceId::Syncer(Blockchain::Bitcoin, Network::Mainnet);
Expand Down
25 changes: 2 additions & 23 deletions src/syncerd/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub struct SweepBitcoinAddress {
#[display(Debug)]
pub struct Abort {
pub task_target: TaskTarget,
pub respond: Boolean,
pub respond: bool,
}

#[derive(Clone, Debug, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -173,7 +173,7 @@ pub struct WatchAddress {
pub id: TaskId,
pub lifetime: u64,
pub addendum: AddressAddendum,
pub include_tx: Boolean,
pub include_tx: bool,
pub filter: TxFilter,
}

Expand All @@ -190,27 +190,6 @@ pub enum TxFilter {
All,
}

#[derive(Clone, Debug, Display, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
#[display(Debug)]
pub enum Boolean {
True,
False,
}

impl From<Boolean> for bool {
fn from(w: Boolean) -> bool {
match w {
Boolean::True => true,
Boolean::False => false,
}
}
}

#[derive(Clone, Display, Debug, StrictEncode, StrictDecode, Eq, PartialEq, Hash)]
#[cfg_attr(
feature = "serde",
Expand Down
18 changes: 9 additions & 9 deletions tests/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use farcaster_node::syncerd::bitcoin_syncer::BitcoinSyncer;
use farcaster_node::syncerd::opts::Opts;
use farcaster_node::syncerd::runtime::SyncerdTask;
use farcaster_node::syncerd::types::{
Abort, AddressAddendum, Boolean, BroadcastTransaction, BtcAddressAddendum, GetTx, SweepAddress,
Abort, AddressAddendum, BroadcastTransaction, BtcAddressAddendum, GetTx, SweepAddress,
SweepAddressAddendum, Task, WatchAddress, WatchEstimateFee, WatchHeight, WatchTransaction,
};
use farcaster_node::syncerd::{runtime::Synclet, TaskId, TaskTarget};
Expand Down Expand Up @@ -240,7 +240,7 @@ fn bitcoin_syncer_address_test() {
id: TaskId(1),
lifetime: blocks + 1,
addendum: addendum_1,
include_tx: Boolean::True,
include_tx: true,
filter: TxFilter::All,
}),
source: SOURCE1.clone(),
Expand All @@ -256,7 +256,7 @@ fn bitcoin_syncer_address_test() {
id: TaskId(1),
lifetime: blocks + 2,
addendum: addendum_2.clone(),
include_tx: Boolean::True,
include_tx: true,
filter: TxFilter::All,
}),
source: SOURCE1.clone(),
Expand Down Expand Up @@ -318,7 +318,7 @@ fn bitcoin_syncer_address_test() {
id: TaskId(1),
lifetime: blocks + 2,
addendum: addendum_2,
include_tx: Boolean::True,
include_tx: true,
filter: TxFilter::All,
}),
source: SOURCE1.clone(),
Expand All @@ -345,7 +345,7 @@ fn bitcoin_syncer_address_test() {
id: TaskId(i),
lifetime: blocks + 5,
addendum: addendum_4.clone(),
include_tx: Boolean::True,
include_tx: true,
filter: TxFilter::All,
}),
source: SOURCE1.clone(),
Expand Down Expand Up @@ -659,7 +659,7 @@ fn bitcoin_syncer_abort_test() {
let task = SyncerdTask {
task: Task::Abort(Abort {
task_target: TaskTarget::TaskId(TaskId(0)),
respond: Boolean::True,
respond: true,
}),
source: SOURCE1.clone(),
};
Expand All @@ -673,7 +673,7 @@ fn bitcoin_syncer_abort_test() {
let task = SyncerdTask {
task: Task::Abort(Abort {
task_target: TaskTarget::TaskId(TaskId(0)),
respond: Boolean::True,
respond: true,
}),
source: SOURCE1.clone(),
};
Expand Down Expand Up @@ -721,7 +721,7 @@ fn bitcoin_syncer_abort_test() {
let task = SyncerdTask {
task: Task::Abort(Abort {
task_target: TaskTarget::AllTasks,
respond: Boolean::True,
respond: true,
}),
source: SOURCE1.clone(),
};
Expand All @@ -735,7 +735,7 @@ fn bitcoin_syncer_abort_test() {
let task = SyncerdTask {
task: Task::Abort(Abort {
task_target: TaskTarget::TaskId(TaskId(0)),
respond: Boolean::True,
respond: true,
}),
source: SOURCE1.clone(),
};
Expand Down
Loading

0 comments on commit 624bc1b

Please sign in to comment.