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
use pallet_contracts::debug::{CallInterceptor, ExecResult, ExportedFunction};
use parity_scale_codec::{Decode, Encode};

use crate::runtime::{
    pallet_contracts_debugging::{runtime::contract_call_debugger, DrinkDebug},
    AccountIdFor,
};

impl<R: pallet_contracts::Config> CallInterceptor<R> for DrinkDebug {
    fn intercept_call(
        contract_address: &AccountIdFor<R>,
        entry_point: &ExportedFunction,
        input_data: &[u8],
    ) -> Option<ExecResult> {
        // Pass the data to the runtime interface. The data must be encoded (only simple types are
        // supported).
        contract_call_debugger::intercept_call(
            contract_address.encode(),
            matches!(*entry_point, ExportedFunction::Call),
            input_data.to_vec(),
        )
        .and_then(|intercepting_result| {
            Decode::decode(&mut intercepting_result.as_slice()).expect("Decoding should succeed")
        })
    }
}