event.move 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module pyth::event {
  2. use std::event::{Self, EventHandle};
  3. use pyth::price_feed::{PriceFeed};
  4. use std::account;
  5. friend pyth::pyth;
  6. /// Signifies that a price feed has been updated
  7. struct PriceFeedUpdate has store, drop {
  8. /// Value of the price feed
  9. price_feed: PriceFeed,
  10. /// Timestamp of the update
  11. timestamp: u64,
  12. }
  13. struct PriceFeedUpdateHandle has key, store {
  14. event: EventHandle<PriceFeedUpdate>
  15. }
  16. public(friend) fun init(pyth: &signer) {
  17. move_to(
  18. pyth,
  19. PriceFeedUpdateHandle {
  20. event: account::new_event_handle<PriceFeedUpdate>(pyth)
  21. }
  22. );
  23. }
  24. public(friend) fun emit_price_feed_update(price_feed: PriceFeed, timestamp: u64) acquires PriceFeedUpdateHandle {
  25. let event_handle = borrow_global_mut<PriceFeedUpdateHandle>(@pyth);
  26. event::emit_event<PriceFeedUpdate>(
  27. &mut event_handle.event,
  28. PriceFeedUpdate {
  29. price_feed,
  30. timestamp,
  31. }
  32. );
  33. }
  34. }