@@ -15,6 +15,7 @@ use crate::commands::builtin::{InitRPC, ManifestRPC};
15
15
use crate :: commands:: types:: { CLNConf , RPCHookInfo , RPCMethodInfo } ;
16
16
use crate :: commands:: RPCCommand ;
17
17
use crate :: errors:: PluginError ;
18
+ use crate :: io:: AsyncIO ;
18
19
use crate :: types:: { LogLevel , RpcOption } ;
19
20
20
21
#[ cfg( feature = "log" ) ]
@@ -257,9 +258,6 @@ impl<'a, T: 'a + Clone> Plugin<T> {
257
258
}
258
259
259
260
pub fn start ( mut self ) {
260
- let reader = io:: stdin ( ) ;
261
- let mut writer = io:: stdout ( ) ;
262
- let mut buffer = String :: new ( ) ;
263
261
#[ cfg( feature = "log" ) ]
264
262
{
265
263
use std:: str:: FromStr ;
@@ -276,29 +274,26 @@ impl<'a, T: 'a + Clone> Plugin<T> {
276
274
on_init : self . on_init . clone ( ) ,
277
275
} ) ,
278
276
) ;
279
- // FIXME: core lightning end with the double endline, so this can cause
280
- // problem for some input reader.
281
- // we need to parse the writer, and avoid this while loop
282
- while let Ok ( _) = reader. read_line ( & mut buffer) {
283
- let req_str = buffer. to_string ( ) ;
284
- buffer. clear ( ) ;
285
- let Ok ( request) = serde_json:: from_str :: < Request < serde_json:: Value > > ( & req_str) else {
286
- continue ;
287
- } ;
277
+ let mut asyncio = AsyncIO :: new ( ) . unwrap ( ) ;
278
+ asyncio. register ( ) . unwrap ( ) ;
279
+ asyncio. into_loop ( |buffer| {
280
+ self . log (
281
+ LogLevel :: Info ,
282
+ & format ! ( "looping around the string: {buffer}" ) ,
283
+ ) ;
284
+ let request: Request < serde_json:: Value > = serde_json:: from_str ( & buffer) . unwrap ( ) ;
288
285
if let Some ( id) = request. id {
289
286
// when the id is specified this is a RPC or Hook, so we need to return a response
290
287
let response = self . call_rpc_method ( & request. method , request. params ) ;
291
288
let mut rpc_response = init_success_response ( id) ;
292
289
self . write_respose ( & response, & mut rpc_response) ;
293
- writer
294
- . write_all ( serde_json:: to_string ( & rpc_response) . unwrap ( ) . as_bytes ( ) )
295
- . unwrap ( ) ;
296
- writer. flush ( ) . unwrap ( ) ;
290
+ return serde_json:: to_string ( & rpc_response) . unwrap ( ) ;
297
291
} else {
298
292
// in case of the id is None, we are receiving the notification, so the server is not
299
293
// interested in the answer.
300
294
self . handle_notification ( & request. method , request. params ) ;
295
+ return String :: new ( ) ;
301
296
}
302
- }
297
+ } ) ;
303
298
}
304
299
}
0 commit comments