use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Meta {
#[serde(rename = "chainId")]
pub chain_id: String,
pub sender: String,
#[serde(rename = "gasLimit")]
pub gas_limit: u64,
#[serde(rename = "gasPrice")]
pub gas_price: f64,
pub ttl: u64,
#[serde(rename = "creationTime")]
pub creation_time: u64,
}
impl Meta {
pub fn new(chain_id: &str, sender: &str) -> Self {
Self {
chain_id: chain_id.to_string(),
sender: sender.to_string(),
gas_limit: 1500, gas_price: 0.00000001, ttl: 3600, creation_time: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs(),
}
}
pub fn with_params(
chain_id: &str,
sender: &str,
gas_limit: u64,
gas_price: f64,
ttl: u64,
creation_time: u64,
) -> Self {
Self {
chain_id: chain_id.to_string(),
sender: sender.to_string(),
gas_limit,
gas_price,
ttl,
creation_time,
}
}
pub fn with_gas_limit(mut self, gas_limit: u64) -> Self {
self.gas_limit = gas_limit;
self
}
pub fn with_gas_price(mut self, gas_price: f64) -> Self {
self.gas_price = gas_price;
self
}
pub fn with_ttl(mut self, ttl: u64) -> Self {
self.ttl = ttl;
self
}
}