cuprate_blockchain/
tables.rs

1//! Database tables.
2//!
3//! # Table marker structs
4//! This module contains all the table definitions used by `cuprate_blockchain`.
5//!
6//! The zero-sized structs here represents the table type;
7//! they all are essentially marker types that implement [`cuprate_database::Table`].
8//!
9//! Table structs are `CamelCase`, and their static string
10//! names used by the actual database backend are `snake_case`.
11//!
12//! For example: [`BlockHeaderBlobs`] -> `block_header_blobs`.
13//!
14//! # Traits
15//! This module also contains a set of traits for
16//! accessing _all_ tables defined here at once.
17
18//---------------------------------------------------------------------------------------------------- Import
19use crate::types::{
20    AltBlockHeight, AltChainInfo, AltTransactionInfo, Amount, AmountIndex, AmountIndices,
21    BlockBlob, BlockHash, BlockHeaderBlob, BlockHeight, BlockInfo, BlockTxHashes,
22    CompactAltBlockInfo, KeyImage, Output, PreRctOutputId, PrunableBlob, PrunableHash, PrunedBlob,
23    RawChainId, RctOutput, TxBlob, TxHash, TxId, UnlockTime,
24};
25
26//---------------------------------------------------------------------------------------------------- Tables
27// Notes:
28// - Keep this sorted A-Z (by table name)
29// - Tables are defined in plural to avoid name conflicts with types
30// - If adding/changing a table also edit:
31//   - the tests in `src/backend/tests.rs`
32cuprate_database::define_tables! {
33    /// Serialized block header blobs (bytes).
34    ///
35    /// Contains the serialized version of all blocks headers.
36    0 => BlockHeaderBlobs,
37    BlockHeight => BlockHeaderBlob,
38
39    /// Block transactions hashes
40    ///
41    /// Contains all the transaction hashes of all blocks.
42    1 => BlockTxsHashes,
43    BlockHeight => BlockTxHashes,
44
45    /// Block heights.
46    ///
47    /// Contains the height of all blocks.
48    2 => BlockHeights,
49    BlockHash => BlockHeight,
50
51    /// Block information.
52    ///
53    /// Contains metadata of all blocks.
54    3 => BlockInfos,
55    BlockHeight => BlockInfo,
56
57    /// Set of key images.
58    ///
59    /// Contains all the key images known to be spent.
60    ///
61    /// This table has `()` as the value type, as in,
62    /// it is a set of key images.
63    4 => KeyImages,
64    KeyImage => (),
65
66    /// Maps an output's amount to the number of outputs with that amount.
67    ///
68    /// For example, if there are 5 outputs with `amount = 123`
69    /// then calling `get(123)` on this table will return 5.
70    5 => NumOutputs,
71    Amount => u64,
72
73    /// Pre-RCT output data.
74    6 => Outputs,
75    PreRctOutputId => Output,
76
77    /// Pruned transaction blobs (bytes).
78    ///
79    /// Contains the pruned portion of serialized transaction data.
80    7 => PrunedTxBlobs,
81    TxId => PrunedBlob,
82
83    /// Prunable transaction blobs (bytes).
84    ///
85    /// Contains the prunable portion of serialized transaction data.
86    // SOMEDAY: impl when `monero-serai` supports pruning
87    8 => PrunableTxBlobs,
88    TxId => PrunableBlob,
89
90    /// Prunable transaction hashes.
91    ///
92    /// Contains the prunable portion of transaction hashes.
93    // SOMEDAY: impl when `monero-serai` supports pruning
94    9 => PrunableHashes,
95    TxId => PrunableHash,
96
97    // SOMEDAY: impl a properties table:
98    // - db version
99    // - pruning seed
100    // Properties,
101    // StorableString => StorableVec,
102
103    /// RCT output data.
104    10 => RctOutputs,
105    AmountIndex => RctOutput,
106
107    /// Transaction blobs (bytes).
108    ///
109    /// Contains the serialized version of all transactions.
110    // SOMEDAY: remove when `monero-serai` supports pruning
111    11 => TxBlobs,
112    TxId => TxBlob,
113
114    /// Transaction indices.
115    ///
116    /// Contains the indices all transactions.
117    12 => TxIds,
118    TxHash => TxId,
119
120    /// Transaction heights.
121    ///
122    /// Contains the block height associated with all transactions.
123    13 => TxHeights,
124    TxId => BlockHeight,
125
126    /// Transaction outputs.
127    ///
128    /// Contains the list of `AmountIndex`'s of the
129    /// outputs associated with all transactions.
130    14 => TxOutputs,
131    TxId => AmountIndices,
132
133    /// Transaction unlock time.
134    ///
135    /// Contains the unlock time of transactions IF they have one.
136    /// Transactions without unlock times will not exist in this table.
137    15 => TxUnlockTime,
138    TxId => UnlockTime,
139
140    /// Information on alt-chains.
141    16 => AltChainInfos,
142    RawChainId => AltChainInfo,
143
144    /// Alt-block heights.
145    ///
146    /// Contains the height of all alt-blocks.
147    17 => AltBlockHeights,
148    BlockHash => AltBlockHeight,
149
150    /// Alt-block information.
151    ///
152    /// Contains information on all alt-blocks.
153    18 => AltBlocksInfo,
154    AltBlockHeight => CompactAltBlockInfo,
155
156    /// Alt-block blobs.
157    ///
158    /// Contains the raw bytes of all alt-blocks.
159    19 => AltBlockBlobs,
160    AltBlockHeight => BlockBlob,
161
162    /// Alt-block transaction blobs.
163    ///
164    /// Contains the raw bytes of alt transactions, if those transactions are not in the main-chain.
165    20 => AltTransactionBlobs,
166    TxHash => TxBlob,
167
168    /// Alt-block transaction information.
169    ///
170    /// Contains information on all alt transactions, even if they are in the main-chain.
171    21 => AltTransactionInfos,
172    TxHash => AltTransactionInfo,
173}
174
175//---------------------------------------------------------------------------------------------------- Tests
176#[cfg(test)]
177mod test {
178    // use super::*;
179}