Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh 595 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions node/src/accountant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,24 +1021,21 @@ impl Accountant {
transaction_id: PendingPayableId,
ctx: &mut Context<Self>,
) {
let closure = |msg: CancelFailedPendingTransaction| ctx.notify(msg);
self.tools.notify_cancel_failed_transaction.notify(
CancelFailedPendingTransaction { id: transaction_id },
Box::new(closure),
)
self.tools
.notify_cancel_failed_transaction
.notify(CancelFailedPendingTransaction { id: transaction_id }, ctx)
}

fn order_confirm_transaction(
&self,
pending_payable_fingerprint: PendingPayableFingerprint,
ctx: &mut Context<Self>,
) {
let closure = |msg: ConfirmPendingTransaction| ctx.notify(msg);
self.tools.notify_confirm_transaction.notify(
ConfirmPendingTransaction {
pending_payable_fingerprint,
},
Box::new(closure),
ctx,
);
}

Expand Down Expand Up @@ -1820,7 +1817,8 @@ mod tests {
subject.scanners.payables = Box::new(NullScanner);
subject.tools.notify_later_scan_for_receivable = Box::new(
NotifyLaterHandleMock::default()
.notify_later_params(&notify_later_receivable_params_arc),
.notify_later_params(&notify_later_receivable_params_arc)
.enable_proceeding(),
);
let peer_actors = peer_actors_builder()
.blockchain_bridge(blockchain_bridge)
Expand Down Expand Up @@ -1922,7 +1920,8 @@ mod tests {
subject.scanners.payables = Box::new(NullScanner); //skipping
subject.tools.notify_later_scan_for_pending_payable = Box::new(
NotifyLaterHandleMock::default()
.notify_later_params(&notify_later_pending_payable_params_arc),
.notify_later_params(&notify_later_pending_payable_params_arc)
.enable_proceeding(),
);
let subject_addr: Addr<Accountant> = subject.start();
let subject_subs = Accountant::make_subs_from(&subject_addr);
Expand Down Expand Up @@ -2007,7 +2006,9 @@ mod tests {
subject.scanners.pending_payables = Box::new(NullScanner); //skipping
subject.scanners.receivables = Box::new(NullScanner); //skipping
subject.tools.notify_later_scan_for_payable = Box::new(
NotifyLaterHandleMock::default().notify_later_params(&notify_later_payables_params_arc),
NotifyLaterHandleMock::default()
.notify_later_params(&notify_later_payables_params_arc)
.enable_proceeding(),
);
let subject_addr = subject.start();
let subject_subs = Accountant::make_subs_from(&subject_addr);
Expand Down Expand Up @@ -3582,16 +3583,17 @@ mod tests {
.build();
subject.scanners.receivables = Box::new(NullScanner);
let notify_later_half_mock = NotifyLaterHandleMock::default()
.notify_later_params(&notify_later_scan_for_pending_payable_arc_cloned);
.notify_later_params(&notify_later_scan_for_pending_payable_arc_cloned)
.enable_proceeding();
subject.tools.notify_later_scan_for_pending_payable =
Box::new(notify_later_half_mock);
let mut notify_half_mock = NotifyHandleMock::default()
.notify_params(&notify_cancel_failed_transaction_params_arc_cloned);
notify_half_mock.do_you_want_to_proceed_after = true;
let notify_half_mock = NotifyHandleMock::default()
.notify_params(&notify_cancel_failed_transaction_params_arc_cloned)
.enable_proceeding();
subject.tools.notify_cancel_failed_transaction = Box::new(notify_half_mock);
let mut notify_half_mock = NotifyHandleMock::default()
.notify_params(&notify_confirm_transaction_params_arc_cloned);
notify_half_mock.do_you_want_to_proceed_after = true;
let notify_half_mock = NotifyHandleMock::default()
.notify_params(&notify_confirm_transaction_params_arc_cloned)
.enable_proceeding();
subject.tools.notify_confirm_transaction = Box::new(notify_half_mock);
subject
});
Expand Down
79 changes: 36 additions & 43 deletions node/src/accountant/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,9 @@ pub(in crate::accountant) mod accountant_tools {
RequestTransactionReceipts, ScanForPayables, ScanForPendingPayable, ScanForReceivables,
};
use crate::sub_lib::utils::{NotifyHandle, NotifyLaterHandle};
use actix::{AsyncContext, Context, Recipient};
use actix::{Context, Recipient};
#[cfg(test)]
use std::any::Any;
use std::time::Duration;

macro_rules! notify_later_assertable {
($accountant: expr, $ctx: expr, $message_type: ident, $notify_later_handle_field: ident,$scan_interval_field: ident) => {
let closure =
Box::new(|msg: $message_type, interval: Duration| $ctx.notify_later(msg, interval));
let _ = $accountant.tools.$notify_later_handle_field.notify_later(
$message_type {},
$accountant.config.scan_intervals.$scan_interval_field,
closure,
);
};
}

pub struct Scanners {
pub pending_payables: Box<dyn Scanner>,
Expand All @@ -32,7 +19,7 @@ pub(in crate::accountant) mod accountant_tools {
impl Default for Scanners {
fn default() -> Self {
Scanners {
pending_payables: Box::new(PendingPaymentsScanner),
pending_payables: Box::new(PendingPayablesScanner),
payables: Box::new(PayablesScanner),
receivables: Box::new(ReceivablesScanner),
}
Expand All @@ -46,20 +33,24 @@ pub(in crate::accountant) mod accountant_tools {
}

#[derive(Debug, PartialEq)]
pub struct PendingPaymentsScanner;
pub struct PendingPayablesScanner;

impl Scanner for PendingPaymentsScanner {
impl Scanner for PendingPayablesScanner {
fn scan(&self, accountant: &Accountant) {
accountant.scan_for_pending_payable()
}
fn notify_later_assertable(&self, accountant: &Accountant, ctx: &mut Context<Accountant>) {
notify_later_assertable!(
accountant,
ctx,
ScanForPendingPayable,
notify_later_scan_for_pending_payable,
pending_payable_scan_interval
);
let _ = accountant
.tools
.notify_later_scan_for_pending_payable
.notify_later(
ScanForPendingPayable {},
accountant
.config
.scan_intervals
.pending_payable_scan_interval,
ctx,
);
}
as_any_impl!();
}
Expand All @@ -73,12 +64,10 @@ pub(in crate::accountant) mod accountant_tools {
}

fn notify_later_assertable(&self, accountant: &Accountant, ctx: &mut Context<Accountant>) {
notify_later_assertable!(
accountant,
let _ = accountant.tools.notify_later_scan_for_payable.notify_later(
ScanForPayables {},
accountant.config.scan_intervals.payable_scan_interval,
ctx,
ScanForPayables,
notify_later_scan_for_payable,
payable_scan_interval
);
}

Expand All @@ -95,13 +84,14 @@ pub(in crate::accountant) mod accountant_tools {
}

fn notify_later_assertable(&self, accountant: &Accountant, ctx: &mut Context<Accountant>) {
notify_later_assertable!(
accountant,
ctx,
ScanForReceivables,
notify_later_scan_for_receivable,
receivable_scan_interval
);
let _ = accountant
.tools
.notify_later_scan_for_receivable
.notify_later(
ScanForReceivables {},
accountant.config.scan_intervals.receivable_scan_interval,
ctx,
);
}

as_any_impl!();
Expand All @@ -125,19 +115,22 @@ pub(in crate::accountant) mod accountant_tools {
#[derive(Default)]
pub struct TransactionConfirmationTools {
pub notify_later_scan_for_pending_payable:
Box<dyn NotifyLaterHandle<ScanForPendingPayable>>,
pub notify_later_scan_for_payable: Box<dyn NotifyLaterHandle<ScanForPayables>>,
pub notify_later_scan_for_receivable: Box<dyn NotifyLaterHandle<ScanForReceivables>>,
pub notify_confirm_transaction: Box<dyn NotifyHandle<ConfirmPendingTransaction>>,
pub notify_cancel_failed_transaction: Box<dyn NotifyHandle<CancelFailedPendingTransaction>>,
Box<dyn NotifyLaterHandle<ScanForPendingPayable, Accountant>>,
pub notify_later_scan_for_payable: Box<dyn NotifyLaterHandle<ScanForPayables, Accountant>>,
pub notify_later_scan_for_receivable:
Box<dyn NotifyLaterHandle<ScanForReceivables, Accountant>>,
pub notify_confirm_transaction:
Box<dyn NotifyHandle<ConfirmPendingTransaction, Accountant>>,
pub notify_cancel_failed_transaction:
Box<dyn NotifyHandle<CancelFailedPendingTransaction, Accountant>>,
pub request_transaction_receipts_subs_opt: Option<Recipient<RequestTransactionReceipts>>,
}
}

#[cfg(test)]
mod tests {
use crate::accountant::tools::accountant_tools::{
PayablesScanner, PendingPaymentsScanner, ReceivablesScanner, Scanners,
PayablesScanner, PendingPayablesScanner, ReceivablesScanner, Scanners,
};

#[test]
Expand All @@ -146,7 +139,7 @@ mod tests {

assert_eq!(
subject.pending_payables.as_any().downcast_ref(),
Some(&PendingPaymentsScanner)
Some(&PendingPayablesScanner)
);
assert_eq!(
subject.payables.as_any().downcast_ref(),
Expand Down
Loading