use crate::{Client, Result};
use serde::{de::DeserializeOwned, Deserialize};
#[must_use = "Does nothing until you send or execute it"]
pub struct StakeAssetRequest {
client: Client,
asset: String,
amount: String,
method: String, }
impl StakeAssetRequest {
pub async fn execute<T: DeserializeOwned>(self) -> Result<T> {
let query = format!(
"asset={}&amount={}&method={}",
self.asset, self.amount, self.method
);
self.client
.send_private("/0/private/Stake", Some(query))
.await
}
pub async fn send(self) -> Result<StakeAssetResponse> {
self.execute().await
}
}
#[derive(Debug, Deserialize)]
pub struct StakeAssetResponse {
refid: String,
}
impl Client {
pub fn stake_asset(&self, asset: &str, amount: &str, method: &str) -> StakeAssetRequest {
StakeAssetRequest {
client: self.clone(),
asset: asset.to_string(),
amount: amount.to_string(),
method: method.to_string(),
}
}
}