rpc.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use serde_json::{json, Value};
  2. use darkfi::{rpc::jsonrpc::JsonRequest, Result};
  3. use crate::Rpc;
  4. impl Rpc {
  5. // --> {"jsonrpc": "2.0", "method": "init", "params": [], "id": 42}
  6. // <-- {"jsonrpc": "2.0", "result": "initializing...", "id": 42}
  7. pub async fn init(&self) -> Result<Value> {
  8. let req = JsonRequest::new("init", json!([]));
  9. self.client.request(req).await
  10. }
  11. // --> {"jsonrpc": "2.0", "method": "create", "params": [], "id": 42}
  12. // <-- {"jsonrpc": "2.0", "result": "creating dao...", "id": 42}
  13. pub async fn create(&self) -> Result<Value> {
  14. let req = JsonRequest::new("create", json!([]));
  15. self.client.request(req).await
  16. }
  17. // --> {"jsonrpc": "2.0", "method": "airdrop", "params": [], "id": 42}
  18. // <-- {"jsonrpc": "2.0", "result": "airdropping tokens...", "id": 42}
  19. pub async fn airdrop(&self) -> Result<Value> {
  20. let req = JsonRequest::new("airdrop", json!([]));
  21. self.client.request(req).await
  22. }
  23. // --> {"jsonrpc": "2.0", "method": "propose", "params": [], "id": 42}
  24. // <-- {"jsonrpc": "2.0", "result": "creating proposal...", "id": 42}
  25. pub async fn propose(&self) -> Result<Value> {
  26. let req = JsonRequest::new("propose", json!([]));
  27. self.client.request(req).await
  28. }
  29. // --> {"jsonrpc": "2.0", "method": "vote", "params": [], "id": 42}
  30. // <-- {"jsonrpc": "2.0", "result": "voting...", "id": 42}
  31. pub async fn vote(&self) -> Result<Value> {
  32. let req = JsonRequest::new("vote", json!([]));
  33. self.client.request(req).await
  34. }
  35. // --> {"jsonrpc": "2.0", "method": "exec", "params": [], "id": 42}
  36. // <-- {"jsonrpc": "2.0", "result": "executing...", "id": 42}
  37. pub async fn exec(&self) -> Result<Value> {
  38. let req = JsonRequest::new("exec", json!([]));
  39. self.client.request(req).await
  40. }
  41. }