node/ledger_effectful/
ledger_effectful_effects.rs1use redux::ActionWithMeta;
2
3use crate::{
4 ledger::{
5 read::{LedgerReadAction, LedgerReadInitCallback},
6 write::LedgerWriteAction,
7 LedgerService,
8 },
9 Store,
10};
11
12use super::LedgerEffectfulAction;
13
14pub fn ledger_effectful_effects<S>(
15 store: &mut Store<S>,
16 action: ActionWithMeta<LedgerEffectfulAction>,
17) where
18 S: LedgerService,
19{
20 let (action, _meta) = action.split();
21
22 match action {
23 LedgerEffectfulAction::WriteInit { request, on_init } => {
24 store.service.write_init(request.clone());
25 store.dispatch(LedgerWriteAction::Pending);
26 store.dispatch_callback(on_init, request);
27 }
28 LedgerEffectfulAction::ReadInit {
29 request,
30 callback,
31 id,
32 } => {
33 store.service.read_init(id, request.clone());
34 store.dispatch(LedgerReadAction::Pending { id, request });
35
36 match callback {
37 LedgerReadInitCallback::RpcLedgerAccountsGetPending { callback, args } => {
38 store.dispatch_callback(callback, args);
39 }
40 LedgerReadInitCallback::RpcScanStateSummaryGetPending { callback, args } => {
41 store.dispatch_callback(callback, args);
42 }
43 LedgerReadInitCallback::P2pChannelsResponsePending { callback, args } => {
44 store.dispatch_callback(callback, args);
45 }
46 LedgerReadInitCallback::RpcLedgerStatusGetPending { callback, args } => {
47 store.dispatch_callback(callback, args);
48 }
49 LedgerReadInitCallback::RpcLedgerAccountDelegatorsGetPending { callback, args } => {
50 store.dispatch_callback(callback, args);
51 }
52 LedgerReadInitCallback::None => {}
53 }
54 }
55 }
56}