mx-core 0.1.0

Core utilities for MultiversX Rust services.
Documentation
//! `MultiversX` protocol constants.
//!
//! This module provides shared protocol constants used across the entire workspace.
//! All crates should import these constants from mx-core to ensure consistency.

/// Special shard ID for metachain (0xFFFFFFFF).
///
/// This value represents `u32::MAX` and is used throughout the `MultiversX` protocol
/// to identify operations and data structures that belong to the metachain.
///
/// Prefer [`METACHAIN_SHARD_ID`] which is the canonical name used across
/// the codebase. Both constants hold the same value (`0xFFFF_FFFF`).
#[deprecated(note = "Use METACHAIN_SHARD_ID instead")]
pub const META_SHARD_ID: u32 = u32::MAX;

/// Alias for metachain shard ID used in P2P topics.
///
/// This is identical to `META_SHARD_ID` (both are `0xFFFF_FFFF`) and exists
/// for clarity when working with gossipsub topic names.
pub const METACHAIN_SHARD_ID: u32 = 0xFFFF_FFFF;

/// Shard ID representing all shards in P2P topics.
///
/// This special value (`0xFFFF_FFF0`) is used in gossipsub topic suffixes
/// to indicate that a message should be broadcast to all shards.
pub const ALL_SHARD_ID: u32 = 0xFFFF_FFF0;

/// Transaction option flag for hash signing (keccak256 hash instead of raw JSON).
///
/// When this flag is set in the transaction options field, the signature
/// is computed over the keccak256 hash of the transaction JSON payload
/// rather than the raw JSON bytes.
pub const TX_OPTION_HASH_SIGN: u32 = 1;

/// Transaction option flag for guarded transactions.
///
/// When this flag is set, the transaction includes a guardian signature
/// for additional security.
pub const TX_OPTION_GUARDED: u32 = 2;

#[cfg(test)]
mod tests {
    use super::*;

    #[allow(deprecated)]
    #[test]
    fn test_meta_shard_id_consistency() {
        // Verify that META_SHARD_ID and METACHAIN_SHARD_ID are identical
        assert_eq!(META_SHARD_ID, METACHAIN_SHARD_ID);
        assert_eq!(META_SHARD_ID, 0xFFFF_FFFF);
        assert_eq!(META_SHARD_ID, u32::MAX);
    }

    #[allow(deprecated)]
    #[test]
    fn test_all_shard_id() {
        assert_eq!(ALL_SHARD_ID, 0xFFFF_FFF0);
        // Verify it's distinct from metachain
        assert_ne!(ALL_SHARD_ID, META_SHARD_ID);
    }

    #[test]
    fn test_tx_option_flags() {
        assert_eq!(TX_OPTION_HASH_SIGN, 1);
        assert_eq!(TX_OPTION_GUARDED, 2);
        // Verify flags are distinct
        assert_ne!(TX_OPTION_HASH_SIGN, TX_OPTION_GUARDED);
    }
}