vectis_wallet/interface/
plugin_registry.rs

1use crate::types::{
2    plugin::{
3        Plugin, PluginCodeData, PluginMetadataData, PluginWithVersionResponse, PluginsResponse,
4    },
5    plugin_registry::{RegistryConfigResponse, Subscriber, SubscriptionTier, TierDetails},
6};
7use cosmwasm_std::{Coin, Response, StdError, StdResult};
8use cw2::ContractVersion;
9use sylvia::types::{ExecCtx, QueryCtx};
10use sylvia::{interface, schemars};
11
12pub mod registry_service_trait {
13    use super::*;
14
15    /// The trait for each authenticator contract
16    #[interface]
17    pub trait RegistryServiceTrait {
18        type Error: From<StdError>;
19
20        /// Called by proxy contract to record increase in plugins
21        /// Codehash of the caller is checked
22        #[msg(exec)]
23        fn proxy_install_plugin(
24            &self,
25            ctx: ExecCtx,
26            id: u64,
27            addr: String,
28        ) -> Result<Response, Self::Error>;
29
30        /// Called by proxy contract to remove the plugin in this state and in the proxy state
31        /// Codehash of the caller is checked
32        /// This is called with `auth_remove_plugin`
33        #[msg(exec)]
34        fn proxy_remove_plugins(
35            &self,
36            ctx: ExecCtx,
37            addr: Vec<String>,
38        ) -> Result<Response, Self::Error>;
39
40        /// Called by users to subscribe to a different tier for both upgrade & downgrades
41        #[msg(exec)]
42        fn subscribe(&self, ctx: ExecCtx, tier: SubscriptionTier) -> Result<Response, Self::Error>;
43
44        #[msg(query)]
45        fn subsciption_details(
46            &self,
47            ctx: QueryCtx,
48            addr: String,
49        ) -> Result<Option<Subscriber>, StdError>;
50    }
51}
52
53pub mod registry_management_trait {
54    use super::*;
55
56    /// The trait for each authenticator contract
57    #[interface]
58    pub trait RegistryManagementTrait {
59        type Error: From<StdError>;
60
61        #[msg(exec)]
62        fn register_plugin(
63            &self,
64            ctx: ExecCtx,
65            code_data: PluginCodeData,
66            metadata_data: PluginMetadataData,
67        ) -> Result<Response, Self::Error>;
68
69        #[msg(exec)]
70        fn unregister_plugin(&self, ctx: ExecCtx, id: u64) -> Result<Response, Self::Error>;
71
72        #[msg(exec)]
73        fn new_plugin_version(
74            &self,
75            ctx: ExecCtx,
76            /// The id on the vectis plugin registry
77            id: u64,
78            /// Code update must pump latest_contract_version
79            code_update: Option<PluginCodeData>,
80            /// Metadata update will not require code version pump
81            metadata_update: PluginMetadataData,
82        ) -> Result<Response, Self::Error>;
83
84        #[msg(exec)]
85        fn update_registry_fee(&self, ctx: ExecCtx, new_fee: Coin)
86            -> Result<Response, Self::Error>;
87
88        /// Adding new tiers
89        /// To remove tier there may already be subscribers and so it will require a migration
90        /// function
91        #[msg(exec)]
92        fn add_or_update_subscription_tiers(
93            &self,
94            ctx: ExecCtx,
95            tier: u8,
96            details: TierDetails,
97        ) -> Result<Response, Self::Error>;
98
99        #[msg(query)]
100        fn get_plugins(
101            &self,
102            ctx: QueryCtx,
103            limit: Option<u32>,
104            start_after: Option<u32>,
105        ) -> StdResult<PluginsResponse>;
106
107        #[msg(query)]
108        fn get_plugin_by_id(&self, ctx: QueryCtx, id: u64) -> StdResult<Option<Plugin>>;
109
110        /// This helps to do all the neccessary queries to allow caller to know the ipfs_hash
111        #[msg(query)]
112        fn get_plugin_by_address(
113            &self,
114            ctx: QueryCtx,
115            contract_addr: String,
116        ) -> StdResult<PluginWithVersionResponse>;
117
118        #[msg(query)]
119        fn get_config(&self, ctx: QueryCtx) -> StdResult<RegistryConfigResponse>;
120
121        #[msg(query)]
122        fn contract_version(&self, ctx: QueryCtx) -> Result<ContractVersion, StdError>;
123    }
124}