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
38
39
40
41
42
43
44
45
46
use pallet_contracts::{
    debug::{CallSpan, ExportedFunction},
    ExecReturnValue, Tracing,
};

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

impl<R: pallet_contracts::Config> Tracing<R> for DrinkDebug {
    type CallSpan = DrinkCallSpan<AccountIdFor<R>>;

    fn new_call_span(
        contract_address: &AccountIdFor<R>,
        entry_point: ExportedFunction,
        input_data: &[u8],
    ) -> Self::CallSpan {
        DrinkCallSpan {
            contract_address: contract_address.clone(),
            entry_point,
            input_data: input_data.to_vec(),
        }
    }
}

/// A contract's call span.
///
/// It is created just before the call is made and `Self::after_call` is called after the call is
/// done.
pub struct DrinkCallSpan<AccountId> {
    /// The address of the contract that has been called.
    pub contract_address: AccountId,
    /// The entry point that has been called (either constructor or call).
    pub entry_point: ExportedFunction,
    /// The input data of the call.
    pub input_data: Vec<u8>,
}

impl<AccountId: parity_scale_codec::Encode> CallSpan for DrinkCallSpan<AccountId> {
    fn after_call(self, output: &ExecReturnValue) {
        crate::runtime::pallet_contracts_debugging::runtime::contract_call_debugger::after_call(
            self.contract_address.encode(),
            matches!(self.entry_point, ExportedFunction::Call),
            self.input_data.to_vec(),
            output.data.clone(),
        );
    }
}