|
|
@@ -1,5 +1,9 @@
|
|
|
use crate::ethereum::swap_creator::Swap; // TODO: shouldn't depend on this
|
|
|
-use crate::{error::Error, ethereum::swap_creator::SwapCreator, protocol::initiator::Event};
|
|
|
+use crate::{
|
|
|
+ error::Error,
|
|
|
+ ethereum::swap_creator::SwapCreator,
|
|
|
+ protocol::{follower, initiator},
|
|
|
+};
|
|
|
use darkfi_serial::async_trait;
|
|
|
use ethers::{prelude::*, utils::hex};
|
|
|
use pasta_curves::pallas;
|
|
|
@@ -107,30 +111,30 @@ pub(crate) trait Initiator {
|
|
|
#[async_trait]
|
|
|
pub(crate) trait InitiatorEventWatcher {
|
|
|
async fn run_received_counterparty_keys_watcher(
|
|
|
- event_tx: channel::Sender<Event>,
|
|
|
+ event_tx: channel::Sender<initiator::Event>,
|
|
|
counterparty_keys_rx: channel::Receiver<CounterpartyKeys>,
|
|
|
) -> Result<(), Error>;
|
|
|
|
|
|
async fn run_counterparty_funds_locked_watcher(
|
|
|
- event_tx: channel::Sender<Event>,
|
|
|
+ event_tx: channel::Sender<initiator::Event>,
|
|
|
) -> Result<(), Error>;
|
|
|
|
|
|
// TODO: make this generic for both chains
|
|
|
async fn run_counterparty_funds_claimed_watcher<M: Middleware>(
|
|
|
- event_tx: channel::Sender<Event>,
|
|
|
+ event_tx: channel::Sender<initiator::Event>,
|
|
|
contract: SwapCreator<M>,
|
|
|
contract_swap_id: &[u8; 32],
|
|
|
from_block: u64,
|
|
|
) -> Result<(), Error>;
|
|
|
|
|
|
async fn run_timeout_1_watcher(
|
|
|
- event_tx: channel::Sender<Event>,
|
|
|
+ event_tx: channel::Sender<initiator::Event>,
|
|
|
timeout_1: u64,
|
|
|
buffer_seconds: u64,
|
|
|
) -> Result<(), Error>;
|
|
|
|
|
|
async fn run_timeout_2_watcher(
|
|
|
- event_tx: channel::Sender<Event>,
|
|
|
+ event_tx: channel::Sender<initiator::Event>,
|
|
|
timeout_2: u64,
|
|
|
) -> Result<(), Error>;
|
|
|
}
|
|
|
@@ -138,7 +142,10 @@ pub(crate) trait InitiatorEventWatcher {
|
|
|
/// the chain that is the counterparty to the swap; ie. the second-mover
|
|
|
pub(crate) trait Follower {
|
|
|
// handle the swap initiation by locking funds on chain B
|
|
|
- fn handle_counterparty_funds_locked(&self) -> Result<(), crate::Error>;
|
|
|
+ fn handle_counterparty_funds_locked(
|
|
|
+ &self,
|
|
|
+ contract_swap_id: [u8; 32],
|
|
|
+ ) -> Result<(), crate::Error>;
|
|
|
|
|
|
// handle the funds being ready to be claimed by us
|
|
|
fn handle_ready_to_claim(&self) -> Result<(), crate::Error>;
|
|
|
@@ -149,3 +156,24 @@ pub(crate) trait Follower {
|
|
|
counterparty_secret: [u8; 32],
|
|
|
) -> Result<(), crate::Error>;
|
|
|
}
|
|
|
+
|
|
|
+#[async_trait]
|
|
|
+pub(crate) trait FollowerEventWatcher {
|
|
|
+ async fn run_counterparty_funds_locked_watcher(
|
|
|
+ event_tx: channel::Sender<follower::Event>,
|
|
|
+ ) -> Result<(), Error>;
|
|
|
+
|
|
|
+ async fn run_ready_to_claim_watcher<M: Middleware>(
|
|
|
+ event_tx: channel::Sender<follower::Event>,
|
|
|
+ contract: SwapCreator<M>,
|
|
|
+ contract_swap_id: &[u8; 32],
|
|
|
+ from_block: u64,
|
|
|
+ ) -> Result<(), Error>;
|
|
|
+
|
|
|
+ async fn run_counterparty_funds_refunded_watcher<M: Middleware>(
|
|
|
+ event_tx: channel::Sender<follower::Event>,
|
|
|
+ contract: SwapCreator<M>,
|
|
|
+ contract_swap_id: &[u8; 32],
|
|
|
+ from_block: u64,
|
|
|
+ ) -> Result<(), Error>;
|
|
|
+}
|