mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
drafted dummy features() method
This commit is contained in:
@@ -32,8 +32,8 @@ use ff::PrimeField;
|
||||
|
||||
// network: String specifier
|
||||
// asset_id: Token HEX
|
||||
struct Networks {
|
||||
supported_networks: Vec<String>,
|
||||
struct Features {
|
||||
networks: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -110,6 +110,7 @@ impl Cashierd {
|
||||
match req.method.as_str() {
|
||||
Some("deposit") => return self.deposit(req.id, req.params).await,
|
||||
Some("withdraw") => return self.withdraw(req.id, req.params).await,
|
||||
Some("features") => return self.features(req.id, req.params).await,
|
||||
Some(_) => {}
|
||||
None => {}
|
||||
};
|
||||
@@ -180,6 +181,11 @@ impl Cashierd {
|
||||
|
||||
JsonResult::Err(jsonerr(InvalidParams, None, id))
|
||||
}
|
||||
|
||||
// TODO: implement this
|
||||
async fn features(self, id: Value, _params: Value) -> JsonResult {
|
||||
JsonResult::Err(jsonerr(InvalidParams, None, id))
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
||||
@@ -64,6 +64,7 @@ impl Darkfid {
|
||||
Some("key_gen") => return self.key_gen(req.id, req.params).await,
|
||||
Some("get_key") => return self.get_key(req.id, req.params).await,
|
||||
Some("get_token_id") => return self.get_token_id(req.id, req.params).await,
|
||||
Some("features") => return self.features(req.id, req.params).await,
|
||||
Some("deposit") => return self.deposit(req.id, req.params).await,
|
||||
Some("withdraw") => return self.withdraw(req.id, req.params).await,
|
||||
Some("transfer") => return self.transfer(req.id, req.params).await,
|
||||
@@ -145,6 +146,26 @@ impl Darkfid {
|
||||
return JsonResult::Err(jsonerr(InvalidParams, None, id));
|
||||
}
|
||||
|
||||
// --> {"jsonrpc": "2.0", "method": "features", "params": [], "id": 42}
|
||||
// <-- {"jsonrpc": "2.0", "result": ["network": "btc", "sol"], "id": 42}
|
||||
async fn features(self, id: Value, params: Value) -> JsonResult {
|
||||
// TODO: return a dictionary of features
|
||||
let req = jsonreq(json!("features"), json!([]));
|
||||
let rep: JsonResult;
|
||||
match send_request(self.config.cashier_url, json!(req)).await {
|
||||
Ok(v) => rep = v,
|
||||
Err(e) => {
|
||||
return JsonResult::Err(jsonerr(ServerError(-32004), Some(e.to_string()), id))
|
||||
}
|
||||
}
|
||||
|
||||
match rep {
|
||||
JsonResult::Resp(r) => return JsonResult::Resp(r),
|
||||
JsonResult::Err(e) => return JsonResult::Err(e),
|
||||
JsonResult::Notif(_n) => return JsonResult::Err(jsonerr(InternalError, None, id)),
|
||||
}
|
||||
}
|
||||
|
||||
// --> {"jsonrpc": "2.0", "method": "deposit",
|
||||
// "params": [network, token, publickey],
|
||||
// "id": 42}
|
||||
|
||||
@@ -82,6 +82,13 @@ impl Drk {
|
||||
Ok(self.request(req).await?)
|
||||
}
|
||||
|
||||
// --> {"jsonrpc": "2.0", "method": "features", "params": [], "id": 42}
|
||||
// <-- {"jsonrpc": "2.0", "result": ["network": "btc", "sol"], "id": 42}
|
||||
async fn features(&self) -> Result<Value> {
|
||||
let req = jsonrpc::request(json!("features"), json!([]));
|
||||
Ok(self.request(req).await?)
|
||||
}
|
||||
|
||||
// --> {"jsonrpc": "2.0", "method": "deposit", "params": ["solana", "usdc"], "id": 42}
|
||||
// <-- {"jsonrpc": "2.0", "result": "Ht5G1RhkcKnpLVLMhqJc5aqZ4wYUEbxbtZwGCVbgU7DL", "id": 42}
|
||||
async fn deposit(&self, network: &str, asset: &str) -> Result<Value> {
|
||||
@@ -150,6 +157,12 @@ async fn start(config: &DrkConfig, options: ArgMatches<'_>) -> Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if options.is_present("features") {
|
||||
let reply = client.features().await?;
|
||||
println!("Server replied: {}", &reply.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(matches) = options.subcommand_matches("deposit") {
|
||||
let network = matches.value_of("network").unwrap().to_lowercase();
|
||||
let token = matches.value_of("TOKEN").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user