use std::sync::Arc;
use async_trait::async_trait;
use multiversx_sc_scenario::multiversx_sc::codec::TopDecodeMulti;
use num_bigint::BigUint;
use tokio::sync::Mutex;
use novax_data::{Address, NativeConvertible};
use crate::error::executor::ExecutorError;
use crate::TokenTransfer;
#[async_trait]
pub trait QueryExecutor: Send + Sync {
async fn execute<OutputManaged>(
&self,
to: &Address,
function: String,
arguments: Vec<Vec<u8>>,
egld_value: BigUint,
esdt_transfers: Vec<TokenTransfer>
) -> Result<OutputManaged::Native, ExecutorError>
where
OutputManaged: TopDecodeMulti + NativeConvertible + Send + Sync;
}
#[async_trait]
impl<T: QueryExecutor> QueryExecutor for Arc<T> {
async fn execute<OutputManaged>(
&self,
to: &Address,
function: String,
arguments: Vec<Vec<u8>>,
egld_value: BigUint,
esdt_transfers: Vec<TokenTransfer>
) -> Result<OutputManaged::Native, ExecutorError>
where
OutputManaged: TopDecodeMulti + NativeConvertible + Send + Sync
{
T::execute::<OutputManaged>(
self,
to,
function,
arguments,
egld_value,
esdt_transfers
).await
}
}
#[async_trait]
impl<T: QueryExecutor> QueryExecutor for Arc<Mutex<T>> {
async fn execute<OutputManaged>(
&self,
to: &Address,
function: String,
arguments: Vec<Vec<u8>>,
egld_value: BigUint,
esdt_transfers: Vec<TokenTransfer>
) -> Result<OutputManaged::Native, ExecutorError>
where
OutputManaged: TopDecodeMulti + NativeConvertible + Send + Sync
{
{
let executor = self.lock().await;
executor.execute::<OutputManaged>(
to,
function,
arguments,
egld_value,
esdt_transfers
).await
}
}
}