Skip to content

Commit

Permalink
feat: Cast deps to empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Aug 23, 2023
1 parent 9e42a78 commit eaf5054
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 193 deletions.
44 changes: 13 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/contracts/cw1-subkeys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tests = ["library", "cw-multi-test", "anyhow"]
[dependencies]
anyhow = { version = "1.0.68", optional = true }
cosmwasm-schema = "1.2"
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cw-multi-test = { version = "0.16.2", optional = true }
cw-storage-plus = "1.0"
cw-utils = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/cw1-whitelist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tests = ["library", "cw-multi-test", "anyhow"]
mt = ["sylvia/mt", "library"]

[dependencies]
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cosmwasm-schema = "1.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
Expand Down
4 changes: 2 additions & 2 deletions examples/contracts/cw20-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests = ["library", "cw-multi-test", "anyhow"]
[dependencies]
anyhow = { version = "1.0", optional = true }
cosmwasm-schema = "1.2"
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cw-multi-test = { version = "0.16", optional = true }
cw-storage-plus = "1.0"
cw-utils = "1.0"
Expand All @@ -39,7 +39,7 @@ cw-multi-test = "0.16"
cw-utils = "1.0"
sylvia = { path = "../../../sylvia", features = ["mt"] }
cw20-allowances = { path = "../../interfaces/cw20-allowances", features = [
"mt",
"mt",
] }
cw20-marketing = { path = "../../interfaces/cw20-marketing", features = ["mt"] }
cw20-minting = { path = "../../interfaces/cw20-minting", features = ["mt"] }
2 changes: 1 addition & 1 deletion examples/contracts/entry-points-overriding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests = ["library", "cw-multi-test", "anyhow"]
[dependencies]
anyhow = { version = "1.0", optional = true }
cosmwasm-schema = "1.2"
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cw-multi-test = { version = "0.16", optional = true }
cw-storage-plus = "1.0"
cw-utils = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://cosmwasm.com"
mt = ["sylvia/mt"]

[dependencies]
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cosmwasm-schema = "1.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw20-allowances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://cosmwasm.com"
mt = ["sylvia/mt"]

[dependencies]
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cosmwasm-schema = "1.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw20-marketing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://cosmwasm.com"
mt = ["sylvia/mt"]

[dependencies]
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cosmwasm-schema = "1.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw20-minting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://cosmwasm.com"
mt = ["sylvia/mt"]

[dependencies]
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cosmwasm-schema = "1.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
Expand Down
2 changes: 1 addition & 1 deletion examples/interfaces/cw4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://cosmwasm.com"
mt = ["sylvia/mt"]

[dependencies]
cosmwasm-std = { version = "1.2.1", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cosmwasm-schema = "1.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
sylvia = { path = "../../../sylvia" }
Expand Down
25 changes: 19 additions & 6 deletions sylvia-derive/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,28 @@ impl<'a> GlueMessage<'a> {
let ContractMessageAttr {
variant,
has_custom_msg,
has_custom_query,
..
} = interface;

match *has_custom_msg&& msg_ty == &MsgType::Exec
{
true => quote! { #contract_name :: #variant(msg) => Ok( #sylvia ::into_response::IntoResponse::into_response(msg.dispatch(contract, Into::into(ctx))?)?) },
false => quote! { #contract_name :: #variant(msg) => msg.dispatch(contract, Into::into(ctx)) }
}
let ctx = match (msg_ty, has_custom_query) {
(MsgType::Exec, true )=> quote! {
( ctx.0.into_empty(), ctx.1, ctx.2)
},
(MsgType::Query, true )=> quote! {
( ctx.0.into_empty(), ctx.1)
},
_=> quote! { ctx },
};

match (msg_ty, has_custom_msg) {
(MsgType::Exec, true) => quote! {
#contract_name :: #variant(msg) => #sylvia ::into_response::IntoResponse::into_response(msg.dispatch(contract, Into::into( #ctx ))?)
},
_ => quote! {
#contract_name :: #variant(msg) => msg.dispatch(contract, Into::into( #ctx ))
},
}
});

let dispatch_arm = quote! {#contract_name :: #contract (msg) =>msg.dispatch(contract, ctx)};
Expand Down Expand Up @@ -1042,7 +1055,7 @@ impl<'a> GlueMessage<'a> {
pub fn dispatch(
self,
contract: &#contract,
ctx: #ctx_type,
mut ctx: #ctx_type,
) -> #ret_type {
const _: () = {
let msgs: [&[&str]; #interfaces_cnt] = [#(#interface_names),*];
Expand Down
47 changes: 36 additions & 11 deletions sylvia-derive/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ pub struct ContractMessageAttr {
pub query_generic_params: Vec<Path>,
pub variant: Ident,
pub has_custom_msg: bool,
pub has_custom_query: bool,
}

#[cfg(not(tarpaulin_include))]
Expand All @@ -262,6 +263,35 @@ fn parse_generics(content: &ParseBuffer) -> Result<Vec<Path>> {
Ok(params)
}

fn interface_has_custom(content: ParseStream) -> Result<(bool, bool)> {
let mut has_custom_msg = false;
let mut has_custom_query = false;

let _: Token![:] = content.parse()?;
let attr: Ident = content.parse()?;
if attr != "custom" {
return Ok((has_custom_msg, has_custom_query));
}

let custom_content;
parenthesized!(custom_content in content);

while !custom_content.is_empty() {
let custom = custom_content.parse::<Path>()?;
match custom.get_ident() {
Some(ident) if ident == "msg" => has_custom_msg = true,
Some(ident) if ident == "query" => has_custom_query = true,
_ => {
return Err(Error::new(
custom.span(),
"Invalid custom attribute, expected one of: `msg`, `query`",
))
}
}
}
Ok((has_custom_msg, has_custom_query))
}

#[cfg(not(tarpaulin_include))]
// False negative. It is being called in closure
impl Parse for ContractMessageAttr {
Expand All @@ -274,7 +304,6 @@ impl Parse for ContractMessageAttr {
let generics_open: Option<Token![:]> = content.parse()?;
let mut exec_generic_params = vec![];
let mut query_generic_params = vec![];
let mut has_custom_msg = false;

if generics_open.is_some() {
loop {
Expand All @@ -300,16 +329,11 @@ impl Parse for ContractMessageAttr {
let _: Token![as] = content.parse()?;
let variant = content.parse()?;

if content.peek(Token![:]) {
let _: Token![:] = content.parse()?;
let attr: Ident = content.parse()?;
if attr == "custom" {
let custom_content;
parenthesized!(custom_content in content);
let custom = custom_content.parse::<Path>()?;
has_custom_msg = custom.is_ident("msg");
}
}
let (has_custom_msg, has_custom_query) = if content.peek(Token![:]) {
interface_has_custom(&content)?
} else {
(false, false)
};

if !content.is_empty() {
return Err(Error::new(
Expand All @@ -324,6 +348,7 @@ impl Parse for ContractMessageAttr {
query_generic_params,
variant,
has_custom_msg,
has_custom_query,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion sylvia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ staking = ["cosmwasm-std/staking", "cw-multi-test?/staking"]

[dependencies]
sylvia-derive = { workspace = true }
cosmwasm-std = { version = "1.2", features = ["staking"] }
cosmwasm-std = { version = "1.3", features = ["staking"] }
cosmwasm-schema = "1.2"
schemars = "0.8"
serde = { version = "1.0", default-features = false, features = ["derive"] }
Expand Down
Loading

0 comments on commit eaf5054

Please sign in to comment.