rpc.rs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2022 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use serde_json::{json, Value};
  19. use darkfi::{rpc::jsonrpc::JsonRequest, Result};
  20. use crate::Rpc;
  21. impl Rpc {
  22. // --> {"jsonrpc": "2.0", "method": "create", "params": [], "id": 42}
  23. // <-- {"jsonrpc": "2.0", "result": "creating dao...", "id": 42}
  24. pub async fn create(
  25. &self,
  26. dao_proposer_limit: u64,
  27. dao_quorum: u64,
  28. dao_approval_ratio_quot: u64,
  29. dao_approval_ratio_base: u64,
  30. ) -> Result<Value> {
  31. let req = JsonRequest::new(
  32. "create",
  33. json!([
  34. dao_proposer_limit,
  35. dao_quorum,
  36. dao_approval_ratio_quot,
  37. dao_approval_ratio_base,
  38. ]),
  39. );
  40. self.client.request(req).await
  41. }
  42. // --> {"jsonrpc": "2.0", "method": "mint", "params": [], "id": 42}
  43. // <-- {"jsonrpc": "2.0", "result": "minting tokens...", "id": 42}
  44. pub async fn addr(&self) -> Result<Value> {
  45. let req = JsonRequest::new("get_dao_addr", json!([]));
  46. self.client.request(req).await
  47. }
  48. // --> {"jsonrpc": "2.0", "method": "mint", "params": [], "id": 42}
  49. // <-- {"jsonrpc": "2.0", "result": "minting tokens...", "id": 42}
  50. pub async fn mint(&self, token_supply: u64, dao_addr: String) -> Result<Value> {
  51. let req = JsonRequest::new("mint", json!([token_supply, dao_addr]));
  52. self.client.request(req).await
  53. }
  54. // --> {"jsonrpc": "2.0", "method": "airdrop", "params": [], "id": 42}
  55. // <-- {"jsonrpc": "2.0", "result": "airdropping tokens...", "id": 42}
  56. pub async fn airdrop(&self, nym: String, value: u64) -> Result<Value> {
  57. let req = JsonRequest::new("airdrop", json!([nym, value]));
  58. self.client.request(req).await
  59. }
  60. // --> {"jsonrpc": "2.0", "method": "airdrop", "params": [], "id": 42}
  61. // <-- {"jsonrpc": "2.0", "result": "airdropping tokens...", "id": 42}
  62. pub async fn keygen(&self) -> Result<Value> {
  63. let req = JsonRequest::new("keygen", json!([]));
  64. self.client.request(req).await
  65. }
  66. // --> {"jsonrpc": "2.0", "method": "airdrop", "params": [], "id": 42}
  67. // <-- {"jsonrpc": "2.0", "result": "airdropping tokens...", "id": 42}
  68. pub async fn dao_balance(&self) -> Result<Value> {
  69. let req = JsonRequest::new("dao_balance", json!([]));
  70. self.client.request(req).await
  71. }
  72. // --> {"jsonrpc": "2.0", "method": "airdrop", "params": [], "id": 42}
  73. // <-- {"jsonrpc": "2.0", "result": "airdropping tokens...", "id": 42}
  74. pub async fn dao_bulla(&self) -> Result<Value> {
  75. let req = JsonRequest::new("dao_bulla", json!([]));
  76. self.client.request(req).await
  77. }
  78. // --> {"jsonrpc": "2.0", "method": "airdrop", "params": [], "id": 42}
  79. // <-- {"jsonrpc": "2.0", "result": "airdropping tokens...", "id": 42}
  80. pub async fn user_balance(&self, nym: String) -> Result<Value> {
  81. let req = JsonRequest::new("user_balance", json!([nym]));
  82. self.client.request(req).await
  83. }
  84. // --> {"jsonrpc": "2.0", "method": "propose", "params": [], "id": 42}
  85. // <-- {"jsonrpc": "2.0", "result": "creating proposal...", "id": 42}
  86. pub async fn propose(&self, sender: String, recipient: String, amount: u64) -> Result<Value> {
  87. let req = JsonRequest::new("propose", json!([sender, recipient, amount]));
  88. self.client.request(req).await
  89. }
  90. // --> {"jsonrpc": "2.0", "method": "vote", "params": [], "id": 42}
  91. // <-- {"jsonrpc": "2.0", "result": "voting...", "id": 42}
  92. pub async fn vote(&self, nym: String, vote: String) -> Result<Value> {
  93. let req = JsonRequest::new("vote", json!([nym, vote]));
  94. self.client.request(req).await
  95. }
  96. // --> {"jsonrpc": "2.0", "method": "exec", "params": [], "id": 42}
  97. // <-- {"jsonrpc": "2.0", "result": "executing...", "id": 42}
  98. pub async fn get_votes(&self) -> Result<Value> {
  99. let req = JsonRequest::new("get_votes", json!([]));
  100. self.client.request(req).await
  101. }
  102. // --> {"jsonrpc": "2.0", "method": "exec", "params": [], "id": 42}
  103. // <-- {"jsonrpc": "2.0", "result": "executing...", "id": 42}
  104. pub async fn get_proposals(&self) -> Result<Value> {
  105. let req = JsonRequest::new("get_proposals", json!([]));
  106. self.client.request(req).await
  107. }
  108. // --> {"jsonrpc": "2.0", "method": "exec", "params": [], "id": 42}
  109. // <-- {"jsonrpc": "2.0", "result": "executing...", "id": 42}
  110. pub async fn exec(&self, bulla: String) -> Result<Value> {
  111. let req = JsonRequest::new("exec", json!([bulla]));
  112. self.client.request(req).await
  113. }
  114. }