use serde::de::DeserializeOwned;
use crate::obs::{Log, Metric};
use crate::types::Trade;
use crate::{Result, State, Wallet, host};
#[derive(Clone, Copy)]
pub struct Ctx;
impl Ctx {
pub fn config<T: DeserializeOwned>(&self) -> Result<T> {
Ok(serde_json::from_slice(&host::config_raw())?)
}
pub async fn price(&self, token: &str) -> Result<f64> {
host::price(token).await
}
pub fn wallet(&self) -> Wallet {
Wallet
}
pub fn rpc(&self) -> Rpc {
Rpc
}
pub fn state(&self) -> State {
State
}
pub fn log(&self) -> Log {
Log
}
pub fn metric(&self) -> Metric {
Metric
}
pub fn emit(&self, trade: Trade) {
let bytes = serde_json::to_vec(&trade).unwrap_or_default();
host::emit(&bytes);
}
}
pub struct Rpc;
impl Rpc {
pub async fn submit_tx(&self, signed_tx: &[u8]) -> Result<String> {
host::submit_tx(signed_tx).await
}
}