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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use chain_impl_mockchain::{
    fragment::Fragment,
    transaction::{Input, Output, Witness},
};

pub(crate) fn on_tx_output<FO>(fragment: &Fragment, on_output: FO)
where
    FO: FnMut((usize, Output<chain_addr::Address>)),
{
    match fragment {
        Fragment::Initial(_config_params) => {}
        Fragment::UpdateProposal(_update_proposal) => {}
        Fragment::UpdateVote(_signed_update) => {}
        Fragment::OldUtxoDeclaration(_utxos) => {}
        Fragment::Evm(_) => {}
        Fragment::Transaction(tx) => for_each_output(tx, on_output),
        Fragment::OwnerStakeDelegation(tx) => for_each_output(tx, on_output),
        Fragment::StakeDelegation(tx) => for_each_output(tx, on_output),
        Fragment::PoolRegistration(tx) => for_each_output(tx, on_output),
        Fragment::PoolRetirement(tx) => for_each_output(tx, on_output),
        Fragment::PoolUpdate(tx) => for_each_output(tx, on_output),
        Fragment::VotePlan(tx) => for_each_output(tx, on_output),
        Fragment::VoteCast(tx) => for_each_output(tx, on_output),
        Fragment::VoteTally(tx) => for_each_output(tx, on_output),
        Fragment::MintToken(tx) => for_each_output(tx, on_output),
        Fragment::EvmMapping(tx) => for_each_output(tx, on_output),
    }
}

fn for_each_output<F, Extra>(
    tx: &chain_impl_mockchain::transaction::Transaction<Extra>,
    on_output: F,
) where
    F: FnMut((usize, Output<chain_addr::Address>)),
{
    tx.as_slice()
        .outputs()
        .iter()
        .enumerate()
        .for_each(on_output)
}

pub(crate) fn on_tx_input_and_witnesses<FI>(fragment: &Fragment, on_input: FI)
where
    FI: FnMut((Input, Witness)),
{
    match fragment {
        Fragment::Initial(_config_params) => {}
        Fragment::UpdateProposal(_update_proposal) => {}
        Fragment::UpdateVote(_signed_update) => {}
        Fragment::OldUtxoDeclaration(_utxos) => {}
        Fragment::Evm(_) => {}
        Fragment::Transaction(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::OwnerStakeDelegation(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::StakeDelegation(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::PoolRegistration(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::PoolRetirement(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::PoolUpdate(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::VotePlan(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::VoteCast(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::VoteTally(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::MintToken(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
        Fragment::EvmMapping(tx) => tx
            .as_slice()
            .inputs_and_witnesses()
            .iter()
            .for_each(on_input),
    }
}