hapi 0.1.4

Rust library for using HAPI protocol in cmart contracts on NEAR.
Documentation
use near_sdk::{ext_contract, Gas, AccountId};

use super::{Category, RiskScore, AML};

pub const AML_CHECK_GAS: Gas = near_sdk::Gas(10_000_000_000_000);
pub const CALLBACK_AML_GAS: Gas = near_sdk::Gas(10_000_000_000_000);

pub type CategoryRisk = (Category, RiskScore);

#[ext_contract(ext_aml)]
pub trait ExtAmlContract {
    fn get_address(&self, address: AccountId) -> CategoryRisk;
}

impl AML {
    /// Checks the category according to the set level of risk. If the risk level is not set for this category, it checks the All category.
    pub fn assert_risk(&self, category_risk: CategoryRisk) {
        let (category, risk) = category_risk;
        if category != Category::None {
            let accepted_risk = match self.aml_conditions.get(&category) {
                Some(risk) => risk,
                None => self
                    .aml_conditions
                    .get(&Category::All)
                    .expect("ERR_NO_DEFAULT_CATEGORY"),
            };

            assert!(risk <= accepted_risk, "ERR_AML_NOT_ALLOWED");
        }
    }
}