Skip to main content

vialabs_stellar_common/
storage.rs

1/// # Storage Module
2///
3/// This module provides storage keys and data structures used across contracts.
4use soroban_sdk::{contracttype, symbol_short, Address, Symbol};
5
6/// Storage key for chain details (chain ID and next transaction ID)
7pub const CHAIN_DETAILS_KEY: Symbol = symbol_short!("chain");
8
9/// Storage key for system enabled status (as byte string)
10pub const SYSTEM_ENABLED_KEY: &[u8] = b"system_enabled\0";
11
12/// Storage key for deployer address
13pub const DEPLOYER_ADDRESS_KEY: Symbol = symbol_short!("deployer");
14
15/// Storage key for gateway contract address
16pub const GATEWAY_CONTRACT_ADDRESS: Symbol = symbol_short!("gateway");
17
18/// Zero bytes array (32 bytes of zeros) used for address validation
19pub const ZERO_BYTES: [u8; 32] = [0u8; 32];
20
21/// Factor used for transaction ID generation (10^23)
22pub const TX_ID_FACTOR: u128 = 10u128.pow(23);
23
24/// Minimum TTL (Time To Live) for persistent storage entries (100,000 ledgers)
25pub const PERSISTENT_STORAGE_MIN_TTL: u32 = 100_000;
26
27/// Maximum TTL for persistent storage entries (200,000 ledgers)
28pub const PERSISTENT_STORAGE_MAX_TTL: u32 = 200_000;
29
30/// Minimum TTL for temporary storage entries (17,280 ledgers, ~30 days)
31pub const TEMPORARY_STORAGE_MIN_TTL: u32 = 17_280;
32
33/// Maximum TTL for temporary storage entries (34,560 ledgers, ~60 days)
34pub const TEMPORARY_STORAGE_MAX_TTL: u32 = 34_560;
35
36#[contracttype]
37#[derive(Clone, Debug, PartialEq)]
38pub struct ChainDetails {
39  /// Next transaction ID to be used for cross-chain messages
40  pub next_tx_id: u128,
41  /// Chain ID of the current chain
42  pub chain_id: u64,
43}
44
45#[contracttype]
46#[derive(Clone, Debug, PartialEq)]
47pub enum DataKey {
48  /// Storage key for chain details (chain ID and next transaction ID)
49  ChainDetails,
50
51  /// Storage key for the list of chain signers
52  ChainSigners,
53  /// Storage key for mapping chain signer addresses to their status
54  ChainSignersMap(Address),
55  /// Storage key for the required number of chain signatures
56  ChainSignersRequired,
57
58  /// Storage key for the list of VIA signers
59  ViaSigners,
60  /// Storage key for mapping VIA signer addresses to their status
61  ViaSignersMap(Address),
62  /// Storage key for the required number of VIA signatures
63  ViaSignersRequired,
64
65  /// Storage key for project signers list for a specific contract
66  ProjectSigners(Address),
67  /// Storage key for mapping project signer addresses to their status for a specific contract
68  ProjectSignersMap(Address, Address),
69  /// Storage key for the required number of project signatures for a specific contract
70  ProjectSignersRequired(Address),
71
72  /// Storage key for the list of relayers
73  Relayers,
74  /// Storage key for mapping relayer addresses to their status
75  RelayersMap(Address),
76  /// Storage key indicating whether relayers are required
77  RelayersRequired,
78
79  /// Storage key for contract-specific relayers list
80  ContractRelayers(Address),
81  /// Storage key for mapping contract-specific relayer addresses to their status
82  ContractRelayersMap(Address, Address),
83  /// Storage key indicating whether relayers are enabled for a specific contract
84  ContractRelayersEnabled(Address),
85
86  /// Storage key for tracking processed transfers by transaction ID
87  ProcessedTransfers(u128),
88
89  /// Storage key for the fee handler contract address
90  FeeHandler,
91  /// Storage key for tracking if process_fee was called for a specific address
92  ProcessFeeCalledFor(Address),
93  /// Storage key for fees offline status
94  FeesOffline,
95  /// Storage key for custom source fee amount for a specific client contract
96  CustomSourceFee(Address),
97  /// Storage key for maximum fee amount for a specific client contract
98  MaxFeeAmount(Address),
99  /// Storage key for fee token contract address for a specific client contract
100  FeeTokenContract(Address),
101
102  /// Storage key for the gas handler contract address
103  GasHandler,
104  /// Storage key for maximum gas amount for a specific client contract
105  MaxGasAmount(Address),
106  /// Storage key for tracking if process_gas_refund was called for a specific contract and relayer
107  ProcessGasRefundCalledFor(Address, Address),
108  /// Storage key for gas token contract address for a specific client contract
109  GasTokenContract(Address),
110  /// Storage key for unwrap token contract address
111  UnwrapToken(Address),
112
113  /// Storage key for the POS (Proof of Stake) handler contract address
114  PosHandler,
115  /// Storage key for message validation result
116  MessageValidateResult,
117
118  /// Storage key for gateway contract address (used in message clients)
119  GatewayContractAddress,
120  /// Storage key for chain endpoint address for a specific chain ID
121  ChainsEndpoints(u64),
122
123  /// Storage key for block tip information
124  BlockTip,
125}