srb_trfc/aplk_exec.rs
1use core::panic;
2
3use soroban_sdk::{contractclient, Address, Bytes, Env, String};
4
5use crate::aplk_gw::AxelarGatewayClient;
6
7/// Interface for an Axelar Executable app.
8#[contractclient(name = "AxelarExecutableClient")]
9pub trait AxelarExecutableInterface {
10 /// Return the trusted gateway contract id.
11 fn gateway(env: &Env) -> Address;
12
13 /// Execute a cross-chain contract call with the given payload. This function must validate that the contract call is received from the trusted gateway.
14 fn execute(
15 env: Env,
16 source_chain: String,
17 message_id: String,
18 source_address: String,
19 payload: Bytes,
20 );
21
22 /// Validate if a gateway has approved a contract call.
23 /// This should be called from an implementation of `execute` before executing custom app logic.
24 /// This method doesn't get exposed from the contract, as Soroban SDK's contractimpl macro ignores default trait methods.
25 fn validate(
26 env: Env,
27 source_chain: String,
28 message_id: String,
29 source_address: String,
30 payload: Bytes,
31 ) {
32 let gateway = AxelarGatewayClient::new(&env, &Self::gateway(&env));
33
34 // Validate the contract call was approved by the gateway
35 if !gateway.validate_message(
36 &env.current_contract_address(),
37 &source_chain,
38 &message_id,
39 &source_address,
40 &env.crypto().keccak256(&payload).into(),
41 ) {
42 panic!("not approved");
43 };
44 }
45}