message.rs

Overview

This file defines the ArchMessage struct and related functionality for representing and serializing blockchain messages within the GOSH DAO system. It provides a structured archival format for messages, capturing essential metadata, serialized content, and associated cryptographic proofs. The file also includes utility functions for extracting fee information from messages.

The primary functionality revolves around transforming raw message data, encapsulated in the MessageSerializationSet type, into the archival-friendly ArchMessage form. This transformation includes serialization of message bodies and state initialization components, as well as categorizing messages by their header types.


Structs and Functions

ArchMessage

A data structure representing a blockchain message archive entry. It contains identifiers, serialized message content, cryptographic hashes, metadata about message status and type, source and destination details, value and fee information, temporal markers, and optional proof and state initialization data.

Fields

Field Name

Type

Description

id

String

Unique identifier of the message, hex-encoded.

transaction_id

Option<String>

Optional transaction identifier in hex string form.

boc

Option<Vec<u8>>

Serialized Bag of Cells (BOC) representation of the entire message.

body

Option<Vec<u8>>

Serialized BOC of the message body, if present.

body_hash

Option<String>

Optional hash of the message body.

status

Option<u8>

Optional status code indicating message state.

msg_type

Option<u8>

Optional message type indicator (0 = internal, 1 = external inbound, 2 = external outbound).

src

Option<String>

Optional source address of the message.

src_dapp_id

Option<String>

Optional source decentralized app identifier.

src_workchain_id

Option<i32>

Optional source workchain identifier.

dst

Option<String>

Optional destination address of the message.

dst_workchain_id

Option<i32>

Optional destination workchain identifier.

fwd_fee

Option<String>

Optional forwarding fee, represented as a hexadecimal string.

bounce

Option<bool>

Optional bounce flag indicating if the message is bounceable.

bounced

Option<bool>

Optional bounced flag indicating if the message was bounced.

value

Option<String>

Optional message value in hexadecimal format.

value_other

Option<Vec<u8>>

Optional serialized additional value data.

created_lt

Option<String>

Optional logical time of message creation, as string.

created_at

Option<u32>

Optional creation timestamp (unix time).

dst_chain_order

Option<String>

Optional destination chain order identifier.

src_chain_order

Option<String>

Optional source chain order identifier.

proof

Option<Vec<u8>>

Optional cryptographic proof data associated with the message.

code

Option<Vec<u8>>

Optional serialized BOC of the message's state initialization code.

code_hash

Option<String>

Optional hash of the state initialization code.

data

Option<Vec<u8>>

Optional serialized BOC of the message's state initialization data.

data_hash

Option<String>

Optional hash of the state initialization data.

msg_chain_order

Option<String>

Optional message chain order identifier.

Traits Derived


impl From<MessageSerializationSet> for ArchMessage

Converts a MessageSerializationSet instance into an ArchMessage. This conversion serializes various message components, extracts metadata, and sets archival fields accordingly.

Parameters

Returns

Description

This implementation leverages write_boc for serialization of cells and uses hash functions to produce hex-encoded hashes for the code and data cells.

Usage Example

let arch_msg: ArchMessage = message_serialization_set_instance.into();

pub(crate) fn get_msg_fees(msg: &Message) -> Option<(&Grams, &Grams)>

Extracts the internal message fees from a given Message if it is an internal message.

Parameters

Returns

Description

This function inspects the message header using msg.header() and matches on the CommonMsgInfo enum. Only internal messages (IntMsgInfo) contain fee information; for external messages, fees are not applicable or accessible in this context.

Usage Example

if let Some((ihr_fee, fwd_fee)) = get_msg_fees(&message) {
    println!("Import fee: {}, Forwarding fee: {}", ihr_fee, fwd_fee);
}

Important Implementation Details


Interaction with Other Modules

The ArchMessage type acts as a bridge between raw blockchain message data and archival storage or further processing components that require a structured, serializable message format.


Visual Diagram: Class Diagram for ArchMessage and Related Conversion

classDiagram
class ArchMessage {
+id: String
+transaction_id: Option<String>
+boc: Option<Vec<u8>>
+body: Option<Vec<u8>>
+body_hash: Option<String>
+status: Option<u8>
+msg_type: Option<u8>
+src: Option<String>
+src_dapp_id: Option<String>
+src_workchain_id: Option<i32>
+dst: Option<String>
+dst_workchain_id: Option<i32>
+fwd_fee: Option<String>
+bounce: Option<bool>
+bounced: Option<bool>
+value: Option<String>
+value_other: Option<Vec<u8>>
+created_lt: Option<String>
+created_at: Option<u32>
+dst_chain_order: Option<String>
+src_chain_order: Option<String>
+proof: Option<Vec<u8>>
+code: Option<Vec<u8>>
+code_hash: Option<String>
+data: Option<Vec<u8>>
+data_hash: Option<String>
+msg_chain_order: Option<String>
}
class MessageSerializationSet {
<<struct>>
}
ArchMessage <|-- MessageSerializationSet : from()
class Message {
<<struct>>
+header()
}
class CommonMsgInfo {
<<enum>>
IntMsgInfo
ExtInMsgInfo
ExtOutMsgInfo
}
ArchMessage ..> MessageSerializationSet : Conversion Input
MessageSerializationSet ..> Message : Contains
Message ..> CommonMsgInfo : header() returns

References