From c454d487a898e941d777951a8a45d95ecb37a8ed Mon Sep 17 00:00:00 2001 From: Sammy Date: Thu, 22 Feb 2024 02:53:15 +0800 Subject: [PATCH] refactor: connection router picks up gateway-api (#277) * refactor: connection router picks up gateway-api * cargo sort --- Cargo.lock | 4 ++++ contracts/connection-router/Cargo.toml | 1 + .../connection-router/src/contract/execute.rs | 8 ++++---- contracts/gateway/Cargo.toml | 1 + contracts/gateway/src/bin/schema.rs | 3 ++- contracts/gateway/src/contract.rs | 6 ++++-- contracts/gateway/src/msg.rs | 19 +------------------ contracts/gateway/tests/contract.rs | 3 ++- contracts/multisig-prover/Cargo.toml | 1 + contracts/multisig-prover/src/execute.rs | 2 +- .../multisig-prover/src/test/mocks/gateway.rs | 3 ++- integration-tests/Cargo.toml | 1 + integration-tests/tests/test_utils/mod.rs | 6 +++--- packages/gateway-api/src/msg.rs | 11 +++++++++-- 14 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f7ff9e97..965657509 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1478,6 +1478,7 @@ dependencies = [ "cw-storage-plus 1.1.0", "error-stack", "flagset", + "gateway-api", "hex", "integration-tests", "itertools 0.11.0", @@ -3358,6 +3359,7 @@ dependencies = [ "cw-multi-test", "cw-storage-plus 1.1.0", "error-stack", + "gateway-api", "itertools 0.11.0", "mockall", "report", @@ -3925,6 +3927,7 @@ dependencies = [ "cw-storage-plus 1.1.0", "error-stack", "gateway", + "gateway-api", "itertools 0.11.0", "k256", "mockall", @@ -4854,6 +4857,7 @@ dependencies = [ "ethabi", "ethers", "gateway", + "gateway-api", "generic-array", "hex", "itertools 0.11.0", diff --git a/contracts/connection-router/Cargo.toml b/contracts/connection-router/Cargo.toml index 0576259b6..323ee2692 100644 --- a/contracts/connection-router/Cargo.toml +++ b/contracts/connection-router/Cargo.toml @@ -42,6 +42,7 @@ cosmwasm-storage = { workspace = true } cw-storage-plus = { workspace = true } error-stack = { workspace = true } flagset = { version = "0.4.3", features = ["serde"] } +gateway-api = { workspace = true } itertools = { workspace = true } mockall = "0.11.4" report = { workspace = true } diff --git a/contracts/connection-router/src/contract/execute.rs b/contracts/connection-router/src/contract/execute.rs index 0e24eefb1..54143c777 100644 --- a/contracts/connection-router/src/contract/execute.rs +++ b/contracts/connection-router/src/contract/execute.rs @@ -2,7 +2,6 @@ use std::vec; use axelar_wasm_std::flagset::FlagSet; use connection_router_api::error::Error; -use connection_router_api::msg::ExecuteMsg; use connection_router_api::{ChainEndpoint, ChainName, Gateway, GatewayDirection, Message}; use cosmwasm_std::{to_binary, Addr, DepsMut, MessageInfo, Response, StdResult, WasmMsg}; use error_stack::report; @@ -175,9 +174,10 @@ where Ok(WasmMsg::Execute { contract_addr: gateway.to_string(), - // TODO: this happens to work because the router and the gateways have the same definition of RouteMessages - msg: to_binary(&ExecuteMsg::RouteMessages(msgs.cloned().collect())) - .expect("must serialize message"), + msg: to_binary(&gateway_api::msg::ExecuteMsg::RouteMessages( + msgs.cloned().collect(), + )) + .expect("must serialize message"), funds: vec![], }) }) diff --git a/contracts/gateway/Cargo.toml b/contracts/gateway/Cargo.toml index 0ca1f2f08..5e665bab3 100644 --- a/contracts/gateway/Cargo.toml +++ b/contracts/gateway/Cargo.toml @@ -44,6 +44,7 @@ cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } cw-storage-plus = { workspace = true } error-stack = { workspace = true } +gateway-api = { workspace = true } itertools = { workspace = true } mockall = "0.11.3" report = { workspace = true } diff --git a/contracts/gateway/src/bin/schema.rs b/contracts/gateway/src/bin/schema.rs index f32637149..afb8679ae 100644 --- a/contracts/gateway/src/bin/schema.rs +++ b/contracts/gateway/src/bin/schema.rs @@ -1,6 +1,7 @@ use cosmwasm_schema::write_api; +use gateway_api::msg::{ExecuteMsg, QueryMsg}; -use gateway::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use gateway::msg::InstantiateMsg; fn main() { write_api! { diff --git a/contracts/gateway/src/contract.rs b/contracts/gateway/src/contract.rs index 4752a92f2..7cb4518fa 100644 --- a/contracts/gateway/src/contract.rs +++ b/contracts/gateway/src/contract.rs @@ -1,9 +1,10 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response}; +use gateway_api::msg::{ExecuteMsg, QueryMsg}; use std::fmt::Debug; -use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use crate::msg::InstantiateMsg; mod execute; mod query; @@ -58,9 +59,10 @@ mod internal { use connection_router_api::client::Router; use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response}; use error_stack::{Result, ResultExt}; + use gateway_api::msg::{ExecuteMsg, QueryMsg}; use crate::contract::Error; - use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; + use crate::msg::InstantiateMsg; use crate::state::Config; use crate::{contract, state}; diff --git a/contracts/gateway/src/msg.rs b/contracts/gateway/src/msg.rs index d26077521..a28a90ba3 100644 --- a/contracts/gateway/src/msg.rs +++ b/contracts/gateway/src/msg.rs @@ -1,24 +1,7 @@ -use connection_router_api::{CrossChainId, Message}; -use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_schema::cw_serde; #[cw_serde] pub struct InstantiateMsg { pub verifier_address: String, pub router_address: String, } - -#[cw_serde] -pub enum ExecuteMsg { - // Permissionless - VerifyMessages(Vec), - - // Permissionless - RouteMessages(Vec), -} - -#[cw_serde] -#[derive(QueryResponses)] -pub enum QueryMsg { - #[returns(Vec)] - GetMessages { message_ids: Vec }, -} diff --git a/contracts/gateway/tests/contract.rs b/contracts/gateway/tests/contract.rs index 5839e287e..790cabc53 100644 --- a/contracts/gateway/tests/contract.rs +++ b/contracts/gateway/tests/contract.rs @@ -10,7 +10,8 @@ use cosmwasm_std::{ from_binary, to_binary, Addr, ContractResult, DepsMut, QuerierResult, WasmQuery, }; use gateway::contract::*; -use gateway::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use gateway::msg::InstantiateMsg; +use gateway_api::msg::{ExecuteMsg, QueryMsg}; use itertools::Itertools; use serde::Serialize; diff --git a/contracts/multisig-prover/Cargo.toml b/contracts/multisig-prover/Cargo.toml index bce30a80d..38363fda9 100644 --- a/contracts/multisig-prover/Cargo.toml +++ b/contracts/multisig-prover/Cargo.toml @@ -46,6 +46,7 @@ either = "1.8.1" error-stack = { workspace = true } ethabi = { version = "18.0.0", default-features = false, features = [] } gateway = { workspace = true } +gateway-api = { workspace = true } hex = { version = "0.4.3", default-features = false, features = [] } itertools = "0.11.0" k256 = { version = "0.13.1", features = ["ecdsa"] } diff --git a/contracts/multisig-prover/src/execute.rs b/contracts/multisig-prover/src/execute.rs index 35878ee50..0cb4fb13b 100644 --- a/contracts/multisig-prover/src/execute.rs +++ b/contracts/multisig-prover/src/execute.rs @@ -85,7 +85,7 @@ fn get_messages( ) -> Result, ContractError> { let length = message_ids.len(); - let query = gateway::msg::QueryMsg::GetMessages { message_ids }; + let query = gateway_api::msg::QueryMsg::GetMessages { message_ids }; let messages: Vec = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: gateway.into(), msg: to_binary(&query)?, diff --git a/contracts/multisig-prover/src/test/mocks/gateway.rs b/contracts/multisig-prover/src/test/mocks/gateway.rs index 016b2806d..999a44937 100644 --- a/contracts/multisig-prover/src/test/mocks/gateway.rs +++ b/contracts/multisig-prover/src/test/mocks/gateway.rs @@ -1,7 +1,8 @@ use cosmwasm_std::{ to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, }; -use gateway::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use gateway::msg::InstantiateMsg; +use gateway_api::msg::{ExecuteMsg, QueryMsg}; use crate::test::test_data; diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 30cb1125d..b5c7706db 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -41,6 +41,7 @@ cw-multi-test = "0.15.1" cw-storage-plus = { workspace = true } error-stack = { workspace = true } gateway = { workspace = true } +gateway-api = { workspace = true } itertools = { workspace = true } k256 = { version = "0.13.1", features = ["ecdsa"] } mockall = "0.11.3" diff --git a/integration-tests/tests/test_utils/mod.rs b/integration-tests/tests/test_utils/mod.rs index 761aca995..63a7df15a 100644 --- a/integration-tests/tests/test_utils/mod.rs +++ b/integration-tests/tests/test_utils/mod.rs @@ -47,7 +47,7 @@ pub fn verify_messages( let response = app.execute_contract( Addr::unchecked("relayer"), gateway_address.clone(), - &gateway::msg::ExecuteMsg::VerifyMessages(msgs.to_vec()), + &gateway_api::msg::ExecuteMsg::VerifyMessages(msgs.to_vec()), &[], ); assert!(response.is_ok()); @@ -66,7 +66,7 @@ pub fn route_messages(app: &mut App, gateway_address: &Addr, msgs: &[Message]) { let response = app.execute_contract( Addr::unchecked("relayer"), gateway_address.clone(), - &gateway::msg::ExecuteMsg::RouteMessages(msgs.to_vec()), + &gateway_api::msg::ExecuteMsg::RouteMessages(msgs.to_vec()), &[], ); @@ -221,7 +221,7 @@ pub fn get_messages_from_gateway( ) -> Vec { let query_response = app.wrap().query_wasm_smart( gateway_address, - &gateway::msg::QueryMsg::GetMessages { + &gateway_api::msg::QueryMsg::GetMessages { message_ids: message_ids.to_owned(), }, ); diff --git a/packages/gateway-api/src/msg.rs b/packages/gateway-api/src/msg.rs index 673c1c756..37de48160 100644 --- a/packages/gateway-api/src/msg.rs +++ b/packages/gateway-api/src/msg.rs @@ -1,5 +1,5 @@ -use connection_router_api::Message; -use cosmwasm_schema::cw_serde; +use connection_router_api::{CrossChainId, Message}; +use cosmwasm_schema::{cw_serde, QueryResponses}; #[cw_serde] pub enum ExecuteMsg { @@ -13,3 +13,10 @@ pub enum ExecuteMsg { /// they have to be verified first. RouteMessages(Vec), } + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(Vec)] + GetMessages { message_ids: Vec }, +}