pub enum WebSocketOperation {
Connect {
url: RexUrl,
rex_id: RexId,
},
Read {
connection_rex_id: RexId,
mode: WebSocketReadMode,
},
Send {
connection_rex_id: RexId,
messages: Vec<RexValue>,
},
Close {
connection_rex_id: RexId,
},
}Expand description
WebSocket operation types for the WebSocket REX.
This enum defines the different operations that can be performed on WebSocket connections.
All WebSocket operations are handled through a single TargetRexProgram::WebSocket variant.
§Variants
Connect- Establish a new WebSocket connection to an external serverRead- Read the latest data from an existing WebSocket connection
§Future Extensions
Additional operations like Send and Close may be added in the future.
Variants§
Connect
Establish a new WebSocket connection.
When this operation is executed:
- A validator is randomly selected to handle the connection
- The TEE establishes the WebSocket connection to the specified URL
- On success, the connection is registered in the WebSocket Registry
- The assigned validator is recorded for future routing
Fields
Read
Read data from an existing WebSocket connection.
When this operation is executed:
- The operation is automatically routed to the TEE holding the connection
- Returns messages from the connection’s buffer based on the read mode
- The referenced connection must exist and be active
§Read Modes
Latest(default): Returns only the most recent messageAll: Returns all accumulated messages in the bufferFromIndex(n): Returns all messages with index > n, with gap detection
§Validation
The handler implementation must verify that:
connection_rex_idreferences an existing Connect operation in the WebSocket Registry- The connection is still active and hasn’t been closed
- The requesting validator has permission to read from this connection
§Error Handling
If validation fails, the REX should return an appropriate error indicating:
ConnectionNotFound- if the referenced REX ID doesn’t existConnectionClosed- if the connection has been terminatedInvalidConnectionType- if the referenced REX is not a WebSocket Connect operation
Fields
connection_rex_id: RexIdReferences the RexId of the Connect operation that established the connection
mode: WebSocketReadModeThe read mode determining which messages to return (defaults to Latest for backward compatibility)
Send
Send messages to an existing WebSocket connection.
When this operation is executed:
- The operation is automatically routed to the TEE holding the connection
- Each
RexValueinmessagesis sent as a separate WebSocket message - The inner value is extracted:
Plain(String)→ sent as-is,Encrypted(String)→ decrypted then sent - Returns the number of messages successfully sent
- The referenced connection must exist and be active
§Validation
The handler implementation must verify that:
connection_rex_idreferences an existing Connect operation in the WebSocket Registry- The connection is still active and hasn’t been closed
- The requesting validator has permission to send to this connection
§Error Handling
If validation fails, the REX should return an appropriate error indicating:
ConnectionNotFound- if the referenced REX ID doesn’t existConnectionClosed- if the connection has been terminatedInvalidConnectionType- if the referenced REX is not a WebSocket Connect operationSecretDecryptionFailed- if an encrypted message cannot be decrypted
Fields
Close
Close an existing WebSocket connection.
When this operation is executed:
- The operation is automatically routed to the TEE holding the connection
- The WebSocket connection is gracefully closed
- The connection status in the WebSocket Registry is updated to
Closed - The referenced connection must exist and be active
§Validation
The handler implementation must verify that:
connection_rex_idreferences an existing Connect operation in the WebSocket Registry- The requesting validator has permission to close this connection
§Error Handling
If validation fails, the REX should return an appropriate error indicating:
ConnectionNotFound- if the referenced REX ID doesn’t existConnectionAlreadyClosed- if the connection has already been terminatedInvalidConnectionType- if the referenced REX is not a WebSocket Connect operation
Implementations§
Source§impl WebSocketOperation
impl WebSocketOperation
Sourcepub fn read(connection_rex_id: RexId) -> Self
pub fn read(connection_rex_id: RexId) -> Self
Create a new Read operation with default Latest mode.
Sourcepub fn read_with_mode(connection_rex_id: RexId, mode: WebSocketReadMode) -> Self
pub fn read_with_mode(connection_rex_id: RexId, mode: WebSocketReadMode) -> Self
Create a new Read operation with a specific mode.
Sourcepub fn send(connection_rex_id: RexId, messages: Vec<RexValue>) -> Self
pub fn send(connection_rex_id: RexId, messages: Vec<RexValue>) -> Self
Create a new Send operation.
Sourcepub fn is_connect(&self) -> bool
pub fn is_connect(&self) -> bool
Returns true if this is a Connect operation.
Sourcepub fn url(&self) -> Option<&RexUrl>
pub fn url(&self) -> Option<&RexUrl>
Returns the URL if this is a Connect operation, None otherwise.
Sourcepub fn rex_id(&self) -> Option<&RexId>
pub fn rex_id(&self) -> Option<&RexId>
Returns the rex_id if this is a Connect operation, None otherwise.
Sourcepub fn connection_rex_id(&self) -> Option<&RexId>
pub fn connection_rex_id(&self) -> Option<&RexId>
Returns the connection_rex_id if this is a Read, Send, or Close operation, None otherwise.
Sourcepub fn read_mode(&self) -> Option<&WebSocketReadMode>
pub fn read_mode(&self) -> Option<&WebSocketReadMode>
Returns the read mode if this is a Read operation, None otherwise.
Trait Implementations§
Source§impl BorshDeserialize for WebSocketOperation
impl BorshDeserialize for WebSocketOperation
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for WebSocketOperation
impl BorshSerialize for WebSocketOperation
Source§impl Clone for WebSocketOperation
impl Clone for WebSocketOperation
Source§fn clone(&self) -> WebSocketOperation
fn clone(&self) -> WebSocketOperation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WebSocketOperation
impl Debug for WebSocketOperation
Source§impl<'de> Deserialize<'de> for WebSocketOperation
impl<'de> Deserialize<'de> for WebSocketOperation
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for WebSocketOperation
impl Display for WebSocketOperation
Source§impl EnumExt for WebSocketOperation
impl EnumExt for WebSocketOperation
impl Eq for WebSocketOperation
Source§impl PartialEq for WebSocketOperation
impl PartialEq for WebSocketOperation
Source§fn eq(&self, other: &WebSocketOperation) -> bool
fn eq(&self, other: &WebSocketOperation) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for WebSocketOperation
impl Serialize for WebSocketOperation
impl StructuralPartialEq for WebSocketOperation
Auto Trait Implementations§
impl Freeze for WebSocketOperation
impl RefUnwindSafe for WebSocketOperation
impl Send for WebSocketOperation
impl Sync for WebSocketOperation
impl Unpin for WebSocketOperation
impl UnsafeUnpin for WebSocketOperation
impl UnwindSafe for WebSocketOperation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.