@ -21,6 +21,7 @@ use sqlx::pool::PoolConnection;
use sqlx ::Sqlite ;
use sqlx ::Sqlite ;
use std ::collections ::HashMap ;
use std ::collections ::HashMap ;
use std ::time ::SystemTime ;
use std ::time ::SystemTime ;
use time ::Duration ;
use tokio ::sync ::watch ;
use tokio ::sync ::watch ;
use xtra ::prelude ::* ;
use xtra ::prelude ::* ;
@ -62,6 +63,7 @@ pub struct FromTaker {
pub struct Actor < O , M , T > {
pub struct Actor < O , M , T > {
db : sqlx ::SqlitePool ,
db : sqlx ::SqlitePool ,
wallet : Wallet ,
wallet : Wallet ,
term : Duration ,
oracle_pk : schnorrsig ::PublicKey ,
oracle_pk : schnorrsig ::PublicKey ,
cfd_feed_actor_inbox : watch ::Sender < Vec < Cfd > > ,
cfd_feed_actor_inbox : watch ::Sender < Vec < Cfd > > ,
order_feed_sender : watch ::Sender < Option < Order > > ,
order_feed_sender : watch ::Sender < Option < Order > > ,
@ -98,6 +100,7 @@ impl<O, M, T> Actor<O, M, T> {
pub fn new (
pub fn new (
db : sqlx ::SqlitePool ,
db : sqlx ::SqlitePool ,
wallet : Wallet ,
wallet : Wallet ,
term : Duration ,
oracle_pk : schnorrsig ::PublicKey ,
oracle_pk : schnorrsig ::PublicKey ,
cfd_feed_actor_inbox : watch ::Sender < Vec < Cfd > > ,
cfd_feed_actor_inbox : watch ::Sender < Vec < Cfd > > ,
order_feed_sender : watch ::Sender < Option < Order > > ,
order_feed_sender : watch ::Sender < Option < Order > > ,
@ -109,6 +112,7 @@ impl<O, M, T> Actor<O, M, T> {
Self {
Self {
db ,
db ,
wallet ,
wallet ,
term ,
oracle_pk ,
oracle_pk ,
cfd_feed_actor_inbox ,
cfd_feed_actor_inbox ,
order_feed_sender ,
order_feed_sender ,
@ -637,7 +641,7 @@ where
max_quantity : Usd ,
max_quantity : Usd ,
) -> Result < ( ) > {
) -> Result < ( ) > {
let oracle_event_id =
let oracle_event_id =
oracle ::next_announcement_after ( time ::OffsetDateTime ::now_utc ( ) + Order ::TERM ) ? ;
oracle ::next_announcement_after ( time ::OffsetDateTime ::now_utc ( ) + self . term ) ? ;
self . oracle_actor
self . oracle_actor
. do_send_async ( oracle ::FetchAnnouncement ( oracle_event_id ) )
. do_send_async ( oracle ::FetchAnnouncement ( oracle_event_id ) )
@ -649,6 +653,7 @@ where
max_quantity ,
max_quantity ,
Origin ::Ours ,
Origin ::Ours ,
oracle_event_id ,
oracle_event_id ,
self . term ,
) ? ;
) ? ;
// 1. Save to DB
// 1. Save to DB
@ -751,7 +756,7 @@ where
let dlc = cfd . open_dlc ( ) . context ( "CFD was in wrong state" ) ? ;
let dlc = cfd . open_dlc ( ) . context ( "CFD was in wrong state" ) ? ;
let oracle_event_id =
let oracle_event_id =
oracle ::next_announcement_after ( time ::OffsetDateTime ::now_utc ( ) + Order ::TERM ) ? ;
oracle ::next_announcement_after ( time ::OffsetDateTime ::now_utc ( ) + cfd . order . term ) ? ;
let announcement = self
let announcement = self
. oracle_actor
. oracle_actor
. send ( oracle ::GetAnnouncement ( oracle_event_id ) )
. send ( oracle ::GetAnnouncement ( oracle_event_id ) )