|
@@ -1,3 +1,4 @@
|
|
|
|
|
+use crate::cli::Asset;
|
|
|
use crate::client::{Client, ClientFailed};
|
|
use crate::client::{Client, ClientFailed};
|
|
|
use crate::serial::{deserialize, serialize, Decodable};
|
|
use crate::serial::{deserialize, serialize, Decodable};
|
|
|
use crate::service::CashierClient;
|
|
use crate::service::CashierClient;
|
|
@@ -31,15 +32,15 @@ pub trait RpcClient {
|
|
|
|
|
|
|
|
/// transfer
|
|
/// transfer
|
|
|
#[rpc(name = "transfer")]
|
|
#[rpc(name = "transfer")]
|
|
|
- fn transfer(&self, asset_id: u64, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>>;
|
|
|
|
|
|
|
+ fn transfer(&self, asset: Asset, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>>;
|
|
|
|
|
|
|
|
/// withdraw
|
|
/// withdraw
|
|
|
#[rpc(name = "withdraw")]
|
|
#[rpc(name = "withdraw")]
|
|
|
- fn withdraw(&self, asset_id: u64, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>>;
|
|
|
|
|
|
|
+ fn withdraw(&self, asset: Asset, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>>;
|
|
|
|
|
|
|
|
/// deposit
|
|
/// deposit
|
|
|
#[rpc(name = "deposit")]
|
|
#[rpc(name = "deposit")]
|
|
|
- fn deposit(&self, asset_id: u64) -> BoxFuture<Result<String>>;
|
|
|
|
|
|
|
+ fn deposit(&self, asset: Asset) -> BoxFuture<Result<String>>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pub struct RpcClientAdapter {
|
|
pub struct RpcClientAdapter {
|
|
@@ -75,7 +76,7 @@ impl RpcClientAdapter {
|
|
|
|
|
|
|
|
async fn transfer_process(
|
|
async fn transfer_process(
|
|
|
client: Arc<Mutex<Client>>,
|
|
client: Arc<Mutex<Client>>,
|
|
|
- asset_id: u64,
|
|
|
|
|
|
|
+ asset: Asset,
|
|
|
address: Vec<u8>,
|
|
address: Vec<u8>,
|
|
|
amount: f64,
|
|
amount: f64,
|
|
|
) -> Result<String> {
|
|
) -> Result<String> {
|
|
@@ -90,7 +91,7 @@ impl RpcClientAdapter {
|
|
|
client
|
|
client
|
|
|
.lock()
|
|
.lock()
|
|
|
.await
|
|
.await
|
|
|
- .transfer(asset_id, address.clone(), amount)
|
|
|
|
|
|
|
+ .transfer(asset.id, address.clone(), amount)
|
|
|
.await?;
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(format!("transfered {} DRK to {}", amount, address))
|
|
Ok(format!("transfered {} DRK to {}", amount, address))
|
|
@@ -99,14 +100,14 @@ impl RpcClientAdapter {
|
|
|
async fn withdraw_process(
|
|
async fn withdraw_process(
|
|
|
client: Arc<Mutex<Client>>,
|
|
client: Arc<Mutex<Client>>,
|
|
|
cashier_client: Arc<Mutex<CashierClient>>,
|
|
cashier_client: Arc<Mutex<CashierClient>>,
|
|
|
- asset_id: u64,
|
|
|
|
|
|
|
+ asset: Asset,
|
|
|
address: Vec<u8>,
|
|
address: Vec<u8>,
|
|
|
amount: f64,
|
|
amount: f64,
|
|
|
) -> Result<String> {
|
|
) -> Result<String> {
|
|
|
let drk_public = cashier_client
|
|
let drk_public = cashier_client
|
|
|
.lock()
|
|
.lock()
|
|
|
.await
|
|
.await
|
|
|
- .withdraw(asset_id, address)
|
|
|
|
|
|
|
+ .withdraw(asset.id.clone(), address)
|
|
|
.await
|
|
.await
|
|
|
.map_err(|err| ClientFailed::from(err))?;
|
|
.map_err(|err| ClientFailed::from(err))?;
|
|
|
|
|
|
|
@@ -114,7 +115,7 @@ impl RpcClientAdapter {
|
|
|
client
|
|
client
|
|
|
.lock()
|
|
.lock()
|
|
|
.await
|
|
.await
|
|
|
- .transfer(asset_id, drk_addr.clone(), amount)
|
|
|
|
|
|
|
+ .transfer(asset.id.clone(), drk_addr.clone(), amount)
|
|
|
.await?;
|
|
.await?;
|
|
|
|
|
|
|
|
return Ok(format!(
|
|
return Ok(format!(
|
|
@@ -129,7 +130,7 @@ impl RpcClientAdapter {
|
|
|
async fn deposit_process<T>(
|
|
async fn deposit_process<T>(
|
|
|
client: Arc<Mutex<Client>>,
|
|
client: Arc<Mutex<Client>>,
|
|
|
cashier_client: Arc<Mutex<CashierClient>>,
|
|
cashier_client: Arc<Mutex<CashierClient>>,
|
|
|
- asset_id: u64,
|
|
|
|
|
|
|
+ asset: Asset,
|
|
|
) -> Result<String>
|
|
) -> Result<String>
|
|
|
where
|
|
where
|
|
|
T: Decodable + ToString,
|
|
T: Decodable + ToString,
|
|
@@ -138,7 +139,7 @@ impl RpcClientAdapter {
|
|
|
let coin_public = cashier_client
|
|
let coin_public = cashier_client
|
|
|
.lock()
|
|
.lock()
|
|
|
.await
|
|
.await
|
|
|
- .get_address(asset_id, deposit_addr)
|
|
|
|
|
|
|
+ .get_address(asset.id, deposit_addr)
|
|
|
.await
|
|
.await
|
|
|
.map_err(|err| ClientFailed::from(err))?;
|
|
.map_err(|err| ClientFailed::from(err))?;
|
|
|
|
|
|
|
@@ -172,12 +173,17 @@ impl RpcClient for RpcClientAdapter {
|
|
|
Self::key_gen_process(self.client.clone()).boxed()
|
|
Self::key_gen_process(self.client.clone()).boxed()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fn transfer(&self, asset_id: u64, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>> {
|
|
|
|
|
|
|
+ fn transfer(&self, asset: Asset, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>> {
|
|
|
debug!(target: "RPC USER ADAPTER", "transfer() [START]");
|
|
debug!(target: "RPC USER ADAPTER", "transfer() [START]");
|
|
|
- Self::transfer_process(self.client.clone(), asset_id, pub_key, amount).boxed()
|
|
|
|
|
|
|
+ Self::transfer_process(self.client.clone(), asset, pub_key, amount).boxed()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fn withdraw(&self, asset_id: u64, pub_key: Vec<u8>, amount: f64) -> BoxFuture<Result<String>> {
|
|
|
|
|
|
|
+ fn withdraw(
|
|
|
|
|
+ &self,
|
|
|
|
|
+ asset_id: Asset,
|
|
|
|
|
+ pub_key: Vec<u8>,
|
|
|
|
|
+ amount: f64,
|
|
|
|
|
+ ) -> BoxFuture<Result<String>> {
|
|
|
debug!(target: "RPC USER ADAPTER", "withdraw() [START]");
|
|
debug!(target: "RPC USER ADAPTER", "withdraw() [START]");
|
|
|
Self::withdraw_process(
|
|
Self::withdraw_process(
|
|
|
self.client.clone(),
|
|
self.client.clone(),
|
|
@@ -189,7 +195,7 @@ impl RpcClient for RpcClientAdapter {
|
|
|
.boxed()
|
|
.boxed()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fn deposit(&self, asset_id: u64) -> BoxFuture<Result<String>> {
|
|
|
|
|
|
|
+ fn deposit(&self, asset_id: Asset) -> BoxFuture<Result<String>> {
|
|
|
debug!(target: "RPC USER ADAPTER", "deposit() [START]");
|
|
debug!(target: "RPC USER ADAPTER", "deposit() [START]");
|
|
|
#[cfg(feature = "default")]
|
|
#[cfg(feature = "default")]
|
|
|
Self::deposit_process::<bitcoin::PublicKey>(
|
|
Self::deposit_process::<bitcoin::PublicKey>(
|