1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::amp::messages::AMPPkt;
use cosmwasm_std::{DepsMut, Env, MessageInfo};

pub struct ExecuteContext<'a> {
    pub deps: DepsMut<'a>,
    pub info: MessageInfo,
    pub env: Env,
    pub amp_ctx: Option<AMPPkt>,
}

impl<'a> ExecuteContext<'a> {
    #[inline]
    pub fn new(deps: DepsMut, info: MessageInfo, env: Env) -> ExecuteContext {
        ExecuteContext {
            deps,
            info,
            env,
            amp_ctx: None,
        }
    }

    pub fn with_ctx(mut self, amp_ctx: AMPPkt) -> Self {
        self.amp_ctx = Some(amp_ctx);
        self
    }

    pub fn contains_sender(&self, addr: &str) -> bool {
        if self.info.sender == addr {
            return true;
        }

        match &self.amp_ctx {
            None => false,
            Some(ctx) => ctx.ctx.get_origin() == addr || ctx.ctx.get_previous_sender() == addr,
        }
    }
}