use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize)]
pub struct JsonRpcRequest<'a> {
pub jsonrpc: &'a str,
pub id: u64,
pub method: &'a str,
pub params: serde_json::Value,
}
impl<'a> JsonRpcRequest<'a> {
pub fn new(method: &'a str, params: serde_json::Value) -> Self {
Self {
jsonrpc: "2.0",
id: 1,
method,
params,
}
}
}
#[derive(Debug, Deserialize)]
pub struct JsonRpcResponse {
pub id: u64,
pub result: Option<serde_json::Value>,
pub error: Option<JsonRpcError>,
}
#[derive(Debug, Deserialize)]
pub struct JsonRpcError {
pub code: i64,
pub message: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Chain {
Ethereum,
Solana,
}
impl std::fmt::Display for Chain {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Chain::Ethereum => write!(f, "Ethereum"),
Chain::Solana => write!(f, "Solana"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionReceipt {
pub chain: Chain,
pub tx_hash: String,
}
impl std::fmt::Display for TransactionReceipt {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "[{}] tx: {}", self.chain, self.tx_hash)
}
}