From 03e8a228ffe0bba831f1b7b2ce5d11a9051bdaad Mon Sep 17 00:00:00 2001 From: Haiyi Zhong Date: Mon, 21 Oct 2024 22:47:04 +0800 Subject: [PATCH] address comments --- .../axelarnet-gateway/src/contract/execute.rs | 58 +++++++------------ 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/contracts/axelarnet-gateway/src/contract/execute.rs b/contracts/axelarnet-gateway/src/contract/execute.rs index 3d97fe94d..38b5ccbdc 100644 --- a/contracts/axelarnet-gateway/src/contract/execute.rs +++ b/contracts/axelarnet-gateway/src/contract/execute.rs @@ -96,9 +96,8 @@ pub fn call_contract( call_contract: CallContractData, ) -> Result> { let Config { - router, chain_name, - nexus, + .. } = state::load_config(storage); let client: nexus::Client = client::CosmosClient::new(querier).into(); @@ -119,24 +118,7 @@ pub fn call_contract( token: token.clone(), }; - let res = match determine_routing_destination( - storage, - &info.sender, - &client, - &msg.destination_chain, - )? { - RoutingDestination::Nexus => { - Response::new().add_messages(route_to_nexus(&client, &nexus, msg, token)?) - } - RoutingDestination::Router if token.is_none() => { - let (messages, events) = route_to_router(&Router::new(router), vec![msg])?; - Response::new().add_messages(messages).add_events(events) - } - _ => bail!(Error::InvalidRoutingDestination), - } - .add_event(event.into()); - - Ok(res) + route_messages(storage, querier, info.sender, vec![msg]).map(|res| res.add_event(event.into())) } pub fn route_messages( @@ -170,16 +152,21 @@ pub fn route_messages( .group_by(|msg| msg.destination_chain.to_owned()) .into_iter() .try_fold(Response::new(), |acc, (dest_chain, msgs)| { - let (messages, events) = - match determine_routing_destination(storage, &sender, &client, &dest_chain)? { - RoutingDestination::This => { - prepare_msgs_for_execution(storage, chain_name.clone(), msgs.collect()) - } - RoutingDestination::Nexus => { - route_messages_to_nexus(&client, &nexus, msgs.collect()) - } - RoutingDestination::Router => route_to_router(&router, msgs.collect()), - }?; + let (messages, events) = match determine_routing_destination( + &sender, + &client, + &dest_chain, + &router.address, + &chain_name, + )? { + RoutingDestination::This => { + prepare_msgs_for_execution(storage, chain_name.clone(), msgs.collect()) + } + RoutingDestination::Nexus => { + route_messages_to_nexus(&client, &nexus, msgs.collect()) + } + RoutingDestination::Router => route_to_router(&router, msgs.collect()), + }?; Ok(acc.add_messages(messages).add_events(events)) }) @@ -323,24 +310,19 @@ fn unique_cross_chain_id(client: &nexus::Client, chain_name: ChainName) -> Resul /// Query Nexus module in core to decide should route message to core fn determine_routing_destination( - storage: &dyn Storage, sender: &Addr, client: &nexus::Client, dest_chain: &ChainName, + router: &Addr, + this_chain: &ChainName, ) -> Result { - let Config { - chain_name: this_chain, - router, - .. - } = state::load_config(storage); - if client .is_chain_registered(dest_chain) .change_context(Error::Nexus)? { RoutingDestination::Nexus } else if sender == router { - ensure!(*dest_chain == this_chain, Error::InvalidRoutingDestination); + ensure!(dest_chain == this_chain, Error::InvalidRoutingDestination); RoutingDestination::This } else { RoutingDestination::Router