use serde::{Deserialize, Serialize};
use crate::types::{Address, ChainId, HexData, LogQuery, RawLog, TransactionHash};
use super::signer::Signer;
use super::transaction::{BlockInfo, TransactionReceipt, TransactionRequest};
#[expect(
async_fn_in_trait,
reason = "the trait surface adopts native async fn in trait per ADR 0010 runtime-neutral posture; the resulting non-Send futures are covered by the workspace future_not_send allow so wasm callbacks can satisfy the same trait without an explicit Send bound"
)]
pub trait Provider {
type Error;
async fn get_chain_id(&self) -> Result<ChainId, Self::Error>;
async fn get_code(&self, address: &Address) -> Result<Option<HexData>, Self::Error>;
async fn get_transaction_receipt(
&self,
transaction_hash: &TransactionHash,
) -> Result<Option<TransactionReceipt>, Self::Error>;
async fn call(&self, tx: &TransactionRequest) -> Result<HexData, Self::Error>;
async fn read_contract(&self, request: &ContractCall) -> Result<String, Self::Error>;
async fn get_block(&self, block_tag: &str) -> Result<BlockInfo, Self::Error>;
}
#[expect(
async_fn_in_trait,
reason = "the trait surface adopts native async fn in trait per ADR 0010 runtime-neutral posture; the resulting non-Send futures are covered by the workspace future_not_send allow so wasm callbacks can satisfy the same trait without an explicit Send bound"
)]
pub trait SigningProvider: Provider {
type Signer: Signer<Error = Self::Error>;
async fn create_signer(&self, signer_hint: &str) -> Result<Self::Signer, Self::Error>;
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown", feature = "ts-bindings"),
derive(tsify::Tsify)
)]
#[cfg_attr(
all(target_arch = "wasm32", target_os = "unknown", feature = "ts-bindings"),
tsify(into_wasm_abi, from_wasm_abi)
)]
#[serde(rename_all = "camelCase")]
pub struct ContractCall {
pub address: Address,
pub method: String,
pub abi_json: String,
pub args_json: String,
}
impl ContractCall {
#[inline]
#[must_use]
pub const fn new(
address: Address,
method: String,
abi_json: String,
args_json: String,
) -> Self {
Self {
address,
method,
abi_json,
args_json,
}
}
}
#[expect(
async_fn_in_trait,
reason = "the trait surface adopts native async fn in trait per ADR 0010 runtime-neutral posture; the resulting non-Send futures are covered by the workspace future_not_send allow so wasm callbacks can satisfy the same trait without an explicit Send bound"
)]
pub trait LogProvider: Provider {
async fn get_logs(&self, query: &LogQuery) -> Result<Vec<RawLog>, Self::Error>;
}