mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
change the type of amount in TransferParams and WithdrawParams from
String to u64
This commit is contained in:
@@ -77,15 +77,13 @@ impl Drk {
|
||||
Ok(self.request(r).await?)
|
||||
}
|
||||
|
||||
// TODO: Should amount be an integer? Also, keep same order in array.
|
||||
pub async fn transfer(&self, address: String, amount: String) -> Result<()> {
|
||||
let r = jsonrpc::request(json!("transfer"), json!([amount, address]));
|
||||
pub async fn transfer(&self, address: String, amount: u64) -> Result<()> {
|
||||
let r = jsonrpc::request(json!("transfer"), json!([address, amount]));
|
||||
Ok(self.request(r).await?)
|
||||
}
|
||||
|
||||
// TODO: Should amount be an integer? Also, keep same order in array.
|
||||
pub async fn withdraw(&self, address: String, amount: String) -> Result<()> {
|
||||
let r = jsonrpc::request(json!("withdraw"), json!([amount, address]));
|
||||
pub async fn withdraw(&self, address: String, amount: u64) -> Result<()> {
|
||||
let r = jsonrpc::request(json!("withdraw"), json!([address, amount]));
|
||||
Ok(self.request(r).await?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,29 +2,27 @@
|
||||
use crate::Result;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use serde::Deserialize;
|
||||
|
||||
pub struct Transfer {
|
||||
pub pub_key: String,
|
||||
pub amount: String,
|
||||
fn is_u64<'a>(v: &'a str) -> std::result::Result<(), String> {
|
||||
if v.parse::<u64>().is_ok() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(String::from("The value is not an integer of type u64"))
|
||||
}
|
||||
}
|
||||
|
||||
impl Transfer {
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct TransferParams {
|
||||
pub pub_key: String,
|
||||
pub amount: u64,
|
||||
}
|
||||
|
||||
impl TransferParams {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
pub_key: String::new(),
|
||||
amount: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_amount(amount: &str) -> Result<()> {
|
||||
if amount.parse::<u64>().is_ok() || amount.parse::<f64>().is_ok() {
|
||||
Ok(())
|
||||
} else {
|
||||
let err = format!(
|
||||
"Unable to parse input amount as integer or float: {}",
|
||||
amount
|
||||
);
|
||||
Err(crate::Error::ParseFailed(Box::leak(err.into_boxed_str())))
|
||||
amount: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,28 +39,17 @@ impl Deposit {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Withdraw {
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct WithdrawParams {
|
||||
pub pub_key: String,
|
||||
pub amount: String,
|
||||
pub amount: u64,
|
||||
}
|
||||
|
||||
impl Withdraw {
|
||||
impl WithdrawParams {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
pub_key: String::new(),
|
||||
amount: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verify_amount(amount: &str) -> Result<()> {
|
||||
if amount.parse::<u64>().is_ok() || amount.parse::<f64>().is_ok() {
|
||||
Ok(())
|
||||
} else {
|
||||
let err = format!(
|
||||
"Unable to parse input amount as integer or float: {}",
|
||||
amount
|
||||
);
|
||||
Err(crate::Error::ParseFailed(Box::leak(err.into_boxed_str())))
|
||||
amount: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,9 +63,9 @@ pub struct DrkCli {
|
||||
pub info: bool,
|
||||
pub hello: bool,
|
||||
pub stop: bool,
|
||||
pub transfer: Option<Transfer>,
|
||||
pub transfer: Option<TransferParams>,
|
||||
pub deposit: Option<Deposit>,
|
||||
pub withdraw: Option<Withdraw>,
|
||||
pub withdraw: Option<WithdrawParams>,
|
||||
}
|
||||
|
||||
impl DrkCli {
|
||||
@@ -151,6 +138,7 @@ impl DrkCli {
|
||||
.value_name("AMOUNT")
|
||||
.takes_value(true)
|
||||
.index(2)
|
||||
.validator(is_u64)
|
||||
.help_heading(Some("Amount to send, in DBTC"))
|
||||
.required(true),
|
||||
),
|
||||
@@ -172,6 +160,7 @@ impl DrkCli {
|
||||
.value_name("AMOUNT")
|
||||
.takes_value(true)
|
||||
.index(2)
|
||||
.validator(is_u64)
|
||||
.help_heading(Some("Amount to send, in BTC"))
|
||||
.required(true),
|
||||
),
|
||||
@@ -222,13 +211,12 @@ impl DrkCli {
|
||||
let mut transfer = None;
|
||||
match app.subcommand_matches("transfer") {
|
||||
Some(transfer_sub) => {
|
||||
let mut trn = Transfer::new();
|
||||
let mut trn = TransferParams::new();
|
||||
if let Some(address) = transfer_sub.value_of("address") {
|
||||
trn.pub_key = address.to_string();
|
||||
}
|
||||
if let Some(amount) = transfer_sub.value_of("amount") {
|
||||
Transfer::verify_amount(amount)?;
|
||||
trn.amount = amount.to_string();
|
||||
trn.amount = amount.parse()?;
|
||||
}
|
||||
transfer = Some(trn);
|
||||
}
|
||||
@@ -238,13 +226,12 @@ impl DrkCli {
|
||||
let mut withdraw = None;
|
||||
match app.subcommand_matches("withdraw") {
|
||||
Some(withdraw_sub) => {
|
||||
let mut wdraw = Withdraw::new();
|
||||
let mut wdraw = WithdrawParams::new();
|
||||
if let Some(address) = withdraw_sub.value_of("address") {
|
||||
wdraw.pub_key = address.to_string();
|
||||
}
|
||||
if let Some(amount) = withdraw_sub.value_of("amount") {
|
||||
Transfer::verify_amount(amount)?;
|
||||
wdraw.amount = amount.to_string();
|
||||
wdraw.amount = amount.parse()?;
|
||||
}
|
||||
withdraw = Some(wdraw);
|
||||
}
|
||||
|
||||
@@ -8,5 +8,5 @@ pub use cashierd_cli::CashierdCli;
|
||||
pub use cli_config::{CashierdConfig, DarkfidConfig, DrkConfig, GatewaydConfig, Config};
|
||||
pub use darkfid_cli::DarkfidCli;
|
||||
pub use drk_cli::DrkCli;
|
||||
pub use drk_cli::Transfer;
|
||||
pub use drk_cli::{TransferParams, WithdrawParams};
|
||||
pub use gatewayd_cli::GatewaydCli;
|
||||
|
||||
@@ -2,8 +2,7 @@ use crate::service::btc::PubAddress;
|
||||
use crate::service::cashier::CashierClient;
|
||||
use crate::wallet::WalletDb;
|
||||
use crate::{Error, Result};
|
||||
|
||||
use super::TransferParams;
|
||||
use crate::cli::TransferParams;
|
||||
|
||||
use log::*;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use crate::cli::DarkfidConfig;
|
||||
use crate::rpc::adapter::RpcAdapter;
|
||||
use crate::{Error, Result};
|
||||
|
||||
use super::{TransferParams, WithdrawParams};
|
||||
use crate::cli::{TransferParams, WithdrawParams};
|
||||
|
||||
use async_executor::Executor;
|
||||
use async_native_tls::TlsAcceptor;
|
||||
@@ -250,7 +249,7 @@ impl RpcInterface {
|
||||
let self2 = self1.clone();
|
||||
async move {
|
||||
let parsed: TransferParams = params.parse().unwrap();
|
||||
let address = parsed.address.clone();
|
||||
let address = parsed.pub_key.clone();
|
||||
self2.adapter.transfer(parsed).await?;
|
||||
Ok(jsonrpc_core::Value::String(format!("Transfer To: {}", address)))
|
||||
}
|
||||
|
||||
@@ -3,18 +3,4 @@ pub mod jsonrpc;
|
||||
pub mod jsonserver;
|
||||
pub mod test;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct TransferParams {
|
||||
pub address: String,
|
||||
pub amount: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct WithdrawParams {
|
||||
address: String,
|
||||
amount: String,
|
||||
}
|
||||
|
||||
pub use adapter::{AdapterPtr, RpcAdapter};
|
||||
|
||||
Reference in New Issue
Block a user