Skip to content

Commit

Permalink
feat: Remove #[contract(module=...)] support
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Mar 5, 2024
1 parent b294a36 commit 0e6a870
Show file tree
Hide file tree
Showing 30 changed files with 18 additions and 259 deletions.
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,6 @@ but only one - the one with info about the trait being implemented.

`Sylvia` works with multiple attributes. I will explain here how and when to use which of them.

```rust
#[contract(module=contract_module::inner_module)]
impl Interface for MyContract {
...
}
```

`module` is meant to be used when implementing interface on the contract. Its purpose
is to inform `sylvia` where is the contract defined. If the contract is implemented in the same
scope this attribute can and should be omitted.

```rust
#[entry_point]
Expand Down Expand Up @@ -906,7 +896,6 @@ we can either make the interface to work only with specified message type via
pub trait SomeInterface {
}

#[contract(module=super)]
impl SomeInterface for crate::MyContract {
}
```
Expand All @@ -924,7 +913,6 @@ pub trait AssociatedInterface {
type QueryC: CustomQuery;
}

#[contract(module=super)]
impl AssociatedInterface for crate::MyContract {
type Error = StdError;
type ExecC = MyMsg;
Expand Down Expand Up @@ -1036,8 +1024,6 @@ Rust will force the user to specify the types of the associates during the imple
We can either use some concrete types here or forward the generics defined on contract.

```rust
#[contract(module = crate::contract)]
#[sv::messages(generic as Generic)]
impl<InstantiateParam, ExecParam, FieldType>
Generic
for crate::contract::GenericContract<
Expand Down
5 changes: 0 additions & 5 deletions examples/contracts/custom/src/cw1.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult};
use cw1::{CanExecuteResp, Cw1};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

use crate::contract::CustomContract;

#[contract(module=crate::contract)]
#[sv::messages(cw1 as Cw1)]
impl Cw1 for CustomContract {
type Error = StdError;

#[sv::msg(exec)]
fn execute(&self, _ctx: ExecCtx, _msgs: Vec<CosmosMsg>) -> StdResult<Response> {
Ok(Response::new())
}

#[sv::msg(query)]
fn can_execute(
&self,
_ctx: QueryCtx,
Expand Down
5 changes: 0 additions & 5 deletions examples/contracts/cw1-subkeys/src/cw1.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use cosmwasm_std::{ensure, Addr, Response, StdResult};
use cw1::{CanExecuteResp, Cw1};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

use crate::contract::Cw1SubkeysContract;
use crate::error::ContractError;

#[contract(module=crate::contract)]
#[sv::messages(cw1 as Cw1)]
impl Cw1 for Cw1SubkeysContract<'_> {
type Error = ContractError;

#[sv::msg(exec)]
fn execute(
&self,
ctx: ExecCtx,
Expand All @@ -30,7 +26,6 @@ impl Cw1 for Cw1SubkeysContract<'_> {
Ok(res)
}

#[sv::msg(query)]
fn can_execute(
&self,
ctx: QueryCtx,
Expand Down
6 changes: 0 additions & 6 deletions examples/contracts/cw1-subkeys/src/whitelist.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
use cosmwasm_std::{Response, StdResult};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};
use whitelist::responses::AdminListResponse;
use whitelist::Whitelist;

use crate::contract::Cw1SubkeysContract;
use crate::error::ContractError;

#[contract(module=crate::contract)]
#[sv::messages(whitelist as Whitelist)]
impl Whitelist for Cw1SubkeysContract<'_> {
type Error = ContractError;

#[sv::msg(exec)]
fn freeze(&self, ctx: ExecCtx) -> Result<Response, Self::Error> {
self.whitelist.freeze(ctx).map_err(From::from)
}

#[sv::msg(exec)]
fn update_admins(&self, ctx: ExecCtx, admins: Vec<String>) -> Result<Response, Self::Error> {
self.whitelist
.update_admins(ctx, admins)
.map_err(From::from)
}

#[sv::msg(query)]
fn admin_list(&self, ctx: QueryCtx) -> StdResult<AdminListResponse> {
self.whitelist.admin_list(ctx)
}
Expand Down
5 changes: 0 additions & 5 deletions examples/contracts/cw1-whitelist/src/cw1.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use cosmwasm_std::{Addr, CosmosMsg, Response, StdResult};
use cw1::{CanExecuteResp, Cw1};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

use crate::contract::Cw1WhitelistContract;
use crate::error::ContractError;

#[contract(module=crate::contract)]
#[sv::messages(cw1 as Cw1)]
impl Cw1 for Cw1WhitelistContract<'_> {
type Error = ContractError;

#[sv::msg(exec)]
fn execute(&self, ctx: ExecCtx, msgs: Vec<CosmosMsg>) -> Result<Response, ContractError> {
if !self.is_admin(ctx.deps.as_ref(), &ctx.info.sender) {
return Err(ContractError::Unauthorized);
Expand All @@ -23,7 +19,6 @@ impl Cw1 for Cw1WhitelistContract<'_> {
Ok(resp)
}

#[sv::msg(query)]
fn can_execute(
&self,
ctx: QueryCtx,
Expand Down
6 changes: 0 additions & 6 deletions examples/contracts/cw1-whitelist/src/whitelist.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use cosmwasm_std::{Empty, Order, Response, StdResult};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};
use whitelist::responses::AdminListResponse;
use whitelist::Whitelist;

use crate::contract::Cw1WhitelistContract;
use crate::error::ContractError;

#[contract(module=crate::contract)]
#[sv::messages(whitelist as Whitelist)]
impl Whitelist for Cw1WhitelistContract<'_> {
type Error = ContractError;

#[sv::msg(exec)]
fn freeze(&self, ctx: ExecCtx) -> Result<Response, ContractError> {
if !self.is_admin(ctx.deps.as_ref(), &ctx.info.sender) {
return Err(ContractError::Unauthorized);
Expand All @@ -24,7 +20,6 @@ impl Whitelist for Cw1WhitelistContract<'_> {
Ok(resp)
}

#[sv::msg(exec)]
fn update_admins(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -84,7 +79,6 @@ impl Whitelist for Cw1WhitelistContract<'_> {
Ok(resp)
}

#[sv::msg(query)]
fn admin_list(&self, ctx: QueryCtx) -> StdResult<AdminListResponse> {
let admins: Result<_, _> = self
.admins
Expand Down
12 changes: 0 additions & 12 deletions examples/contracts/cw20-base/src/allowances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use cw20_allowances::responses::{
use cw20_allowances::Cw20Allowances;
use cw_storage_plus::{Bound, Bounder};
use cw_utils::Expiration;
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

use crate::contract::Cw20Base;
Expand All @@ -17,14 +16,11 @@ use crate::responses::Cw20ReceiveMsg;
const MAX_LIMIT: u32 = 30;
const DEFAULT_LIMIT: u32 = 10;

#[contract(module=crate::contract)]
#[sv::messages(cw20_allowances as Cw20Allowances)]
impl Cw20Allowances for Cw20Base<'_> {
type Error = ContractError;

/// Allows spender to access an additional amount tokens from the owner's (env.sender) account.
/// If expires is Some(), overwrites current allowance expiration with this one.
#[sv::msg(exec)]
fn increase_allowance(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -69,7 +65,6 @@ impl Cw20Allowances for Cw20Base<'_> {

/// Lowers the spender's access of tokens from the owner's (env.sender) account by amount.
/// If expires is Some(), overwrites current allowance expiration with this one.
#[sv::msg(exec)]
fn decrease_allowance(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -119,7 +114,6 @@ impl Cw20Allowances for Cw20Base<'_> {

/// Transfers amount tokens from owner -> recipient
/// if `env.sender` has sufficient pre-approval.
#[sv::msg(exec)]
fn transfer_from(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -176,7 +170,6 @@ impl Cw20Allowances for Cw20Base<'_> {

/// Sends amount tokens from owner -> contract
/// if `env.sender` has sufficient pre-approval.
#[sv::msg(exec)]
fn send_from(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -231,7 +224,6 @@ impl Cw20Allowances for Cw20Base<'_> {
}

/// Destroys amount of tokens forever
#[sv::msg(exec)]
fn burn_from(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -273,7 +265,6 @@ impl Cw20Allowances for Cw20Base<'_> {
}

/// Returns how much spender can use from owner account, 0 if unset.
#[sv::msg(query)]
fn allowance(
&self,
ctx: QueryCtx,
Expand All @@ -290,7 +281,6 @@ impl Cw20Allowances for Cw20Base<'_> {
}

/// Returns all allowances this owner has approved. Supports pagination.
#[sv::msg(query)]
fn all_allowances(
&self,
ctx: QueryCtx,
Expand Down Expand Up @@ -319,7 +309,6 @@ impl Cw20Allowances for Cw20Base<'_> {
}

/// Returns all allowances this spender has been granted. Supports pagination.
#[sv::msg(query)]
fn all_spender_allowances(
&self,
ctx: QueryCtx,
Expand Down Expand Up @@ -349,7 +338,6 @@ impl Cw20Allowances for Cw20Base<'_> {
}

/// Returns all allowances this spender has been granted. Supports pagination.
#[sv::msg(query)]
fn all_accounts(
&self,
ctx: QueryCtx,
Expand Down
7 changes: 0 additions & 7 deletions examples/contracts/cw20-base/src/marketing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ use crate::validation::verify_logo;
use cosmwasm_std::{Response, StdError, StdResult};
use cw20_marketing::responses::{DownloadLogoResponse, LogoInfo, MarketingInfoResponse};
use cw20_marketing::{Cw20Marketing, EmbeddedLogo, Logo};
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

#[contract(module=crate::contract)]
#[sv::messages(cw20_marketing as Cw20Marketing)]
impl Cw20Marketing for Cw20Base<'_> {
type Error = ContractError;

#[sv::msg(exec)]
fn update_marketing(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -69,7 +65,6 @@ impl Cw20Marketing for Cw20Base<'_> {
Ok(res)
}

#[sv::msg(exec)]
fn upload_logo(&self, ctx: ExecCtx, logo: Logo) -> Result<Response, Self::Error> {
let mut marketing_info = self
.marketing_info
Expand Down Expand Up @@ -102,15 +97,13 @@ impl Cw20Marketing for Cw20Base<'_> {
Ok(res)
}

#[sv::msg(query)]
fn marketing_info(&self, ctx: QueryCtx) -> StdResult<MarketingInfoResponse> {
Ok(self
.marketing_info
.may_load(ctx.deps.storage)?
.unwrap_or_default())
}

#[sv::msg(query)]
fn download_logo(&self, ctx: QueryCtx) -> StdResult<DownloadLogoResponse> {
let logo = self.logo.load(ctx.deps.storage)?;
match logo {
Expand Down
6 changes: 0 additions & 6 deletions examples/contracts/cw20-base/src/minting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ use crate::error::ContractError;
use cosmwasm_std::{Response, StdResult, Uint128};
use cw20_minting::responses::MinterResponse;
use cw20_minting::Cw20Minting;
use sylvia::contract;
use sylvia::types::{ExecCtx, QueryCtx};

#[contract(module=crate::contract)]
#[sv::messages(cw20_minting as Cw20Minting)]
impl Cw20Minting for Cw20Base<'_> {
type Error = ContractError;

#[sv::msg(exec)]
fn mint(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -61,7 +57,6 @@ impl Cw20Minting for Cw20Base<'_> {
Ok(res)
}

#[sv::msg(exec)]
fn update_minter(
&self,
ctx: ExecCtx,
Expand Down Expand Up @@ -101,7 +96,6 @@ impl Cw20Minting for Cw20Base<'_> {
Ok(resp)
}

#[sv::msg(query)]
fn minter(&self, ctx: QueryCtx) -> StdResult<Option<MinterResponse>> {
let meta = self.token_info.load(ctx.deps.storage)?;
let minter = match meta.mint {
Expand Down
4 changes: 0 additions & 4 deletions examples/contracts/cw20-base/src/multitest/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ pub trait Receiver {
pub mod impl_receiver {
use crate::multitest::receiver_contract::ReceiverContract;
use cosmwasm_std::{Response, StdError};
use sylvia::contract;
use sylvia::types::ExecCtx;

#[contract(module=crate::multitest::receiver_contract)]
#[sv::messages(crate::multitest::receiver as Receiver)]
impl super::Receiver for ReceiverContract {
type Error = StdError;

#[sv::msg(exec)]
fn receive(
&self,
_ctx: ExecCtx,
Expand Down
Loading

0 comments on commit 0e6a870

Please sign in to comment.