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