/home/runner/actions-runner/_work/fuel-vm/fuel-vm/fuel-tx/src/lib.rs
Line | Count | Source (jump to first uncovered line) |
1 | | #![cfg_attr(not(feature = "std"), no_std)] |
2 | | #![allow(clippy::too_many_arguments)] |
3 | | #![allow(clippy::try_err)] |
4 | | // Wrong clippy convention; check |
5 | | // https://rust-lang.github.io/api-guidelines/naming.html |
6 | | #![allow(clippy::wrong_self_convention)] |
7 | | #![deny( |
8 | | clippy::arithmetic_side_effects, |
9 | | clippy::cast_sign_loss, |
10 | | clippy::cast_possible_truncation, |
11 | | clippy::cast_possible_wrap, |
12 | | clippy::string_slice |
13 | | )] |
14 | | #![deny(unused_crate_dependencies)] |
15 | | #![deny(unsafe_code)] |
16 | | |
17 | | // TODO: Add docs |
18 | | |
19 | | #[cfg(feature = "alloc")] |
20 | | extern crate alloc; |
21 | | extern crate core; |
22 | | |
23 | | pub mod consts; |
24 | | mod tx_pointer; |
25 | | |
26 | | pub use fuel_asm::{ |
27 | | PanicInstruction, |
28 | | PanicReason, |
29 | | }; |
30 | | pub use fuel_types::{ |
31 | | Address, |
32 | | AssetId, |
33 | | BlobId, |
34 | | Bytes32, |
35 | | Bytes4, |
36 | | Bytes64, |
37 | | Bytes8, |
38 | | ContractId, |
39 | | MessageId, |
40 | | Salt, |
41 | | Word, |
42 | | }; |
43 | | pub use tx_pointer::TxPointer; |
44 | | |
45 | | #[cfg(feature = "test-helpers")] |
46 | | mod builder; |
47 | | |
48 | | #[cfg(feature = "alloc")] |
49 | | mod contract; |
50 | | |
51 | | #[cfg(feature = "alloc")] |
52 | | mod receipt; |
53 | | |
54 | | #[cfg(feature = "alloc")] |
55 | | mod transaction; |
56 | | |
57 | | #[cfg(test)] |
58 | | mod tests; |
59 | | |
60 | | #[cfg(feature = "test-helpers")] |
61 | | pub mod test_helper; |
62 | | |
63 | | #[cfg(feature = "test-helpers")] |
64 | | pub use builder::{ |
65 | | Buildable, |
66 | | Finalizable, |
67 | | TransactionBuilder, |
68 | | }; |
69 | | |
70 | | #[cfg(feature = "alloc")] |
71 | | pub use receipt::{ |
72 | | Receipt, |
73 | | ScriptExecutionResult, |
74 | | }; |
75 | | |
76 | | #[cfg(feature = "alloc")] |
77 | | pub use transaction::{ |
78 | | consensus_parameters, |
79 | | field, |
80 | | input, |
81 | | input::Input, |
82 | | input::InputRepr, |
83 | | output, |
84 | | output::Output, |
85 | | output::OutputRepr, |
86 | | policies, |
87 | | Blob, |
88 | | BlobBody, |
89 | | BlobIdExt, |
90 | | BlobMetadata, |
91 | | Cacheable, |
92 | | Chargeable, |
93 | | ChargeableMetadata, |
94 | | ChargeableTransaction, |
95 | | ConsensusParameters, |
96 | | ContractParameters, |
97 | | Create, |
98 | | CreateMetadata, |
99 | | DependentCost, |
100 | | Executable, |
101 | | FeeParameters, |
102 | | FormatValidityChecks, |
103 | | GasCosts, |
104 | | GasCostsValues, |
105 | | Mint, |
106 | | PredicateParameters, |
107 | | Script, |
108 | | ScriptParameters, |
109 | | StorageSlot, |
110 | | Transaction, |
111 | | TransactionFee, |
112 | | TransactionRepr, |
113 | | TxId, |
114 | | TxParameters, |
115 | | Upgrade, |
116 | | UpgradeBody, |
117 | | UpgradeMetadata, |
118 | | UpgradePurpose, |
119 | | Upload, |
120 | | UploadBody, |
121 | | UploadMetadata, |
122 | | UploadSubsection, |
123 | | UtxoId, |
124 | | ValidityError, |
125 | | Witness, |
126 | | }; |
127 | | |
128 | | #[cfg(feature = "da-compression")] |
129 | | pub use transaction::CompactTransaction; |
130 | | |
131 | | pub use transaction::{ |
132 | | PrepareSign, |
133 | | Signable, |
134 | | UniqueIdentifier, |
135 | | }; |
136 | | |
137 | | #[cfg(feature = "alloc")] |
138 | | pub use contract::Contract; |
139 | | |
140 | | /// Trait extends the functionality of the `ContractId` type. |
141 | | pub trait ContractIdExt { |
142 | | /// Creates an `AssetId` from the `ContractId` and `sub_id`. |
143 | | fn asset_id(&self, sub_id: &Bytes32) -> AssetId; |
144 | | |
145 | | /// Creates an `AssetId` from the `ContractId` and the default 0x00..000 `sub_id`. |
146 | | fn default_asset(&self) -> AssetId; |
147 | | } |
148 | | |
149 | | impl ContractIdExt for ContractId { |
150 | 85 | fn asset_id(&self, sub_id: &Bytes32) -> AssetId { |
151 | 85 | let hasher = fuel_crypto::Hasher::default(); |
152 | 85 | AssetId::new( |
153 | 85 | *hasher |
154 | 85 | .chain(self.as_slice()) |
155 | 85 | .chain(sub_id.as_slice()) |
156 | 85 | .finalize(), |
157 | 85 | ) |
158 | 85 | } |
159 | | |
160 | 0 | fn default_asset(&self) -> AssetId { |
161 | 0 | self.asset_id(&Bytes32::zeroed()) |
162 | 0 | } |
163 | | } |