Skip to content

Commit

Permalink
refactor: connection router picks up gateway-api (#277)
Browse files Browse the repository at this point in the history
* refactor: connection router picks up gateway-api

* cargo sort
  • Loading branch information
fish-sammy authored Feb 21, 2024
1 parent 2644fba commit c454d48
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions contracts/connection-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 4 additions & 4 deletions contracts/connection-router/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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![],
})
})
Expand Down
1 change: 1 addition & 0 deletions contracts/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion contracts/gateway/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -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! {
Expand Down
6 changes: 4 additions & 2 deletions contracts/gateway/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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};

Expand Down
19 changes: 1 addition & 18 deletions contracts/gateway/src/msg.rs
Original file line number Diff line number Diff line change
@@ -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<Message>),

// Permissionless
RouteMessages(Vec<Message>),
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(Vec<Message>)]
GetMessages { message_ids: Vec<CrossChainId> },
}
3 changes: 2 additions & 1 deletion contracts/gateway/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions contracts/multisig-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion contracts/multisig-prover/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn get_messages(
) -> Result<Vec<Message>, 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<Message> = querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: gateway.into(),
msg: to_binary(&query)?,
Expand Down
3 changes: 2 additions & 1 deletion contracts/multisig-prover/src/test/mocks/gateway.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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()),
&[],
);

Expand Down Expand Up @@ -221,7 +221,7 @@ pub fn get_messages_from_gateway(
) -> Vec<Message> {
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(),
},
);
Expand Down
11 changes: 9 additions & 2 deletions packages/gateway-api/src/msg.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -13,3 +13,10 @@ pub enum ExecuteMsg {
/// they have to be verified first.
RouteMessages(Vec<Message>),
}

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
#[returns(Vec<Message>)]
GetMessages { message_ids: Vec<CrossChainId> },
}

0 comments on commit c454d48

Please sign in to comment.