fuel_core_storage/
tables.rs1use crate::Mappable;
5use fuel_core_types::{
6 blockchain::{
7 block::CompressedBlock,
8 consensus::Consensus,
9 header::{
10 ConsensusParametersVersion,
11 StateTransitionBytecodeVersion,
12 },
13 },
14 entities::{
15 coins::coin::CompressedCoin,
16 contract::ContractUtxoInfo,
17 relayer::message::Message,
18 },
19 fuel_tx::{
20 Bytes32,
21 ConsensusParameters,
22 Transaction,
23 TxId,
24 UtxoId,
25 },
26 fuel_types::{
27 BlockHeight,
28 ContractId,
29 Nonce,
30 },
31};
32pub use fuel_vm_private::storage::{
33 BlobData,
34 ContractsAssets,
35 ContractsRawCode,
36 ContractsState,
37 UploadedBytecodes,
38};
39
40pub struct FuelBlocks;
43
44impl Mappable for FuelBlocks {
45 type Key = Self::OwnedKey;
47 type OwnedKey = BlockHeight;
48 type Value = Self::OwnedValue;
49 type OwnedValue = CompressedBlock;
50}
51
52pub struct ContractsLatestUtxo;
56
57impl Mappable for ContractsLatestUtxo {
58 type Key = Self::OwnedKey;
59 type OwnedKey = ContractId;
60 type Value = Self::OwnedValue;
62 type OwnedValue = ContractUtxoInfo;
63}
64
65pub struct SealedBlockConsensus;
67
68impl Mappable for SealedBlockConsensus {
69 type Key = Self::OwnedKey;
70 type OwnedKey = BlockHeight;
71 type Value = Self::OwnedValue;
72 type OwnedValue = Consensus;
73}
74
75pub struct Coins;
78
79impl Mappable for Coins {
80 type Key = Self::OwnedKey;
81 type OwnedKey = UtxoId;
82 type Value = Self::OwnedValue;
83 type OwnedValue = CompressedCoin;
84}
85
86pub struct Messages;
88
89impl Mappable for Messages {
90 type Key = Self::OwnedKey;
91 type OwnedKey = Nonce;
92 type Value = Self::OwnedValue;
93 type OwnedValue = Message;
94}
95
96pub struct Transactions;
98
99impl Mappable for Transactions {
100 type Key = Self::OwnedKey;
101 type OwnedKey = TxId;
102 type Value = Self::OwnedValue;
103 type OwnedValue = Transaction;
104}
105
106pub struct ProcessedTransactions;
109
110impl Mappable for ProcessedTransactions {
111 type Key = Self::OwnedKey;
112 type OwnedKey = TxId;
113 type Value = Self::OwnedValue;
114 type OwnedValue = ();
115}
116
117pub struct ConsensusParametersVersions;
119
120impl Mappable for ConsensusParametersVersions {
121 type Key = Self::OwnedKey;
122 type OwnedKey = ConsensusParametersVersion;
123 type Value = Self::OwnedValue;
124 type OwnedValue = ConsensusParameters;
125}
126
127pub struct StateTransitionBytecodeVersions;
129
130impl Mappable for StateTransitionBytecodeVersions {
131 type Key = Self::OwnedKey;
132 type OwnedKey = StateTransitionBytecodeVersion;
133 type Value = Self::OwnedValue;
134 type OwnedValue = Bytes32;
136}
137
138pub mod merkle {
140 use crate::{
141 Mappable,
142 MerkleRoot,
143 };
144 use fuel_core_types::{
145 fuel_merkle::{
146 binary,
147 sparse,
148 },
149 fuel_types::BlockHeight,
150 };
151
152 #[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
155 pub enum DenseMetadataKey<PrimaryKey> {
156 Primary(PrimaryKey),
158 #[default]
159 Latest,
161 }
162
163 #[cfg(feature = "test-helpers")]
164 impl<PrimaryKey> rand::distributions::Distribution<DenseMetadataKey<PrimaryKey>>
165 for rand::distributions::Standard
166 where
167 rand::distributions::Standard: rand::distributions::Distribution<PrimaryKey>,
168 {
169 fn sample<R: rand::Rng + ?Sized>(
170 &self,
171 rng: &mut R,
172 ) -> DenseMetadataKey<PrimaryKey> {
173 DenseMetadataKey::Primary(rng.r#gen())
174 }
175 }
176
177 #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
179 pub enum DenseMerkleMetadata {
180 V1(DenseMerkleMetadataV1),
182 }
183
184 impl Default for DenseMerkleMetadata {
185 fn default() -> Self {
186 Self::V1(Default::default())
187 }
188 }
189
190 impl DenseMerkleMetadata {
191 pub fn new(root: MerkleRoot, version: u64) -> Self {
194 let metadata = DenseMerkleMetadataV1 { root, version };
195 Self::V1(metadata)
196 }
197
198 pub fn root(&self) -> &MerkleRoot {
200 match self {
201 DenseMerkleMetadata::V1(metadata) => &metadata.root,
202 }
203 }
204
205 pub fn version(&self) -> u64 {
207 match self {
208 DenseMerkleMetadata::V1(metadata) => metadata.version,
209 }
210 }
211 }
212
213 #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
215 pub struct DenseMerkleMetadataV1 {
216 pub root: MerkleRoot,
218 pub version: u64,
222 }
223
224 impl Default for DenseMerkleMetadataV1 {
225 fn default() -> Self {
226 let empty_merkle_tree = binary::root_calculator::MerkleRootCalculator::new();
227 Self {
228 root: empty_merkle_tree.root(),
229 version: 0,
230 }
231 }
232 }
233
234 impl From<DenseMerkleMetadataV1> for DenseMerkleMetadata {
235 fn from(value: DenseMerkleMetadataV1) -> Self {
236 Self::V1(value)
237 }
238 }
239
240 #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
242 pub enum SparseMerkleMetadata {
243 V1(SparseMerkleMetadataV1),
245 }
246
247 impl Default for SparseMerkleMetadata {
248 fn default() -> Self {
249 Self::V1(Default::default())
250 }
251 }
252
253 impl SparseMerkleMetadata {
254 pub fn new(root: MerkleRoot) -> Self {
257 let metadata = SparseMerkleMetadataV1 { root };
258 Self::V1(metadata)
259 }
260
261 pub fn root(&self) -> &MerkleRoot {
263 match self {
264 SparseMerkleMetadata::V1(metadata) => &metadata.root,
265 }
266 }
267 }
268
269 #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
271 pub struct SparseMerkleMetadataV1 {
272 pub root: MerkleRoot,
274 }
275
276 impl Default for SparseMerkleMetadataV1 {
277 fn default() -> Self {
278 let empty_merkle_tree = sparse::in_memory::MerkleTree::new();
279 Self {
280 root: empty_merkle_tree.root(),
281 }
282 }
283 }
284
285 impl From<SparseMerkleMetadataV1> for SparseMerkleMetadata {
286 fn from(value: SparseMerkleMetadataV1) -> Self {
287 Self::V1(value)
288 }
289 }
290
291 pub struct FuelBlockMerkleData;
293
294 impl Mappable for FuelBlockMerkleData {
295 type Key = u64;
296 type OwnedKey = Self::Key;
297 type Value = binary::Primitive;
298 type OwnedValue = Self::Value;
299 }
300
301 pub struct FuelBlockMerkleMetadata;
303
304 impl Mappable for FuelBlockMerkleMetadata {
305 type Key = DenseMetadataKey<BlockHeight>;
306 type OwnedKey = Self::Key;
307 type Value = DenseMerkleMetadata;
308 type OwnedValue = Self::Value;
309 }
310}