version_control.move 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: Apache 2
  2. /// Note: this module is adapted from Wormhole's version_control.move module.
  3. ///
  4. /// This module implements dynamic field keys as empty structs. These keys are
  5. /// used to determine the latest version for this build. If the current version
  6. /// is not this build's, then paths through the `state` module will abort.
  7. ///
  8. /// See `pyth::state` and `wormhole::package_utils` for more info.
  9. module pyth::version_control {
  10. ////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Hard-coded Version Control
  13. //
  14. // Before upgrading, please set the types for `current_version` and
  15. // `previous_version` to match the correct types (current being the latest
  16. // version reflecting this build).
  17. //
  18. ////////////////////////////////////////////////////////////////////////////
  19. public(friend) fun current_version(): V__0_1_1 {
  20. V__0_1_1 {}
  21. }
  22. public(friend) fun previous_version(): V__DUMMY {
  23. V__DUMMY {}
  24. }
  25. ////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Change Log
  28. //
  29. // Please write release notes as doc strings for each version struct. These
  30. // notes will be our attempt at tracking upgrades. Wish us luck.
  31. //
  32. ////////////////////////////////////////////////////////////////////////////
  33. /// RELEASE NOTES
  34. ///
  35. /// - Refactor state to use package management via
  36. /// `wormhole::package_utils`.
  37. /// - Add `MigrateComplete` event in `migrate`.
  38. ///
  39. /// Also added `migrate__v__0_1_1` in `wormhole::state`, which is
  40. /// meant to perform a one-time `State` modification via `migrate`.
  41. struct V__0_1_1 has store, drop, copy {}
  42. // Dummy.
  43. struct V__DUMMY has store, drop, copy {}
  44. ////////////////////////////////////////////////////////////////////////////
  45. //
  46. // Implementation and Test-Only Methods
  47. //
  48. ////////////////////////////////////////////////////////////////////////////
  49. friend pyth::state;
  50. #[test_only]
  51. public fun dummy(): V__DUMMY {
  52. V__DUMMY {}
  53. }
  54. #[test_only]
  55. struct V__MIGRATED has store, drop, copy {}
  56. #[test_only]
  57. public fun next_version(): V__MIGRATED {
  58. V__MIGRATED {}
  59. }
  60. #[test_only]
  61. public fun previous_version_test_only(): V__DUMMY {
  62. previous_version()
  63. }
  64. }