Coverage Report

Created: 2024-06-13 15:24

/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
    Bytes32,
34
    Bytes4,
35
    Bytes64,
36
    Bytes8,
37
    ContractId,
38
    MessageId,
39
    Salt,
40
    Word,
41
};
42
pub use tx_pointer::TxPointer;
43
44
#[cfg(feature = "test-helpers")]
45
mod builder;
46
47
#[cfg(feature = "alloc")]
48
mod contract;
49
50
#[cfg(feature = "alloc")]
51
mod receipt;
52
53
#[cfg(feature = "alloc")]
54
mod transaction;
55
56
#[cfg(test)]
57
mod tests;
58
59
#[cfg(feature = "test-helpers")]
60
pub mod test_helper;
61
62
#[cfg(feature = "test-helpers")]
63
pub use builder::{
64
    Buildable,
65
    Finalizable,
66
    TransactionBuilder,
67
};
68
69
#[cfg(feature = "alloc")]
70
pub use receipt::{
71
    Receipt,
72
    ScriptExecutionResult,
73
};
74
75
#[cfg(feature = "alloc")]
76
pub use transaction::{
77
    consensus_parameters,
78
    field,
79
    input,
80
    input::Input,
81
    input::InputRepr,
82
    output,
83
    output::Output,
84
    output::OutputRepr,
85
    policies,
86
    Cacheable,
87
    Chargeable,
88
    ChargeableMetadata,
89
    ChargeableTransaction,
90
    ConsensusParameters,
91
    ContractParameters,
92
    Create,
93
    DependentCost,
94
    Executable,
95
    FeeParameters,
96
    FormatValidityChecks,
97
    GasCosts,
98
    GasCostsValues,
99
    Mint,
100
    PredicateParameters,
101
    Script,
102
    ScriptParameters,
103
    StorageSlot,
104
    Transaction,
105
    TransactionFee,
106
    TransactionRepr,
107
    TxId,
108
    TxParameters,
109
    Upgrade,
110
    UpgradeBody,
111
    UpgradeMetadata,
112
    UpgradePurpose,
113
    Upload,
114
    UploadBody,
115
    UploadMetadata,
116
    UploadSubsection,
117
    UtxoId,
118
    ValidityError,
119
    Witness,
120
};
121
122
pub use transaction::{
123
    PrepareSign,
124
    Signable,
125
    UniqueIdentifier,
126
};
127
128
#[cfg(feature = "alloc")]
129
pub use contract::Contract;
130
131
/// Trait extends the functionality of the `ContractId` type.
132
pub trait ContractIdExt {
133
    /// Creates an `AssetId` from the `ContractId` and `sub_id`.
134
    fn asset_id(&self, sub_id: &Bytes32) -> AssetId;
135
136
    /// Creates an `AssetId` from the `ContractId` and the default 0x00..000 `sub_id`.
137
    fn default_asset(&self) -> AssetId;
138
}
139
140
impl ContractIdExt for ContractId {
141
48
    fn asset_id(&self, sub_id: &Bytes32) -> AssetId {
142
48
        let hasher = fuel_crypto::Hasher::default();
143
48
        AssetId::new(
144
48
            *hasher
145
48
                .chain(self.as_slice())
146
48
                .chain(sub_id.as_slice())
147
48
                .finalize(),
148
48
        )
149
48
    }
150
151
0
    fn default_asset(&self) -> AssetId {
152
0
        self.asset_id(&Bytes32::zeroed())
153
0
    }
154
}