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
use soroban_env_common::{xdr::AccountId, CheckedEnv, InvokerType, TryFromVal, TryIntoVal};
use soroban_native_sdk_macros::contracttype;
use crate::{Host, HostError};
use super::base_types::BytesN;
#[derive(Clone, PartialEq)]
#[contracttype]
pub enum Invoker {
Account(AccountId),
Contract(BytesN<32>),
}
pub fn invoker(env: &Host) -> Result<Invoker, HostError> {
let invoker_type: InvokerType = Host::get_invoker_type(&env)?.try_into()?;
Ok(match invoker_type {
InvokerType::Account => Invoker::Account(AccountId::try_from_val(
env,
Host::get_invoking_account(&env)?,
)?),
InvokerType::Contract => Invoker::Contract(BytesN::<32>::try_from_val(
env,
Host::get_invoking_contract(&env)?,
)?),
})
}