use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Cap {
pub name: String,
pub args: Vec<Value>,
}
impl Cap {
pub fn new(name: &str) -> Self {
Self {
name: name.to_string(),
args: Vec::new(),
}
}
pub fn with_args(name: &str, args: Vec<Value>) -> Self {
Self {
name: name.to_string(),
args,
}
}
pub fn add_arg<T: Into<Value>>(mut self, arg: T) -> Self {
self.args.push(arg.into());
self
}
pub fn transfer(from: &str, to: &str, amount: f64) -> Self {
Self::with_args("coin.TRANSFER", vec![json!(from), json!(to), json!(amount)])
}
}