Skip to main content

tempo_precompiles/receive_policy_guard/
dispatch.rs

1//! ABI dispatch for the [`ReceivePolicyGuard`] precompile.
2
3use crate::{
4    Precompile, charge_input_cost, dispatch_call, mutate_void,
5    receive_policy_guard::ReceivePolicyGuard, view,
6};
7use alloy::{primitives::Address, sol_types::SolInterface};
8use revm::precompile::PrecompileResult;
9use tempo_contracts::precompiles::IReceivePolicyGuard::IReceivePolicyGuardCalls;
10
11impl Precompile for ReceivePolicyGuard {
12    fn call(&mut self, calldata: &[u8], msg_sender: Address) -> PrecompileResult {
13        if let Some(err) = charge_input_cost(&mut self.storage, calldata) {
14            return err;
15        }
16
17        dispatch_call(
18            calldata,
19            &[],
20            IReceivePolicyGuardCalls::abi_decode,
21            |call| match call {
22                IReceivePolicyGuardCalls::balanceOf(call) => {
23                    view(call, |c| self.balance_of(c.receipt))
24                }
25                IReceivePolicyGuardCalls::claim(call) => {
26                    mutate_void(call, msg_sender, |s, c| self.claim(s, c.to, c.receipt))
27                }
28                IReceivePolicyGuardCalls::burnBlockedReceipt(call) => {
29                    mutate_void(call, msg_sender, |s, c| {
30                        self.burn_blocked_receipt(s, c.receipt)
31                    })
32                }
33            },
34        )
35    }
36}