Skip to content

Commit

Permalink
bin/darkfid2: Add protocol as comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
parazyd committed Sep 17, 2021
1 parent 5290cc2 commit 017b5f9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/bin/darkfid2.rs
Expand Up @@ -106,24 +106,32 @@ impl Darkfid {
));
}

// --> {"method": "say_hello", "params": []}
// <-- {"result": "hello world"}
async fn say_hello(self, id: Value, _params: Value) -> JsonResult {
JsonResult::Resp(jsonrpc::response(json!("hello world"), id))
}

// --> {"method": "create_wallet", "params": []}
// <-- {"result": true}
async fn create_wallet(self, id: Value, _params: Value) -> JsonResult {
match self.wallet.init_db() {
Ok(()) => return JsonResult::Resp(jsonrpc::response(json!(true), id)),
Err(e) => return JsonResult::Err(jsonrpc::error(-69, e.to_string(), id)),
}
}

// --> {"method": "key_gen", "params": []}
// <-- {"result": true}
async fn key_gen(self, id: Value, _params: Value) -> JsonResult {
match self.wallet.key_gen() {
Ok((_, _)) => return JsonResult::Resp(jsonrpc::response(json!(true), id)),
Err(e) => return JsonResult::Err(jsonrpc::error(-69, e.to_string(), id)),
}
}

// --> {"method": "get_key", "params": []}
// <-- {"result": "vdNS7oBj7KvsMWWmo9r96SV4SqATLrGsH2a3PGpCfJC"}
async fn get_key(self, id: Value, _params: Value) -> JsonResult {
match self.wallet.get_keypairs() {
Ok(v) => {
Expand All @@ -140,6 +148,7 @@ impl Darkfid {
// "id": 42}
// The publickey sent here is used so the cashier can know where to send
// assets once the deposit is received.
// <-- {"result": "Ht5G1RhkcKnpLVLMhqJc5aqZ4wYUEbxbtZwGCVbgU7DL"}
async fn deposit(self, id: Value, params: Value) -> JsonResult {
let args = params.as_array().unwrap();
if args.len() != 2 {
Expand Down Expand Up @@ -182,6 +191,13 @@ impl Darkfid {
}
}

// --> {"method": "withdraw", "params": [network, token, publickey, amount]}
// The publickey sent here is the address where the caller wants to receive
// the tokens they plan to withdraw.
// On request, send request to cashier to get deposit address, and then transfer
// dark assets to the cashier's wallet. Following that, the cashier should return
// a transaction ID of them sending the funds that are requested for withdrawal.
// <-- {"result": "txID"}
async fn withdraw(self, id: Value, params: Value) -> JsonResult {
let args = params.as_array().unwrap();
if args.len() != 4 {
Expand All @@ -201,6 +217,8 @@ impl Darkfid {
return JsonResult::Err(jsonrpc::error(-69, "failed to withdraw".to_string(), id));
}

// --> {"method": "transfer", [dToken, address, amount]}
// <-- {"result": "txID"}
async fn transfer(self, id: Value, _params: Value) -> JsonResult {
return JsonResult::Err(jsonrpc::error(-69, "failed to transfer".to_string(), id));
}
Expand Down

0 comments on commit 017b5f9

Please sign in to comment.