fuels_types/
input.rs

1#![cfg(feature = "std")]
2
3use std::hash::Hash;
4
5use fuel_tx::{TxPointer, UtxoId};
6use fuel_types::{Bytes32, ContractId};
7
8use crate::{coin_type::CoinType, unresolved_bytes::UnresolvedBytes};
9
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11pub enum Input {
12    ResourceSigned {
13        resource: CoinType,
14        witness_index: u8,
15    },
16    ResourcePredicate {
17        resource: CoinType,
18        code: Vec<u8>,
19        data: UnresolvedBytes,
20    },
21    Contract {
22        utxo_id: UtxoId,
23        balance_root: Bytes32,
24        state_root: Bytes32,
25        tx_pointer: TxPointer,
26        contract_id: ContractId,
27    },
28}
29
30impl Input {
31    pub const fn resource_signed(resource: CoinType, witness_index: u8) -> Self {
32        Self::ResourceSigned {
33            resource,
34            witness_index,
35        }
36    }
37
38    pub const fn resource_predicate(
39        resource: CoinType,
40        code: Vec<u8>,
41        data: UnresolvedBytes,
42    ) -> Self {
43        Self::ResourcePredicate {
44            resource,
45            code,
46            data,
47        }
48    }
49
50    pub fn amount(&self) -> Option<u64> {
51        match self {
52            Self::ResourceSigned { resource, .. } | Self::ResourcePredicate { resource, .. } => {
53                Some(resource.amount())
54            }
55            _ => None,
56        }
57    }
58
59    pub const fn contract(
60        utxo_id: UtxoId,
61        balance_root: Bytes32,
62        state_root: Bytes32,
63        tx_pointer: TxPointer,
64        contract_id: ContractId,
65    ) -> Self {
66        Self::Contract {
67            utxo_id,
68            balance_root,
69            state_root,
70            tx_pointer,
71            contract_id,
72        }
73    }
74}