channel.move 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. module pyth_lazer::channel;
  2. public enum Channel has copy, drop {
  3. Invalid,
  4. RealTime,
  5. FixedRate50ms,
  6. FixedRate200ms,
  7. }
  8. /// Create a new Invalid channel
  9. public fun new_invalid(): Channel {
  10. Channel::Invalid
  11. }
  12. /// Create a new RealTime channel
  13. public fun new_real_time(): Channel {
  14. Channel::RealTime
  15. }
  16. /// Create a new FixedRate50ms channel
  17. public fun new_fixed_rate_50ms(): Channel {
  18. Channel::FixedRate50ms
  19. }
  20. /// Create a new FixedRate200ms channel
  21. public fun new_fixed_rate_200ms(): Channel {
  22. Channel::FixedRate200ms
  23. }
  24. /// Check if the channel is Invalid
  25. public fun is_invalid(channel: &Channel): bool {
  26. match (channel) {
  27. Channel::Invalid => true,
  28. _ => false,
  29. }
  30. }
  31. /// Check if the channel is RealTime
  32. public fun is_real_time(channel: &Channel): bool {
  33. match (channel) {
  34. Channel::RealTime => true,
  35. _ => false,
  36. }
  37. }
  38. /// Check if the channel is FixedRate50ms
  39. public fun is_fixed_rate_50ms(channel: &Channel): bool {
  40. match (channel) {
  41. Channel::FixedRate50ms => true,
  42. _ => false,
  43. }
  44. }
  45. /// Check if the channel is FixedRate200ms
  46. public fun is_fixed_rate_200ms(channel: &Channel): bool {
  47. match (channel) {
  48. Channel::FixedRate200ms => true,
  49. _ => false,
  50. }
  51. }
  52. /// Get the update interval in milliseconds for fixed rate channels, returns 0 for non-fixed rate channels
  53. public fun get_update_interval_ms(channel: &Channel): u64 {
  54. match (channel) {
  55. Channel::FixedRate50ms => 50,
  56. Channel::FixedRate200ms => 200,
  57. _ => 0,
  58. }
  59. }