From 4ee25a67f5704c2e4172d3f31d9805e1a0ccc9de Mon Sep 17 00:00:00 2001 From: Sammy Date: Fri, 16 Feb 2024 18:00:04 +0800 Subject: [PATCH] refactor(connection-router-api): replace dependencies of connection-router with connection-router-api --- Cargo.lock | 20 +- ampd/Cargo.toml | 2 +- ampd/src/commands/deregister_chain_support.rs | 2 +- ampd/src/commands/register_chain_support.rs | 2 +- ampd/src/evm/mod.rs | 10 +- ampd/src/handlers/evm_verify_msg.rs | 6 +- ampd/src/handlers/evm_verify_worker_set.rs | 4 +- ampd/src/handlers/multisig.rs | 2 +- ampd/src/handlers/sui_verify_msg.rs | 2 +- ampd/src/handlers/sui_verify_worker_set.rs | 2 +- ampd/src/sui/verifier.rs | 2 +- contracts/aggregate-verifier/Cargo.toml | 2 +- contracts/aggregate-verifier/src/client.rs | 5 +- contracts/aggregate-verifier/src/contract.rs | 4 +- contracts/aggregate-verifier/src/error.rs | 2 +- contracts/aggregate-verifier/src/msg.rs | 4 +- contracts/aggregate-verifier/tests/mock.rs | 2 +- contracts/aggregate-verifier/tests/test.rs | 2 +- contracts/connection-router/Cargo.toml | 1 + contracts/connection-router/src/bin/schema.rs | 3 +- contracts/connection-router/src/contract.rs | 3 +- .../connection-router/src/contract/execute.rs | 80 ++-- .../connection-router/src/contract/query.rs | 27 +- contracts/connection-router/src/error.rs | 51 --- contracts/connection-router/src/events.rs | 32 +- contracts/connection-router/src/lib.rs | 5 - contracts/connection-router/src/msg.rs | 51 +-- contracts/connection-router/src/state.rs | 407 +----------------- contracts/connection-router/tests/mock.rs | 10 +- contracts/connection-router/tests/test.rs | 114 ++--- .../connection-router/tests/test_utils/mod.rs | 3 +- contracts/gateway/Cargo.toml | 2 +- contracts/gateway/src/contract.rs | 9 +- contracts/gateway/src/contract/execute.rs | 11 +- contracts/gateway/src/contract/query.rs | 8 +- contracts/gateway/src/events.rs | 11 +- contracts/gateway/src/msg.rs | 2 +- contracts/gateway/src/state.rs | 10 +- contracts/gateway/tests/contract.rs | 11 +- contracts/multisig-prover/Cargo.toml | 2 +- contracts/multisig-prover/src/contract.rs | 10 +- contracts/multisig-prover/src/encoding/abi.rs | 2 +- contracts/multisig-prover/src/encoding/bcs.rs | 2 +- contracts/multisig-prover/src/encoding/mod.rs | 2 +- contracts/multisig-prover/src/events.rs | 2 +- contracts/multisig-prover/src/execute.rs | 2 +- contracts/multisig-prover/src/msg.rs | 2 +- contracts/multisig-prover/src/state.rs | 2 +- .../multisig-prover/src/test/test_data.rs | 2 +- contracts/multisig-prover/src/types.rs | 2 +- contracts/multisig/Cargo.toml | 2 +- contracts/multisig/src/contract.rs | 2 +- contracts/multisig/src/contract/execute.rs | 2 +- contracts/multisig/src/events.rs | 2 +- contracts/multisig/src/msg.rs | 2 +- contracts/multisig/src/signing.rs | 2 +- contracts/nexus-gateway/Cargo.toml | 2 +- .../nexus-gateway/src/contract/execute.rs | 18 +- contracts/nexus-gateway/src/msg.rs | 2 +- contracts/nexus-gateway/src/nexus.rs | 8 +- contracts/nexus-gateway/src/state.rs | 2 +- contracts/rewards/Cargo.toml | 2 +- contracts/rewards/src/contract.rs | 2 +- contracts/rewards/src/contract/execute.rs | 2 +- contracts/rewards/src/msg.rs | 2 +- contracts/rewards/src/state.rs | 4 +- contracts/service-registry/Cargo.toml | 2 +- contracts/service-registry/src/contract.rs | 4 +- contracts/service-registry/src/msg.rs | 2 +- contracts/service-registry/src/state.rs | 2 +- contracts/service-registry/tests/tests.rs | 4 +- contracts/voting-verifier/Cargo.toml | 2 +- contracts/voting-verifier/src/error.rs | 5 +- contracts/voting-verifier/src/events.rs | 2 +- contracts/voting-verifier/src/execute.rs | 2 +- contracts/voting-verifier/src/msg.rs | 4 +- contracts/voting-verifier/src/query.rs | 2 +- contracts/voting-verifier/src/state.rs | 2 +- contracts/voting-verifier/tests/tests.rs | 2 +- integration-tests/Cargo.toml | 1 + integration-tests/tests/message_routing.rs | 2 +- integration-tests/tests/test_utils/mod.rs | 6 +- integration-tests/tests/update_worker_set.rs | 6 +- .../connection-router-api}/src/client.rs | 3 +- packages/connection-router-api/src/error.rs | 39 +- packages/connection-router-api/src/lib.rs | 1 + 86 files changed, 326 insertions(+), 779 deletions(-) delete mode 100644 contracts/connection-router/src/error.rs rename {contracts/connection-router => packages/connection-router-api}/src/client.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 4e5bf3228..a03b2ce27 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,7 +79,7 @@ version = "0.1.0" dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", - "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", @@ -158,7 +158,7 @@ dependencies = [ "bcs", "clap", "config", - "connection-router", + "connection-router-api", "cosmos-sdk-proto 0.16.0", "cosmrs", "cosmwasm-std", @@ -1469,6 +1469,7 @@ version = "0.1.0" dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", @@ -3349,7 +3350,7 @@ dependencies = [ "aggregate-verifier", "axelar-wasm-std", "axelar-wasm-std-derive", - "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", @@ -3915,6 +3916,7 @@ dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", @@ -4809,7 +4811,7 @@ version = "0.1.0" dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", - "connection-router", + "connection-router-api", "cosmwasm-crypto", "cosmwasm-schema", "cosmwasm-std", @@ -4838,7 +4840,7 @@ dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", "bcs", - "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", @@ -5025,7 +5027,7 @@ version = "0.1.0" dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", - "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.1.0", @@ -6454,7 +6456,7 @@ version = "0.1.0" dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", - "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cw-multi-test", @@ -7116,7 +7118,7 @@ version = "0.1.0" dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", - "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", @@ -8810,7 +8812,7 @@ version = "0.1.0" dependencies = [ "axelar-wasm-std", "axelar-wasm-std-derive", - "connection-router", + "connection-router-api", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", diff --git a/ampd/Cargo.toml b/ampd/Cargo.toml index de814c8a9..d669f97c4 100644 --- a/ampd/Cargo.toml +++ b/ampd/Cargo.toml @@ -12,7 +12,7 @@ base64 = "0.21.2" bcs = "0.1.5" clap = { version = "4.2.7", features = ["derive", "cargo"] } config = "0.13.2" -connection-router = { workspace = true } +connection-router-api = { workspace = true } cosmos-sdk-proto = "0.16.0" cosmrs = { version = "0.14.0", features = ["cosmwasm"] } cosmwasm-std = { version = "1.2.1", features = ["stargate"] } diff --git a/ampd/src/commands/deregister_chain_support.rs b/ampd/src/commands/deregister_chain_support.rs index 8b7db779b..412f12747 100644 --- a/ampd/src/commands/deregister_chain_support.rs +++ b/ampd/src/commands/deregister_chain_support.rs @@ -1,7 +1,7 @@ use std::path::Path; use axelar_wasm_std::nonempty; -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmrs::cosmwasm::MsgExecuteContract; use cosmrs::tx::Msg; use error_stack::Result; diff --git a/ampd/src/commands/register_chain_support.rs b/ampd/src/commands/register_chain_support.rs index 563c6e1ce..61a5ef302 100644 --- a/ampd/src/commands/register_chain_support.rs +++ b/ampd/src/commands/register_chain_support.rs @@ -1,7 +1,7 @@ use std::path::Path; use axelar_wasm_std::nonempty; -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmrs::cosmwasm::MsgExecuteContract; use cosmrs::tx::Msg; use error_stack::Result; diff --git a/ampd/src/evm/mod.rs b/ampd/src/evm/mod.rs index 08422f619..3de002e1f 100644 --- a/ampd/src/evm/mod.rs +++ b/ampd/src/evm/mod.rs @@ -15,18 +15,20 @@ pub enum ChainName { Other(String), } -impl PartialEq for ChainName { - fn eq(&self, other: &connection_router::state::ChainName) -> bool { +impl PartialEq for ChainName { + fn eq(&self, other: &connection_router_api::ChainName) -> bool { self.to_string().eq_ignore_ascii_case(other.as_ref()) } } #[cfg(test)] mod tests { - use crate::evm; - use connection_router::state::ChainName; use std::str::FromStr; + use connection_router_api::ChainName; + + use crate::evm; + #[test] fn chain_name_partial_eq() { let chain_name = evm::ChainName::Ethereum; diff --git a/ampd/src/handlers/evm_verify_msg.rs b/ampd/src/handlers/evm_verify_msg.rs index 9206df96c..03019d9d6 100644 --- a/ampd/src/handlers/evm_verify_msg.rs +++ b/ampd/src/handlers/evm_verify_msg.rs @@ -12,7 +12,7 @@ use tracing::{info, info_span}; use valuable::Valuable; use axelar_wasm_std::voting::{PollId, Vote}; -use connection_router::state::ID_SEPARATOR; +use connection_router_api::ID_SEPARATOR; use events::Error::EventTypeMismatch; use events_derive::try_from; use voting_verifier::msg::ExecuteMsg; @@ -33,7 +33,7 @@ pub struct Message { pub tx_id: Hash, pub event_index: u64, pub destination_address: String, - pub destination_chain: connection_router::state::ChainName, + pub destination_chain: connection_router_api::ChainName, pub source_address: EVMAddress, pub payload_hash: Hash, } @@ -42,7 +42,7 @@ pub struct Message { #[try_from("wasm-messages_poll_started")] struct PollStartedEvent { poll_id: PollId, - source_chain: connection_router::state::ChainName, + source_chain: connection_router_api::ChainName, source_gateway_address: EVMAddress, confirmation_height: u64, expires_at: u64, diff --git a/ampd/src/handlers/evm_verify_worker_set.rs b/ampd/src/handlers/evm_verify_worker_set.rs index 0be19c085..a3b9422e6 100644 --- a/ampd/src/handlers/evm_verify_worker_set.rs +++ b/ampd/src/handlers/evm_verify_worker_set.rs @@ -13,7 +13,7 @@ use events::Error::EventTypeMismatch; use events_derive::try_from; use axelar_wasm_std::voting::{PollId, Vote}; -use connection_router::state::ID_SEPARATOR; +use connection_router_api::ID_SEPARATOR; use voting_verifier::msg::ExecuteMsg; use crate::event_processor::EventHandler; @@ -43,7 +43,7 @@ pub struct WorkerSetConfirmation { struct PollStartedEvent { worker_set: WorkerSetConfirmation, poll_id: PollId, - source_chain: connection_router::state::ChainName, + source_chain: connection_router_api::ChainName, source_gateway_address: EVMAddress, expires_at: u64, confirmation_height: u64, diff --git a/ampd/src/handlers/multisig.rs b/ampd/src/handlers/multisig.rs index 5608b8517..8a47e92f9 100644 --- a/ampd/src/handlers/multisig.rs +++ b/ampd/src/handlers/multisig.rs @@ -191,7 +191,7 @@ mod test { use base64::engine::general_purpose::STANDARD; use base64::Engine; - use connection_router::state::ChainName; + use connection_router_api::ChainName; use cosmos_sdk_proto::cosmos::base::abci::v1beta1::TxResponse; use cosmrs::{AccountId, Gas}; use cosmwasm_std::{HexBinary, Uint64}; diff --git a/ampd/src/handlers/sui_verify_msg.rs b/ampd/src/handlers/sui_verify_msg.rs index cfe2c6c82..b2a731c01 100644 --- a/ampd/src/handlers/sui_verify_msg.rs +++ b/ampd/src/handlers/sui_verify_msg.rs @@ -27,7 +27,7 @@ pub struct Message { pub tx_id: TransactionDigest, pub event_index: u64, pub destination_address: String, - pub destination_chain: connection_router::state::ChainName, + pub destination_chain: connection_router_api::ChainName, pub source_address: SuiAddress, pub payload_hash: Hash, } diff --git a/ampd/src/handlers/sui_verify_worker_set.rs b/ampd/src/handlers/sui_verify_worker_set.rs index b21d2d4ec..bac852da2 100644 --- a/ampd/src/handlers/sui_verify_worker_set.rs +++ b/ampd/src/handlers/sui_verify_worker_set.rs @@ -9,7 +9,7 @@ use tokio::sync::watch::Receiver; use tracing::{info, info_span}; use axelar_wasm_std::voting::{PollId, Vote}; -use connection_router::state::ID_SEPARATOR; +use connection_router_api::ID_SEPARATOR; use cosmwasm_std::HexBinary; use cosmwasm_std::Uint128; use events::{Error::EventTypeMismatch, Event}; diff --git a/ampd/src/sui/verifier.rs b/ampd/src/sui/verifier.rs index 15cee5f6d..a61198877 100644 --- a/ampd/src/sui/verifier.rs +++ b/ampd/src/sui/verifier.rs @@ -132,7 +132,7 @@ pub fn verify_worker_set( #[cfg(test)] mod tests { use axelar_wasm_std::voting::Vote; - use connection_router::state::ChainName; + use connection_router_api::ChainName; use cosmwasm_std::HexBinary; use ethers::abi::AbiEncode; use move_core_types::language_storage::StructTag; diff --git a/contracts/aggregate-verifier/Cargo.toml b/contracts/aggregate-verifier/Cargo.toml index af78d5c94..ec3b5ad3b 100644 --- a/contracts/aggregate-verifier/Cargo.toml +++ b/contracts/aggregate-verifier/Cargo.toml @@ -35,7 +35,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } -connection-router = { workspace = true, features = ["library"] } +connection-router-api = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } diff --git a/contracts/aggregate-verifier/src/client.rs b/contracts/aggregate-verifier/src/client.rs index c163bcc40..16b4142b4 100644 --- a/contracts/aggregate-verifier/src/client.rs +++ b/contracts/aggregate-verifier/src/client.rs @@ -1,7 +1,6 @@ use axelar_wasm_std::utils::TryMapExt; use axelar_wasm_std::{FnExt, VerificationStatus}; -use connection_router::state::CrossChainId; -use connection_router::Message; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_std::{to_binary, Addr, QuerierWrapper, QueryRequest, WasmMsg, WasmQuery}; use error_stack::{Result, ResultExt}; use serde::de::DeserializeOwned; @@ -91,7 +90,7 @@ pub enum Error { #[cfg(test)] mod tests { use axelar_wasm_std::VerificationStatus; - use connection_router::state::CrossChainId; + use connection_router_api::CrossChainId; use cosmwasm_std::testing::MockQuerier; use std::str::FromStr; diff --git a/contracts/aggregate-verifier/src/contract.rs b/contracts/aggregate-verifier/src/contract.rs index e6c30aebb..d238c4c2c 100644 --- a/contracts/aggregate-verifier/src/contract.rs +++ b/contracts/aggregate-verifier/src/contract.rs @@ -1,5 +1,5 @@ use axelar_wasm_std::VerificationStatus; -use connection_router::state::CrossChainId; +use connection_router_api::CrossChainId; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ @@ -47,7 +47,7 @@ pub fn execute( pub mod execute { use cosmwasm_std::{to_binary, SubMsg, WasmMsg}; - use connection_router::state::Message; + use connection_router_api::Message; use super::*; diff --git a/contracts/aggregate-verifier/src/error.rs b/contracts/aggregate-verifier/src/error.rs index c264d2671..f5c4c66f9 100644 --- a/contracts/aggregate-verifier/src/error.rs +++ b/contracts/aggregate-verifier/src/error.rs @@ -8,7 +8,7 @@ pub enum ContractError { Std(#[from] StdError), #[error(transparent)] - RouterError(#[from] connection_router::ContractError), + RouterError(#[from] connection_router_api::error::Error), #[error("received invalid verifier reply: {0}")] InvalidVerifierReply(String), diff --git a/contracts/aggregate-verifier/src/msg.rs b/contracts/aggregate-verifier/src/msg.rs index b1c21ff39..1eb76b754 100644 --- a/contracts/aggregate-verifier/src/msg.rs +++ b/contracts/aggregate-verifier/src/msg.rs @@ -1,5 +1,5 @@ use axelar_wasm_std::VerificationStatus; -use connection_router::state::Message; +use connection_router_api::Message; use cosmwasm_schema::{cw_serde, QueryResponses}; #[cw_serde] @@ -16,6 +16,6 @@ pub enum ExecuteMsg { #[cw_serde] #[derive(QueryResponses)] pub enum QueryMsg { - #[returns(Vec<(connection_router::state::CrossChainId, VerificationStatus)>)] + #[returns(Vec<(connection_router_api::CrossChainId, VerificationStatus)>)] GetMessagesStatus { messages: Vec }, } diff --git a/contracts/aggregate-verifier/tests/mock.rs b/contracts/aggregate-verifier/tests/mock.rs index daf98b99d..2e241238b 100644 --- a/contracts/aggregate-verifier/tests/mock.rs +++ b/contracts/aggregate-verifier/tests/mock.rs @@ -1,6 +1,6 @@ use aggregate_verifier::error::ContractError; use axelar_wasm_std::VerificationStatus; -use connection_router::state::{CrossChainId, Message}; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_schema::cw_serde; use cosmwasm_std::{to_binary, Addr, DepsMut, Env, MessageInfo, Response}; use cw_multi_test::{App, ContractWrapper, Executor}; diff --git a/contracts/aggregate-verifier/tests/test.rs b/contracts/aggregate-verifier/tests/test.rs index d6c1930cb..7f71b8d3f 100644 --- a/contracts/aggregate-verifier/tests/test.rs +++ b/contracts/aggregate-verifier/tests/test.rs @@ -1,7 +1,7 @@ use aggregate_verifier::contract::*; use aggregate_verifier::msg::{ExecuteMsg, InstantiateMsg}; use axelar_wasm_std::VerificationStatus; -use connection_router::state::{CrossChainId, Message, ID_SEPARATOR}; +use connection_router_api::{CrossChainId, Message, ID_SEPARATOR}; use cosmwasm_std::from_binary; use cosmwasm_std::Addr; use cw_multi_test::{App, ContractWrapper, Executor}; diff --git a/contracts/connection-router/Cargo.toml b/contracts/connection-router/Cargo.toml index cf75f4eff..0576259b6 100644 --- a/contracts/connection-router/Cargo.toml +++ b/contracts/connection-router/Cargo.toml @@ -35,6 +35,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } +connection-router-api = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } diff --git a/contracts/connection-router/src/bin/schema.rs b/contracts/connection-router/src/bin/schema.rs index 99835b68b..681f435dc 100644 --- a/contracts/connection-router/src/bin/schema.rs +++ b/contracts/connection-router/src/bin/schema.rs @@ -1,6 +1,7 @@ +use connection_router_api::msg::{ExecuteMsg, QueryMsg}; use cosmwasm_schema::write_api; -use connection_router::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use connection_router::msg::InstantiateMsg; fn main() { write_api! { diff --git a/contracts/connection-router/src/contract.rs b/contracts/connection-router/src/contract.rs index 1a5dd2ea6..68b4f488c 100644 --- a/contracts/connection-router/src/contract.rs +++ b/contracts/connection-router/src/contract.rs @@ -1,9 +1,10 @@ +use connection_router_api::msg::{ExecuteMsg, QueryMsg}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response}; use crate::events::RouterInstantiated; -use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use crate::msg::InstantiateMsg; use crate::state::{Config, RouterStore, Store}; mod execute; diff --git a/contracts/connection-router/src/contract/execute.rs b/contracts/connection-router/src/contract/execute.rs index 25745f5c1..0e24eefb1 100644 --- a/contracts/connection-router/src/contract/execute.rs +++ b/contracts/connection-router/src/contract/execute.rs @@ -1,30 +1,24 @@ 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; use itertools::Itertools; -use axelar_wasm_std::flagset::FlagSet; - use crate::events::{ChainFrozen, ChainRegistered, GatewayInfo, GatewayUpgraded, MessageRouted}; -use crate::msg::ExecuteMsg; -use crate::state::{ - chain_endpoints, ChainEndpoint, ChainName, Gateway, GatewayDirection, Message, Store, CONFIG, -}; -use crate::ContractError; +use crate::state::{chain_endpoints, Store, CONFIG}; use super::Contract; -pub fn register_chain( - deps: DepsMut, - name: ChainName, - gateway: Addr, -) -> Result { +pub fn register_chain(deps: DepsMut, name: ChainName, gateway: Addr) -> Result { if find_chain_for_gateway(&deps, &gateway)?.is_some() { - return Err(ContractError::GatewayAlreadyRegistered); + return Err(Error::GatewayAlreadyRegistered); } chain_endpoints().update(deps.storage, name.clone(), |chain| match chain { - Some(_) => Err(ContractError::ChainAlreadyExists), + Some(_) => Err(Error::ChainAlreadyExists), None => Ok(ChainEndpoint { name: name.clone(), gateway: Gateway { @@ -51,12 +45,12 @@ pub fn upgrade_gateway( deps: DepsMut, chain: ChainName, contract_address: Addr, -) -> Result { +) -> Result { if find_chain_for_gateway(&deps, &contract_address)?.is_some() { - return Err(ContractError::GatewayAlreadyRegistered); + return Err(Error::GatewayAlreadyRegistered); } chain_endpoints().update(deps.storage, chain.clone(), |chain| match chain { - None => Err(ContractError::ChainNotFound), + None => Err(Error::ChainNotFound), Some(mut chain) => { chain.gateway.address = contract_address.clone(); Ok(chain) @@ -77,9 +71,9 @@ pub fn freeze_chain( deps: DepsMut, chain: ChainName, direction: GatewayDirection, -) -> Result { +) -> Result { chain_endpoints().update(deps.storage, chain.clone(), |chain| match chain { - None => Err(ContractError::ChainNotFound), + None => Err(Error::ChainNotFound), Some(mut chain) => { *chain.frozen_status |= direction; Ok(chain) @@ -92,9 +86,9 @@ pub fn unfreeze_chain( deps: DepsMut, chain: ChainName, direction: GatewayDirection, -) -> Result { +) -> Result { chain_endpoints().update(deps.storage, chain.clone(), |chain| match chain { - None => Err(ContractError::ChainNotFound), + None => Err(Error::ChainNotFound), Some(mut chain) => { *chain.frozen_status -= direction; Ok(chain) @@ -103,18 +97,18 @@ pub fn unfreeze_chain( Ok(Response::new().add_event(ChainFrozen { name: chain }.into())) } -pub fn require_admin(deps: &DepsMut, info: MessageInfo) -> Result<(), ContractError> { +pub fn require_admin(deps: &DepsMut, info: MessageInfo) -> Result<(), Error> { let config = CONFIG.load(deps.storage)?; if config.admin != info.sender { - return Err(ContractError::Unauthorized); + return Err(Error::Unauthorized); } Ok(()) } -pub fn require_governance(deps: &DepsMut, info: MessageInfo) -> Result<(), ContractError> { +pub fn require_governance(deps: &DepsMut, info: MessageInfo) -> Result<(), Error> { let config = CONFIG.load(deps.storage)?; if config.governance != info.sender { - return Err(ContractError::Unauthorized); + return Err(Error::Unauthorized); } Ok(()) } @@ -127,7 +121,7 @@ where &self, sender: &Addr, msgs: Vec, - ) -> error_stack::Result, ContractError> { + ) -> error_stack::Result, Error> { // if sender is the nexus gateway, we cannot validate the source chain // because the source chain is registered in the core nexus module if sender == self.config.nexus_gateway { @@ -137,15 +131,15 @@ where let source_chain = self .store .load_chain_by_gateway(sender)? - .ok_or(ContractError::GatewayNotRegistered)?; + .ok_or(Error::GatewayNotRegistered)?; if source_chain.incoming_frozen() { - return Err(report!(ContractError::ChainFrozen { + return Err(report!(Error::ChainFrozen { chain: source_chain.name, })); } if msgs.iter().any(|msg| msg.cc_id.chain != source_chain.name) { - return Err(report!(ContractError::WrongSourceChain)); + return Err(report!(Error::WrongSourceChain)); } Ok(msgs) @@ -155,7 +149,7 @@ where self, sender: Addr, msgs: Vec, - ) -> error_stack::Result { + ) -> error_stack::Result { let msgs = self.validate_msgs(&sender, msgs)?; let wasm_msgs = msgs @@ -165,7 +159,7 @@ where .map(|(destination_chain, msgs)| { let gateway = match self.store.load_chain_by_chain_name(&destination_chain)? { Some(destination_chain) if destination_chain.outgoing_frozen() => { - return Err(report!(ContractError::ChainFrozen { + return Err(report!(Error::ChainFrozen { chain: destination_chain.name, })); } @@ -176,7 +170,7 @@ where None if sender != self.config.nexus_gateway => { self.config.nexus_gateway.clone() } - _ => return Err(report!(ContractError::ChainNotFound)), + _ => return Err(report!(Error::ChainNotFound)), }; Ok(WasmMsg::Execute { @@ -198,17 +192,17 @@ where #[cfg(test)] mod test { use axelar_wasm_std::flagset::FlagSet; + use connection_router_api::error::Error; + use connection_router_api::{ + ChainEndpoint, ChainName, CrossChainId, Gateway, GatewayDirection, Message, + }; use cosmwasm_std::Addr; use mockall::predicate; use rand::{Rng, RngCore}; use crate::{ contract::Contract, - state::{ - ChainEndpoint, ChainName, Config, CrossChainId, Gateway, GatewayDirection, MockStore, - ID_SEPARATOR, - }, - ContractError, Message, + state::{Config, MockStore, ID_SEPARATOR}, }; fn rand_message(source_chain: ChainName, destination_chain: ChainName) -> Message { @@ -272,7 +266,7 @@ mod test { assert!(contract .route_messages(sender, vec![rand_message(source_chain, destination_chain)]) .is_err_and(move |err| { - matches!(err.current_context(), ContractError::GatewayNotRegistered) + matches!(err.current_context(), Error::GatewayNotRegistered) })); } @@ -309,7 +303,7 @@ mod test { assert!(contract .route_messages(sender, vec![rand_message(source_chain.clone(), destination_chain)]) .is_err_and(move |err| { - matches!(err.current_context(), ContractError::ChainFrozen { chain } if *chain == source_chain) + matches!(err.current_context(), Error::ChainFrozen { chain } if *chain == source_chain) })); } @@ -348,9 +342,7 @@ mod test { sender, vec![rand_message("polygon".parse().unwrap(), destination_chain)] ) - .is_err_and(|err| { - matches!(err.current_context(), ContractError::WrongSourceChain) - })); + .is_err_and(|err| { matches!(err.current_context(), Error::WrongSourceChain) })); } #[test] @@ -398,7 +390,7 @@ mod test { assert!(contract .route_messages(sender, vec![rand_message(source_chain, destination_chain.clone())]) .is_err_and(move |err| { - matches!(err.current_context(), ContractError::ChainFrozen { chain } if *chain == destination_chain) + matches!(err.current_context(), Error::ChainFrozen { chain } if *chain == destination_chain) })); } @@ -557,7 +549,7 @@ mod test { destination_chain.clone() )] ) - .is_err_and(|err| { matches!(err.current_context(), ContractError::ChainNotFound) })); + .is_err_and(|err| { matches!(err.current_context(), Error::ChainNotFound) })); } #[test] diff --git a/contracts/connection-router/src/contract/query.rs b/contracts/connection-router/src/contract/query.rs index b837be64a..d2274faa0 100644 --- a/contracts/connection-router/src/contract/query.rs +++ b/contracts/connection-router/src/contract/query.rs @@ -1,27 +1,25 @@ +use connection_router_api::error::Error; +use connection_router_api::{ChainEndpoint, ChainName}; use cosmwasm_std::Deps; - -use crate::{ - state::{chain_endpoints, ChainEndpoint, ChainName}, - ContractError, -}; use error_stack::{Result, ResultExt}; -pub fn get_chain_info(deps: Deps, chain: ChainName) -> Result { +use crate::state::chain_endpoints; + +pub fn get_chain_info(deps: Deps, chain: ChainName) -> Result { chain_endpoints() .may_load(deps.storage, chain) - .change_context(ContractError::StoreFailure)? - .ok_or(ContractError::ChainNotFound.into()) + .change_context(Error::StoreFailure)? + .ok_or(Error::ChainNotFound.into()) } #[cfg(test)] mod test { use axelar_wasm_std::flagset::FlagSet; + use connection_router_api::error::Error; + use connection_router_api::{ChainEndpoint, ChainName, Gateway, GatewayDirection}; use cosmwasm_std::{testing::mock_dependencies, Addr}; - use crate::{ - state::{chain_endpoints, ChainEndpoint, ChainName, Gateway, GatewayDirection}, - ContractError, - }; + use crate::state::chain_endpoints; use super::get_chain_info; @@ -51,9 +49,6 @@ mod test { let chain_name: ChainName = "Ethereum".to_string().try_into().unwrap(); let result = get_chain_info(deps.as_ref(), chain_name); assert!(result.is_err()); - assert_eq!( - result.unwrap_err().current_context(), - &ContractError::ChainNotFound - ); + assert_eq!(result.unwrap_err().current_context(), &Error::ChainNotFound); } } diff --git a/contracts/connection-router/src/error.rs b/contracts/connection-router/src/error.rs deleted file mode 100644 index fcadc9200..000000000 --- a/contracts/connection-router/src/error.rs +++ /dev/null @@ -1,51 +0,0 @@ -use cosmwasm_std::StdError; -use thiserror::Error; - -use axelar_wasm_std_derive::IntoContractError; - -use crate::state::ChainName; - -#[derive(Error, Debug, PartialEq, IntoContractError)] -pub enum ContractError { - #[error(transparent)] - Std(#[from] StdError), - - #[error("caller is not authorized")] - Unauthorized, - - #[error("chain already exists")] - ChainAlreadyExists, - - #[error("chain name is invalid")] - InvalidChainName, - - #[error("message ID is invalid")] - InvalidMessageId, - - #[error("chain is not found")] - ChainNotFound, - - #[error("gateway is not registered")] - GatewayNotRegistered, - - #[error("gateway is already registered")] - GatewayAlreadyRegistered, - - #[error("chain is frozen")] - ChainFrozen { chain: ChainName }, - - #[error("address is invalid")] - InvalidAddress, - - #[error("source chain does not match registered gateway")] - WrongSourceChain, - - #[error("store failed saving/loading data")] - StoreFailure, -} - -impl From for StdError { - fn from(value: ContractError) -> Self { - Self::generic_err(value.to_string()) - } -} diff --git a/contracts/connection-router/src/events.rs b/contracts/connection-router/src/events.rs index b4df83e87..6c6c0091a 100644 --- a/contracts/connection-router/src/events.rs +++ b/contracts/connection-router/src/events.rs @@ -1,7 +1,5 @@ -use cosmwasm_std::{Addr, Attribute, Event, HexBinary}; -use std::ops::Deref; - -use crate::state::{ChainName, Message}; +use connection_router_api::{ChainName, Message}; +use cosmwasm_std::{Addr, Attribute, Event}; pub struct RouterInstantiated { pub admin: Addr, @@ -101,30 +99,10 @@ impl From for Event { } } -impl From for Vec { - fn from(other: Message) -> Self { - vec![ - ("id", other.cc_id.id).into(), - ("source_chain", other.cc_id.chain).into(), - ("source_addresses", other.source_address.deref()).into(), - ("destination_chain", other.destination_chain).into(), - ("destination_addresses", other.destination_address.deref()).into(), - ( - "payload_hash", - HexBinary::from(other.payload_hash).to_string(), - ) - .into(), - ] - } -} - -pub fn make_message_event(event_name: &str, msg: Message) -> Event { - let attrs: Vec = msg.into(); - Event::new(event_name).add_attributes(attrs) -} - impl From for Event { fn from(other: MessageRouted) -> Self { - make_message_event("message_routed", other.msg) + let attrs: Vec = other.msg.into(); + + Event::new("message_routed").add_attributes(attrs) } } diff --git a/contracts/connection-router/src/lib.rs b/contracts/connection-router/src/lib.rs index 6467694bd..cdacc8154 100644 --- a/contracts/connection-router/src/lib.rs +++ b/contracts/connection-router/src/lib.rs @@ -1,9 +1,4 @@ -pub mod client; pub mod contract; -pub mod error; pub mod events; pub mod msg; pub mod state; - -pub use crate::error::ContractError; -pub use state::Message; diff --git a/contracts/connection-router/src/msg.rs b/contracts/connection-router/src/msg.rs index 593b2ea2f..fe286dc29 100644 --- a/contracts/connection-router/src/msg.rs +++ b/contracts/connection-router/src/msg.rs @@ -1,5 +1,4 @@ -use crate::state::{ChainEndpoint, ChainName, GatewayDirection, Message}; -use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_schema::cw_serde; #[cw_serde] pub struct InstantiateMsg { @@ -10,51 +9,3 @@ pub struct InstantiateMsg { // the address of the nexus gateway pub nexus_gateway: String, } - -#[cw_serde] -pub enum ExecuteMsg { - /* - * Governance Methods - * All of the below messages can only be called by governance - */ - // Registers a new chain with the router - RegisterChain { - chain: ChainName, - gateway_address: String, - }, - // Changes the gateway address associated with a particular chain - UpgradeGateway { - chain: ChainName, - contract_address: String, - }, - - /* - * Router Admin Methods - * All of the below messages can only be called by the router admin - */ - // Freezes a chain, in the specified direction. - FreezeChain { - chain: ChainName, - direction: GatewayDirection, - }, - // Unfreezes a chain, in the specified direction. - UnfreezeChain { - chain: ChainName, - direction: GatewayDirection, - }, - - /* - * Gateway Messages - * The below messages can only be called by registered gateways - */ - // Routes each message to the gateway registered to the destination chain. - // Called by a registered gateway - RouteMessages(Vec), -} - -#[cw_serde] -#[derive(QueryResponses)] -pub enum QueryMsg { - #[returns(ChainEndpoint)] - GetChainInfo(ChainName), -} diff --git a/contracts/connection-router/src/state.rs b/contracts/connection-router/src/state.rs index 59e9ef381..8a40a4d0b 100644 --- a/contracts/connection-router/src/state.rs +++ b/contracts/connection-router/src/state.rs @@ -1,42 +1,25 @@ -use std::any::type_name; -use std::fmt; -use std::fmt::{Display, Formatter}; -use std::ops::Deref; -use std::str::FromStr; - -use axelar_wasm_std::hash::Hash; +use connection_router_api::error::Error; +use connection_router_api::{ChainEndpoint, ChainName}; use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, DepsMut, Order, StdError, StdResult, Storage}; -use cw_storage_plus::{ - Index, IndexList, IndexedMap, Item, Key, KeyDeserialize, MultiIndex, Prefixer, PrimaryKey, -}; -use error_stack::{Report, ResultExt}; -use flagset::flags; +use cosmwasm_std::{Addr, DepsMut, Order, StdResult, Storage}; +use cw_storage_plus::{Index, IndexList, IndexedMap, Item, MultiIndex}; +use error_stack::ResultExt; use mockall::automock; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -use valuable::Valuable; - -use axelar_wasm_std::flagset::FlagSet; -use axelar_wasm_std::{nonempty, FnExt}; -use sha3::{Digest, Keccak256}; - -use crate::ContractError; pub const ID_SEPARATOR: char = ':'; #[automock] pub trait Store { - fn save_config(&mut self, config: Config) -> error_stack::Result<(), ContractError>; - fn load_config(&self) -> error_stack::Result; + fn save_config(&mut self, config: Config) -> error_stack::Result<(), Error>; + fn load_config(&self) -> error_stack::Result; fn load_chain_by_gateway( &self, gateway: &Addr, - ) -> error_stack::Result, ContractError>; + ) -> error_stack::Result, Error>; fn load_chain_by_chain_name( &self, chain_name: &ChainName, - ) -> error_stack::Result, ContractError>; + ) -> error_stack::Result, Error>; } pub struct RouterStore<'a> { @@ -44,36 +27,36 @@ pub struct RouterStore<'a> { } impl Store for RouterStore<'_> { - fn save_config(&mut self, config: Config) -> error_stack::Result<(), ContractError> { + fn save_config(&mut self, config: Config) -> error_stack::Result<(), Error> { CONFIG .save(self.storage, &config) - .change_context(ContractError::StoreFailure) + .change_context(Error::StoreFailure) } - fn load_config(&self) -> error_stack::Result { + fn load_config(&self) -> error_stack::Result { CONFIG .load(self.storage) - .change_context(ContractError::StoreFailure) + .change_context(Error::StoreFailure) } fn load_chain_by_gateway( &self, gateway: &Addr, - ) -> error_stack::Result, ContractError> { + ) -> error_stack::Result, Error> { chain_endpoints() .idx .gateway .load_chain_by_gateway(self.storage, gateway) - .change_context(ContractError::StoreFailure) + .change_context(Error::StoreFailure) } fn load_chain_by_chain_name( &self, chain_name: &ChainName, - ) -> error_stack::Result, ContractError> { + ) -> error_stack::Result, Error> { chain_endpoints() .may_load(self.storage, chain_name.clone()) - .change_context(ContractError::StoreFailure) + .change_context(Error::StoreFailure) } } @@ -156,359 +139,3 @@ impl<'a> IndexList for ChainEndpointIndexes<'a> { Box::new(v.into_iter()) } } - -#[cw_serde] -pub struct Message { - pub cc_id: CrossChainId, - pub source_address: Address, - pub destination_chain: ChainName, - pub destination_address: Address, - /// for better user experience, the payload hash gets encoded into hex at the edges (input/output), - /// but internally, we treat it as raw bytes to enforce it's format. - #[serde(with = "axelar_wasm_std::hex")] - #[schemars(with = "String")] // necessary attribute in conjunction with #[serde(with ...)] - pub payload_hash: [u8; 32], -} - -impl Message { - pub fn hash(&self) -> Hash { - let mut hasher = Keccak256::new(); - hasher.update(self.cc_id.to_string()); - hasher.update(self.source_address.as_str()); - hasher.update(self.destination_chain.as_ref()); - hasher.update(self.destination_address.as_str()); - hasher.update(self.payload_hash); - hasher.finalize().into() - } -} - -#[cw_serde] -pub struct Address(nonempty::String); - -impl Deref for Address { - type Target = String; - - fn deref(&self) -> &Self::Target { - self.0.deref() - } -} - -impl FromStr for Address { - type Err = Report; - - fn from_str(s: &str) -> Result { - Address::try_from(s.to_string()) - } -} - -impl TryFrom for Address { - type Error = Report; - - fn try_from(value: String) -> Result { - Ok(Address( - value - .parse::() - .change_context(ContractError::InvalidAddress)?, - )) - } -} - -#[cw_serde] -#[derive(Eq, Hash)] -pub struct CrossChainId { - pub chain: ChainName, - pub id: nonempty::String, -} - -/// todo: remove this when state::NewMessage is used -impl FromStr for CrossChainId { - type Err = ContractError; - - fn from_str(s: &str) -> Result { - let parts = s.split_once(ID_SEPARATOR); - let (chain, id) = parts - .map(|(chain, id)| { - ( - chain.parse::(), - id.parse::() - .map_err(|_| ContractError::InvalidMessageId), - ) - }) - .ok_or(ContractError::InvalidMessageId)?; - Ok(CrossChainId { - chain: chain?, - id: id?, - }) - } -} - -impl Display for CrossChainId { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{}{}{}", self.chain, ID_SEPARATOR, *self.id) - } -} - -impl PrimaryKey<'_> for CrossChainId { - type Prefix = ChainName; - type SubPrefix = (); - type Suffix = String; - type SuperSuffix = (ChainName, String); - - fn key(&self) -> Vec { - let mut keys = self.chain.key(); - keys.extend(self.id.key()); - keys - } -} - -impl KeyDeserialize for CrossChainId { - type Output = Self; - - fn from_vec(value: Vec) -> StdResult { - let (chain, id) = <(ChainName, String)>::from_vec(value)?; - Ok(CrossChainId { - chain, - id: id - .try_into() - .map_err(|err| StdError::parse_err(type_name::(), err))?, - }) - } -} - -#[cw_serde] -#[serde(try_from = "String")] -#[derive(Eq, Hash, Valuable)] -pub struct ChainName(String); - -impl FromStr for ChainName { - type Err = ContractError; - - fn from_str(s: &str) -> Result { - if s.contains(ID_SEPARATOR) || s.is_empty() { - return Err(ContractError::InvalidChainName); - } - - Ok(ChainName(s.to_lowercase())) - } -} - -impl From for String { - fn from(d: ChainName) -> Self { - d.0 - } -} - -impl TryFrom for ChainName { - type Error = ContractError; - - fn try_from(value: String) -> Result { - value.parse() - } -} - -impl Display for ChainName { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -impl PartialEq for ChainName { - fn eq(&self, other: &String) -> bool { - self.0 == other.to_lowercase() - } -} - -impl<'a> PrimaryKey<'a> for ChainName { - type Prefix = (); - type SubPrefix = (); - type Suffix = Self; - type SuperSuffix = Self; - - fn key(&self) -> Vec { - vec![Key::Ref(self.0.as_bytes())] - } -} - -impl<'a> Prefixer<'a> for ChainName { - fn prefix(&self) -> Vec { - vec![Key::Ref(self.0.as_bytes())] - } -} - -impl KeyDeserialize for ChainName { - type Output = Self; - - #[inline(always)] - fn from_vec(value: Vec) -> StdResult { - String::from_utf8(value) - .map_err(StdError::invalid_utf8)? - .then(ChainName::try_from) - .map_err(StdError::invalid_utf8) - } -} - -impl KeyDeserialize for &ChainName { - type Output = ChainName; - - #[inline(always)] - fn from_vec(value: Vec) -> StdResult { - ChainName::from_vec(value) - } -} - -impl AsRef for ChainName { - fn as_ref(&self) -> &str { - self.0.as_str() - } -} - -#[cw_serde] -pub struct Gateway { - pub address: Addr, -} - -#[cw_serde] -pub struct ChainEndpoint { - pub name: ChainName, - pub gateway: Gateway, - pub frozen_status: FlagSet, -} - -flags! { - #[repr(u8)] - #[derive(Deserialize, Serialize, Hash, JsonSchema)] - pub enum GatewayDirection: u8 { - None = 0, - Incoming = 1, - Outgoing = 2, - Bidirectional = (GatewayDirection::Incoming | GatewayDirection::Outgoing).bits(), - } -} - -impl ChainEndpoint { - pub fn incoming_frozen(&self) -> bool { - self.frozen_status.contains(GatewayDirection::Incoming) - } - - pub fn outgoing_frozen(&self) -> bool { - self.frozen_status.contains(GatewayDirection::Outgoing) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use cosmwasm_std::to_vec; - use hex; - use rand::distributions::Alphanumeric; - use rand::{thread_rng, Rng}; - use sha3::{Digest, Sha3_256}; - - use crate::ContractError; - - #[test] - // Any modifications to the Message struct fields or their types - // will cause this test to fail, indicating that a migration is needed. - fn test_message_struct_unchanged() { - let expected_message_hash = - "9f9b9c55ccf5ce5a82f66385cae9e84e402a272fece5a2e22a199dbefc91d8bf"; - - let msg = dummy_message(); - - assert_eq!( - hex::encode(Sha3_256::digest(&to_vec(&msg).unwrap())), - expected_message_hash - ); - } - - // If this test fails, it means the message hash has changed and therefore a migration is needed. - #[test] - fn hash_id_unchanged() { - let expected_message_hash = - "0135c407f6a58fdcfb879f8d9eae19f870a89f8619537dcde265b4599361a7b6"; - - let msg = dummy_message(); - - assert_eq!(hex::encode(msg.hash()), expected_message_hash); - } - - #[test] - fn should_fail_to_parse_invalid_chain_name() { - // empty - assert_eq!( - "".parse::().unwrap_err(), - ContractError::InvalidChainName - ); - - // name contains id separator - assert_eq!( - format!("chain {ID_SEPARATOR}") - .parse::() - .unwrap_err(), - ContractError::InvalidChainName - ); - } - - #[test] - fn should_parse_to_case_insensitive_chain_name() { - let rand_str: String = thread_rng() - .sample_iter(&Alphanumeric) - .take(10) - .map(char::from) - .collect(); - - let chain_name: ChainName = rand_str.parse().unwrap(); - - assert_eq!( - chain_name, - rand_str.to_lowercase().parse::().unwrap() - ); - assert_eq!( - chain_name, - rand_str.to_uppercase().parse::().unwrap() - ); - } - - #[test] - fn should_not_deserialize_invalid_chain_name() { - assert_eq!( - "chain name is invalid", - serde_json::from_str::(format!("\"\"").as_str()) - .unwrap_err() - .to_string() - ); - - assert_eq!( - "chain name is invalid", - serde_json::from_str::(format!("\"chain{ID_SEPARATOR}\"").as_str()) - .unwrap_err() - .to_string() - ); - } - - #[test] - fn chain_name_case_insensitive_comparison() { - let chain_name = ChainName::from_str("ethereum").unwrap(); - - assert!(chain_name.eq(&"Ethereum".to_string())); - assert!(chain_name.eq(&"ETHEREUM".to_string())); - assert!(chain_name.eq(&"ethereum".to_string())); - assert!(chain_name.eq(&"ethEReum".to_string())); - - assert!(!chain_name.eq(&"Ethereum-1".to_string())); - } - - fn dummy_message() -> Message { - Message { - cc_id: CrossChainId { - id: "hash:index".parse().unwrap(), - chain: "chain".parse().unwrap(), - }, - source_address: "source_address".parse().unwrap(), - destination_chain: "destination_chain".parse().unwrap(), - destination_address: "destination_address".parse().unwrap(), - payload_hash: [1; 32].into(), - } - } -} diff --git a/contracts/connection-router/tests/mock.rs b/contracts/connection-router/tests/mock.rs index 9bbccfd52..67bc0c1dd 100644 --- a/contracts/connection-router/tests/mock.rs +++ b/contracts/connection-router/tests/mock.rs @@ -1,5 +1,5 @@ -use connection_router::state::{CrossChainId, Message}; -use connection_router::ContractError; +use connection_router_api::error::Error; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_schema::cw_serde; use cosmwasm_std::{to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use cw_multi_test::{App, ContractWrapper, Executor}; @@ -17,7 +17,7 @@ pub fn mock_gateway_execute( _env: Env, _info: MessageInfo, msg: MockGatewayExecuteMsg, -) -> Result { +) -> Result { match msg { MockGatewayExecuteMsg::RouteMessages(messages) => { for m in messages { @@ -66,9 +66,7 @@ pub fn get_gateway_messages( pub fn make_mock_gateway(app: &mut App) -> Addr { let code = ContractWrapper::new( mock_gateway_execute, - |_, _, _, _: connection_router::msg::InstantiateMsg| { - Ok::(Response::new()) - }, + |_, _, _, _: connection_router::msg::InstantiateMsg| Ok::(Response::new()), mock_gateway_query, ); let code_id = app.store_code(Box::new(code)); diff --git a/contracts/connection-router/tests/test.rs b/contracts/connection-router/tests/test.rs index 31ef6f0eb..835659fd5 100644 --- a/contracts/connection-router/tests/test.rs +++ b/contracts/connection-router/tests/test.rs @@ -4,14 +4,14 @@ mod test_utils; use std::str::FromStr; use std::{collections::HashMap, vec}; +use connection_router_api::error::Error; +use connection_router_api::msg::ExecuteMsg; +use connection_router_api::{ChainName, CrossChainId, GatewayDirection, Message}; use cosmwasm_std::Addr; -use cw_multi_test::{App, Executor}; +use cw_multi_test::App; +use integration_tests::contract::Contract; use crate::test_utils::ConnectionRouterContract; -use connection_router::error::ContractError; -use connection_router::msg::ExecuteMsg; -use connection_router::state::{ChainName, CrossChainId, GatewayDirection, Message}; -use integration_tests::contract::Contract; struct TestConfig { app: App, @@ -63,7 +63,7 @@ fn register_chain(config: &mut TestConfig, chain: &Chain) { config.governance_address.clone(), &ExecuteMsg::RegisterChain { chain: chain.chain_name.clone(), - gateway_address: chain.gateway.to_string(), + gateway_address: chain.gateway.to_string().try_into().unwrap(), }, ) .unwrap(); @@ -149,7 +149,7 @@ fn wrong_source_chain() { &ExecuteMsg::RouteMessages(vec![messages.clone()]), ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::WrongSourceChain); + test_utils::are_contract_err_strings_equal(err, Error::WrongSourceChain); } #[test] @@ -219,11 +219,11 @@ fn authorization() { Addr::unchecked("random"), &ExecuteMsg::RegisterChain { chain: chain.chain_name.clone(), - gateway_address: chain.gateway.to_string(), + gateway_address: chain.gateway.to_string().try_into().unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let err = config .connection_router @@ -232,18 +232,18 @@ fn authorization() { config.admin_address.clone(), &ExecuteMsg::RegisterChain { chain: chain.chain_name.clone(), - gateway_address: chain.gateway.to_string(), + gateway_address: chain.gateway.to_string().try_into().unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let res = config.connection_router.execute( &mut config.app, config.governance_address.clone(), &ExecuteMsg::RegisterChain { chain: chain.chain_name.clone(), - gateway_address: chain.gateway.to_string(), + gateway_address: chain.gateway.to_string().try_into().unwrap(), }, ); assert!(res.is_ok()); @@ -259,7 +259,7 @@ fn authorization() { }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let err = config .connection_router @@ -272,7 +272,7 @@ fn authorization() { }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let res = config.connection_router.execute( &mut config.app, @@ -295,7 +295,7 @@ fn authorization() { }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let err = config .connection_router @@ -308,7 +308,7 @@ fn authorization() { }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let res = config.connection_router.execute( &mut config.app, @@ -327,11 +327,14 @@ fn authorization() { Addr::unchecked("random"), &ExecuteMsg::UpgradeGateway { chain: chain.chain_name.clone(), - contract_address: Addr::unchecked("new gateway").to_string(), + contract_address: Addr::unchecked("new gateway") + .to_string() + .try_into() + .unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let err = config .connection_router @@ -340,18 +343,24 @@ fn authorization() { config.admin_address.clone(), &ExecuteMsg::UpgradeGateway { chain: chain.chain_name.clone(), - contract_address: Addr::unchecked("new gateway").to_string(), + contract_address: Addr::unchecked("new gateway") + .to_string() + .try_into() + .unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::Unauthorized); + test_utils::are_contract_err_strings_equal(err, Error::Unauthorized); let res = config.connection_router.execute( &mut config.app, config.governance_address.clone(), &ExecuteMsg::UpgradeGateway { chain: chain.chain_name.clone(), - contract_address: Addr::unchecked("new gateway").to_string(), + contract_address: Addr::unchecked("new gateway") + .to_string() + .try_into() + .unwrap(), }, ); assert!(res.is_ok()); @@ -374,7 +383,7 @@ fn upgrade_gateway_outgoing() { config.governance_address.clone(), &ExecuteMsg::UpgradeGateway { chain: polygon.chain_name.clone(), - contract_address: new_gateway.to_string(), + contract_address: new_gateway.to_string().try_into().unwrap(), }, ) .unwrap(); @@ -416,7 +425,7 @@ fn upgrade_gateway_incoming() { config.governance_address.clone(), &ExecuteMsg::UpgradeGateway { chain: polygon.chain_name.clone(), - contract_address: new_gateway.to_string(), + contract_address: new_gateway.to_string().try_into().unwrap(), }, ) .unwrap(); @@ -430,7 +439,7 @@ fn upgrade_gateway_incoming() { &ExecuteMsg::RouteMessages(vec![message.clone()]), ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::GatewayNotRegistered); + test_utils::are_contract_err_strings_equal(err, Error::GatewayNotRegistered); let res = config.connection_router.execute( &mut config.app, @@ -459,7 +468,7 @@ fn register_chain_test() { &ExecuteMsg::RouteMessages(vec![message.clone()]), ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::GatewayNotRegistered); + test_utils::are_contract_err_strings_equal(err, Error::GatewayNotRegistered); register_chain(&mut config, ð); register_chain(&mut config, &polygon); @@ -485,11 +494,14 @@ fn chain_already_registered() { config.governance_address.clone(), &ExecuteMsg::RegisterChain { chain: eth.chain_name, - gateway_address: Addr::unchecked("new gateway").to_string(), + gateway_address: Addr::unchecked("new gateway") + .to_string() + .try_into() + .unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::ChainAlreadyExists); + test_utils::are_contract_err_strings_equal(err, Error::ChainAlreadyExists); // case insensitive let err = config @@ -499,23 +511,26 @@ fn chain_already_registered() { config.governance_address.clone(), &ExecuteMsg::RegisterChain { chain: ChainName::from_str("ETHEREUM").unwrap(), - gateway_address: Addr::unchecked("new gateway").to_string(), + gateway_address: Addr::unchecked("new gateway") + .to_string() + .try_into() + .unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::ChainAlreadyExists); + test_utils::are_contract_err_strings_equal(err, Error::ChainAlreadyExists); } #[test] fn invalid_chain_name() { test_utils::are_contract_err_strings_equal( ChainName::from_str("bad:").unwrap_err(), - ContractError::InvalidChainName, + Error::InvalidChainName, ); test_utils::are_contract_err_strings_equal( ChainName::from_str("").unwrap_err(), - ContractError::InvalidChainName, + Error::InvalidChainName, ); } @@ -533,11 +548,11 @@ fn gateway_already_registered() { config.governance_address.clone(), &ExecuteMsg::RegisterChain { chain: polygon.chain_name.clone(), - gateway_address: eth.gateway.to_string(), + gateway_address: eth.gateway.to_string().try_into().unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::GatewayAlreadyRegistered); + test_utils::are_contract_err_strings_equal(err, Error::GatewayAlreadyRegistered); register_chain(&mut config, &polygon); let err = config @@ -547,12 +562,12 @@ fn gateway_already_registered() { config.governance_address.clone(), &ExecuteMsg::UpgradeGateway { chain: eth.chain_name, - contract_address: polygon.gateway.to_string(), + contract_address: polygon.gateway.to_string().try_into().unwrap(), }, ) .unwrap_err(); - test_utils::are_contract_err_strings_equal(err, ContractError::GatewayAlreadyRegistered); + test_utils::are_contract_err_strings_equal(err, Error::GatewayAlreadyRegistered); } #[test] @@ -587,7 +602,7 @@ fn freeze_incoming() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -658,7 +673,7 @@ fn freeze_outgoing() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -728,7 +743,7 @@ fn freeze_chain() { // can't route to frozen chain test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -745,7 +760,7 @@ fn freeze_chain() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -845,7 +860,7 @@ fn unfreeze_incoming() { // can't route to the chain test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -896,7 +911,7 @@ fn unfreeze_outgoing() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -956,7 +971,7 @@ fn freeze_incoming_then_outgoing() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -973,7 +988,7 @@ fn freeze_incoming_then_outgoing() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -1024,7 +1039,7 @@ fn freeze_outgoing_then_incoming() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -1041,7 +1056,7 @@ fn freeze_outgoing_then_incoming() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -1218,7 +1233,7 @@ fn unfreeze_nothing() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -1235,7 +1250,7 @@ fn unfreeze_nothing() { .unwrap_err(); test_utils::are_contract_err_strings_equal( err, - ContractError::ChainFrozen { + Error::ChainFrozen { chain: polygon.chain_name.clone(), }, ); @@ -1255,7 +1270,10 @@ fn bad_gateway() { config.governance_address.clone(), &ExecuteMsg::UpgradeGateway { chain: polygon.chain_name.clone(), - contract_address: Addr::unchecked("some random address").to_string(), // gateway address does not implement required interface + contract_address: Addr::unchecked("some random address") + .to_string() + .try_into() + .unwrap(), // gateway address does not implement required interface }, ); diff --git a/contracts/connection-router/tests/test_utils/mod.rs b/contracts/connection-router/tests/test_utils/mod.rs index 2b978d6dc..96b93932d 100644 --- a/contracts/connection-router/tests/test_utils/mod.rs +++ b/contracts/connection-router/tests/test_utils/mod.rs @@ -1,7 +1,8 @@ use connection_router::{ contract::{execute, instantiate, query}, - msg::{ExecuteMsg, InstantiateMsg, QueryMsg}, + msg::InstantiateMsg, }; +use connection_router_api::msg::{ExecuteMsg, QueryMsg}; use cosmwasm_std::Addr; use cw_multi_test::{App, ContractWrapper, Executor}; use integration_tests::contract::Contract; diff --git a/contracts/gateway/Cargo.toml b/contracts/gateway/Cargo.toml index 306efb79f..0ca1f2f08 100644 --- a/contracts/gateway/Cargo.toml +++ b/contracts/gateway/Cargo.toml @@ -38,7 +38,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ aggregate-verifier = { workspace = true, features = ["library"] } axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } -connection-router = { workspace = true, features = ["library"] } +connection-router-api = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } diff --git a/contracts/gateway/src/contract.rs b/contracts/gateway/src/contract.rs index eb0480a8e..4752a92f2 100644 --- a/contracts/gateway/src/contract.rs +++ b/contracts/gateway/src/contract.rs @@ -54,14 +54,15 @@ pub enum Error { } mod internal { + use aggregate_verifier::client::Verifier; + use connection_router_api::client::Router; + use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response}; + use error_stack::{Result, ResultExt}; + use crate::contract::Error; use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; use crate::state::Config; use crate::{contract, state}; - use aggregate_verifier::client::Verifier; - use connection_router::client::Router; - use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response}; - use error_stack::{Result, ResultExt}; pub(crate) fn instantiate( deps: DepsMut, diff --git a/contracts/gateway/src/contract/execute.rs b/contracts/gateway/src/contract/execute.rs index 06b035c2b..198696d7c 100644 --- a/contracts/gateway/src/contract/execute.rs +++ b/contracts/gateway/src/contract/execute.rs @@ -1,14 +1,15 @@ -use crate::contract::Error; -use crate::events::GatewayEvent; -use crate::state; use aggregate_verifier::client::Verifier; use axelar_wasm_std::{FnExt, VerificationStatus}; -use connection_router::client::Router; -use connection_router::state::Message; +use connection_router_api::client::Router; +use connection_router_api::Message; use cosmwasm_std::{Event, Response, Storage, WasmMsg}; use error_stack::{Result, ResultExt}; use itertools::Itertools; +use crate::contract::Error; +use crate::events::GatewayEvent; +use crate::state; + pub fn verify_messages(verifier: &Verifier, msgs: Vec) -> Result { apply(verifier, msgs, |msgs_by_status| { verify(verifier, msgs_by_status) diff --git a/contracts/gateway/src/contract/query.rs b/contracts/gateway/src/contract/query.rs index 4118218e1..3a173f13f 100644 --- a/contracts/gateway/src/contract/query.rs +++ b/contracts/gateway/src/contract/query.rs @@ -1,11 +1,11 @@ -use crate::contract::Error; -use crate::state; -use connection_router::state::CrossChainId; -use connection_router::Message; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_std::Storage; use error_stack::{Result, ResultExt}; use itertools::Itertools; +use crate::contract::Error; +use crate::state; + pub fn get_outgoing_messages( storage: &dyn Storage, cross_chain_ids: Vec, diff --git a/contracts/gateway/src/events.rs b/contracts/gateway/src/events.rs index 2a607c910..434e6efa4 100644 --- a/contracts/gateway/src/events.rs +++ b/contracts/gateway/src/events.rs @@ -1,6 +1,5 @@ -use connection_router::events::make_message_event; -use connection_router::state::Message; -use cosmwasm_std::Event; +use connection_router_api::Message; +use cosmwasm_std::{Attribute, Event}; pub enum GatewayEvent { Verifying { msg: Message }, @@ -10,6 +9,12 @@ pub enum GatewayEvent { UnfitForRouting { msg: Message }, } +fn make_message_event(event_name: &str, msg: Message) -> Event { + let attrs: Vec = msg.into(); + + Event::new(event_name).add_attributes(attrs) +} + impl From for Event { fn from(other: GatewayEvent) -> Self { match other { diff --git a/contracts/gateway/src/msg.rs b/contracts/gateway/src/msg.rs index eaffe7b0d..d26077521 100644 --- a/contracts/gateway/src/msg.rs +++ b/contracts/gateway/src/msg.rs @@ -1,4 +1,4 @@ -use connection_router::state::{CrossChainId, Message}; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_schema::{cw_serde, QueryResponses}; #[cw_serde] diff --git a/contracts/gateway/src/state.rs b/contracts/gateway/src/state.rs index 03b631c92..19b915e8a 100644 --- a/contracts/gateway/src/state.rs +++ b/contracts/gateway/src/state.rs @@ -1,4 +1,4 @@ -use connection_router::state::{CrossChainId, Message}; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Storage}; use cw_storage_plus::{Item, Map}; @@ -57,13 +57,13 @@ const OUTGOING_MESSAGES: Map = Map::new(OUTGOING_MESSAGES #[cfg(test)] mod test { + use connection_router_api::{CrossChainId, Message}; + use cosmwasm_std::testing::mock_dependencies; + use cosmwasm_std::Addr; + use crate::state::{ load_config, may_load_outgoing_msg, save_config, save_outgoing_msg, Config, }; - use connection_router::state::CrossChainId; - use connection_router::Message; - use cosmwasm_std::testing::mock_dependencies; - use cosmwasm_std::Addr; #[test] fn config_storage() { diff --git a/contracts/gateway/tests/contract.rs b/contracts/gateway/tests/contract.rs index 992667c25..5839e287e 100644 --- a/contracts/gateway/tests/contract.rs +++ b/contracts/gateway/tests/contract.rs @@ -1,5 +1,10 @@ +use std::collections::HashMap; +use std::fmt::Debug; +use std::fs::File; +use std::iter; + use axelar_wasm_std::{ContractError, VerificationStatus}; -use connection_router::state::{CrossChainId, Message, ID_SEPARATOR}; +use connection_router_api::{CrossChainId, Message, ID_SEPARATOR}; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info, MockQuerier}; use cosmwasm_std::{ from_binary, to_binary, Addr, ContractResult, DepsMut, QuerierResult, WasmQuery, @@ -8,10 +13,6 @@ use gateway::contract::*; use gateway::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; use itertools::Itertools; use serde::Serialize; -use std::collections::HashMap; -use std::fmt::Debug; -use std::fs::File; -use std::iter; #[cfg(not(feature = "generate_golden_files"))] use cosmwasm_std::Response; diff --git a/contracts/multisig-prover/Cargo.toml b/contracts/multisig-prover/Cargo.toml index edbc43873..bce30a80d 100644 --- a/contracts/multisig-prover/Cargo.toml +++ b/contracts/multisig-prover/Cargo.toml @@ -36,7 +36,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } bcs = "0.1.5" -connection-router = { workspace = true, features = ["library"] } +connection-router-api = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } diff --git a/contracts/multisig-prover/src/contract.rs b/contracts/multisig-prover/src/contract.rs index 52b77f9e1..ead593a88 100644 --- a/contracts/multisig-prover/src/contract.rs +++ b/contracts/multisig-prover/src/contract.rs @@ -4,10 +4,6 @@ use cosmwasm_std::{ to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, }; -use std::str::FromStr; - -use connection_router::state::ChainName; - use crate::{ error::ContractError, execute, @@ -41,7 +37,9 @@ pub fn instantiate( destination_chain_id: msg.destination_chain_id, signing_threshold: msg.signing_threshold, service_name: msg.service_name, - chain_name: ChainName::from_str(&msg.chain_name) + chain_name: msg + .chain_name + .parse() .map_err(|_| ContractError::InvalidChainName)?, worker_set_diff_threshold: msg.worker_set_diff_threshold, encoder: msg.encoder, @@ -98,7 +96,7 @@ mod tests { use anyhow::Error; use axelar_wasm_std::Threshold; - use connection_router::state::CrossChainId; + use connection_router_api::CrossChainId; use cosmwasm_std::{ testing::{mock_dependencies, mock_env, mock_info}, Addr, Fraction, Uint256, Uint64, diff --git a/contracts/multisig-prover/src/encoding/abi.rs b/contracts/multisig-prover/src/encoding/abi.rs index 9ecec67b3..305bff6d8 100644 --- a/contracts/multisig-prover/src/encoding/abi.rs +++ b/contracts/multisig-prover/src/encoding/abi.rs @@ -237,7 +237,7 @@ pub fn command_params( #[cfg(test)] mod test { - use connection_router::state::CrossChainId; + use connection_router_api::CrossChainId; use elliptic_curve::consts::U32; use ethers::types::Signature as EthersSignature; use generic_array::GenericArray; diff --git a/contracts/multisig-prover/src/encoding/bcs.rs b/contracts/multisig-prover/src/encoding/bcs.rs index 86ea5762a..f16dc8e26 100644 --- a/contracts/multisig-prover/src/encoding/bcs.rs +++ b/contracts/multisig-prover/src/encoding/bcs.rs @@ -199,7 +199,7 @@ mod test { use axelar_wasm_std::operators::Operators; use bcs::from_bytes; - use connection_router::state::{CrossChainId, Message}; + use connection_router_api::{CrossChainId, Message}; use cosmwasm_std::{Addr, HexBinary, Uint256}; use multisig::{ diff --git a/contracts/multisig-prover/src/encoding/mod.rs b/contracts/multisig-prover/src/encoding/mod.rs index f84f29c25..ca042d0b1 100644 --- a/contracts/multisig-prover/src/encoding/mod.rs +++ b/contracts/multisig-prover/src/encoding/mod.rs @@ -6,7 +6,7 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::{HexBinary, Uint256}; use sha3::{Digest, Keccak256}; -use connection_router::state::{CrossChainId, Message}; +use connection_router_api::{CrossChainId, Message}; use multisig::{key::Signature, msg::Signer, worker_set::WorkerSet}; use crate::{ diff --git a/contracts/multisig-prover/src/events.rs b/contracts/multisig-prover/src/events.rs index 23f1c1698..5b25e8dcd 100644 --- a/contracts/multisig-prover/src/events.rs +++ b/contracts/multisig-prover/src/events.rs @@ -1,6 +1,6 @@ use crate::types::BatchId; use axelar_wasm_std::event; -use connection_router::state::{ChainName, CrossChainId}; +use connection_router_api::{ChainName, CrossChainId}; use cosmwasm_std::Uint64; pub enum Event { diff --git a/contracts/multisig-prover/src/execute.rs b/contracts/multisig-prover/src/execute.rs index ab3290bd0..35878ee50 100644 --- a/contracts/multisig-prover/src/execute.rs +++ b/contracts/multisig-prover/src/execute.rs @@ -6,7 +6,7 @@ use cosmwasm_std::{ use multisig::{key::PublicKey, msg::Signer, worker_set::WorkerSet}; use axelar_wasm_std::{snapshot, VerificationStatus}; -use connection_router::state::{ChainName, CrossChainId, Message}; +use connection_router_api::{ChainName, CrossChainId, Message}; use service_registry::state::Worker; use crate::{ diff --git a/contracts/multisig-prover/src/msg.rs b/contracts/multisig-prover/src/msg.rs index 2442b1b94..85eea7ee5 100644 --- a/contracts/multisig-prover/src/msg.rs +++ b/contracts/multisig-prover/src/msg.rs @@ -1,5 +1,5 @@ use axelar_wasm_std::MajorityThreshold; -use connection_router::state::CrossChainId; +use connection_router_api::CrossChainId; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{HexBinary, Uint256, Uint64}; use multisig::key::KeyType; diff --git a/contracts/multisig-prover/src/state.rs b/contracts/multisig-prover/src/state.rs index 446ea7231..c1eef5eb7 100644 --- a/contracts/multisig-prover/src/state.rs +++ b/contracts/multisig-prover/src/state.rs @@ -1,5 +1,5 @@ use axelar_wasm_std::MajorityThreshold; -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Uint256}; use cw_storage_plus::{Item, Map}; diff --git a/contracts/multisig-prover/src/test/test_data.rs b/contracts/multisig-prover/src/test/test_data.rs index 3f47df005..a804c37ee 100644 --- a/contracts/multisig-prover/src/test/test_data.rs +++ b/contracts/multisig-prover/src/test/test_data.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use axelar_wasm_std::{nonempty, MajorityThreshold, Threshold}; -use connection_router::state::Message; +use connection_router_api::Message; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, HexBinary, Uint256, Uint64}; use multisig::{ diff --git a/contracts/multisig-prover/src/types.rs b/contracts/multisig-prover/src/types.rs index 390ec1824..2e94db66f 100644 --- a/contracts/multisig-prover/src/types.rs +++ b/contracts/multisig-prover/src/types.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use axelar_wasm_std::{Participant, Snapshot}; -use connection_router::state::CrossChainId; +use connection_router_api::CrossChainId; use cosmwasm_schema::cw_serde; use cosmwasm_std::{from_binary, HexBinary, StdResult, Uint256}; use cw_storage_plus::{Key, KeyDeserialize, PrimaryKey}; diff --git a/contracts/multisig/Cargo.toml b/contracts/multisig/Cargo.toml index a5883ee30..130f41438 100644 --- a/contracts/multisig/Cargo.toml +++ b/contracts/multisig/Cargo.toml @@ -40,7 +40,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } -connection-router = { workspace = true, features = ["library"] } +connection-router-api = { workspace = true } cosmwasm-crypto = "1.2.7" cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } diff --git a/contracts/multisig/src/contract.rs b/contracts/multisig/src/contract.rs index 261274fb7..fcf1ec9ab 100644 --- a/contracts/multisig/src/contract.rs +++ b/contracts/multisig/src/contract.rs @@ -123,7 +123,7 @@ mod tests { }; use super::*; - use connection_router::state::ChainName; + use connection_router_api::ChainName; use cosmwasm_std::{ from_binary, testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage}, diff --git a/contracts/multisig/src/contract/execute.rs b/contracts/multisig/src/contract/execute.rs index 13e1233dc..db2643e10 100644 --- a/contracts/multisig/src/contract/execute.rs +++ b/contracts/multisig/src/contract/execute.rs @@ -1,4 +1,4 @@ -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmwasm_std::WasmMsg; use sha3::{Digest, Keccak256}; use signature_verifier_api::client::SignatureVerifier; diff --git a/contracts/multisig/src/events.rs b/contracts/multisig/src/events.rs index 3a9e08290..23218e235 100644 --- a/contracts/multisig/src/events.rs +++ b/contracts/multisig/src/events.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmwasm_std::{Addr, HexBinary, Uint64}; use serde_json::to_string; diff --git a/contracts/multisig/src/msg.rs b/contracts/multisig/src/msg.rs index 93dffec6c..d5baeff1a 100644 --- a/contracts/multisig/src/msg.rs +++ b/contracts/multisig/src/msg.rs @@ -1,4 +1,4 @@ -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, HexBinary, Uint256, Uint64}; diff --git a/contracts/multisig/src/signing.rs b/contracts/multisig/src/signing.rs index 3b8018de7..8803a86e4 100644 --- a/contracts/multisig/src/signing.rs +++ b/contracts/multisig/src/signing.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Uint256, Uint64}; use signature_verifier_api::client::SignatureVerifier; diff --git a/contracts/nexus-gateway/Cargo.toml b/contracts/nexus-gateway/Cargo.toml index 4b2f6b97e..4b180754e 100644 --- a/contracts/nexus-gateway/Cargo.toml +++ b/contracts/nexus-gateway/Cargo.toml @@ -15,7 +15,7 @@ path = "src/bin/schema.rs" [dependencies] axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } -connection-router = { workspace = true, features = ["library"] } +connection-router-api = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } diff --git a/contracts/nexus-gateway/src/contract/execute.rs b/contracts/nexus-gateway/src/contract/execute.rs index c848d6ec5..9cba415f9 100644 --- a/contracts/nexus-gateway/src/contract/execute.rs +++ b/contracts/nexus-gateway/src/contract/execute.rs @@ -24,7 +24,7 @@ where let msgs: Vec<_> = msgs .into_iter() - .map(connection_router::Message::from) + .map(connection_router_api::Message::from) .collect(); if msgs.is_empty() { return Ok(Response::default()); @@ -32,7 +32,7 @@ where Ok(Response::new().add_message(WasmMsg::Execute { contract_addr: self.config.router.to_string(), - msg: to_binary(&connection_router::msg::ExecuteMsg::RouteMessages(msgs)) + msg: to_binary(&connection_router_api::msg::ExecuteMsg::RouteMessages(msgs)) .expect("must serialize route-messages message"), funds: vec![], })) @@ -41,7 +41,7 @@ where pub fn route_to_nexus( mut self, sender: Addr, - msgs: Vec, + msgs: Vec, ) -> Result> { if sender != self.config.router { return Err(report!(ContractError::Unauthorized)); @@ -67,7 +67,7 @@ where #[cfg(test)] mod test { - use connection_router::state::CrossChainId; + use connection_router_api::CrossChainId; use cosmwasm_std::{from_binary, CosmosMsg}; use crate::state::{Config, MockStore}; @@ -164,7 +164,7 @@ mod test { msg, funds, }) => { - if let Ok(connection_router::msg::ExecuteMsg::RouteMessages(msgs)) = + if let Ok(connection_router_api::msg::ExecuteMsg::RouteMessages(msgs)) = from_binary(msg) { return *contract_addr == Addr::unchecked("router") @@ -234,7 +234,7 @@ mod test { let contract = Contract::new(store); let msgs = vec![ - connection_router::Message { + connection_router_api::Message { cc_id: CrossChainId { chain: "sourceChain".parse().unwrap(), id: "0x2fe4:0".parse().unwrap(), @@ -249,7 +249,7 @@ mod test { .try_into() .unwrap(), }, - connection_router::Message { + connection_router_api::Message { cc_id: CrossChainId { chain: "sourceChain".parse().unwrap(), id: "0x6b33:10".parse().unwrap(), @@ -295,7 +295,7 @@ mod test { let contract = Contract::new(store); let msgs = vec![ - connection_router::Message { + connection_router_api::Message { cc_id: CrossChainId { chain: "sourceChain".parse().unwrap(), id: "0x2fe4:0".parse().unwrap(), @@ -310,7 +310,7 @@ mod test { .try_into() .unwrap(), }, - connection_router::Message { + connection_router_api::Message { cc_id: CrossChainId { chain: "sourceChain".parse().unwrap(), id: "0x6b33:10".parse().unwrap(), diff --git a/contracts/nexus-gateway/src/msg.rs b/contracts/nexus-gateway/src/msg.rs index 845991574..22eefc9b2 100644 --- a/contracts/nexus-gateway/src/msg.rs +++ b/contracts/nexus-gateway/src/msg.rs @@ -10,7 +10,7 @@ pub struct InstantiateMsg { #[cw_serde] pub enum ExecuteMsg { - RouteMessages(Vec), + RouteMessages(Vec), RouteMessagesFromNexus(Vec), } diff --git a/contracts/nexus-gateway/src/nexus.rs b/contracts/nexus-gateway/src/nexus.rs index 9e6b418e5..7da4d02ac 100644 --- a/contracts/nexus-gateway/src/nexus.rs +++ b/contracts/nexus-gateway/src/nexus.rs @@ -1,5 +1,5 @@ use axelar_wasm_std::nonempty; -use connection_router::state::{Address, ChainName, CrossChainId, ID_SEPARATOR}; +use connection_router_api::{Address, ChainName, CrossChainId, ID_SEPARATOR}; use cosmwasm_std::{CosmosMsg, CustomMsg}; use error_stack::{Result, ResultExt}; use hex::{FromHex, ToHex}; @@ -45,8 +45,8 @@ fn parse_message_id(message_id: &str) -> Result<(nonempty::Vec, u64), Contra Ok((tx_id, index)) } -impl From for Message { - fn from(msg: connection_router::Message) -> Self { +impl From for Message { + fn from(msg: connection_router_api::Message) -> Self { // fallback to using the message ID as the tx ID if it's not in the expected format let (source_tx_id, source_tx_index) = parse_message_id(&msg.cc_id.id).unwrap_or((msg.cc_id.id.into(), u64::MAX)); @@ -63,7 +63,7 @@ impl From for Message { } } -impl From for connection_router::Message { +impl From for connection_router_api::Message { fn from(msg: Message) -> Self { Self { cc_id: CrossChainId { diff --git a/contracts/nexus-gateway/src/state.rs b/contracts/nexus-gateway/src/state.rs index c709eb5b1..13c570c3c 100644 --- a/contracts/nexus-gateway/src/state.rs +++ b/contracts/nexus-gateway/src/state.rs @@ -1,4 +1,4 @@ -use connection_router::state::CrossChainId; +use connection_router_api::CrossChainId; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Storage}; use cw_storage_plus::{Item, Map}; diff --git a/contracts/rewards/Cargo.toml b/contracts/rewards/Cargo.toml index b5a42d959..4bac85b6d 100644 --- a/contracts/rewards/Cargo.toml +++ b/contracts/rewards/Cargo.toml @@ -35,7 +35,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } -connection-router = { workspace = true, features = ["library"] } +connection-router-api = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cw-storage-plus = { workspace = true } diff --git a/contracts/rewards/src/contract.rs b/contracts/rewards/src/contract.rs index 86fcc3ef1..e6ac590f0 100644 --- a/contracts/rewards/src/contract.rs +++ b/contracts/rewards/src/contract.rs @@ -123,7 +123,7 @@ pub fn execute( #[cfg(test)] mod tests { - use connection_router::state::ChainName; + use connection_router_api::ChainName; use cosmwasm_std::{coins, Addr, Binary, BlockInfo, Deps, Env, StdResult, Uint128}; use cw_multi_test::{App, ContractWrapper, Executor}; diff --git a/contracts/rewards/src/contract/execute.rs b/contracts/rewards/src/contract/execute.rs index 848ab652d..55d0edcaf 100644 --- a/contracts/rewards/src/contract/execute.rs +++ b/contracts/rewards/src/contract/execute.rs @@ -248,7 +248,7 @@ mod test { }; use axelar_wasm_std::nonempty; - use connection_router::state::ChainName; + use connection_router_api::ChainName; use cosmwasm_std::{Addr, Uint128, Uint64}; use crate::{ diff --git a/contracts/rewards/src/msg.rs b/contracts/rewards/src/msg.rs index 3e4b73ce5..5fd361596 100644 --- a/contracts/rewards/src/msg.rs +++ b/contracts/rewards/src/msg.rs @@ -1,5 +1,5 @@ use axelar_wasm_std::{nonempty, Threshold}; -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmwasm_schema::{cw_serde, QueryResponses}; use crate::state::PoolId; diff --git a/contracts/rewards/src/state.rs b/contracts/rewards/src/state.rs index a7d0f1b24..8139ad0e4 100644 --- a/contracts/rewards/src/state.rs +++ b/contracts/rewards/src/state.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::ops::Deref; use axelar_wasm_std::{nonempty, Threshold}; -use connection_router::state::ChainName; +use connection_router_api::ChainName; use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, StdResult, Storage, Uint128}; use cw_storage_plus::{Item, Key, KeyDeserialize, Map, Prefixer, PrimaryKey}; @@ -368,7 +368,7 @@ mod test { use super::{Epoch, EpochTally, Event, PoolId, RewardsPool, RewardsStore, Store}; use crate::error::ContractError; use crate::{msg::Params, state::StoredParams}; - use connection_router::state::ChainName; + use connection_router_api::ChainName; use cosmwasm_std::{testing::mock_dependencies, Addr, Uint128, Uint64}; use std::collections::HashMap; diff --git a/contracts/service-registry/Cargo.toml b/contracts/service-registry/Cargo.toml index 6621e39ba..6b9535257 100644 --- a/contracts/service-registry/Cargo.toml +++ b/contracts/service-registry/Cargo.toml @@ -35,7 +35,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ [dependencies] axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } -connection-router = { workspace = true, features = ["library"] } +connection-router-api = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } cosmwasm-storage = { workspace = true } diff --git a/contracts/service-registry/src/contract.rs b/contracts/service-registry/src/contract.rs index 4ecd8bbf1..c8f2c950c 100644 --- a/contracts/service-registry/src/contract.rs +++ b/contracts/service-registry/src/contract.rs @@ -114,7 +114,7 @@ pub fn execute( } pub mod execute { - use connection_router::state::ChainName; + use connection_router_api::ChainName; use crate::state::{AuthorizationState, WORKERS, WORKERS_PER_CHAIN}; @@ -370,7 +370,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result)] + #[returns(Vec<(CrossChainId, VerificationStatus)>)] GetMessagesStatus { messages: Vec }, #[returns(VerificationStatus)] diff --git a/contracts/voting-verifier/src/query.rs b/contracts/voting-verifier/src/query.rs index 5beba7a6f..ecc5a221e 100644 --- a/contracts/voting-verifier/src/query.rs +++ b/contracts/voting-verifier/src/query.rs @@ -3,7 +3,7 @@ use axelar_wasm_std::{ voting::{PollStatus, Vote}, VerificationStatus, }; -use connection_router::state::{CrossChainId, Message}; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_std::Deps; use crate::error::ContractError; diff --git a/contracts/voting-verifier/src/state.rs b/contracts/voting-verifier/src/state.rs index a671a4c4a..fe6e333d3 100644 --- a/contracts/voting-verifier/src/state.rs +++ b/contracts/voting-verifier/src/state.rs @@ -10,7 +10,7 @@ use axelar_wasm_std::{ voting::{PollId, WeightedPoll}, MajorityThreshold, }; -use connection_router::state::{ChainName, Message}; +use connection_router_api::{ChainName, Message}; use crate::error::ContractError; diff --git a/contracts/voting-verifier/tests/tests.rs b/contracts/voting-verifier/tests/tests.rs index 2fd4106c2..e02e68523 100644 --- a/contracts/voting-verifier/tests/tests.rs +++ b/contracts/voting-verifier/tests/tests.rs @@ -4,7 +4,7 @@ use cw_multi_test::{App, ContractWrapper, Executor}; use axelar_wasm_std::operators::Operators; use axelar_wasm_std::{nonempty, Threshold, VerificationStatus}; -use connection_router::state::{ChainName, CrossChainId, Message, ID_SEPARATOR}; +use connection_router_api::{ChainName, CrossChainId, Message, ID_SEPARATOR}; use mock::make_mock_rewards; use service_registry::state::Worker; use voting_verifier::events::TxEventConfirmation; diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index ea879bba7..17a28bb38 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -32,6 +32,7 @@ optimize = """docker run --rm -v "$(pwd)":/code \ aggregate-verifier = { workspace = true, features = ["library"] } axelar-wasm-std = { workspace = true } axelar-wasm-std-derive = { workspace = true } +connection-router-api = { workspace = true } connection-router = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } diff --git a/integration-tests/tests/message_routing.rs b/integration-tests/tests/message_routing.rs index 1ea8ab0a5..f85a994da 100644 --- a/integration-tests/tests/message_routing.rs +++ b/integration-tests/tests/message_routing.rs @@ -1,4 +1,4 @@ -use connection_router::state::{CrossChainId, Message}; +use connection_router_api::{CrossChainId, Message}; use cosmwasm_std::{HexBinary, Uint128}; use crate::test_utils::AXL_DENOMINATION; diff --git a/integration-tests/tests/test_utils/mod.rs b/integration-tests/tests/test_utils/mod.rs index 2b983355b..761aca995 100644 --- a/integration-tests/tests/test_utils/mod.rs +++ b/integration-tests/tests/test_utils/mod.rs @@ -3,7 +3,7 @@ use axelar_wasm_std::{ voting::{PollId, Vote}, Participant, Threshold, }; -use connection_router::state::{ChainName, CrossChainId, Message}; +use connection_router_api::{ChainName, CrossChainId, Message}; use cosmwasm_std::{ coins, Addr, Attribute, Binary, BlockInfo, Deps, Env, Event, HexBinary, StdResult, Uint128, Uint256, Uint64, @@ -730,9 +730,9 @@ pub fn setup_chain(protocol: &mut Protocol, chain_name: ChainName) -> Chain { let response = protocol.app.execute_contract( protocol.governance_address.clone(), protocol.router_address.clone(), - &connection_router::msg::ExecuteMsg::RegisterChain { + &connection_router_api::msg::ExecuteMsg::RegisterChain { chain: chain_name.clone(), - gateway_address: gateway_address.to_string(), + gateway_address: gateway_address.to_string().try_into().unwrap(), }, &[], ); diff --git a/integration-tests/tests/update_worker_set.rs b/integration-tests/tests/update_worker_set.rs index 34c800ce0..ef739d973 100644 --- a/integration-tests/tests/update_worker_set.rs +++ b/integration-tests/tests/update_worker_set.rs @@ -1,4 +1,4 @@ -use connection_router::Message; +use connection_router_api::Message; use cosmwasm_std::Addr; use cw_multi_test::Executor; use test_utils::Worker; @@ -7,7 +7,7 @@ mod test_utils; #[test] fn worker_set_can_be_initialized_and_then_manually_updated() { - let chains: Vec = vec![ + let chains: Vec = vec![ "Ethereum".to_string().try_into().unwrap(), "Polygon".to_string().try_into().unwrap(), ]; @@ -287,7 +287,7 @@ fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed( let second_wave_of_new_workers = test_utils::create_new_workers_vec(chains.clone(), vec![("worker5".to_string(), 5)]); - let second_wave_session_id = test_utils::update_registry_and_construct_proof( + let _second_wave_session_id = test_utils::update_registry_and_construct_proof( &mut protocol, &second_wave_of_new_workers, &first_wave_of_new_workers, diff --git a/contracts/connection-router/src/client.rs b/packages/connection-router-api/src/client.rs similarity index 99% rename from contracts/connection-router/src/client.rs rename to packages/connection-router-api/src/client.rs index 552502ffa..a0a8cad01 100644 --- a/contracts/connection-router/src/client.rs +++ b/packages/connection-router-api/src/client.rs @@ -1,6 +1,7 @@ +use cosmwasm_std::{to_binary, Addr, WasmMsg}; + use crate::msg::ExecuteMsg; use crate::Message; -use cosmwasm_std::{to_binary, Addr, WasmMsg}; pub struct Router { pub address: Addr, diff --git a/packages/connection-router-api/src/error.rs b/packages/connection-router-api/src/error.rs index f179a6a6b..72167a0bf 100644 --- a/packages/connection-router-api/src/error.rs +++ b/packages/connection-router-api/src/error.rs @@ -1,6 +1,8 @@ +use axelar_wasm_std_derive::IntoContractError; +use cosmwasm_std::StdError; use thiserror::Error; -use axelar_wasm_std_derive::IntoContractError; +use crate::ChainName; /// A chain name must adhere to the following rules: /// 1. it can optionally start with an uppercase letter, followed by one or more lowercase letters @@ -9,12 +11,39 @@ pub const CHAIN_NAME_REGEX: &str = "^[A-Z]?[a-z]+(-?[0-9]+)?$"; #[derive(Error, Debug, PartialEq, IntoContractError)] pub enum Error { - #[error("address is invalid")] - InvalidAddress, + #[error(transparent)] + Std(#[from] StdError), - #[error("message ID is invalid")] - InvalidMessageId, + #[error("caller is not authorized")] + Unauthorized, + + #[error("chain already exists")] + ChainAlreadyExists, #[error("chain name is invalid")] InvalidChainName, + + #[error("message ID is invalid")] + InvalidMessageId, + + #[error("chain is not found")] + ChainNotFound, + + #[error("gateway is not registered")] + GatewayNotRegistered, + + #[error("gateway is already registered")] + GatewayAlreadyRegistered, + + #[error("chain is frozen")] + ChainFrozen { chain: ChainName }, + + #[error("address is invalid")] + InvalidAddress, + + #[error("source chain does not match registered gateway")] + WrongSourceChain, + + #[error("store failed saving/loading data")] + StoreFailure, } diff --git a/packages/connection-router-api/src/lib.rs b/packages/connection-router-api/src/lib.rs index 50248ad6d..4e306efaf 100644 --- a/packages/connection-router-api/src/lib.rs +++ b/packages/connection-router-api/src/lib.rs @@ -3,3 +3,4 @@ mod primitives; pub mod error; pub mod msg; pub use primitives::*; +pub mod client;