11use mina_p2p_messages:: v2;
22use p2p:: channels:: rpc:: P2pRpcRequest ;
33use p2p:: channels:: streaming_rpc:: { P2pChannelsStreamingRpcAction , P2pStreamingRpcRequest } ;
4+ use p2p:: P2pAction ;
45
56use crate :: block_producer:: vrf_evaluator:: BlockProducerVrfEvaluatorAction ;
67use crate :: p2p:: channels:: rpc:: { P2pChannelsRpcAction , P2pRpcId , P2pRpcResponse } ;
@@ -10,8 +11,8 @@ use crate::transition_frontier::sync::TransitionFrontierSyncAction;
1011use crate :: { BlockProducerAction , RpcAction , Store } ;
1112
1213use super :: read:: {
13- LedgerReadAction , LedgerReadId , LedgerReadRequest , LedgerReadResponse ,
14- LedgerReadStagedLedgerAuxAndPendingCoinbases , PropagateLedgerReadInit ,
14+ LedgerReadAction , LedgerReadId , LedgerReadInitCallback , LedgerReadRequest , LedgerReadResponse ,
15+ LedgerReadStagedLedgerAuxAndPendingCoinbases ,
1516} ;
1617use super :: write:: { LedgerWriteAction , LedgerWriteResponse } ;
1718use super :: { LedgerAction , LedgerActionWithMeta , LedgerAddress , LedgerService } ;
@@ -36,47 +37,26 @@ pub fn ledger_effects<S: LedgerService>(store: &mut Store<S>, action: LedgerActi
3637 LedgerReadAction :: FindTodos => {
3738 next_read_requests_init ( store) ;
3839 }
39- LedgerReadAction :: Init { request, propagate } => {
40+ LedgerReadAction :: Init { request, callback } => {
4041 if store. state ( ) . ledger . read . has_same_request ( & request) {
4142 return ;
4243 }
4344 let id = store. state ( ) . ledger . read . next_req_id ( ) ;
4445 store. service . read_init ( id, request. clone ( ) ) ;
4546 store. dispatch ( LedgerReadAction :: Pending { id, request } ) ;
4647
47- if let Some ( propagate) = propagate {
48- match propagate {
49- PropagateLedgerReadInit :: RpcLedgerAccountsGetPending { rpc_id } => {
50- store. dispatch ( RpcAction :: LedgerAccountsGetPending { rpc_id } ) ;
51- }
52- PropagateLedgerReadInit :: RpcScanStateSummaryGetPending {
53- rpc_id,
54- block,
55- } => {
56- store. dispatch ( RpcAction :: ScanStateSummaryGetPending {
57- rpc_id,
58- block : Some ( block) ,
59- } ) ;
60- }
61- PropagateLedgerReadInit :: P2pChannelsResponsePending {
62- is_streaming,
63- id,
64- peer_id,
65- } => {
66- if !is_streaming {
67- store. dispatch ( P2pChannelsRpcAction :: ResponsePending {
68- peer_id,
69- id,
70- } ) ;
71- } else {
72- store. dispatch ( P2pChannelsStreamingRpcAction :: ResponsePending {
73- peer_id,
74- id,
75- } ) ;
76- }
77- }
48+ match callback {
49+ LedgerReadInitCallback :: RpcLedgerAccountsGetPending { callback, args } => {
50+ store. dispatch_callback ( callback, args) ;
7851 }
79- }
52+ LedgerReadInitCallback :: RpcScanStateSummaryGetPending { callback, args } => {
53+ store. dispatch_callback ( callback, args) ;
54+ }
55+ LedgerReadInitCallback :: P2pChannelsResponsePending { callback, args } => {
56+ store. dispatch_callback ( callback, args) ;
57+ }
58+ LedgerReadInitCallback :: None => { }
59+ } ;
8060 }
8161 LedgerReadAction :: Pending { .. } => { }
8262 LedgerReadAction :: Success { id, response } => {
@@ -256,11 +236,22 @@ fn next_read_requests_init<S: redux::Service>(store: &mut Store<S>) {
256236
257237 store. dispatch ( LedgerReadAction :: Init {
258238 request,
259- propagate : Some ( PropagateLedgerReadInit :: P2pChannelsResponsePending {
260- is_streaming,
261- id,
262- peer_id,
263- } ) ,
239+ callback : LedgerReadInitCallback :: P2pChannelsResponsePending
240+ { callback : redux:: callback!( on_ledger_read_init_p2p_channels_response_pending( ( is_streaming: bool , id: P2pRpcId , peer_id: PeerId ) ) -> crate :: Action {
241+ if is_streaming {
242+ P2pAction :: from( P2pChannelsStreamingRpcAction :: ResponsePending {
243+ peer_id,
244+ id,
245+ } )
246+ } else {
247+ P2pAction :: from( P2pChannelsRpcAction :: ResponsePending {
248+ peer_id,
249+ id,
250+ } )
251+ }
252+ } ) ,
253+ args : ( is_streaming, id, peer_id)
254+ }
264255 } ) ;
265256
266257 if !store. state ( ) . ledger . read . is_total_cost_under_limit ( ) {
0 commit comments