state.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. use schemars::JsonSchema;
  2. use serde::{
  3. Deserialize,
  4. Serialize,
  5. };
  6. use cosmwasm_std::{
  7. StdResult,
  8. Storage,
  9. };
  10. use cosmwasm_storage::{
  11. bucket,
  12. bucket_read,
  13. singleton,
  14. singleton_read,
  15. Bucket,
  16. ReadonlyBucket,
  17. ReadonlySingleton,
  18. Singleton,
  19. };
  20. use wormhole::byte_utils::ByteUtils;
  21. type HumanAddr = String;
  22. pub static CONFIG_KEY: &[u8] = b"config";
  23. pub static PRICE_INFO_KEY: &[u8] = b"price_info";
  24. pub static SEQUENCE_KEY: &[u8] = b"sequence";
  25. // Guardian set information
  26. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
  27. pub struct ConfigInfo {
  28. pub wormhole_contract: HumanAddr,
  29. pub pyth_emitter: Vec<u8>,
  30. pub pyth_emitter_chain: u16,
  31. }
  32. pub fn config(storage: &mut dyn Storage) -> Singleton<ConfigInfo> {
  33. singleton(storage, CONFIG_KEY)
  34. }
  35. pub fn config_read(storage: &dyn Storage) -> ReadonlySingleton<ConfigInfo> {
  36. singleton_read(storage, CONFIG_KEY)
  37. }
  38. pub fn sequence(storage: &mut dyn Storage) -> Singleton<u64> {
  39. singleton(storage, SEQUENCE_KEY)
  40. }
  41. pub fn sequence_read(storage: &dyn Storage) -> ReadonlySingleton<u64> {
  42. singleton_read(storage, SEQUENCE_KEY)
  43. }
  44. pub fn price_info(storage: &mut dyn Storage) -> Bucket<Vec<u8>> {
  45. bucket(storage, PRICE_INFO_KEY)
  46. }
  47. pub fn price_info_read(storage: &dyn Storage) -> ReadonlyBucket<Vec<u8>> {
  48. bucket_read(storage, PRICE_INFO_KEY)
  49. }
  50. pub struct UpgradeContract {
  51. pub new_contract: u64,
  52. }
  53. impl UpgradeContract {
  54. pub fn deserialize(data: &Vec<u8>) -> StdResult<Self> {
  55. let data = data.as_slice();
  56. let new_contract = data.get_u64(24);
  57. Ok(UpgradeContract { new_contract })
  58. }
  59. }