Просмотр исходного кода

dao_demo: initial architecture restructuring

lunar-mining 3 лет назад
Родитель
Сommit
0f27a43587
3 измененных файлов с 418 добавлено и 1118 удалено
  1. 384 1101
      bin/dao/daod/src/main.rs
  2. 18 16
      bin/dao/daod/src/rpc.rs
  3. 16 1
      bin/dao/daod/src/util.rs

Разница между файлами не показана из-за своего большого размера
+ 384 - 1101
bin/dao/daod/src/main.rs


+ 18 - 16
bin/dao/daod/src/rpc.rs

@@ -14,7 +14,7 @@ use darkfi::rpc::{
 use crate::DaoDemo;
 
 pub struct JsonRpcInterface {
-    dao_demo: Arc<Mutex<DaoDemo>>,
+    demo: Arc<Mutex<DaoDemo>>,
 }
 
 #[async_trait]
@@ -41,51 +41,53 @@ impl RequestHandler for JsonRpcInterface {
 }
 
 impl JsonRpcInterface {
-    pub fn new(dao_demo: DaoDemo) -> Self {
-        let dao_demo = Arc::new(Mutex::new(dao_demo));
-        Self { dao_demo }
+    pub fn new(demo: DaoDemo) -> Self {
+        let demo = Arc::new(Mutex::new(demo));
+        Self { demo }
     }
 
+    // TODO: add 3 params: dao_proposer_limit, dao_quorum, dao_approval_ratio
+    //
     // --> {"method": "create", "params": []}
     // <-- {"result": "creating dao..."}
     async fn create_dao(&self, id: Value, _params: &[Value]) -> JsonResult {
-        let mut dao_demo = self.dao_demo.lock().await;
-        dao_demo.create().unwrap();
+        let mut demo = self.demo.lock().await;
+        demo.create().unwrap();
         JsonResponse::new(json!("dao created"), id).into()
     }
     // --> {"method": "mint_tokens", "params": []}
     // <-- {"result": "minting tokens..."}
     async fn mint_tokens(&self, id: Value, _params: &[Value]) -> JsonResult {
-        let mut dao_demo = self.dao_demo.lock().await;
-        dao_demo.mint().unwrap();
+        let mut demo = self.demo.lock().await;
+        demo.mint().unwrap();
         JsonResponse::new(json!("tokens minted"), id).into()
     }
     // --> {"method": "airdrop_tokens", "params": []}
     // <-- {"result": "airdropping tokens..."}
     async fn airdrop_tokens(&self, id: Value, _params: &[Value]) -> JsonResult {
-        let mut dao_demo = self.dao_demo.lock().await;
-        dao_demo.airdrop().unwrap();
+        let mut demo = self.demo.lock().await;
+        demo.airdrop().unwrap();
         JsonResponse::new(json!("tokens airdropped"), id).into()
     }
     // --> {"method": "create_proposal", "params": []}
     // <-- {"result": "creating proposal..."}
     async fn create_proposal(&self, id: Value, _params: &[Value]) -> JsonResult {
-        let mut dao_demo = self.dao_demo.lock().await;
-        dao_demo.propose().unwrap();
+        let mut demo = self.demo.lock().await;
+        demo.propose().unwrap();
         JsonResponse::new(json!("proposal created"), id).into()
     }
     // --> {"method": "vote", "params": []}
     // <-- {"result": "voting..."}
     async fn vote(&self, id: Value, _params: &[Value]) -> JsonResult {
-        let mut dao_demo = self.dao_demo.lock().await;
-        dao_demo.vote().unwrap();
+        let mut demo = self.demo.lock().await;
+        demo.vote().unwrap();
         JsonResponse::new(json!("voted"), id).into()
     }
     // --> {"method": "execute", "params": []}
     // <-- {"result": "executing..."}
     async fn execute(&self, id: Value, _params: &[Value]) -> JsonResult {
-        let mut dao_demo = self.dao_demo.lock().await;
-        dao_demo.exec().unwrap();
+        let mut demo = self.demo.lock().await;
+        demo.exec().unwrap();
         JsonResponse::new(json!("executed"), id).into()
     }
 }

+ 16 - 1
bin/dao/daod/src/util.rs

@@ -1,5 +1,10 @@
+use lazy_static::lazy_static;
 use log::debug;
-use pasta_curves::{group::ff::PrimeField, pallas};
+use pasta_curves::{
+    group::ff::{Field, PrimeField},
+    pallas,
+};
+use rand::rngs::OsRng;
 use std::{any::Any, collections::HashMap, hash::Hasher};
 
 use darkfi::{
@@ -15,6 +20,16 @@ use darkfi::{
     zkas::decoder::ZkBinary,
 };
 
+// TODO: base58 encoding/ decoding
+
+lazy_static! {
+    pub static ref XDRK_ID: pallas::Base = pallas::Base::random(&mut OsRng);
+}
+
+lazy_static! {
+    pub static ref GDRK_ID: pallas::Base = pallas::Base::random(&mut OsRng);
+}
+
 #[derive(Eq, PartialEq)]
 pub struct HashableBase(pub pallas::Base);
 

Некоторые файлы не были показаны из-за большого количества измененных файлов