use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde::de::DeserializeOwned;
use super::*;
pub async fn request<T, R>(api: &Pegnetd, req: R) -> ApiResponse<T>
where T: DeserializeOwned + Default,
R: Serialize
{
let response = api.client
.post(api.node)
.json(&req)
.send()
.await
.unwrap()
.json()
.await
.unwrap();
response
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiRequest {
pub jsonrpc: &'static str,
pub id: usize,
pub method: String,
pub params: HashMap<String, Value>
}
impl ApiRequest{
pub fn new(method: &str) -> ApiRequest{
ApiRequest {
jsonrpc: JSONRPC,
id: ID,
method: method.to_string(),
params: HashMap::new()
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TxsApiRequest {
pub jsonrpc: &'static str,
pub id: usize,
pub method: String,
pub params: Value
}
impl TxsApiRequest{
pub fn new(method: &str) -> Self{
Self {
jsonrpc: JSONRPC,
id: ID,
method: method.to_string(),
params: json!(null)
}
}
}