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
#![cfg(feature = "std")]

use std::hash::Hash;

use fuel_tx::{TxPointer, UtxoId};
use fuel_types::{Bytes32, ContractId};

use crate::{coin_type::CoinType, unresolved_bytes::UnresolvedBytes};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Input {
    ResourceSigned {
        resource: CoinType,
        witness_index: u8,
    },
    ResourcePredicate {
        resource: CoinType,
        code: Vec<u8>,
        data: UnresolvedBytes,
    },
    Contract {
        utxo_id: UtxoId,
        balance_root: Bytes32,
        state_root: Bytes32,
        tx_pointer: TxPointer,
        contract_id: ContractId,
    },
}

impl Input {
    pub const fn resource_signed(resource: CoinType, witness_index: u8) -> Self {
        Self::ResourceSigned {
            resource,
            witness_index,
        }
    }

    pub const fn resource_predicate(
        resource: CoinType,
        code: Vec<u8>,
        data: UnresolvedBytes,
    ) -> Self {
        Self::ResourcePredicate {
            resource,
            code,
            data,
        }
    }

    pub fn amount(&self) -> Option<u64> {
        match self {
            Self::ResourceSigned { resource, .. } | Self::ResourcePredicate { resource, .. } => {
                Some(resource.amount())
            }
            _ => None,
        }
    }

    pub const fn contract(
        utxo_id: UtxoId,
        balance_root: Bytes32,
        state_root: Bytes32,
        tx_pointer: TxPointer,
        contract_id: ContractId,
    ) -> Self {
        Self::Contract {
            utxo_id,
            balance_root,
            state_root,
            tx_pointer,
            contract_id,
        }
    }
}