diff --git a/cosmwasm/cw20-ics20/src/contract.rs b/cosmwasm/cw20-ics20/src/contract.rs index 56aaec1c61..c1483d7735 100644 --- a/cosmwasm/cw20-ics20/src/contract.rs +++ b/cosmwasm/cw20-ics20/src/contract.rs @@ -1,8 +1,8 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - from_binary, to_binary, Addr, Binary, Deps, DepsMut, Env, IbcChannel, IbcMsg, IbcQuery, - MessageInfo, Order, PortIdResponse, Response, StdError, StdResult, + from_binary, to_binary, Addr, Binary, Deps, DepsMut, Env, IbcMsg, IbcQuery, MessageInfo, Order, + PortIdResponse, Response, StdError, StdResult, }; use cw2::{get_contract_version, set_contract_version}; use cw20::{Cw20Coin, Cw20ReceiveMsg}; diff --git a/lib/unionlabs/src/ethereum/beacon.rs b/lib/unionlabs/src/ethereum/beacon.rs index 52d0214817..242125f085 100644 --- a/lib/unionlabs/src/ethereum/beacon.rs +++ b/lib/unionlabs/src/ethereum/beacon.rs @@ -339,7 +339,7 @@ mod tests { assert_proto_roundtrip(&finality_update.attested_header); - dbg!(U256::from_dec_str("77")); + dbg!(U256::from_dec_str("77").unwrap()); assert_eq!( finality_update diff --git a/lib/unionlabs/src/ibc/core/channel/channel.rs b/lib/unionlabs/src/ibc/core/channel/channel.rs index 3201a1c54f..6b8fb3ef3a 100644 --- a/lib/unionlabs/src/ibc/core/channel/channel.rs +++ b/lib/unionlabs/src/ibc/core/channel/channel.rs @@ -1,7 +1,7 @@ use crate::{ errors::MissingField, ibc::core::channel::{counterparty::Counterparty, order::Order, state::State}, - IntoProto, TryFromProto, TypeUrl, + Proto, TypeUrl, }; #[derive(Debug, Clone)] @@ -43,11 +43,7 @@ impl TryFrom for Channel { } } -impl IntoProto for Channel { - type Proto = protos::ibc::core::channel::v1::Channel; -} - -impl TryFromProto for Channel { +impl Proto for Channel { type Proto = protos::ibc::core::channel::v1::Channel; } diff --git a/lib/unionlabs/src/ibc/core/channel/packet.rs b/lib/unionlabs/src/ibc/core/channel/packet.rs index 3df0442a68..ef61765429 100644 --- a/lib/unionlabs/src/ibc/core/channel/packet.rs +++ b/lib/unionlabs/src/ibc/core/channel/packet.rs @@ -1,6 +1,4 @@ -use crate::{ - errors::MissingField, ibc::core::client::height::Height, IntoProto, TryFromProto, TypeUrl, -}; +use crate::{errors::MissingField, ibc::core::client::height::Height, Proto, TypeUrl}; #[derive(Debug, Clone)] pub struct Packet { @@ -14,11 +12,7 @@ pub struct Packet { pub timeout_timestamp: u64, } -impl IntoProto for Packet { - type Proto = protos::ibc::core::channel::v1::Packet; -} - -impl TryFromProto for Packet { +impl Proto for Packet { type Proto = protos::ibc::core::channel::v1::Packet; } diff --git a/lib/unionlabs/src/ibc/core/connection/connection_end.rs b/lib/unionlabs/src/ibc/core/connection/connection_end.rs index fb9ab7aea1..6fb3814338 100644 --- a/lib/unionlabs/src/ibc/core/connection/connection_end.rs +++ b/lib/unionlabs/src/ibc/core/connection/connection_end.rs @@ -1,7 +1,7 @@ use crate::{ errors::{MissingField, UnknownEnumVariant}, ibc::core::connection::{counterparty::Counterparty, state::State, version::Version}, - IntoProto, TryFromProto, TypeUrl, + Proto, TypeUrl, }; #[derive(Debug, Clone)] @@ -52,11 +52,7 @@ impl TryFrom for ConnectionEnd } } -impl IntoProto for ConnectionEnd { - type Proto = protos::ibc::core::connection::v1::ConnectionEnd; -} - -impl TryFromProto for ConnectionEnd { +impl Proto for ConnectionEnd { type Proto = protos::ibc::core::connection::v1::ConnectionEnd; } diff --git a/lib/unionlabs/src/ibc/google/protobuf/any.rs b/lib/unionlabs/src/ibc/google/protobuf/any.rs index 7494243359..babddf8029 100644 --- a/lib/unionlabs/src/ibc/google/protobuf/any.rs +++ b/lib/unionlabs/src/ibc/google/protobuf/any.rs @@ -7,7 +7,9 @@ use serde::{ Deserialize, Serialize, }; -use crate::{CosmosAccountId, IntoProto, MsgIntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl}; +use crate::{ + CosmosAccountId, IntoProto, MsgIntoProto, Proto, TryFromProto, TryFromProtoErrorOf, TypeUrl, +}; /// Wrapper type to indicate that a type is to be serialized as an Any. #[derive(Debug, Clone)] @@ -16,7 +18,6 @@ pub struct Any(pub T); impl<'de, T> Deserialize<'de> for Any where T: Deserialize<'de> + TryFromProto, - ::Proto: TypeUrl, { fn deserialize(deserializer: D) -> Result where @@ -27,7 +28,6 @@ where impl<'de, T> Visitor<'de> for AnyVisitor where T: Deserialize<'de> + TryFromProto, - ::Proto: TypeUrl, { type Value = Any; @@ -81,7 +81,6 @@ where impl Serialize for Any where T: Serialize + IntoProto, - ::Proto: TypeUrl, { fn serialize(&self, serializer: S) -> Result where @@ -97,20 +96,18 @@ where impl From> for protos::google::protobuf::Any where T: IntoProto, - ::Proto: TypeUrl, { fn from(val: Any) -> Self { protos::google::protobuf::Any { - type_url: ::Proto::TYPE_URL.to_string(), + type_url: ::Proto::TYPE_URL.to_string(), value: val.0.into_proto().encode_to_vec(), } } } -impl IntoProto for Any +impl Proto for Any where T: IntoProto, - ::Proto: TypeUrl, { type Proto = protos::google::protobuf::Any; } @@ -151,8 +148,8 @@ where impl TryFrom for Any where T: TryFromProto, - T::Proto: TypeUrl + Default, - >::Error: Debug, + T::Proto: Default, + TryFromProtoErrorOf: Debug, { type Error = TryFromAnyError; @@ -171,12 +168,3 @@ where } } } - -impl TryFromProto for Any -where - T: TryFromProto, - T::Proto: TypeUrl + Default, - TryFromProtoErrorOf: Debug, -{ - type Proto = protos::google::protobuf::Any; -} diff --git a/lib/unionlabs/src/ibc/lightclients/cometbls/client_state.rs b/lib/unionlabs/src/ibc/lightclients/cometbls/client_state.rs index 9ef1839180..af16218f44 100644 --- a/lib/unionlabs/src/ibc/lightclients/cometbls/client_state.rs +++ b/lib/unionlabs/src/ibc/lightclients/cometbls/client_state.rs @@ -6,7 +6,7 @@ use crate::{ core::client::height::Height, google::protobuf::duration::Duration, lightclients::tendermint::fraction::Fraction, }, - IntoProto, TryFromProto, TypeUrl, + Proto, TypeUrl, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -36,11 +36,7 @@ impl TypeUrl for protos::union::ibc::lightclients::cometbls::v1::ClientState { const TYPE_URL: &'static str = "/union.ibc.lightclients.cometbls.v1.ClientState"; } -impl IntoProto for ClientState { - type Proto = protos::union::ibc::lightclients::cometbls::v1::ClientState; -} - -impl TryFromProto for ClientState { +impl Proto for ClientState { type Proto = protos::union::ibc::lightclients::cometbls::v1::ClientState; } diff --git a/lib/unionlabs/src/ibc/lightclients/cometbls/consensus_state.rs b/lib/unionlabs/src/ibc/lightclients/cometbls/consensus_state.rs index 72cf215a79..11731a08a0 100644 --- a/lib/unionlabs/src/ibc/lightclients/cometbls/consensus_state.rs +++ b/lib/unionlabs/src/ibc/lightclients/cometbls/consensus_state.rs @@ -1,7 +1,4 @@ -use crate::{ - errors::MissingField, ibc::core::commitment::merkle_root::MerkleRoot, IntoProto, TryFromProto, - TypeUrl, -}; +use crate::{errors::MissingField, ibc::core::commitment::merkle_root::MerkleRoot, Proto, TypeUrl}; #[derive(Debug, Clone)] pub struct ConsensusState { @@ -26,11 +23,7 @@ impl TypeUrl for protos::union::ibc::lightclients::cometbls::v1::ConsensusState const TYPE_URL: &'static str = "/union.ibc.lightclients.cometbls.v1.ConsensusState"; } -impl IntoProto for ConsensusState { - type Proto = protos::union::ibc::lightclients::cometbls::v1::ConsensusState; -} - -impl TryFromProto for ConsensusState { +impl Proto for ConsensusState { type Proto = protos::union::ibc::lightclients::cometbls::v1::ConsensusState; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/account_update.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/account_update.rs index 276331e2e8..fda6a60ca6 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/account_update.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/account_update.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{ibc::lightclients::ethereum::proof::Proof, FromProto, IntoProto, TypeUrl}; +use crate::{ibc::lightclients::ethereum::proof::Proof, Proto, TypeUrl}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct AccountUpdate { @@ -23,11 +23,7 @@ impl From for Acc } } -impl IntoProto for AccountUpdate { - type Proto = protos::union::ibc::lightclients::ethereum::v1::AccountUpdate; -} - -impl FromProto for AccountUpdate { +impl Proto for AccountUpdate { type Proto = protos::union::ibc::lightclients::ethereum::v1::AccountUpdate; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/beacon_block_header.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/beacon_block_header.rs index 90d0879fd3..4a18e3c57c 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/beacon_block_header.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/beacon_block_header.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use ssz::{Decode, Encode}; use tree_hash::TreeHash; -use crate::{errors::InvalidLength, ethereum::H256, IntoProto, TryFromProto, TypeUrl}; +use crate::{errors::InvalidLength, ethereum::H256, Proto, TypeUrl}; #[derive(Clone, Debug, PartialEq, Encode, Decode, TreeHash, Serialize, Deserialize)] pub struct BeaconBlockHeader { @@ -65,10 +65,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::BeaconBlockHead const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.BeaconBlockHeader"; } -impl TryFromProto for BeaconBlockHeader { - type Proto = protos::union::ibc::lightclients::ethereum::v1::BeaconBlockHeader; -} - -impl IntoProto for BeaconBlockHeader { +impl Proto for BeaconBlockHeader { type Proto = protos::union::ibc::lightclients::ethereum::v1::BeaconBlockHeader; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/client_state.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/client_state.rs index 288828c7f2..34e859d77f 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/client_state.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/client_state.rs @@ -7,7 +7,7 @@ use crate::{ core::client::height::Height, lightclients::{ethereum::fork_parameters::ForkParameters, tendermint::fraction::Fraction}, }, - IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + Proto, TryFromProtoErrorOf, TypeUrl, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -30,7 +30,7 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::ClientState { const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.ClientState"; } -impl IntoProto for ClientState { +impl Proto for ClientState { type Proto = protos::union::ibc::lightclients::ethereum::v1::ClientState; } @@ -96,7 +96,3 @@ impl TryFrom for Cl }) } } - -impl TryFromProto for ClientState { - type Proto = protos::union::ibc::lightclients::ethereum::v1::ClientState; -} diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/consensus_state.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/consensus_state.rs index 9711cff67d..1933af0b8a 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/consensus_state.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/consensus_state.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{ - bls::BlsPublicKey, errors::InvalidLength, ethereum::H256, IntoProto, TryFromProto, TypeUrl, -}; +use crate::{bls::BlsPublicKey, errors::InvalidLength, ethereum::H256, Proto, TypeUrl}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ConsensusState { @@ -68,14 +66,10 @@ impl TryFrom for } } -impl IntoProto for ConsensusState { +impl Proto for ConsensusState { type Proto = protos::union::ibc::lightclients::ethereum::v1::ConsensusState; } impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::ConsensusState { const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.ConsensusState"; } - -impl TryFromProto for ConsensusState { - type Proto = protos::union::ibc::lightclients::ethereum::v1::ConsensusState; -} diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs index ce1caef094..568d35bd2b 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/execution_payload_header.rs @@ -8,7 +8,7 @@ use crate::{ errors::InvalidLength, ethereum::{Address, H256}, ethereum_consts_traits::{BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES}, - IntoProto, TryFromProto, TypeUrl, + Proto, TypeUrl, }; #[derive(Clone, Debug, PartialEq, Encode, Decode, TreeHash, Serialize, Deserialize)] @@ -153,10 +153,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::ExecutionPayloa const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.ExecutionPayloadHeader"; } -impl TryFromProto for ExecutionPayloadHeader { - type Proto = protos::union::ibc::lightclients::ethereum::v1::ExecutionPayloadHeader; -} - -impl IntoProto for ExecutionPayloadHeader { +impl Proto for ExecutionPayloadHeader { type Proto = protos::union::ibc::lightclients::ethereum::v1::ExecutionPayloadHeader; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/fork.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/fork.rs index 6f4c843fa4..444960418a 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/fork.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/fork.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use ssz::{Decode, Encode}; -use crate::{errors::InvalidLength, ethereum::Version, IntoProto, TryFromProto, TypeUrl}; +use crate::{errors::InvalidLength, ethereum::Version, Proto, TypeUrl}; #[derive(Debug, Clone, PartialEq, Encode, Decode, Serialize, Deserialize)] pub struct Fork { @@ -35,10 +35,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::Fork { const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.Fork"; } -impl IntoProto for Fork { - type Proto = protos::union::ibc::lightclients::ethereum::v1::Fork; -} - -impl TryFromProto for Fork { +impl Proto for Fork { type Proto = protos::union::ibc::lightclients::ethereum::v1::Fork; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/fork_parameters.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/fork_parameters.rs index 45b97662e3..eee3c63e4d 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/fork_parameters.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/fork_parameters.rs @@ -5,7 +5,7 @@ use crate::{ errors::{InvalidLength, MissingField}, ethereum::Version, ibc::lightclients::ethereum::fork::Fork, - IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + Proto, TryFromProtoErrorOf, TypeUrl, }; #[derive(Debug, Clone, PartialEq, Encode, Decode, Serialize, Deserialize)] @@ -86,10 +86,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::ForkParameters const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.ForkParameters"; } -impl IntoProto for ForkParameters { - type Proto = protos::union::ibc::lightclients::ethereum::v1::ForkParameters; -} - -impl TryFromProto for ForkParameters { +impl Proto for ForkParameters { type Proto = protos::union::ibc::lightclients::ethereum::v1::ForkParameters; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/header.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/header.rs index 53bf70bfcd..3c2364b85d 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/header.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/header.rs @@ -7,7 +7,7 @@ use crate::{ account_update::AccountUpdate, light_client_update::LightClientUpdate, trusted_sync_committee::TrustedSyncCommittee, }, - IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + Proto, TryFromProtoErrorOf, TypeUrl, }; // trait alias would be nice @@ -74,13 +74,7 @@ impl } } -impl IntoProto for Header { - type Proto = protos::union::ibc::lightclients::ethereum::v1::Header; -} - -impl TryFromProto - for Header -{ +impl Proto for Header { type Proto = protos::union::ibc::lightclients::ethereum::v1::Header; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_header.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_header.rs index 376fd2d7e2..649ef43a5b 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_header.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_header.rs @@ -14,7 +14,7 @@ use crate::{ ibc::lightclients::ethereum::{ beacon_block_header::BeaconBlockHeader, execution_payload_header::ExecutionPayloadHeader, }, - IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + Proto, TryFromProtoErrorOf, TypeUrl, }; #[derive(Clone, Debug, PartialEq, Encode, Decode, TreeHash, Serialize, Deserialize)] @@ -89,10 +89,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::LightClientHead const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.LightClientHeader"; } -impl TryFromProto for LightClientHeader { - type Proto = protos::union::ibc::lightclients::ethereum::v1::LightClientHeader; -} - -impl IntoProto for LightClientHeader { +impl Proto for LightClientHeader { type Proto = protos::union::ibc::lightclients::ethereum::v1::LightClientHeader; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs index 81ab3b692e..41a4b67e06 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/light_client_update.rs @@ -12,7 +12,7 @@ use crate::{ light_client_header::LightClientHeader, sync_aggregate::SyncAggregate, sync_committee::SyncCommittee, }, - try_from_proto_branch, IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + try_from_proto_branch, Proto, TryFromProtoErrorOf, TypeUrl, }; /// TODO: Move these to a more central location @@ -136,13 +136,7 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::LightClientUpda const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.LightClientUpdate"; } -impl TryFromProto - for LightClientUpdate -{ - type Proto = protos::union::ibc::lightclients::ethereum::v1::LightClientUpdate; -} - -impl IntoProto +impl Proto for LightClientUpdate { type Proto = protos::union::ibc::lightclients::ethereum::v1::LightClientUpdate; diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/storage_proof.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/storage_proof.rs index c574eede84..70c2ccd05a 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/storage_proof.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/storage_proof.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{ibc::lightclients::ethereum::proof::Proof, FromProto, IntoProto, TypeUrl}; +use crate::{ibc::lightclients::ethereum::proof::Proof, Proto, TypeUrl}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct StorageProof { @@ -23,11 +23,7 @@ impl From for Stor } } -impl IntoProto for StorageProof { - type Proto = protos::union::ibc::lightclients::ethereum::v1::StorageProof; -} - -impl FromProto for StorageProof { +impl Proto for StorageProof { type Proto = protos::union::ibc::lightclients::ethereum::v1::StorageProof; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/sync_aggregate.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/sync_aggregate.rs index 6958653d1c..28f9702d13 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/sync_aggregate.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/sync_aggregate.rs @@ -4,8 +4,8 @@ use ssz_types::BitVector; use tree_hash::TreeHash; use crate::{ - bls::BlsSignature, errors::InvalidLength, ethereum_consts_traits::SYNC_COMMITTEE_SIZE, - IntoProto, TryFromProto, TypeUrl, + bls::BlsSignature, errors::InvalidLength, ethereum_consts_traits::SYNC_COMMITTEE_SIZE, Proto, + TypeUrl, }; #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Encode, Decode, TreeHash)] @@ -55,10 +55,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::SyncAggregate { const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.SyncAggregate"; } -impl TryFromProto for SyncAggregate { - type Proto = protos::union::ibc::lightclients::ethereum::v1::SyncAggregate; -} - -impl IntoProto for SyncAggregate { +impl Proto for SyncAggregate { type Proto = protos::union::ibc::lightclients::ethereum::v1::SyncAggregate; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/sync_committee.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/sync_committee.rs index 05dd967d4c..03ca2be367 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/sync_committee.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/sync_committee.rs @@ -4,8 +4,8 @@ use ssz_types::{fixed_vector, FixedVector}; use tree_hash::TreeHash; use crate::{ - bls::BlsPublicKey, errors::InvalidLength, ethereum_consts_traits::SYNC_COMMITTEE_SIZE, - IntoProto, TryFromProto, TypeUrl, + bls::BlsPublicKey, errors::InvalidLength, ethereum_consts_traits::SYNC_COMMITTEE_SIZE, Proto, + TypeUrl, }; #[derive(Clone, Debug, PartialEq, Encode, Decode, TreeHash, Serialize, Deserialize)] @@ -68,10 +68,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::SyncCommittee { const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.SyncCommittee"; } -impl TryFromProto for SyncCommittee { - type Proto = protos::union::ibc::lightclients::ethereum::v1::SyncCommittee; -} - -impl IntoProto for SyncCommittee { +impl Proto for SyncCommittee { type Proto = protos::union::ibc::lightclients::ethereum::v1::SyncCommittee; } diff --git a/lib/unionlabs/src/ibc/lightclients/ethereum/trusted_sync_committee.rs b/lib/unionlabs/src/ibc/lightclients/ethereum/trusted_sync_committee.rs index 6dc2347536..bac1d4df82 100644 --- a/lib/unionlabs/src/ibc/lightclients/ethereum/trusted_sync_committee.rs +++ b/lib/unionlabs/src/ibc/lightclients/ethereum/trusted_sync_committee.rs @@ -6,7 +6,7 @@ use crate::{ errors::MissingField, ethereum_consts_traits::SYNC_COMMITTEE_SIZE, ibc::{core::client::height::Height, lightclients::ethereum::sync_committee::SyncCommittee}, - IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + Proto, TryFromProtoErrorOf, TypeUrl, }; #[derive(Clone, Debug, PartialEq, Encode, Decode, TreeHash, Serialize, Deserialize)] @@ -67,10 +67,6 @@ impl TypeUrl for protos::union::ibc::lightclients::ethereum::v1::TrustedSyncComm const TYPE_URL: &'static str = "/union.ibc.lightclients.ethereum.v1.TrustedSyncCommittee"; } -impl TryFromProto for TrustedSyncCommittee { - type Proto = protos::union::ibc::lightclients::ethereum::v1::TrustedSyncCommittee; -} - -impl IntoProto for TrustedSyncCommittee { +impl Proto for TrustedSyncCommittee { type Proto = protos::union::ibc::lightclients::ethereum::v1::TrustedSyncCommittee; } diff --git a/lib/unionlabs/src/ibc/lightclients/wasm/client_state.rs b/lib/unionlabs/src/ibc/lightclients/wasm/client_state.rs index 1790625362..806a8c5191 100644 --- a/lib/unionlabs/src/ibc/lightclients/wasm/client_state.rs +++ b/lib/unionlabs/src/ibc/lightclients/wasm/client_state.rs @@ -1,11 +1,10 @@ use std::fmt::Debug; -use prost::Message; use serde::{Deserialize, Serialize}; use crate::{ - errors::InvalidLength, ethereum::H256, ibc::core::client::height::Height, IntoProto, - TryFromProto, TryFromProtoErrorOf, TypeUrl, + errors::InvalidLength, ethereum::H256, ibc::core::client::height::Height, IntoProto, Proto, + TryFromProto, TryFromProtoBytesError, TryFromProtoErrorOf, TypeUrl, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -15,12 +14,6 @@ pub struct ClientState { pub latest_height: Height, } -// impl crate::chain::ClientState for ClientState { -// fn height(&self) -> Height { -// self.latest_height -// } -// } - impl TypeUrl for protos::ibc::lightclients::wasm::v1::ClientState { const TYPE_URL: &'static str = "/ibc.lightclients.wasm.v1.ClientState"; } @@ -31,14 +24,14 @@ where { fn from(val: ClientState) -> Self { Self { - data: val.data.into_proto().encode_to_vec(), + data: val.data.into_proto_bytes(), code_id: val.code_id.into_bytes(), latest_height: Some(val.latest_height.into()), } } } -impl IntoProto for ClientState { +impl Proto for ClientState { type Proto = protos::ibc::lightclients::wasm::v1::ClientState; } @@ -52,21 +45,17 @@ pub enum TryFromWasmClientStateError { impl TryFrom for ClientState where Data: TryFromProto, - ::Proto: prost::Message + Default, + ::Proto: prost::Message + Default, TryFromProtoErrorOf: Debug, { - type Error = - TryFromWasmClientStateError<::Proto>>::Error>; + type Error = TryFromWasmClientStateError>>; fn try_from( value: protos::ibc::lightclients::wasm::v1::ClientState, ) -> Result { Ok(Self { - data: Data::try_from_proto( - ::Proto::decode(&*value.data) - .map_err(TryFromWasmClientStateError::Prost)?, - ) - .map_err(TryFromWasmClientStateError::TryFromProto)?, + data: Data::try_from_proto_bytes(&value.data) + .map_err(TryFromWasmClientStateError::TryFromProto)?, code_id: value .code_id .try_into() @@ -75,14 +64,3 @@ where }) } } - -// , ibc::lightclients::wasm::client_state::ClientState: std::convert::TryFrom - -impl TryFromProto for ClientState -where - Data: TryFromProto, - ::Proto: prost::Message + Default, - TryFromProtoErrorOf: Debug, -{ - type Proto = protos::ibc::lightclients::wasm::v1::ClientState; -} diff --git a/lib/unionlabs/src/ibc/lightclients/wasm/consensus_state.rs b/lib/unionlabs/src/ibc/lightclients/wasm/consensus_state.rs index b5f729acc0..d8cb30f325 100644 --- a/lib/unionlabs/src/ibc/lightclients/wasm/consensus_state.rs +++ b/lib/unionlabs/src/ibc/lightclients/wasm/consensus_state.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use prost::Message; use serde::{Deserialize, Serialize}; -use crate::{IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl}; +use crate::{IntoProto, Proto, TryFromProto, TryFromProtoBytesError, TryFromProtoErrorOf, TypeUrl}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ConsensusState { @@ -26,7 +26,7 @@ impl TypeUrl for protos::ibc::lightclients::wasm::v1::ConsensusState { const TYPE_URL: &'static str = "/ibc.lightclients.wasm.v1.ConsensusState"; } -impl IntoProto for ConsensusState { +impl Proto for ConsensusState { type Proto = protos::ibc::lightclients::wasm::v1::ConsensusState; } @@ -39,31 +39,18 @@ pub enum TryFromWasmConsensusStateError { impl TryFrom for ConsensusState where Data: TryFromProto, - ::Proto: prost::Message + Default, + ::Proto: prost::Message + Default, TryFromProtoErrorOf: Debug, { - type Error = - TryFromWasmConsensusStateError<::Proto>>::Error>; + type Error = TryFromWasmConsensusStateError>>; fn try_from( value: protos::ibc::lightclients::wasm::v1::ConsensusState, ) -> Result { Ok(Self { - data: Data::try_from_proto( - ::Proto::decode(&*value.data) - .map_err(TryFromWasmConsensusStateError::Prost)?, - ) - .map_err(TryFromWasmConsensusStateError::TryFromProto)?, + data: Data::try_from_proto_bytes(&value.data) + .map_err(TryFromWasmConsensusStateError::TryFromProto)?, timestamp: value.timestamp, }) } } - -impl TryFromProto for ConsensusState -where - Data: TryFromProto, - ::Proto: prost::Message + Default, - TryFromProtoErrorOf: Debug, -{ - type Proto = protos::ibc::lightclients::wasm::v1::ConsensusState; -} diff --git a/lib/unionlabs/src/ibc/lightclients/wasm/header.rs b/lib/unionlabs/src/ibc/lightclients/wasm/header.rs index 58fb4e35b9..8337a027cb 100644 --- a/lib/unionlabs/src/ibc/lightclients/wasm/header.rs +++ b/lib/unionlabs/src/ibc/lightclients/wasm/header.rs @@ -1,10 +1,9 @@ -use prost::Message; use serde::{Deserialize, Serialize}; use crate::{ errors::{required, MissingField}, ibc::core::client::height::Height, - IntoProto, TryFromProto, TryFromProtoBytesError, TryFromProtoErrorOf, TypeUrl, + IntoProto, Proto, TryFromProto, TryFromProtoBytesError, TryFromProtoErrorOf, TypeUrl, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -13,14 +12,14 @@ pub struct Header { pub height: Height, } -impl IntoProto for Header { +impl Proto for Header { type Proto = protos::ibc::lightclients::wasm::v1::Header; } impl From> for protos::ibc::lightclients::wasm::v1::Header { fn from(value: Header) -> Self { Self { - data: value.data.into_proto().encode_to_vec(), + data: value.data.into_proto_bytes(), height: Some(value.height.into()), } } @@ -46,7 +45,3 @@ impl TryFrom fo }) } } - -impl TryFromProto for Header { - type Proto = protos::ibc::lightclients::wasm::v1::Header; -} diff --git a/lib/unionlabs/src/lib.rs b/lib/unionlabs/src/lib.rs index 8a7ac66356..ad8837d9ba 100644 --- a/lib/unionlabs/src/lib.rs +++ b/lib/unionlabs/src/lib.rs @@ -86,9 +86,12 @@ where // TODO: Move these traits into `ibc` -pub trait IntoProto: Into { - type Proto: Message + TypeUrl; +pub trait Proto: Into { + // all prost generated code implements Default + type Proto: TypeUrl + Default; +} +pub trait IntoProto: Proto + Into { fn into_proto(self) -> Self::Proto { self.into() } @@ -98,18 +101,22 @@ pub trait IntoProto: Into { } } -/// A type that can be infallibly converted from it's protobuf representation. -pub trait FromProto: From { - type Proto: Message; +impl IntoProto for T where T: Proto + Into {} +impl FromProto for T where T: Proto + From {} +impl TryFromProto for T where T: Proto + TryFrom {} +/// A type that can be infallibly converted from it's protobuf representation. +pub trait FromProto: Proto + From { fn from_proto(proto: Self::Proto) -> Self { proto.into() } -} -pub trait TryFromProto: TryFrom { - type Proto: Message + Default; + fn from_proto_bytes(bytes: &[u8]) -> Result { + ::decode(bytes).map(Into::into) + } +} +pub trait TryFromProto: Proto + TryFrom { fn try_from_proto(proto: Self::Proto) -> Result> { proto.try_into() } @@ -133,15 +140,7 @@ pub enum TryFromProtoBytesError { Decode(prost::DecodeError), } -pub type TryFromProtoErrorOf = ::Proto>>::Error; - -impl TryFromProto for T -where - T: FromProto, - ::Proto: Default, -{ - type Proto = T::Proto; -} +pub type TryFromProtoErrorOf = ::Proto>>::Error; pub trait TypeUrl: Message { const TYPE_URL: &'static str; @@ -150,7 +149,7 @@ pub trait TypeUrl: Message { #[cfg(test)] fn assert_proto_roundtrip(t: &T) where - T: IntoProto::Proto> + TryFromProto + Debug + Clone + PartialEq, + T: IntoProto + TryFromProto + Debug + Clone + PartialEq, TryFromProtoErrorOf: Debug, { let try_from_proto = T::try_from_proto(t.clone().into_proto()).unwrap(); diff --git a/lib/unionlabs/src/tendermint/types/block_id.rs b/lib/unionlabs/src/tendermint/types/block_id.rs index 360cdb1888..39c92b2e5e 100644 --- a/lib/unionlabs/src/tendermint/types/block_id.rs +++ b/lib/unionlabs/src/tendermint/types/block_id.rs @@ -2,7 +2,7 @@ use crate::{ errors::{InvalidLength, MissingField}, ethereum::H256, tendermint::types::part_set_header::PartSetHeader, - IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + Proto, TryFromProtoErrorOf, TypeUrl, }; #[derive(Debug, Clone, PartialEq)] @@ -35,10 +35,6 @@ impl TryFrom for BlockId { } } -impl TryFromProto for BlockId { - type Proto = protos::tendermint::types::BlockId; -} - impl From for protos::tendermint::types::BlockId { fn from(value: BlockId) -> Self { Self { @@ -48,7 +44,7 @@ impl From for protos::tendermint::types::BlockId { } } -impl IntoProto for BlockId { +impl Proto for BlockId { type Proto = protos::tendermint::types::BlockId; } diff --git a/lib/unionlabs/src/tendermint/types/header.rs b/lib/unionlabs/src/tendermint/types/header.rs index b1d9b6457d..a5d9fc5295 100644 --- a/lib/unionlabs/src/tendermint/types/header.rs +++ b/lib/unionlabs/src/tendermint/types/header.rs @@ -5,7 +5,7 @@ use crate::{ ethereum::{Address, H256}, ibc::google::protobuf::timestamp::Timestamp, tendermint::{types::block_id::BlockId, version::consensus::Consensus}, - IntoProto, TryFromProto, TryFromProtoErrorOf, TypeUrl, + Proto, TryFromProtoErrorOf, TypeUrl, }; #[derive(Clone, PartialEq)] @@ -135,11 +135,7 @@ impl TryFrom for Header { } } -impl IntoProto for Header { - type Proto = protos::tendermint::types::Header; -} - -impl TryFromProto for Header { +impl Proto for Header { type Proto = protos::tendermint::types::Header; } diff --git a/lib/unionlabs/src/tendermint/types/part_set_header.rs b/lib/unionlabs/src/tendermint/types/part_set_header.rs index 645a2270d8..82c5dbbdc2 100644 --- a/lib/unionlabs/src/tendermint/types/part_set_header.rs +++ b/lib/unionlabs/src/tendermint/types/part_set_header.rs @@ -1,4 +1,4 @@ -use crate::{errors::InvalidLength, ethereum::H256, IntoProto, TryFromProto, TypeUrl}; +use crate::{errors::InvalidLength, ethereum::H256, Proto, TypeUrl}; #[derive(Debug, Clone, PartialEq)] pub struct PartSetHeader { @@ -25,10 +25,6 @@ impl TryFrom for PartSetHeader { } } -impl TryFromProto for PartSetHeader { - type Proto = protos::tendermint::types::PartSetHeader; -} - impl From for protos::tendermint::types::PartSetHeader { fn from(value: PartSetHeader) -> Self { Self { @@ -38,7 +34,7 @@ impl From for protos::tendermint::types::PartSetHeader { } } -impl IntoProto for PartSetHeader { +impl Proto for PartSetHeader { type Proto = protos::tendermint::types::PartSetHeader; } diff --git a/lib/unionlabs/src/tendermint/version/consensus.rs b/lib/unionlabs/src/tendermint/version/consensus.rs index 50f8784979..735d80449d 100644 --- a/lib/unionlabs/src/tendermint/version/consensus.rs +++ b/lib/unionlabs/src/tendermint/version/consensus.rs @@ -1,4 +1,4 @@ -use crate::{FromProto, IntoProto, TypeUrl}; +use crate::{Proto, TypeUrl}; #[derive(Clone, PartialEq)] pub struct Consensus { @@ -24,11 +24,7 @@ impl From for protos::tendermint::version::Consensus { } } -impl FromProto for Consensus { - type Proto = protos::tendermint::version::Consensus; -} - -impl IntoProto for Consensus { +impl Proto for Consensus { type Proto = protos::tendermint::version::Consensus; }