|
@ -5,7 +5,6 @@ use crate::cfd_actors::insert_cfd_and_update_feed; |
|
|
use crate::cfd_actors::{self}; |
|
|
use crate::cfd_actors::{self}; |
|
|
use crate::collab_settlement_maker; |
|
|
use crate::collab_settlement_maker; |
|
|
use crate::db::load_cfd; |
|
|
use crate::db::load_cfd; |
|
|
use crate::log_error; |
|
|
|
|
|
use crate::maker_inc_connections; |
|
|
use crate::maker_inc_connections; |
|
|
use crate::model::cfd::Cfd; |
|
|
use crate::model::cfd::Cfd; |
|
|
use crate::model::cfd::CfdState; |
|
|
use crate::model::cfd::CfdState; |
|
@ -557,8 +556,10 @@ where |
|
|
M: xtra::Handler<monitor::CollaborativeSettlement>, |
|
|
M: xtra::Handler<monitor::CollaborativeSettlement>, |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
{ |
|
|
{ |
|
|
async fn handle_settlement_completed(&mut self, msg: collab_settlement_maker::Completed) { |
|
|
async fn handle_settlement_completed( |
|
|
log_error!(async { |
|
|
&mut self, |
|
|
|
|
|
msg: collab_settlement_maker::Completed, |
|
|
|
|
|
) -> Result<()> { |
|
|
use collab_settlement_maker::Completed::*; |
|
|
use collab_settlement_maker::Completed::*; |
|
|
let (order_id, settlement, script_pubkey) = match msg { |
|
|
let (order_id, settlement, script_pubkey) = match msg { |
|
|
Confirmed { |
|
|
Confirmed { |
|
@ -598,8 +599,7 @@ where |
|
|
}) |
|
|
}) |
|
|
.await?; |
|
|
.await?; |
|
|
|
|
|
|
|
|
anyhow::Ok(()) |
|
|
Ok(()) |
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -754,8 +754,7 @@ where |
|
|
M: xtra::Handler<monitor::StartMonitoring>, |
|
|
M: xtra::Handler<monitor::StartMonitoring>, |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
{ |
|
|
{ |
|
|
async fn handle_setup_completed(&mut self, msg: setup_maker::Completed) { |
|
|
async fn handle_setup_completed(&mut self, msg: setup_maker::Completed) -> Result<()> { |
|
|
log_error!(async { |
|
|
|
|
|
use setup_maker::Completed::*; |
|
|
use setup_maker::Completed::*; |
|
|
let (order_id, dlc) = match msg { |
|
|
let (order_id, dlc) = match msg { |
|
|
NewContract { order_id, dlc } => (order_id, dlc), |
|
|
NewContract { order_id, dlc } => (order_id, dlc), |
|
@ -803,7 +802,6 @@ where |
|
|
.await?; |
|
|
.await?; |
|
|
|
|
|
|
|
|
Ok(()) |
|
|
Ok(()) |
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -812,8 +810,8 @@ impl<O: 'static, M: 'static, T: 'static, W: 'static> Handler<TakerConnected> for |
|
|
where |
|
|
where |
|
|
T: xtra::Handler<maker_inc_connections::TakerMessage>, |
|
|
T: xtra::Handler<maker_inc_connections::TakerMessage>, |
|
|
{ |
|
|
{ |
|
|
async fn handle(&mut self, msg: TakerConnected, _ctx: &mut Context<Self>) { |
|
|
async fn handle(&mut self, msg: TakerConnected, _ctx: &mut Context<Self>) -> Result<()> { |
|
|
log_error!(self.handle_taker_connected(msg.id)); |
|
|
self.handle_taker_connected(msg.id).await |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -823,8 +821,8 @@ impl<O: 'static, M: 'static, T: 'static, W: 'static> Handler<TakerDisconnected> |
|
|
where |
|
|
where |
|
|
T: xtra::Handler<maker_inc_connections::TakerMessage>, |
|
|
T: xtra::Handler<maker_inc_connections::TakerMessage>, |
|
|
{ |
|
|
{ |
|
|
async fn handle(&mut self, msg: TakerDisconnected, _ctx: &mut Context<Self>) { |
|
|
async fn handle(&mut self, msg: TakerDisconnected, _ctx: &mut Context<Self>) -> Result<()> { |
|
|
log_error!(self.handle_taker_disconnected(msg.id)); |
|
|
self.handle_taker_disconnected(msg.id).await |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -834,8 +832,8 @@ where |
|
|
M: xtra::Handler<monitor::StartMonitoring>, |
|
|
M: xtra::Handler<monitor::StartMonitoring>, |
|
|
O: xtra::Handler<oracle::MonitorAttestation>, |
|
|
O: xtra::Handler<oracle::MonitorAttestation>, |
|
|
{ |
|
|
{ |
|
|
async fn handle(&mut self, msg: Completed, _ctx: &mut Context<Self>) { |
|
|
async fn handle(&mut self, msg: Completed, _ctx: &mut Context<Self>) -> Result<()> { |
|
|
log_error!(self.handle_roll_over_completed(msg)); |
|
|
self.handle_roll_over_completed(msg).await |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -844,8 +842,8 @@ impl<O: 'static, M: 'static, T: 'static, W: 'static> Handler<monitor::Event> for |
|
|
where |
|
|
where |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
{ |
|
|
{ |
|
|
async fn handle(&mut self, msg: monitor::Event, _ctx: &mut Context<Self>) { |
|
|
async fn handle(&mut self, msg: monitor::Event, _ctx: &mut Context<Self>) -> Result<()> { |
|
|
log_error!(self.handle_monitoring_event(msg)) |
|
|
self.handle_monitoring_event(msg).await |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -866,10 +864,15 @@ where |
|
|
+ xtra::Handler<wallet::BuildPartyParams> |
|
|
+ xtra::Handler<wallet::BuildPartyParams> |
|
|
+ xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
+ xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
{ |
|
|
{ |
|
|
async fn handle(&mut self, FromTaker { taker_id, msg }: FromTaker, ctx: &mut Context<Self>) { |
|
|
async fn handle( |
|
|
|
|
|
&mut self, |
|
|
|
|
|
FromTaker { taker_id, msg }: FromTaker, |
|
|
|
|
|
ctx: &mut Context<Self>, |
|
|
|
|
|
) -> Result<()> { |
|
|
match msg { |
|
|
match msg { |
|
|
wire::TakerToMaker::TakeOrder { order_id, quantity } => { |
|
|
wire::TakerToMaker::TakeOrder { order_id, quantity } => { |
|
|
log_error!(self.handle_take_order(taker_id, order_id, quantity, ctx)) |
|
|
self.handle_take_order(taker_id, order_id, quantity, ctx) |
|
|
|
|
|
.await? |
|
|
} |
|
|
} |
|
|
wire::TakerToMaker::Settlement { |
|
|
wire::TakerToMaker::Settlement { |
|
|
order_id, |
|
|
order_id, |
|
@ -881,17 +884,22 @@ where |
|
|
price, |
|
|
price, |
|
|
}, |
|
|
}, |
|
|
} => { |
|
|
} => { |
|
|
log_error!(self.handle_propose_settlement( |
|
|
if let Err(e) = self |
|
|
|
|
|
.handle_propose_settlement( |
|
|
taker_id, |
|
|
taker_id, |
|
|
SettlementProposal { |
|
|
SettlementProposal { |
|
|
order_id, |
|
|
order_id, |
|
|
timestamp, |
|
|
timestamp, |
|
|
taker, |
|
|
taker, |
|
|
maker, |
|
|
maker, |
|
|
price |
|
|
price, |
|
|
}, |
|
|
}, |
|
|
ctx |
|
|
ctx, |
|
|
)) |
|
|
) |
|
|
|
|
|
.await |
|
|
|
|
|
{ |
|
|
|
|
|
tracing::warn!("Failed ot handle settlement proposal: {:#}", e); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
wire::TakerToMaker::Settlement { |
|
|
wire::TakerToMaker::Settlement { |
|
|
msg: wire::taker_to_maker::Settlement::Initiate { .. }, |
|
|
msg: wire::taker_to_maker::Settlement::Initiate { .. }, |
|
@ -903,14 +911,19 @@ where |
|
|
order_id, |
|
|
order_id, |
|
|
timestamp, |
|
|
timestamp, |
|
|
} => { |
|
|
} => { |
|
|
log_error!(self.handle_propose_roll_over( |
|
|
if let Err(e) = self |
|
|
|
|
|
.handle_propose_roll_over( |
|
|
RolloverProposal { |
|
|
RolloverProposal { |
|
|
order_id, |
|
|
order_id, |
|
|
timestamp, |
|
|
timestamp, |
|
|
}, |
|
|
}, |
|
|
taker_id, |
|
|
taker_id, |
|
|
ctx |
|
|
ctx, |
|
|
)) |
|
|
) |
|
|
|
|
|
.await |
|
|
|
|
|
{ |
|
|
|
|
|
tracing::warn!("Failed to handle rollover proposal: {:#}", e); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
wire::TakerToMaker::RollOverProtocol { .. } => { |
|
|
wire::TakerToMaker::RollOverProtocol { .. } => { |
|
|
unreachable!("This kind of message should be sent to the rollover_maker::Actor`") |
|
|
unreachable!("This kind of message should be sent to the rollover_maker::Actor`") |
|
@ -921,7 +934,9 @@ where |
|
|
TakerToMaker::Hello(_) => { |
|
|
TakerToMaker::Hello(_) => { |
|
|
unreachable!("The Hello message is not sent to the cfd actor") |
|
|
unreachable!("The Hello message is not sent to the cfd actor") |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -932,24 +947,26 @@ where |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
W: xtra::Handler<wallet::TryBroadcastTransaction>, |
|
|
{ |
|
|
{ |
|
|
async fn handle(&mut self, msg: oracle::Attestation, _ctx: &mut Context<Self>) { |
|
|
async fn handle(&mut self, msg: oracle::Attestation, _ctx: &mut Context<Self>) { |
|
|
log_error!(self.handle_oracle_attestation(msg)) |
|
|
if let Err(e) = self.handle_oracle_attestation(msg).await { |
|
|
|
|
|
tracing::warn!("Failed to handle oracle attestation: {:#}", e) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Message for TakerConnected { |
|
|
impl Message for TakerConnected { |
|
|
type Result = (); |
|
|
type Result = Result<()>; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Message for TakerDisconnected { |
|
|
impl Message for TakerDisconnected { |
|
|
type Result = (); |
|
|
type Result = Result<()>; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Message for Completed { |
|
|
impl Message for Completed { |
|
|
type Result = (); |
|
|
type Result = Result<()>; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Message for FromTaker { |
|
|
impl Message for FromTaker { |
|
|
type Result = (); |
|
|
type Result = Result<()>; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl<O: 'static, M: 'static, T: 'static, W: 'static> xtra::Actor for Actor<O, M, T, W> {} |
|
|
impl<O: 'static, M: 'static, T: 'static, W: 'static> xtra::Actor for Actor<O, M, T, W> {} |
|
|