Skip to content

Commit

Permalink
feat(voyager): refactor message types
Browse files Browse the repository at this point in the history
now with more gats!
  • Loading branch information
benluelo committed Oct 19, 2023
1 parent 5716391 commit 758450a
Show file tree
Hide file tree
Showing 26 changed files with 1,261 additions and 1,253 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 28 additions & 37 deletions lib/chain-utils/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Display, ops::Div, str::FromStr, sync::Arc};
use std::{ops::Div, str::FromStr, sync::Arc};

use beacon_api::client::BeaconApiClient;
use contracts::{
Expand Down Expand Up @@ -40,13 +40,12 @@ use unionlabs::{
google::protobuf::any::Any,
lightclients::{cometbls, ethereum, tendermint::fraction::Fraction, wasm},
},
id::{ChannelId, Id, IdParseError},
id_type,
id::{ChannelId, ClientId, ConnectionId},
traits::{Chain, ClientState},
EmptyString, TryFromEthAbiErrorOf, TryFromProto,
};

use crate::{chain_client_id, private_key::PrivateKey, ChainEvent, EventSource, Pool};
use crate::{private_key::PrivateKey, ChainEvent, EventSource, Pool};

pub type CometblsMiddleware =
SignerMiddleware<NonceManagerMiddleware<Provider<Ws>>, Wallet<ecdsa::SigningKey>>;
Expand Down Expand Up @@ -95,7 +94,7 @@ impl<C: ChainSpec> Chain for Evm<C> {

type ClientId = EvmClientId;

type ClientType = EvmClientType;
type ClientType = String;

fn chain_id(&self) -> <Self::SelfClientState as ClientState>::ChainId {
self.chain_id
Expand Down Expand Up @@ -412,13 +411,7 @@ impl<C: ChainSpec> Evm<C> {
}
}

chain_client_id! {
#[ty = EvmClientType]
pub enum EvmClientId {
#[id(ty = "cometbls")]
Cometbls(Id<_>),
}
}
pub type EvmClientId = ClientId;

#[derive(Debug)]
pub enum EvmEventSourceError {
Expand All @@ -436,9 +429,9 @@ pub enum EvmEventSourceError {
ConnectionOpenInitConnectionConversion(
TryFromEthAbiErrorOf<ConnectionEnd<EvmClientId, String, EmptyString>>,
),
Parse(IdParseError),
ClientTypeParse(<EvmClientType as FromStr>::Err),
ClientIdParse(<EvmClientId as FromStr>::Err),
ClientIdParse(<ClientId as FromStr>::Err),
ConnectionIdParse(<ConnectionId as FromStr>::Err),
ChannelIdParse(<ChannelId as FromStr>::Err),
EthAbi(ethers::core::abi::Error),
}

Expand Down Expand Up @@ -569,13 +562,13 @@ impl<C: ChainSpec> EventSource for Evm<C> {
.packet
.source_channel
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
packet_dst_port: packet_ack.packet.destination_port,
packet_dst_channel: packet_ack
.packet
.destination_channel
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
packet_channel_ordering: channel_data.ordering,
connection_id: channel_data.connection_hops[0].clone(),
}))
Expand All @@ -592,13 +585,13 @@ impl<C: ChainSpec> EventSource for Evm<C> {
channel_id: event
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
counterparty_port_id: channel.counterparty.port_id,
counterparty_channel_id: channel
.counterparty
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
connection_id: channel.connection_hops[0].clone(),
}))
}
Expand All @@ -612,13 +605,13 @@ impl<C: ChainSpec> EventSource for Evm<C> {
channel_id: event
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
counterparty_port_id: channel.counterparty.port_id,
counterparty_channel_id: channel
.counterparty
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
connection_id: channel.connection_hops[0].clone(),
}))
}
Expand All @@ -632,14 +625,14 @@ impl<C: ChainSpec> EventSource for Evm<C> {
channel_id: event
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
// TODO: Ensure that event.counterparty_channel_id is `EmptyString`
counterparty_channel_id: EmptyString,
counterparty_port_id: event.counterparty_port_id,
connection_id: event
.connection_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ConnectionIdParse)?,
version: channel.version,
}))
}
Expand All @@ -653,17 +646,17 @@ impl<C: ChainSpec> EventSource for Evm<C> {
channel_id: event
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
counterparty_port_id: event.counterparty_port_id,
counterparty_channel_id: channel
.counterparty
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
connection_id: event
.connection_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ConnectionIdParse)?,
version: event.version,
}))
}
Expand All @@ -675,7 +668,7 @@ impl<C: ChainSpec> EventSource for Evm<C> {
connection_id: event
.connection_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ConnectionIdParse)?,
client_id: connection.client_id,
counterparty_client_id: connection.counterparty.client_id,
counterparty_connection_id: connection
Expand All @@ -691,7 +684,7 @@ impl<C: ChainSpec> EventSource for Evm<C> {
connection_id: event
.connection_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ConnectionIdParse)?,
client_id: connection.client_id,
counterparty_client_id: connection.counterparty.client_id,
counterparty_connection_id: connection
Expand Down Expand Up @@ -725,7 +718,7 @@ impl<C: ChainSpec> EventSource for Evm<C> {
connection_id: event
.connection_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ConnectionIdParse)?,
client_id: connection.client_id,
counterparty_client_id: connection.counterparty.client_id,
counterparty_connection_id: connection
Expand All @@ -741,7 +734,7 @@ impl<C: ChainSpec> EventSource for Evm<C> {
connection_id: event
.connection_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ConnectionIdParse)?,
client_id: connection.client_id,
counterparty_client_id: connection.counterparty.client_id,
counterparty_connection_id: connection
Expand Down Expand Up @@ -778,9 +771,7 @@ impl<C: ChainSpec> EventSource for Evm<C> {
.0
.parse()
.map_err(EvmEventSourceError::ClientIdParse)?,
client_type: client_type
.parse()
.map_err(EvmEventSourceError::ClientTypeParse)?,
client_type,
consensus_height: client_state.0.latest_height,
}))
}
Expand All @@ -801,13 +792,13 @@ impl<C: ChainSpec> EventSource for Evm<C> {
.packet
.source_channel
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
packet_dst_port: event.packet.destination_port,
packet_dst_channel: event
.packet
.destination_channel
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
packet_channel_ordering: channel.ordering,
connection_id: channel.connection_hops[0].clone(),
}))
Expand All @@ -828,15 +819,15 @@ impl<C: ChainSpec> EventSource for Evm<C> {
packet_src_channel: event
.source_channel
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
// REVIEW: Should we query the packet instead? Or is that the same info? Is it even possible to
// query packets from the evm?
packet_dst_port: channel.counterparty.port_id,
packet_dst_channel: channel
.counterparty
.channel_id
.parse()
.map_err(EvmEventSourceError::Parse)?,
.map_err(EvmEventSourceError::ChannelIdParse)?,
packet_channel_ordering: channel.ordering,
connection_id: channel.connection_hops[0].clone(),
}))
Expand Down
Loading

0 comments on commit 758450a

Please sign in to comment.