Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit 630a99f

Browse files
workflowTobin Harding
andcommitted
Pass HtlcEvents to create_swap directly
This is part of an ongoing refactor towards removing the LedgerEventFutures indirection. Co-authored-by: Tobin Harding <tobin.harding@tenx.tech>
1 parent d290572 commit 630a99f

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

cnd/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub mod timestamp;
3737

3838
use crate::swap_protocols::{
3939
asset::Asset,
40-
rfc003::{events::LedgerEvents, Ledger},
40+
rfc003::{events::HtlcEvents, Ledger},
4141
};
4242
use anyhow::Context;
4343
use directories::ProjectDirs;
@@ -69,5 +69,5 @@ pub fn data_dir() -> Option<PathBuf> {
6969
}
7070

7171
pub trait CreateLedgerEvents<L: Ledger, A: Asset> {
72-
fn create_ledger_events(&self) -> Box<dyn LedgerEvents<L, A>>;
72+
fn create_ledger_events(&self) -> Box<dyn HtlcEvents<L, A>>;
7373
}

cnd/src/swap_protocols/facade.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
ledger::{Bitcoin, Ethereum},
1313
rfc003::{
1414
self,
15-
events::{HtlcEvents, LedgerEventFutures, LedgerEvents},
15+
events::HtlcEvents,
1616
state_machine::SwapStates,
1717
state_store::{self, InMemoryStateStore, StateStore},
1818
ActorState, Ledger,
@@ -181,10 +181,8 @@ impl<S> CreateLedgerEvents<Bitcoin, Amount> for Facade<S>
181181
where
182182
S: Send + Sync + 'static,
183183
{
184-
fn create_ledger_events(&self) -> Box<dyn LedgerEvents<Bitcoin, Amount>> {
185-
Box::new(LedgerEventFutures::new(Box::new(
186-
self.bitcoin_connector.clone(),
187-
)))
184+
fn create_ledger_events(&self) -> Box<dyn HtlcEvents<Bitcoin, Amount>> {
185+
Box::new(self.bitcoin_connector.clone())
188186
}
189187
}
190188

@@ -194,10 +192,8 @@ where
194192
A: Asset + Send + Sync + 'static,
195193
Web3Connector: HtlcEvents<Ethereum, A>,
196194
{
197-
fn create_ledger_events(&self) -> Box<dyn LedgerEvents<Ethereum, A>> {
198-
Box::new(LedgerEventFutures::new(Box::new(
199-
self.ethereum_connector.clone(),
200-
)))
195+
fn create_ledger_events(&self) -> Box<dyn HtlcEvents<Ethereum, A>> {
196+
Box::new(self.ethereum_connector.clone())
201197
}
202198
}
203199

cnd/src/swap_protocols/rfc003/state_machine.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
asset::Asset,
77
rfc003::{
88
self,
9-
events::{self, Deployed, Funded, LedgerEvents, Redeemed, Refunded},
9+
events::{self, Deployed, Funded, HtlcEvents, LedgerEventFutures, Redeemed, Refunded},
1010
ledger::Ledger,
1111
Accept, Request, SaveState, SecretHash,
1212
},
@@ -272,14 +272,16 @@ pub enum Swap<AL: Ledger, BL: Ledger, AA: Asset, BA: Asset> {
272272
}
273273

274274
pub fn create_swap<AL: Ledger, BL: Ledger, AA: Asset, BA: Asset>(
275-
alpha_ledger_events: Box<dyn LedgerEvents<AL, AA>>,
276-
beta_ledger_events: Box<dyn LedgerEvents<BL, BA>>,
275+
alpha_htlc_events: Box<dyn HtlcEvents<AL, AA>>,
276+
beta_htlc_events: Box<dyn HtlcEvents<BL, BA>>,
277277
request: Request<AL, BL, AA, BA>,
278278
accept: Accept<AL, BL>,
279279
) -> (
280280
impl Future<Item = (), Error = ()> + Send + 'static,
281281
impl Stream<Item = SwapStates<AL, BL, AA, BA>, Error = ()> + Send + 'static,
282282
) {
283+
let alpha_ledger_events = Box::new(LedgerEventFutures::new(alpha_htlc_events));
284+
let beta_ledger_events = Box::new(LedgerEventFutures::new(beta_htlc_events));
283285
let id = request.swap_id;
284286

285287
let (sender, receiver) = mpsc::unbounded();

0 commit comments

Comments
 (0)