mod.rs

Overview

This file defines core data structures and functions for handling external messages and their feedback within the system. It provides serialization-friendly representations of message identifiers, responses, errors, and feedback, facilitating interaction with external components or APIs. The file includes mechanisms to convert between raw data formats and structured types, encapsulates error handling, and supports rendering HTTP JSON responses.

The primary functionalities include:

This module interacts closely with the message submodule (which is declared but not detailed here) and integrates with external authentication tokens (ext_messages_auth::auth::Token) and HTTP response handling from salvo.


Data Structures and Types

ThreadIdentifier

A wrapper over a fixed 34-byte array representing a unique thread identifier.

Usage example:

let id = ThreadIdentifier::try_from("abcdef...".to_string())?;
println!("{:?}", id); // prints hex string representation

ExtMsgResponse

Represents the HTTP response body for external message requests.


ExtMsgResult

Contains detailed information about a successful message processing:


ExtMsgErrorData

Additional context for errors related to external messages.


ExtMsgError

Encapsulates error information for responses.


FeedbackErrorCode

Enumerates possible error codes from message feedback with string representations:


FeedbackError

Contains an error from feedback processing:


ExtMsgFeedback

Represents detailed feedback from external message processing, including:

Implements Display for formatted debug output.


ExtMsgFeedbackList

Wraps a vector of ExtMsgFeedback with basic list operations:

Implements Display to output all contained feedbacks.


ResolvingResult

Holds resolution state related to block producers:


Functions

current_time_millis(ttl: Option<u64>) -> u128

Returns the current system time plus an optional TTL (time-to-live) offset in milliseconds since UNIX epoch.


render_error_response

Renders a JSON error response to an HTTP request with status code 400 BAD REQUEST.

Parameters:


render_error

Renders a JSON error response with a specified HTTP status code.

Parameters:


Implementation Details and Algorithms


Interaction with Other Modules


Diagram: Structure of mod.rs

classDiagram
class ThreadIdentifier {
+[u8;34] bytes
+try_from(String) ThreadIdentifier
+from([u8;34]) ThreadIdentifier
+to_bytes() [u8;34]
}
class ExtMsgResponse {
-Option<ExtMsgResult> result
-Option<ExtMsgError> error
-Option<Token> ext_message_token
+new_with_error(String, String, Option<ExtMsgErrorData>)
+set_producers(Vec<String>)
}
class ExtMsgResult {
-String message_hash
-String block_hash
-String tx_hash
-Vec<String> ext_out_msgs
-bool aborted
-i32 exit_code
-Vec<String> producers
-String current_time
-Option<String> thread_id
}
class ExtMsgErrorData {
-Vec<String> producers
-String message_hash
-Option<i32> exit_code
-String current_time
-Option<String> thread_id
+new(Vec<String>, String, Option<i32>, Option<String>)
}
class ExtMsgError {
-String code
-String message
-Option<ExtMsgErrorData> data
+new(String, String, Option<ExtMsgErrorData>)
+set_producers(Vec<String>)
}
class FeedbackErrorCode {
<<enumeration>>
Ok
TvmError
MessageExpired
TooManyRequestsInQueue
NotActiveProducer
DuplicateMessage
ThreadMismatch
InternalError
ComputeSkipped
QueueOverflow
+to_string()
}
class FeedbackError {
-FeedbackErrorCode code
-Option<String> message
}
class ExtMsgFeedback {
-String message_hash
-Option<String> tx_hash
-Option<String> block_hash
-bool aborted
-i32 exit_code
-Option<[u8;34]> thread_id
-Option<FeedbackError> error
-Vec<SliceData> ext_out_msgs
}
class ExtMsgFeedbackList {
-Vec<ExtMsgFeedback> feedbacks
+new()
+push(ExtMsgFeedback)
}
class ResolvingResult {
-bool i_am_bp
-Vec<String> active_bp
+new(bool, Vec<String>)
}
ExtMsgResponse --> ExtMsgResult
ExtMsgResponse --> ExtMsgError
ExtMsgError --> ExtMsgErrorData
ExtMsgFeedback --> FeedbackError
ExtMsgResponse ..> ExtMsgFeedback : From

This diagram illustrates the main data structures, their relationships, and key methods within the file.