diff --git a/bin/darkirc/src/rpc.rs b/bin/darkirc/src/rpc.rs index 9c253a2cf..3a7b5ab6c 100644 --- a/bin/darkirc/src/rpc.rs +++ b/bin/darkirc/src/rpc.rs @@ -19,6 +19,7 @@ use std::collections::HashSet; use async_trait::async_trait; use darkfi::{ + event_graph::util::recreate_from_replayer_log, net::P2pPtr, rpc::{ jsonrpc::{ErrorCode, JsonError, JsonRequest, JsonResponse, JsonResult}, @@ -48,6 +49,7 @@ impl RequestHandler for DarkIrc { "deg.switch" => self.deg_switch(req.id, req.params).await, "deg.subscribe_events" => self.deg_subscribe_events(req.id, req.params).await, "eventgraph.get_info" => self.eg_get_info(req.id, req.params).await, + "eventgraph.replay" => self.eg_rep_info(req.id, req.params).await, _ => JsonError::new(ErrorCode::MethodNotFound, None, req.id).into(), } @@ -152,6 +154,20 @@ impl DarkIrc { self.event_graph.eventgraph_info(id, params).await } + + // RPCAPI: + // Get replayed EVENTGRAPH info. + // + // --> {"jsonrpc": "2.0", "method": "eventgraph.replay", "params": ..., "id": 42} + // <-- {"jsonrpc": "2.0", "result": true, "id": 42} + async fn eg_rep_info(&self, id: u16, params: JsonValue) -> JsonResult { + let params_ = params.get::>().unwrap(); + if !params_.is_empty() { + return JsonError::new(ErrorCode::InvalidParams, None, id).into() + } + + recreate_from_replayer_log().await + } } impl HandlerP2p for DarkIrc { diff --git a/src/event_graph/mod.rs b/src/event_graph/mod.rs index 8d117d22f..a9fdad637 100644 --- a/src/event_graph/mod.rs +++ b/src/event_graph/mod.rs @@ -56,7 +56,7 @@ pub mod proto; use proto::{EventRep, EventReq, TipRep, TipReq, REPLY_TIMEOUT}; /// Utility functions -mod util; +pub mod util; use util::{generate_genesis, next_rotation_timestamp}; // Debugging event graph