mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 22:28:12 -05:00
drk: get_balances() and prettytable
This commit is contained in:
106
Cargo.lock
generated
106
Cargo.lock
generated
@@ -697,6 +697,18 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.7.1"
|
||||
@@ -1144,6 +1156,28 @@ dependencies = [
|
||||
"crypto_api",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"csv-core",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv-core"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.1.21"
|
||||
@@ -1201,7 +1235,7 @@ dependencies = [
|
||||
"bytes 1.1.0",
|
||||
"clap",
|
||||
"crypto_api_chachapoly",
|
||||
"dirs",
|
||||
"dirs 4.0.0",
|
||||
"easy-parallel",
|
||||
"electrum-client",
|
||||
"ff",
|
||||
@@ -1212,6 +1246,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"log",
|
||||
"native-tls",
|
||||
"prettytable-rs",
|
||||
"rand 0.7.3",
|
||||
"rand_core 0.5.1",
|
||||
"rocksdb",
|
||||
@@ -1324,6 +1359,17 @@ dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users 0.3.5",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "4.0.0"
|
||||
@@ -1350,7 +1396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"redox_users 0.4.0",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
@@ -1361,7 +1407,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"redox_users 0.4.0",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
@@ -2788,6 +2834,20 @@ version = "0.2.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||
|
||||
[[package]]
|
||||
name = "prettytable-rs"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fd04b170004fa2daccf418a7f8253aaf033c27760b5f225889024cf66d7ac2e"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"csv",
|
||||
"encode_unicode",
|
||||
"lazy_static",
|
||||
"term",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "0.1.5"
|
||||
@@ -3136,6 +3196,17 @@ dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
|
||||
dependencies = [
|
||||
"getrandom 0.1.16",
|
||||
"redox_syscall 0.1.57",
|
||||
"rust-argon2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.0"
|
||||
@@ -3157,6 +3228,12 @@ dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.25"
|
||||
@@ -3258,6 +3335,18 @@ dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-argon2"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb"
|
||||
dependencies = [
|
||||
"base64 0.13.0",
|
||||
"blake2b_simd",
|
||||
"constant_time_eq",
|
||||
"crossbeam-utils 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.21"
|
||||
@@ -4288,6 +4377,17 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"dirs 1.0.5",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
|
||||
@@ -134,8 +134,8 @@ impl Darkfid {
|
||||
return JsonResult::Resp(jsonresp(json!(b58), id));
|
||||
}
|
||||
|
||||
// --> {"method": "get_key", "params": []}
|
||||
// <-- {"result": "balances": "[value: 0, token: btc]"}
|
||||
// --> {"method": "get_balances", "params": []}
|
||||
// <-- {"result": "get_balances": "[token: btc, value: 0]"}
|
||||
async fn get_balances(&self, id: Value, _params: Value) -> JsonResult {
|
||||
let result: Result<HashMap<String, u64>> = async {
|
||||
let balances = self.client.lock().await.get_balances().await?;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#[macro_use]
|
||||
extern crate prettytable;
|
||||
|
||||
use drk::cli::{Config, DrkConfig};
|
||||
use drk::util::{join_config_path, NetworkName};
|
||||
use drk::{rpc::jsonrpc, rpc::jsonrpc::JsonResult, Error, Result};
|
||||
@@ -38,7 +41,6 @@ impl Drk {
|
||||
|
||||
async fn request(&self, r: jsonrpc::JsonRequest) -> Result<Value> {
|
||||
let reply: JsonResult;
|
||||
debug!(target: "RPC", "--> {}", serde_json::to_string(&r)?);
|
||||
match jsonrpc::send_request(&self.url, json!(r)).await {
|
||||
Ok(v) => reply = v,
|
||||
Err(e) => return Err(e),
|
||||
@@ -97,8 +99,10 @@ impl Drk {
|
||||
Ok(self.request(req).await?)
|
||||
}
|
||||
|
||||
// --> {"method": "get_balances", "params": []}
|
||||
// <-- {"result": "get_balances": "[token: btc, value: 0]"}
|
||||
async fn get_balances(&self) -> Result<Value> {
|
||||
let req = jsonrpc::request(json!("get_balances"), json![()]);
|
||||
let req = jsonrpc::request(json!("get_balances"), json!([]));
|
||||
Ok(self.request(req).await?)
|
||||
}
|
||||
|
||||
@@ -169,6 +173,7 @@ async fn start(config: &DrkConfig, options: ArgMatches<'_>) -> Result<()> {
|
||||
|
||||
if matches.is_present("balances") {
|
||||
let reply = client.get_balances().await?;
|
||||
let _table = ptable!([reply]);
|
||||
println!("Server replied: {}", &reply.to_string());
|
||||
return Ok(());
|
||||
}
|
||||
@@ -260,6 +265,7 @@ async fn main() -> Result<()> {
|
||||
(@arg create: --create "Initialize a new wallet")
|
||||
(@arg keygen: --keygen "Generate wallet keypair")
|
||||
(@arg address: --address "Get wallet address")
|
||||
(@arg balances: --balances "Get wallet balances")
|
||||
)
|
||||
(@subcommand id =>
|
||||
(about: "Get hexidecimal ID for token symbol")
|
||||
|
||||
Reference in New Issue
Block a user