1use crate::schema::scalars::{
2 Address,
3 AssetId,
4 Bytes32,
5 ContractId,
6 HexString,
7 Nonce,
8 TxPointer,
9 U16,
10 U64,
11 UtxoId,
12};
13use async_graphql::{
14 Object,
15 Union,
16};
17use fuel_core_types::fuel_tx;
18
19#[derive(Union)]
20pub enum Input {
21 Coin(InputCoin),
22 Contract(InputContract),
23 Message(InputMessage),
24}
25
26pub struct InputCoin {
27 utxo_id: UtxoId,
28 owner: Address,
29 amount: U64,
30 asset_id: AssetId,
31 tx_pointer: TxPointer,
32 witness_index: u16,
33 predicate_gas_used: U64,
34 predicate: HexString,
35 predicate_data: HexString,
36}
37
38#[Object]
39impl InputCoin {
40 async fn utxo_id(&self) -> UtxoId {
41 self.utxo_id
42 }
43
44 async fn owner(&self) -> Address {
45 self.owner
46 }
47
48 async fn amount(&self) -> U64 {
49 self.amount
50 }
51
52 async fn asset_id(&self) -> AssetId {
53 self.asset_id
54 }
55
56 async fn tx_pointer(&self) -> TxPointer {
57 self.tx_pointer
58 }
59
60 async fn witness_index(&self) -> U16 {
61 self.witness_index.into()
62 }
63
64 async fn predicate_gas_used(&self) -> U64 {
65 self.predicate_gas_used
66 }
67
68 async fn predicate(&self) -> HexString {
69 self.predicate.clone()
70 }
71
72 async fn predicate_data(&self) -> HexString {
73 self.predicate_data.clone()
74 }
75}
76
77pub struct InputContract {
78 utxo_id: UtxoId,
79 balance_root: Bytes32,
80 state_root: Bytes32,
81 tx_pointer: TxPointer,
82 contract_id: ContractId,
83}
84
85#[Object]
86impl InputContract {
87 async fn utxo_id(&self) -> UtxoId {
88 self.utxo_id
89 }
90
91 async fn balance_root(&self) -> Bytes32 {
92 self.balance_root
93 }
94
95 async fn state_root(&self) -> Bytes32 {
96 self.state_root
97 }
98
99 async fn tx_pointer(&self) -> TxPointer {
100 self.tx_pointer
101 }
102
103 async fn contract_id(&self) -> ContractId {
104 self.contract_id
105 }
106}
107
108pub struct InputMessage {
109 sender: Address,
110 recipient: Address,
111 amount: U64,
112 nonce: Nonce,
113 witness_index: u16,
114 predicate_gas_used: U64,
115 data: HexString,
116 predicate: HexString,
117 predicate_data: HexString,
118}
119
120#[Object]
121impl InputMessage {
122 async fn sender(&self) -> Address {
123 self.sender
124 }
125
126 async fn recipient(&self) -> Address {
127 self.recipient
128 }
129
130 async fn amount(&self) -> U64 {
131 self.amount
132 }
133
134 async fn nonce(&self) -> Nonce {
135 self.nonce
136 }
137
138 async fn witness_index(&self) -> U16 {
139 self.witness_index.into()
140 }
141
142 async fn predicate_gas_used(&self) -> U64 {
143 self.predicate_gas_used
144 }
145
146 async fn data(&self) -> &HexString {
147 &self.data
148 }
149
150 async fn predicate(&self) -> &HexString {
151 &self.predicate
152 }
153
154 async fn predicate_data(&self) -> &HexString {
155 &self.predicate_data
156 }
157}
158
159impl From<&fuel_tx::Input> for Input {
160 fn from(input: &fuel_tx::Input) -> Self {
161 match input {
162 fuel_tx::Input::CoinSigned(fuel_tx::input::coin::CoinSigned {
163 utxo_id,
164 owner,
165 amount,
166 asset_id,
167 tx_pointer,
168 witness_index,
169 ..
170 }) => Input::Coin(InputCoin {
171 utxo_id: UtxoId(*utxo_id),
172 owner: Address(*owner),
173 amount: (*amount).into(),
174 asset_id: AssetId(*asset_id),
175 tx_pointer: TxPointer(*tx_pointer),
176 witness_index: *witness_index,
177 predicate_gas_used: 0.into(),
178 predicate: HexString(Default::default()),
179 predicate_data: HexString(Default::default()),
180 }),
181 fuel_tx::Input::CoinPredicate(fuel_tx::input::coin::CoinPredicate {
182 utxo_id,
183 owner,
184 amount,
185 asset_id,
186 tx_pointer,
187 predicate,
188 predicate_data,
189 predicate_gas_used,
190 ..
191 }) => Input::Coin(InputCoin {
192 utxo_id: UtxoId(*utxo_id),
193 owner: Address(*owner),
194 amount: (*amount).into(),
195 asset_id: AssetId(*asset_id),
196 tx_pointer: TxPointer(*tx_pointer),
197 witness_index: Default::default(),
198 predicate_gas_used: (*predicate_gas_used).into(),
199 predicate: HexString(predicate.to_vec()),
200 predicate_data: HexString(predicate_data.clone().into_inner()),
201 }),
202 fuel_tx::Input::Contract(contract) => Input::Contract(contract.into()),
203 fuel_tx::Input::MessageCoinSigned(
204 fuel_tx::input::message::MessageCoinSigned {
205 sender,
206 recipient,
207 amount,
208 nonce,
209 witness_index,
210 ..
211 },
212 ) => Input::Message(InputMessage {
213 sender: Address(*sender),
214 recipient: Address(*recipient),
215 amount: (*amount).into(),
216 nonce: Nonce(*nonce),
217 witness_index: *witness_index,
218 data: HexString(Default::default()),
219 predicate_gas_used: 0.into(),
220 predicate: HexString(Default::default()),
221 predicate_data: HexString(Default::default()),
222 }),
223 fuel_tx::Input::MessageCoinPredicate(
224 fuel_tx::input::message::MessageCoinPredicate {
225 sender,
226 recipient,
227 amount,
228 nonce,
229 predicate,
230 predicate_data,
231 predicate_gas_used,
232 ..
233 },
234 ) => Input::Message(InputMessage {
235 sender: Address(*sender),
236 recipient: Address(*recipient),
237 amount: (*amount).into(),
238 nonce: Nonce(*nonce),
239 witness_index: Default::default(),
240 predicate_gas_used: (*predicate_gas_used).into(),
241 data: HexString(Default::default()),
242 predicate: HexString(predicate.to_vec()),
243 predicate_data: HexString(predicate_data.clone().into_inner()),
244 }),
245 fuel_tx::Input::MessageDataSigned(
246 fuel_tx::input::message::MessageDataSigned {
247 sender,
248 recipient,
249 amount,
250 nonce,
251 witness_index,
252 data,
253 ..
254 },
255 ) => Input::Message(InputMessage {
256 sender: Address(*sender),
257 recipient: Address(*recipient),
258 amount: (*amount).into(),
259 nonce: Nonce(*nonce),
260 witness_index: *witness_index,
261 predicate_gas_used: 0.into(),
262 data: HexString(data.clone().into_inner()),
263 predicate: HexString(Default::default()),
264 predicate_data: HexString(Default::default()),
265 }),
266 fuel_tx::Input::MessageDataPredicate(
267 fuel_tx::input::message::MessageDataPredicate {
268 sender,
269 recipient,
270 amount,
271 nonce,
272 data,
273 predicate,
274 predicate_data,
275 predicate_gas_used,
276 ..
277 },
278 ) => Input::Message(InputMessage {
279 sender: Address(*sender),
280 recipient: Address(*recipient),
281 amount: (*amount).into(),
282 nonce: Nonce(*nonce),
283 witness_index: Default::default(),
284 predicate_gas_used: (*predicate_gas_used).into(),
285 data: HexString(data.clone().into_inner()),
286 predicate: HexString(predicate.to_vec()),
287 predicate_data: HexString(predicate_data.clone().into_inner()),
288 }),
289 }
290 }
291}
292
293impl From<&fuel_tx::input::contract::Contract> for InputContract {
294 fn from(value: &fuel_tx::input::contract::Contract) -> Self {
295 let fuel_tx::input::contract::Contract {
296 utxo_id,
297 balance_root,
298 state_root,
299 tx_pointer,
300 contract_id,
301 } = value;
302 InputContract {
303 utxo_id: UtxoId(*utxo_id),
304 balance_root: Bytes32(*balance_root),
305 state_root: Bytes32(*state_root),
306 tx_pointer: TxPointer(*tx_pointer),
307 contract_id: ContractId(*contract_id),
308 }
309 }
310}