use std::sync::Arc;
use crate::cosmos_client::CosmosClient;
use crate::market::error::MarketError;
use crate::tx_builder::TxBuilder;
use cosmrs::proto::cosmos::auth::v1beta1::BaseAccount;
use tendermint_rpc::endpoint::broadcast::tx_commit::Response;
pub struct MarketAdminClient {
pub public_market_client: MarketClient,
}
impl MarketAdminClient {
pub fn new(cosmos_client: Arc<CosmosClient>) -> Result<Self, MarketError> {
let public_market_client = MarketClient::new(cosmos_client)?;
Ok(MarketAdminClient {
public_market_client,
})
}
#[cfg(any(test, feature = "test_scenario"))]
pub fn from_scenario(
test_scenario: &crate::test_utils::test_scenario::TestScenario,
) -> Result<Self, MarketError> {
Self::new(test_scenario.cosmos_client.clone())
}
pub async fn account(&self, account_address: String) -> Result<BaseAccount, MarketError> {
self.public_market_client.account(account_address).await
}
pub async fn broadcast_tx(&self, signed_bytes: Vec<u8>) -> Result<Response, MarketError> {
self.public_market_client
.cosmos_client
.broadcast_tx(signed_bytes)
.await
.map_err(MarketError::CosmosClientError)
}
pub async fn execute_tx(&self, builder: TxBuilder) -> Result<Response, MarketError> {
self.public_market_client
.cosmos_client
.execute_tx(builder)
.await
.map_err(MarketError::CosmosClientError)
}
}
pub struct MarketClient {
pub(crate) cosmos_client: Arc<CosmosClient>,
}
impl MarketClient {
pub fn new(cosmos_client: Arc<CosmosClient>) -> Result<Self, MarketError> {
Ok(MarketClient { cosmos_client })
}
pub async fn account(&self, account_address: String) -> Result<BaseAccount, MarketError> {
self.cosmos_client
.account(account_address)
.await
.map_err(MarketError::CosmosClientError)
}
}
#[cfg(test)]
mod tests {
use crate::market::client::{MarketAdminClient, MarketClient};
use crate::test_utils::test_scenario::TestScenario;
#[tokio::test]
#[ignore]
async fn test_market_client() {
let test_scenario = TestScenario::new_from_config("config.json".to_string()).await;
MarketClient::new(test_scenario.cosmos_client).unwrap();
}
#[tokio::test]
#[ignore]
async fn test_market_admin_client() {
let test_scenario = TestScenario::new_from_config("config.json".to_string()).await;
MarketAdminClient::new(test_scenario.cosmos_client.clone()).unwrap();
}
}