vialabs-stellar-common 0.1.10

Common interfaces, types, and utilities for Stellar contracts in the VIA cross-chain messaging system
Documentation
/// # Storage Module
///
/// This module provides storage keys and data structures used across contracts.
use soroban_sdk::{contracttype, symbol_short, Address, Symbol};

/// Storage key for chain details (chain ID and next transaction ID)
pub const CHAIN_DETAILS_KEY: Symbol = symbol_short!("chain");

/// Storage key for system enabled status (as byte string)
pub const SYSTEM_ENABLED_KEY: &[u8] = b"system_enabled\0";

/// Storage key for deployer address
pub const DEPLOYER_ADDRESS_KEY: Symbol = symbol_short!("deployer");

/// Storage key for gateway contract address
pub const GATEWAY_CONTRACT_ADDRESS: Symbol = symbol_short!("gateway");

/// Zero bytes array (32 bytes of zeros) used for address validation
pub const ZERO_BYTES: [u8; 32] = [0u8; 32];

/// Factor used for transaction ID generation (10^23)
pub const TX_ID_FACTOR: u128 = 10u128.pow(23);

/// Minimum TTL (Time To Live) for persistent storage entries (100,000 ledgers)
pub const PERSISTENT_STORAGE_MIN_TTL: u32 = 100_000;

/// Maximum TTL for persistent storage entries (200,000 ledgers)
pub const PERSISTENT_STORAGE_MAX_TTL: u32 = 200_000;

/// Minimum TTL for temporary storage entries (17,280 ledgers, ~30 days)
pub const TEMPORARY_STORAGE_MIN_TTL: u32 = 17_280;

/// Maximum TTL for temporary storage entries (34,560 ledgers, ~60 days)
pub const TEMPORARY_STORAGE_MAX_TTL: u32 = 34_560;

#[contracttype]
#[derive(Clone, Debug, PartialEq)]
pub struct ChainDetails {
  /// Next transaction ID to be used for cross-chain messages
  pub next_tx_id: u128,
  /// Chain ID of the current chain
  pub chain_id: u64,
}

#[contracttype]
#[derive(Clone, Debug, PartialEq)]
pub enum DataKey {
  /// Storage key for chain details (chain ID and next transaction ID)
  ChainDetails,

  /// Storage key for the list of chain signers
  ChainSigners,
  /// Storage key for mapping chain signer addresses to their status
  ChainSignersMap(Address),
  /// Storage key for the required number of chain signatures
  ChainSignersRequired,

  /// Storage key for the list of VIA signers
  ViaSigners,
  /// Storage key for mapping VIA signer addresses to their status
  ViaSignersMap(Address),
  /// Storage key for the required number of VIA signatures
  ViaSignersRequired,

  /// Storage key for project signers list for a specific contract
  ProjectSigners(Address),
  /// Storage key for mapping project signer addresses to their status for a specific contract
  ProjectSignersMap(Address, Address),
  /// Storage key for the required number of project signatures for a specific contract
  ProjectSignersRequired(Address),

  /// Storage key for the list of relayers
  Relayers,
  /// Storage key for mapping relayer addresses to their status
  RelayersMap(Address),
  /// Storage key indicating whether relayers are required
  RelayersRequired,

  /// Storage key for contract-specific relayers list
  ContractRelayers(Address),
  /// Storage key for mapping contract-specific relayer addresses to their status
  ContractRelayersMap(Address, Address),
  /// Storage key indicating whether relayers are enabled for a specific contract
  ContractRelayersEnabled(Address),

  /// Storage key for tracking processed transfers by transaction ID
  ProcessedTransfers(u128),

  /// Storage key for the fee handler contract address
  FeeHandler,
  /// Storage key for tracking if process_fee was called for a specific address
  ProcessFeeCalledFor(Address),
  /// Storage key for fees offline status
  FeesOffline,
  /// Storage key for custom source fee amount for a specific client contract
  CustomSourceFee(Address),
  /// Storage key for maximum fee amount for a specific client contract
  MaxFeeAmount(Address),
  /// Storage key for fee token contract address for a specific client contract
  FeeTokenContract(Address),

  /// Storage key for the gas handler contract address
  GasHandler,
  /// Storage key for maximum gas amount for a specific client contract
  MaxGasAmount(Address),
  /// Storage key for tracking if process_gas_refund was called for a specific contract and relayer
  ProcessGasRefundCalledFor(Address, Address),
  /// Storage key for gas token contract address for a specific client contract
  GasTokenContract(Address),
  /// Storage key for unwrap token contract address
  UnwrapToken(Address),

  /// Storage key for the POS (Proof of Stake) handler contract address
  PosHandler,
  /// Storage key for message validation result
  MessageValidateResult,

  /// Storage key for gateway contract address (used in message clients)
  GatewayContractAddress,
  /// Storage key for chain endpoint address for a specific chain ID
  ChainsEndpoints(u64),

  /// Storage key for block tip information
  BlockTip,
}