Skip to main content

hyperstack_interpreter/
event_type_helpers.rs

1#![allow(dead_code)]
2
3/// Extract the base name from a potentially scoped event type.
4/// "ore::RoundState" -> "RoundState"
5/// "RoundState" -> "RoundState"  (backwards compat)
6pub fn event_type_base_name(event_type: &str) -> &str {
7    event_type.rsplit("::").next().unwrap_or(event_type)
8}
9
10/// Extract the program name from a scoped event type.
11/// "ore::RoundState" -> Some("ore")
12/// "RoundState" -> None
13pub fn event_type_program(event_type: &str) -> Option<&str> {
14    event_type.rsplit_once("::").map(|(prefix, _)| prefix)
15}
16
17/// Strip the "State" or "IxState" suffix from a potentially scoped event type,
18/// returning just the base account/instruction name.
19/// "ore::RoundState" -> "Round"
20/// "ore::DeployIxState" -> "Deploy"
21/// "RoundState" -> "Round"
22pub fn strip_event_type_suffix(event_type: &str) -> &str {
23    let base = event_type_base_name(event_type);
24    base.strip_suffix("IxState")
25        .or_else(|| base.strip_suffix("State"))
26        .unwrap_or(base)
27}
28
29/// Create a scoped event type name.
30/// ("ore", "Round", false) -> "ore::RoundState"
31/// ("ore", "Deploy", true) -> "ore::DeployIxState"
32pub fn scoped_event_type(program_name: &str, type_name: &str, is_instruction: bool) -> String {
33    let suffix = if is_instruction { "IxState" } else { "State" };
34    format!("{}::{}{}", program_name, type_name, suffix)
35}