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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use cfx_parity_trace_types::AddressPocket;
use cfx_types::{address_util::AddressUtil, Address, AddressSpaceUtil, U256};

use self::AddressPocket::*;

use impl_tools::autoimpl;
use impl_trait_for_tuples::impl_for_tuples;

#[impl_for_tuples(3)]
#[autoimpl(for<T: trait + ?Sized> &mut T)]
#[allow(unused_variables)]
/// This trait is used by executive to build traces.
pub trait InternalTransferTracer {
    /// Prepares internal transfer action
    fn trace_internal_transfer(
        &mut self, from: AddressPocket, to: AddressPocket, value: U256,
    ) {
    }

    fn trace_convert_storage_points(
        &mut self, addr: Address, from_balance: U256, from_collateral: U256,
    ) {
        if !from_balance.is_zero() {
            self.trace_internal_transfer(
                SponsorBalanceForStorage(addr),
                MintBurn,
                from_balance,
            );
        }
        if !from_collateral.is_zero() {
            self.trace_internal_transfer(
                StorageCollateral(addr),
                MintBurn,
                from_collateral,
            );
        }
    }

    fn trace_refund_collateral(&mut self, addr: Address, by: U256) {
        if !by.is_zero() {
            self.trace_internal_transfer(
                StorageCollateral(addr),
                if addr.is_contract_address() {
                    SponsorBalanceForStorage(addr)
                } else {
                    Balance(addr.with_native_space())
                },
                by,
            );
        }
    }

    fn trace_occupy_collateral(&mut self, addr: Address, by: U256) {
        if !by.is_zero() {
            self.trace_internal_transfer(
                if addr.is_contract_address() {
                    SponsorBalanceForStorage(addr)
                } else {
                    Balance(addr.with_native_space())
                },
                StorageCollateral(addr),
                by,
            );
        }
    }
}