Skip to content

Commit

Permalink
feat: Remove support for , custom(msg=.. ,query=..) in entry_points
Browse files Browse the repository at this point in the history
macro
  • Loading branch information
jawoznia committed Jul 25, 2024
1 parent d378b56 commit d4c94ca
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 91 deletions.
10 changes: 5 additions & 5 deletions examples/contracts/cw1-subkeys/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
const MAX_LIMIT: u32 = 30;
const DEFAULT_LIMIT: u32 = 10;

pub struct Cw1SubkeysContract<'a> {
pub(crate) whitelist: Cw1WhitelistContract<'a>,
pub(crate) permissions: Map<&'a Addr, Permissions>,
pub(crate) allowances: Map<&'a Addr, Allowance>,
pub struct Cw1SubkeysContract {
pub(crate) whitelist: Cw1WhitelistContract,
pub(crate) permissions: Map<&'static Addr, Permissions>,
pub(crate) allowances: Map<&'static Addr, Allowance>,
}

#[cfg_attr(not(feature = "library"), entry_points)]
#[contract]
#[sv::error(ContractError)]
#[sv::messages(cw1 as Cw1)]
#[sv::messages(whitelist as Whitelist)]
impl<'abcd> Cw1SubkeysContract<'abcd> {
impl Cw1SubkeysContract {
pub const fn new() -> Self {
Self {
whitelist: Cw1WhitelistContract::new(),
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw1-subkeys/src/cw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sylvia::types::{ExecCtx, QueryCtx};
use crate::contract::Cw1SubkeysContract;
use crate::error::ContractError;

impl Cw1 for Cw1SubkeysContract<'_> {
impl Cw1 for Cw1SubkeysContract {
type Error = ContractError;

fn execute(
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw1-subkeys/src/whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use whitelist::Whitelist;
use crate::contract::Cw1SubkeysContract;
use crate::error::ContractError;

impl Whitelist for Cw1SubkeysContract<'_> {
impl Whitelist for Cw1SubkeysContract {
type Error = ContractError;

fn freeze(&self, ctx: ExecCtx) -> Result<Response, Self::Error> {
Expand Down
6 changes: 3 additions & 3 deletions examples/contracts/cw1-whitelist/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use sylvia::entry_points;
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

pub struct Cw1WhitelistContract<'a> {
pub(crate) admins: Map<&'a Addr, Empty>,
pub struct Cw1WhitelistContract {
pub(crate) admins: Map<&'static Addr, Empty>,
pub(crate) mutable: Item<bool>,
}

Expand All @@ -22,7 +22,7 @@ pub struct Cw1WhitelistContract<'a> {
#[sv::error(ContractError)]
#[sv::messages(cw1 as Cw1)]
#[sv::messages(whitelist as Whitelist)]
impl<'a> Cw1WhitelistContract<'a> {
impl Cw1WhitelistContract {
pub const fn new() -> Self {
Self {
admins: Map::new("admins"),
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw1-whitelist/src/cw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sylvia::types::{ExecCtx, QueryCtx};
use crate::contract::Cw1WhitelistContract;
use crate::error::ContractError;

impl Cw1 for Cw1WhitelistContract<'_> {
impl Cw1 for Cw1WhitelistContract {
type Error = ContractError;

fn execute(&self, ctx: ExecCtx, msgs: Vec<CosmosMsg>) -> Result<Response, ContractError> {
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw1-whitelist/src/whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use whitelist::Whitelist;
use crate::contract::Cw1WhitelistContract;
use crate::error::ContractError;

impl Whitelist for Cw1WhitelistContract<'_> {
impl Whitelist for Cw1WhitelistContract {
type Error = ContractError;

fn freeze(&self, ctx: ExecCtx) -> Result<Response, ContractError> {
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw20-base/src/allowances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::responses::Cw20ReceiveMsg;
const MAX_LIMIT: u32 = 30;
const DEFAULT_LIMIT: u32 = 10;

impl Cw20Allowances for Cw20Base<'_> {
impl Cw20Allowances for Cw20Base {
type Error = ContractError;

/// Allows spender to access an additional amount tokens from the owner's (env.sender) account.
Expand Down
10 changes: 5 additions & 5 deletions examples/contracts/cw20-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ pub struct InstantiateMsgData {
pub marketing: Option<InstantiateMarketingInfo>,
}

pub struct Cw20Base<'a> {
pub struct Cw20Base {
pub(crate) token_info: Item<TokenInfo>,
pub(crate) marketing_info: Item<MarketingInfoResponse>,
pub(crate) logo: Item<Logo>,
pub(crate) balances: Map<&'a Addr, Uint128>,
pub(crate) allowances: Map<(&'a Addr, &'a Addr), AllowanceResponse>,
pub(crate) balances: Map<&'static Addr, Uint128>,
pub(crate) allowances: Map<(&'static Addr, &'static Addr), AllowanceResponse>,
// TODO: After https://github.com/CosmWasm/cw-plus/issues/670 is implemented, replace this with a `MultiIndex` over `ALLOWANCES`
pub(crate) allowances_spender: Map<(&'a Addr, &'a Addr), AllowanceResponse>,
pub(crate) allowances_spender: Map<(&'static Addr, &'static Addr), AllowanceResponse>,
}

#[cfg_attr(not(feature = "library"), entry_points)]
Expand All @@ -78,7 +78,7 @@ pub struct Cw20Base<'a> {
#[sv::messages(cw20_allowances as Allowances)]
#[sv::messages(cw20_marketing as Marketing)]
#[sv::messages(cw20_minting as Minting)]
impl<'abcd> Cw20Base<'abcd> {
impl Cw20Base {
pub const fn new() -> Self {
Self {
token_info: Item::new("token_info"),
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw20-base/src/marketing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cw20_marketing::responses::{DownloadLogoResponse, LogoInfo, MarketingInfoRes
use cw20_marketing::{Cw20Marketing, EmbeddedLogo, Logo};
use sylvia::types::{ExecCtx, QueryCtx};

impl Cw20Marketing for Cw20Base<'_> {
impl Cw20Marketing for Cw20Base {
type Error = ContractError;

fn update_marketing(
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw20-base/src/minting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cw20_minting::responses::MinterResponse;
use cw20_minting::Cw20Minting;
use sylvia::types::{ExecCtx, QueryCtx};

impl Cw20Minting for Cw20Base<'_> {
impl Cw20Minting for Cw20Base {
type Error = ContractError;

fn mint(
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/generics_forwarded/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct GenericsForwardedContract<
)>,
}

#[cfg_attr(not(feature = "library"), sylvia::entry_points(generics<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomQuery, String>, custom(msg=SvCustomMsg, query=SvCustomQuery)))]
#[cfg_attr(not(feature = "library"), sylvia::entry_points(generics<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomQuery, String>))]
#[contract]
#[sv::error(ContractError)]
#[sv::messages(generic as Generic: custom(msg, query))]
Expand Down
20 changes: 10 additions & 10 deletions sylvia-derive/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,6 @@ pub struct EntryPoints<'a> {
source: &'a ItemImpl,
name: Type,
error: Type,
custom: Custom,
override_entry_points: Vec<OverrideEntryPoint>,
generics: Vec<&'a GenericParam>,
where_clause: &'a Option<WhereClause>,
Expand All @@ -1313,13 +1312,11 @@ impl<'a> EntryPoints<'a> {

let generics: Vec<_> = source.generics.params.iter().collect();
let where_clause = &source.generics.where_clause;
let custom = parsed_attrs.custom_attr.unwrap_or_default();

Self {
source,
name,
error,
custom,
override_entry_points,
generics,
where_clause,
Expand All @@ -1332,21 +1329,24 @@ impl<'a> EntryPoints<'a> {
source,
name,
error,
custom,
override_entry_points,
generics,
where_clause,
attrs,
} = self;
let sylvia = crate_module();

let custom = match &attrs.custom {
Some(custom) => custom,
None => custom,
};
let bracketed_generics = attrs
.generics
.as_ref()
.map(|generics| match generics.is_empty() {
true => quote! {},
false => quote! { < #generics > },
})
.unwrap_or(quote! {});

let custom_msg = custom.msg_or_default();
let custom_query = custom.query_or_default();
let custom_msg = parse_quote! { < #name #bracketed_generics as #sylvia ::types::ContractApi > :: CustomMsg };
let custom_query = parse_quote! { < #name #bracketed_generics as #sylvia ::types::ContractApi > :: CustomQuery };

let instantiate_variants = MsgVariants::new(
source.as_variants(),
Expand Down
26 changes: 2 additions & 24 deletions sylvia-derive/src/parser/entry_point.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use syn::parse::{Error, Nothing, Parse, ParseStream, Parser};
use syn::parse::{Error, Nothing, Parse, ParseStream};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{parenthesized, GenericArgument, Path, Result, Token};
use syn::{GenericArgument, Path, Result, Token};

use super::attributes::custom::Custom;
use super::extract_generics_from_path;

/// Parsed arguments for `entry_points` macro
#[derive(Default)]
pub struct EntryPointArgs {
/// Types used in place of contracts generics.
pub generics: Option<Punctuated<GenericArgument, Token![,]>>,
/// Concrete custom msg/query used in place of contracts generic ones.
pub custom: Option<Custom>,
}

impl Parse for EntryPointArgs {
Expand All @@ -30,25 +27,6 @@ impl Parse for EntryPointArgs {
_ => return Err(Error::new(generics.span(), "Expected `generics`.")),
};

let comma: Option<Token![,]> = input.parse().ok();
if comma.is_none() {
return Ok(entry_points_args);
}

let custom: Option<Path> = input.parse().ok();
match custom {
Some(custom)
if custom.get_ident().map(|custom| custom.to_string())
== Some("custom".to_owned()) =>
{
let content;
parenthesized!(content in input);
entry_points_args.custom = Some(Custom::parse.parse2(content.parse()?)?);
}
Some(attr) => return Err(Error::new(attr.span(), "Expected `custom`.")),
_ => (),
};

let _: Nothing = input.parse()?;

Ok(entry_points_args)
Expand Down
3 changes: 0 additions & 3 deletions sylvia/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ pub trait InterfaceApi {

/// Api trait for easier access to generated types and messages.
pub trait ContractApi {
// Messages
type Instantiate;
type Query;
type Exec;
Expand All @@ -581,10 +580,8 @@ pub trait ContractApi {
type ContractSudo;
type Migrate;
type Sudo;
// Communication
type Querier<'querier>;
type Remote<'remote>;
// Customs
type CustomMsg: CustomMsg;
type CustomQuery: CustomQuery;
}
2 changes: 2 additions & 0 deletions sylvia/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use sylvia::types::{
use sylvia_derive::contract;

pub struct SomeContract<Instantiate, Query, Exec, Migrate, Sudo, Ret, CMsg, CQuery> {
#[allow(clippy::complexity)]
_phantom: PhantomData<(Instantiate, Query, Exec, Migrate, Sudo, Ret, CMsg, CQuery)>,
}

#[allow(dead_code)]
#[contract]
#[sv::custom(msg=CMsg, query=CQuery)]
impl<Instantiate, Query, Exec, Migrate, Sudo, Ret, CMsg, CQuery>
Expand Down
3 changes: 2 additions & 1 deletion sylvia/tests/custom_msg.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cosmwasm_std::{CustomMsg, Response, StdResult};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sylvia::contract;
use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, SudoCtx};
use sylvia::{contract, entry_points};

#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, JsonSchema)]
pub struct MyMsg;
Expand Down Expand Up @@ -201,6 +201,7 @@ mod impl_associated_interface {
}
}

#[entry_points]
#[contract]
#[sv::messages(some_interface)]
#[sv::messages(other_interface: custom(msg))]
Expand Down
3 changes: 2 additions & 1 deletion sylvia/tests/custom_query.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{CustomQuery, Response, StdResult};
use sylvia::contract;
use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, SudoCtx};
use sylvia::{contract, entry_points};

#[cw_serde]
pub struct MyQuery;
Expand Down Expand Up @@ -206,6 +206,7 @@ mod impl_default_query_interface {
}
}

#[entry_points]
#[contract]
#[sv::messages(some_interface)]
#[sv::messages(associated_type_interface)]
Expand Down
3 changes: 2 additions & 1 deletion sylvia/tests/entry_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ pub mod entry_points {
mod contract {
use cosmwasm_std::{Response, StdError, StdResult};
use cw_storage_plus::Item;
use sylvia::contract;
use sylvia::types::{ExecCtx, InstantiateCtx, MigrateCtx, QueryCtx, SudoCtx};
use sylvia::{contract, entry_points};

use crate::CountResponse;

Expand All @@ -146,6 +146,7 @@ mod contract {
pub(crate) migrates: Item<u32>,
}

#[entry_points]
#[contract]
#[sv::override_entry_point(sudo=crate::entry_points::sudo(crate::sudo::SudoWrapperMsg))]
#[sv::override_entry_point(migrate=crate::entry_points::migrate(crate::migrate::MigrateMsg))]
Expand Down
13 changes: 7 additions & 6 deletions sylvia/tests/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use cosmwasm_std::{Addr, Response, StdResult};
use cw_storage_plus::Item;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sylvia::contract;
use sylvia::types::InstantiateCtx;
use sylvia::{contract, entry_points};

#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug, Default)]
pub struct CountResponse {
Expand Down Expand Up @@ -38,7 +38,7 @@ use counter::Counter;
use sv::Executor as ContractExecutor;
use sylvia::types::{ExecCtx, QueryCtx};

impl Counter for CounterContract<'_> {
impl Counter for CounterContract {
type Error = StdError;

fn count(&self, ctx: QueryCtx) -> StdResult<CountResponse> {
Expand All @@ -56,15 +56,16 @@ impl Counter for CounterContract<'_> {
}
}

pub struct CounterContract<'a> {
pub struct CounterContract {
pub count: Item<u64>,
pub remote_contract: Item<sylvia::types::Remote<'a, CounterContract<'a>>>,
pub remote_interface: Item<sylvia::types::Remote<'a, dyn Counter<Error = StdError>>>,
pub remote_contract: Item<sylvia::types::Remote<'static, CounterContract>>,
pub remote_interface: Item<sylvia::types::Remote<'static, dyn Counter<Error = StdError>>>,
}

#[entry_points]
#[contract]
#[sv::messages(counter)]
impl<'a> CounterContract<'a> {
impl CounterContract {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {
Expand Down
3 changes: 2 additions & 1 deletion sylvia/tests/interface_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{Response, StdError, StdResult};
use sylvia::contract;
use sylvia::types::{ExecCtx, InstantiateCtx, QueryCtx, SudoCtx};
use sylvia::{contract, entry_points};

mod interface1 {
use cosmwasm_std::{Response, StdError, StdResult};
Expand Down Expand Up @@ -46,6 +46,7 @@ mod interface2 {

pub struct Contract;

#[entry_points]
#[contract]
#[sv::messages(interface1)]
#[sv::messages(interface2)]
Expand Down
Loading

0 comments on commit d4c94ca

Please sign in to comment.