pub struct ChainStateMachine<S: ChainStore> { /* private fields */ }Expand description
Pure state machine for chain connections — no networking, no async.
Processes JSON-RPC responses from smoldot (or smoldot-js on WASM),
tracks chain status, and persists chain databases via a ChainStore.
Implementations§
Source§impl<S: ChainStore> ChainStateMachine<S>
impl<S: ChainStore> ChainStateMachine<S>
pub fn new(store: S) -> Self
Sourcepub fn register_chain(&mut self, chain: ChainId)
pub fn register_chain(&mut self, chain: ChainId)
Register a chain for tracking. Initial state is Connecting.
Sourcepub fn register_chain_entry(&mut self, entry: &ChainRegistryEntry)
pub fn register_chain_entry(&mut self, entry: &ChainRegistryEntry)
Register a chain from a [ChainRegistryEntry], using the entry’s owned
strings for db keys and chain specs instead of the ChainId enum methods.
Sourcepub fn unregister_chain(&mut self, chain: ChainId)
pub fn unregister_chain(&mut self, chain: ChainId)
Unregister a chain (sets state to Disconnected).
Sourcepub fn set_state(&mut self, chain: ChainId, state: ChainState)
pub fn set_state(&mut self, chain: ChainId, state: ChainState)
Set the chain state, preserving existing extra.
Sourcepub fn set_state_with_extra(
&mut self,
chain: ChainId,
state: ChainState,
extra: ChainExtra,
)
pub fn set_state_with_extra( &mut self, chain: ChainId, state: ChainState, extra: ChainExtra, )
Set both state and extra data.
Sourcepub fn process_response(&mut self, chain: ChainId, text: &str)
pub fn process_response(&mut self, chain: ChainId, text: &str)
Process a JSON-RPC response from smoldot for a given chain.
Sourcepub fn process_relay_response(&mut self, chain: ChainId, text: &str)
pub fn process_relay_response(&mut self, chain: ChainId, text: &str)
Process a JSON-RPC response for a relay chain DB save.
pub fn status(&self, chain: ChainId) -> ChainStatus
pub fn all_statuses(&self) -> Vec<ChainStatus>
Sourcepub fn subscribe_new_heads_request() -> String
pub fn subscribe_new_heads_request() -> String
Generate the chain_subscribeNewHeads JSON-RPC request.
Sourcepub fn health_check_request(&mut self, chain: ChainId) -> Option<String>
pub fn health_check_request(&mut self, chain: ChainId) -> Option<String>
Generate a system_health JSON-RPC request with an incrementing ID.
Returns None if the chain is not registered.
Sourcepub fn para_db_save_request() -> String
pub fn para_db_save_request() -> String
Generate a parachain DB save request.
Sourcepub fn relay_db_save_request() -> String
pub fn relay_db_save_request() -> String
Generate a relay chain DB save request.
Sourcepub fn load_relay_db(&self, chain: ChainId) -> String
pub fn load_relay_db(&self, chain: ChainId) -> String
Load persisted relay chain DB.
Sourcepub fn load_para_db(&self, chain: ChainId) -> String
pub fn load_para_db(&self, chain: ChainId) -> String
Load persisted parachain DB.
Sourcepub fn chain_specs(chain: ChainId) -> Option<(&'static str, &'static str)>
pub fn chain_specs(chain: ChainId) -> Option<(&'static str, &'static str)>
Get chain specs for a smoldot chain. Returns (relay_spec, para_spec).
Sourcepub fn chain_specs_owned(&self, chain: ChainId) -> Option<(String, String)>
pub fn chain_specs_owned(&self, chain: ChainId) -> Option<(String, String)>
Get chain specs from the registered entry as owned strings.
Returns None for unregistered chains or chains without specs.
Sourcepub fn clear_chain_dbs(&self, chain: ChainId)
pub fn clear_chain_dbs(&self, chain: ChainId)
Clear both relay and para chain databases (used after a smoldot panic).
Sourcepub fn statement_submit_request(encoded_hex: &str, request_id: u64) -> String
pub fn statement_submit_request(encoded_hex: &str, request_id: u64) -> String
Generate a statement_submit JSON-RPC request.
Sourcepub fn statement_subscribe_request(request_id: u64) -> String
pub fn statement_subscribe_request(request_id: u64) -> String
Generate a statement_subscribeStatement JSON-RPC request.
Sourcepub fn statement_unsubscribe_request(sub_id: &str, request_id: u64) -> String
pub fn statement_unsubscribe_request(sub_id: &str, request_id: u64) -> String
Generate a statement_unsubscribeStatement JSON-RPC request.
Sourcepub fn statement_broadcasts_request(
topic_hexes: &[String],
request_id: u64,
) -> String
pub fn statement_broadcasts_request( topic_hexes: &[String], request_id: u64, ) -> String
Generate a statement_broadcastsStatement JSON-RPC request.
Sourcepub fn parse_statement_notification(text: &str) -> Vec<String>
pub fn parse_statement_notification(text: &str) -> Vec<String>
Parse a statement_subscribeStatement notification. Returns hex-encoded statement strings found in the notification, or an empty vec if this is not a statement notification.