Browse Source
Introduce ActorName trait for better error messages
resilient-broadcast
luckysori
3 years ago
committed by
Lucas Soriano del Pino
No known key found for this signature in database
GPG Key ID: 89CE0DB40A19D524
6 changed files with
40 additions and
4 deletions
-
daemon/src/actor_name.rs
-
daemon/src/address_map.rs
-
daemon/src/collab_settlement_taker.rs
-
daemon/src/lib.rs
-
daemon/src/rollover_taker.rs
-
daemon/src/setup_maker.rs
|
|
@ -0,0 +1,3 @@ |
|
|
|
pub trait ActorName { |
|
|
|
fn actor_name() -> String; |
|
|
|
} |
|
|
@ -3,6 +3,8 @@ use std::collections::HashMap; |
|
|
|
use std::hash::Hash; |
|
|
|
use xtra::{Address, Handler, Message}; |
|
|
|
|
|
|
|
use crate::actor_name::ActorName; |
|
|
|
|
|
|
|
pub struct AddressMap<K, A> { |
|
|
|
inner: HashMap<K, xtra::Address<A>>, |
|
|
|
} |
|
|
@ -49,7 +51,7 @@ where |
|
|
|
pub async fn send<M>(&self, key: &K, msg: M) -> Result<(), NotConnected> |
|
|
|
where |
|
|
|
M: Message<Result = ()>, |
|
|
|
A: Handler<M>, |
|
|
|
A: Handler<M> + ActorName, |
|
|
|
{ |
|
|
|
match self.inner.get(key) { |
|
|
|
Some(addr) if addr.is_connected() => { |
|
|
@ -58,14 +60,23 @@ where |
|
|
|
.expect("we checked that we are connected"); |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
_ => Err(NotConnected), |
|
|
|
_ => Err(NotConnected::new::<A>()), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(thiserror::Error, Debug)] |
|
|
|
#[error("Receiving actor is down")] |
|
|
|
pub struct NotConnected; |
|
|
|
#[error("{0} actor is down")] |
|
|
|
pub struct NotConnected(String); |
|
|
|
|
|
|
|
impl NotConnected { |
|
|
|
pub fn new<A>() -> Self |
|
|
|
where |
|
|
|
A: ActorName, |
|
|
|
{ |
|
|
|
NotConnected(A::actor_name()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// A message to notify that an actor instance is stopping.
|
|
|
|
pub struct Stopping<A> { |
|
|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
use crate::actor_name::ActorName; |
|
|
|
use crate::address_map::Stopping; |
|
|
|
use crate::model::cfd::{ |
|
|
|
Cfd, CollaborativeSettlement, OrderId, SettlementKind, SettlementProposal, |
|
|
@ -192,3 +193,9 @@ impl Actor { |
|
|
|
self.complete(completed, ctx).await; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
impl ActorName for Actor { |
|
|
|
fn actor_name() -> String { |
|
|
|
"Taker collab settlement".to_string() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -21,6 +21,7 @@ use xtra::{Actor, Address}; |
|
|
|
|
|
|
|
pub mod sqlx_ext; // Must come first because it is a macro.
|
|
|
|
|
|
|
|
pub mod actor_name; |
|
|
|
pub mod actors; |
|
|
|
pub mod address_map; |
|
|
|
pub mod auth; |
|
|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
use crate::actor_name::ActorName; |
|
|
|
use crate::address_map::Stopping; |
|
|
|
use crate::connection; |
|
|
|
use crate::model::cfd::{Cfd, Dlc, OrderId, Role, RollOverProposal, SettlementKind}; |
|
|
@ -317,3 +318,9 @@ pub enum Completed { |
|
|
|
impl xtra::Message for Completed { |
|
|
|
type Result = Result<()>; |
|
|
|
} |
|
|
|
|
|
|
|
impl ActorName for Actor { |
|
|
|
fn actor_name() -> String { |
|
|
|
"Taker rollover".to_string() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
@ -1,3 +1,4 @@ |
|
|
|
use crate::actor_name::ActorName; |
|
|
|
use crate::address_map::Stopping; |
|
|
|
use crate::model::cfd::{Cfd, CfdState, Dlc, Order, OrderId, Role}; |
|
|
|
use crate::model::{Identity, Usd}; |
|
|
@ -284,3 +285,9 @@ pub enum Completed { |
|
|
|
impl xtra::Message for Started { |
|
|
|
type Result = (); |
|
|
|
} |
|
|
|
|
|
|
|
impl ActorName for Actor { |
|
|
|
fn actor_name() -> String { |
|
|
|
"Taker contract setup".to_string() |
|
|
|
} |
|
|
|
} |
|
|
|