identifier.rs
Overview
This file defines the MessageIdentifier struct, which serves as a unique identifier for outbound messages within the messaging system. It encapsulates the OutMsgQueueKey type, providing serialization, deserialization, and convenient conversions from message-related types. This identifier is used primarily to reference messages in outbound message queues and related processing components.
The file implements traits for serialization and deserialization using serde, supports debugging output, and defines conversions from wrapped messages and queue keys. It leverages cryptographic hashing and account identification logic from the underlying tvm_block crate to construct unique keys.
Structs and Implementations
MessageIdentifier
pub struct MessageIdentifier(OutMsgQueueKey);
Purpose: Wraps an
OutMsgQueueKeyto uniquely identify an outbound message.Derives:
Clone,PartialEq,Eq,Hashfor easy comparison and use in hashed collections.Attributes: Uses
#[serde_as]to enable custom serialization behaviors.
Methods
inner(&self) -> &OutMsgQueueKeyReturns a reference to the inner
OutMsgQueueKeyinstance.Usage example:
let msg_id: MessageIdentifier = ...; let key_ref: &OutMsgQueueKey = msg_id.inner();
Trait Implementations
DebugFormats the identifier by showing its hash in hexadecimal form for easier inspection.
Output example:
MessageIdentifier(a1b2c3d4...)SerializeSerializes the contained
OutMsgQueueKeyby converting it to bytes first, then serializing those bytes. Panics if serialization fails, as the identifier must always be serializable.DeserializeDeserializes a byte slice into an
OutMsgQueueKeyand wraps it in aMessageIdentifier. Panics if deserialization fails.From<&WrappedMessage>Constructs a
MessageIdentifierfrom a reference to aWrappedMessageby:Extracting the internal destination account ID from the message.
Deriving a prefix using
get_next_u64()on the account ID.Creating an
OutMsgQueueKeywith a fixed workchain ID0, the derived prefix, and the message hash.
Panics if any step fails (e.g., missing destination, failed prefix calculation, or missing message hash).
From<Arc<WrappedMessage>>Converts from an atomically reference-counted wrapped message by delegating to the reference conversion.
From<OutMsgQueueKey>Directly wraps an
OutMsgQueueKeyinto aMessageIdentifier.
Important Implementation Details
The
MessageIdentifierrelies heavily on theOutMsgQueueKeytype from thetvm_blockcrate, which encapsulates the logic for uniquely identifying outbound message queue entries.Serialization and deserialization use byte representations of the key to ensure compact and consistent storage and transmission.
Conversion from
WrappedMessageinvolves cryptographic hash extraction and deterministic prefix calculation from the destination account ID, ensuring globally unique and consistent identifiers.Panic behavior is used aggressively to enforce the invariant that serialization, deserialization, and conversion operations must succeed during normal operation, reflecting the critical nature of these identifiers in the messaging workflow.
Interactions with Other Components
WrappedMessage: This file depends onWrappedMessagefrom themessagemodule for creating identifiers associated with actual messages.tvm_blockcrate: UtilizesOutMsgQueueKey,Serializable,Deserializable, and related traits to manage the representation and serialization of queue keys.Serialization Framework: Integrates with
serdeandserde_withfor serialization compatibility, enabling usage in broader systems that serialize message identifiers for network transmission or storage.
The MessageIdentifier acts as a bridge between raw messages and their queue representations, ensuring consistent identification across message processing subsystems.
Diagram: Structure of identifier.rs
classDiagram
class MessageIdentifier {
-OutMsgQueueKey 0:1
+inner()
+from(&WrappedMessage)
+from(Arc<WrappedMessage>)
+from(OutMsgQueueKey)
+serialize()
+deserialize()
+fmt()
}
MessageIdentifier ..> OutMsgQueueKey : encapsulates
MessageIdentifier ..> WrappedMessage : converts from
MessageIdentifier ..|> Debug
MessageIdentifier ..|> Serialize
MessageIdentifier ..|> Deserialize