fuel_tx/
lib.rs

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")]
20extern crate alloc;
21extern crate core;
22
23pub mod consts;
24mod tx_pointer;
25
26pub use fuel_asm::{
27    PanicInstruction,
28    PanicReason,
29};
30pub 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};
43pub use tx_pointer::TxPointer;
44
45#[cfg(feature = "test-helpers")]
46mod builder;
47
48#[cfg(feature = "alloc")]
49mod contract;
50
51#[cfg(feature = "alloc")]
52mod receipt;
53
54#[cfg(feature = "alloc")]
55mod transaction;
56
57#[cfg(test)]
58mod tests;
59
60#[cfg(feature = "test-helpers")]
61pub mod test_helper;
62
63#[cfg(feature = "test-helpers")]
64pub use builder::{
65    Buildable,
66    Finalizable,
67    TransactionBuilder,
68};
69
70#[cfg(feature = "alloc")]
71pub use receipt::{
72    Receipt,
73    ScriptExecutionResult,
74};
75
76#[cfg(feature = "alloc")]
77pub 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    ScriptCode,
109    ScriptParameters,
110    StorageSlot,
111    Transaction,
112    TransactionFee,
113    TransactionRepr,
114    TxId,
115    TxParameters,
116    Upgrade,
117    UpgradeBody,
118    UpgradeMetadata,
119    UpgradePurpose,
120    Upload,
121    UploadBody,
122    UploadMetadata,
123    UploadSubsection,
124    UtxoId,
125    ValidityError,
126    Witness,
127};
128
129#[cfg(feature = "da-compression")]
130pub use transaction::{
131    CompressedMint,
132    CompressedTransaction,
133    CompressedUtxoId,
134};
135
136pub use transaction::{
137    PrepareSign,
138    Signable,
139    UniqueIdentifier,
140};
141
142#[cfg(feature = "alloc")]
143pub use contract::Contract;
144
145/// Trait extends the functionality of the `ContractId` type.
146pub trait ContractIdExt {
147    /// Creates an `AssetId` from the `ContractId` and `sub_id`.
148    fn asset_id(&self, sub_id: &Bytes32) -> AssetId;
149
150    /// Creates an `AssetId` from the `ContractId` and the default 0x00..000 `sub_id`.
151    fn default_asset(&self) -> AssetId;
152}
153
154impl ContractIdExt for ContractId {
155    fn asset_id(&self, sub_id: &Bytes32) -> AssetId {
156        let hasher = fuel_crypto::Hasher::default();
157        AssetId::new(
158            *hasher
159                .chain(self.as_slice())
160                .chain(sub_id.as_slice())
161                .finalize(),
162        )
163    }
164
165    fn default_asset(&self) -> AssetId {
166        self.asset_id(&Bytes32::zeroed())
167    }
168}