rpc_misc.rs 840 B

1234567891011121314151617181920212223242526
  1. use serde_json::{json, Value};
  2. use darkfi::{
  3. rpc::jsonrpc::{JsonResponse, JsonResult},
  4. util::time::Timestamp,
  5. };
  6. use super::Darkfid;
  7. impl Darkfid {
  8. // RPCAPI:
  9. // Returns a `pong` to the `ping` request.
  10. // --> {"jsonrpc": "2.0", "method": "ping", "params": [], "id": 1}
  11. // <-- {"jsonrpc": "2.0", "result": "pong", "id": 1}
  12. pub async fn pong(&self, id: Value, _params: &[Value]) -> JsonResult {
  13. JsonResponse::new(json!("pong"), id).into()
  14. }
  15. // RPCAPI:
  16. // Returns current system clock in `Timestamp` format.
  17. // --> {"jsonrpc": "2.0", "method": "clock", "params": [], "id": 1}
  18. // <-- {"jsonrpc": "2.0", "result": {...}, "id": 1}
  19. pub async fn clock(&self, id: Value, _params: &[Value]) -> JsonResult {
  20. JsonResponse::new(json!(Timestamp::current_time()), id).into()
  21. }
  22. }