use std::fmt::Debug;
use async_graphql::scalar;
use async_trait::async_trait;
use linera_base::http;
pub use linera_ethereum::{
client::EthereumQueries,
common::{EthereumDataType, EthereumEvent},
};
use linera_ethereum::{client::JsonRpcClient, common::EthereumServiceError};
use serde::{Deserialize, Serialize};
use crate::{
contract::wit::base_runtime_api as contract_wit, service::wit::base_runtime_api as service_wit,
};
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct ContractEthereumClient {
pub url: String,
}
scalar!(ContractEthereumClient);
impl ContractEthereumClient {
pub fn new(url: String) -> Self {
Self { url }
}
}
#[async_trait]
impl JsonRpcClient for ContractEthereumClient {
type Error = EthereumServiceError;
async fn get_id(&self) -> u64 {
1
}
async fn request_inner(&self, payload: Vec<u8>) -> Result<Vec<u8>, Self::Error> {
let response = contract_wit::perform_http_request(
&http::Request {
method: http::Method::Post,
url: self.url.clone(),
headers: Vec::from([http::Header::new("Content-Type", b"application/json")]),
body: payload,
}
.into(),
);
Ok(response.body)
}
}
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct ServiceEthereumClient {
pub url: String,
}
scalar!(ServiceEthereumClient);
impl ServiceEthereumClient {
pub fn new(url: String) -> Self {
Self { url }
}
}
#[async_trait]
impl JsonRpcClient for ServiceEthereumClient {
type Error = EthereumServiceError;
async fn get_id(&self) -> u64 {
1
}
async fn request_inner(&self, payload: Vec<u8>) -> Result<Vec<u8>, Self::Error> {
let response = service_wit::perform_http_request(
&http::Request {
method: http::Method::Post,
url: self.url.clone(),
headers: Vec::from([http::Header::new("Content-Type", b"application/json")]),
body: payload,
}
.into(),
);
Ok(response.body)
}
}