clone_cw_multi_test/wasm_emulation/
channel.rs

1use anyhow::Result as AnyResult;
2use cw_orch::daemon::GrpcChannel;
3use tokio::runtime::{Handle, Runtime};
4use tonic::transport::Channel;
5
6/// Simple helper to get the GRPC transport channel
7fn get_channel(
8    grpc_urls: &[String],
9    chain_id: impl Into<String>,
10    rt: &Runtime,
11) -> anyhow::Result<tonic::transport::Channel> {
12    let channel = rt.block_on(GrpcChannel::connect(grpc_urls, &chain_id.into()))?;
13    Ok(channel)
14}
15
16#[derive(Clone)]
17pub struct RemoteChannel {
18    pub rt: Handle,
19    pub channel: Channel,
20    pub pub_address_prefix: String,
21    // For caching
22    pub chain_id: String,
23}
24
25impl RemoteChannel {
26    pub fn new(
27        rt: &Runtime,
28        grpc_urls: &[&str],
29        chain_id: impl Into<String>,
30        pub_address_prefix: impl Into<String>,
31    ) -> AnyResult<Self> {
32        let chain_id = chain_id.into();
33        Ok(Self {
34            rt: rt.handle().clone(),
35            channel: get_channel(
36                &grpc_urls
37                    .iter()
38                    .cloned()
39                    .map(Into::into)
40                    .collect::<Vec<_>>(),
41                chain_id.clone(),
42                rt,
43            )?,
44            pub_address_prefix: pub_address_prefix.into(),
45            chain_id,
46        })
47    }
48}