mod.rs
Overview
This file defines GraphQL schema types and enums related to messages in a blockchain or distributed ledger system. It provides data structures for inbound messages (InMsg), outbound messages (OutMsg), message envelopes (MsgEnvelope), and a comprehensive Message type. Additionally, it includes enumerations that classify message types and their processing statuses.
The primary functionality revolves around representing message data in a GraphQL API context, including conversion from database message models to GraphQL objects, formatting of large integer values for client consumption, and encapsulating message metadata. The file also exposes filters and resolvers for querying messages.
Enumerations
InMsgTypeEnum
Defines the types of inbound messages received by the system.
Variants:
ExternalIhrImmediatelyFinalTransitDiscardedFinalDiscardedTransit
Conversion:
Implements
From<Option<i64>>to map numeric codes to enum variants.Defaults to
Externalif no value provided.Usage example:
let msg_type: InMsgTypeEnum = Some(3).into(); // -> InMsgTypeEnum::Final
MessageTypeEnum
Classifies messages into internal or external directions.
Variants:
Internal(0)ExtIn(1)ExtOut(2)
Conversion:
Implements
From<i64>with exhaustive matching.Usage example:
let msg_type = MessageTypeEnum::from(1); // -> ExtIn
MessageProcessingStatusEnum
Represents the internal processing status of messages.
Variants:
UnknownQueuedProcessingPreliminaryProposedFinalizedRefusedTransiting
Conversion:
Implements
From<Option<i64>>with defaultUnknown.Usage example:
let status = MessageProcessingStatusEnum::from(Some(5)); // -> Finalized
OutMsgTypeEnum
Enumerates outbound message types.
Variants include:
None(-1)ExternalImmediatelyOutMsgNewTransitDequeueImmediatelyDequeueTransitRequiredDequeueShort
Conversion:
Implements
From<i32>.Usage example:
let out_type = OutMsgTypeEnum::from(3); // -> Transit
Structs
InMsg
Represents an inbound message with associated metadata and optional fields.
Fields:
fwd_fee: Optional forwarding fee (hidden from GraphQL schema).ihr_fee: Optional IHR fee (hidden).in_msg: OptionalMsgEnveloperepresenting the inbound message envelope.msg_id: Optional message identifier.msg_type: Optional integer code of the message type.msg_type_name: OptionalInMsgTypeEnumvariant.out_msg: Optional outbound message envelope (MsgEnvelope).proof_created: Optional string indicating proof creation.proof_delivered: Optional proof delivery string.transaction_id: Optional linked transaction identifier.transit_fee: Optional transit fee (hidden).
Methods:
Asynchronous GraphQL resolvers for formatting fee fields (
fwd_fee,ihr_fee,transit_fee) into human-readable strings usingformat_big_int.
Conversions:
From
db::Message: Initializes fields from database message model, setting some fees toNone.From
InBlockMessage: Initializes from a block message with minimal fields.
Usage example:
let in_msg = InMsg::from(db_message); let formatted_fee = in_msg.fwd_fee(Some(BigIntFormat::Decimal)).await;
MsgEnvelope
Represents the envelope of a message indicating routing information.
Fields:
cur_addr: Current address as an optional string.fwd_fee_remaining: Optional forwarding fee remaining (hidden).msg_id: Optional message ID.next_addr: Optional next address in routing.
Methods:
Async resolver
fwd_fee_remainingto format the fee.
Message
Represents a detailed message entity with comprehensive metadata.
Public Fields:
id: Unique message ID.block_id: Optional linked block ID.boc: Optional bag of cells encoded as Base64 representing the message structure.body: Optional Base64 encoded message body.body_hash: Optional root hash of the body.bounce: Optional bounce flag (boolean).bounced: Optional bounced flag.code: Optional Base64 encoded contract code.code_hash: Optional root hash of the code.created_at: Optional message creation Unix timestamp.created_lt: Logical creation time (hidden from GraphQL).data: Optional Base64 encoded initial contract data.data_hash: Optional root hash of data.dst: Optional destination address string.dst_transaction: Optional linked transaction for destination.dst_chain_order: Optional string for pagination/order.dst_workchain_id: Optional workchain ID of destination.fwd_fee: Optional forwarding fee (hidden).ihr_disabled: Optional flag indicating if IHR is disabled.ihr_fee: Optional IHR fee (hidden).library: Optional Base64 encoded contract library.library_hash: Optional root hash of library.msg_type: Optional integer message type.msg_type_name: OptionalMessageTypeEnum.proof: Optional Base64 Merkle proof.src: Optional source address string.src_chain_order: Optional pagination field.src_dapp_id: Optional source dapp ID.src_transaction: Optional linked source transaction.src_workchain_id: Optional source workchain ID.status: Optional processing status code.status_name: OptionalMessageProcessingStatusEnum.tick: Optional boolean used for special masterchain contracts.tock: Optional boolean used for special masterchain contracts.transaction_id: Optional linked transaction ID.value: Optional string representing message value (hidden).value_other: Optional vector ofOtherCurrencyrepresenting other currency values.
Methods:
Async resolvers to format:
created_ltihr_feefwd_feevalue
usingformat_big_int.
Conversion:
From
db::Message: Converts database message to GraphQLMessage, encoding byte arrays to Base64 usingtvm_types::base64_encode, converting optional integer fields, and decoding ECC currency values usingecc_from_bytes.
Usage example:
let graphql_msg: Message = db_message.into(); let formatted_value = graphql_msg.value(Some(BigIntFormat::Hex)).await;
OutMsg
Represents an outbound message including import metadata and message envelopes.
Fields:
import_block_lt: Optional block logical time of import (hidden).imported: Optional inboundInMsgthat was imported.msg_env_hash: Optional hash of the message envelope.msg_id: Optional message ID.msg_type: Optional integer message type.msg_type_name: OptionalOutMsgTypeEnum.next_addr_pfx: Optional prefix of next address (hidden).next_workchain: Optional next workchain ID.out_msg: Optional outboundMsgEnvelope.reimport: Optional re-imported inboundInMsg.transaction_id: Optional linked transaction ID.
Methods:
Async resolvers to format
import_block_ltandnext_addr_pfxfields.
Conversion:
From
Message: Constructs anOutMsgby copyingidandtransaction_idfields and leaving most others empty.
Implementation Details
The file uses
async_graphqlmacros and traits to define GraphQL schema objects and enums with PascalCase naming conventions.Fee-related fields are stored as
Option<String>internally and exposed to GraphQL clients via asynchronous formatting functions that support multiple big integer formats (BigIntFormat).Conversion implementations (
From) provide seamless translation from database models (db::Message,InBlockMessage) to GraphQL schema types.Uses helpers such as:
format_big_intto present large integer values in various formats.ecc_from_bytesto deserialize elliptic curve currency data.ToBool,ToInt,ToOptU64traits for safe conversions from optional integer or boolean database fields.
Some fields are hidden from the GraphQL schema using
#[graphql(skip)], serving internal use.The
Messagestruct contains comprehensive blockchain message metadata, including contract code, data, transaction links, and message routing info.The module re-exports
MessageFilterandMessageLoaderfrom internal submodulesfilterandresolver, which are responsible for filtering and loading message data, respectively.
Interactions with Other Modules
Imports from:
super::transaction::Transactionfor transaction linkage.crate::helpersfor data formatting and conversions.crate::schema::db::message::InBlockMessageandcrate::schema::dbfor database message models.crate::schema::graphql_shared::currency::OtherCurrencyfor currency representation.crate::schema::graphql_shared::formats::BigIntFormatfor formatting options.
The
filterandresolversubmodules contain logic to query and load message data, exposingMessageFilterandMessageLoaderfor use in GraphQL resolvers or API endpoints.
Mermaid Diagram
classDiagram
class InMsg {
-fwd_fee: Option<String>
-ihr_fee: Option<String>
+in_msg: Option<MsgEnvelope>
+msg_id: Option<String>
+msg_type: Option<i32>
+msg_type_name: Option<InMsgTypeEnum>
+out_msg: Option<MsgEnvelope>
+proof_created: Option<String>
+proof_delivered: Option<String>
+transaction_id: Option<String>
-transit_fee: Option<String>
+fwd_fee()
+ihr_fee()
+transit_fee()
}
class MsgEnvelope {
+cur_addr: Option<String>
-fwd_fee_remaining: Option<String>
+msg_id: Option<String>
+next_addr: Option<String>
+fwd_fee_remaining()
}
class Message {
+id: String
+block_id: Option<String>
+boc: Option<String>
+body: Option<String>
+body_hash: Option<String>
+bounce: Option<bool>
+bounced: Option<bool>
+code: Option<String>
+code_hash: Option<String>
+created_at: Option<u64>
-created_lt: Option<String>
+data: Option<String>
+data_hash: Option<String>
+dst: Option<String>
+dst_transaction: Option<Transaction>
+dst_chain_order: Option<String>
+dst_workchain_id: Option<i32>
-fwd_fee: Option<String>
+ihr_disabled: Option<bool>
-ihr_fee: Option<String>
+library: Option<String>
+library_hash: Option<String>
+msg_type: Option<i32>
+msg_type_name: Option<MessageTypeEnum>
+proof: Option<String>
+src: Option<String>
+src_chain_order: Option<String>
+src_dapp_id: Option<String>
+src_transaction: Option<Transaction>
+src_workchain_id: Option<i32>
+status: Option<i32>
+status_name: Option<MessageProcessingStatusEnum>
+tick: Option<bool>
+tock: Option<bool>
+transaction_id: Option<String>
-value: Option<String>
+value_other: Option<Vec<OtherCurrency>>
+created_lt()
+ihr_fee()
+fwd_fee()
+value()
}
class OutMsg {
-import_block_lt: Option<String>
+imported: Option<InMsg>
+msg_env_hash: Option<String>
+msg_id: Option<String>
+msg_type: Option<i32>
+msg_type_name: Option<OutMsgTypeEnum>
-next_addr_pfx: Option<String>
+next_workchain: Option<i32>
+out_msg: Option<MsgEnvelope>
+reimport: Option<InMsg>
+transaction_id: Option<String>
+import_block_lt()
+next_addr_pfx()
}
InMsg --> MsgEnvelope
InMsg --> MsgEnvelope : out_msg
Message --> Transaction : dst_transaction
Message --> Transaction : src_transaction
OutMsg --> InMsg : imported
OutMsg --> InMsg : reimport
OutMsg --> MsgEnvelope : out_msg