Coverage Report

Created: 2024-10-28 11:34

/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
    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")]
130
pub use transaction::{
131
    CompressedMint,
132
    CompressedTransaction,
133
    CompressedUtxoId,
134
};
135
136
pub use transaction::{
137
    PrepareSign,
138
    Signable,
139
    UniqueIdentifier,
140
};
141
142
#[cfg(feature = "alloc")]
143
pub use contract::Contract;
144
145
/// Trait extends the functionality of the `ContractId` type.
146
pub 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
154
impl ContractIdExt for ContractId {
155
85
    fn asset_id(&self, sub_id: &Bytes32) -> AssetId {
156
85
        let hasher = fuel_crypto::Hasher::default();
157
85
        AssetId::new(
158
85
            *hasher
159
85
                .chain(self.as_slice())
160
85
                .chain(sub_id.as_slice())
161
85
                .finalize(),
162
85
        )
163
85
    }
164
165
0
    fn default_asset(&self) -> AssetId {
166
0
        self.asset_id(&Bytes32::zeroed())
167
0
    }
168
}