Skip to content

feat: Support duplicated exec generic params #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/contracts/generic_contract/src/bin/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {

write_api! {
instantiate: InstantiateMsg<SvCustomMsg>,
execute: ContractExecMsg<SvCustomMsg>,
execute: ContractExecMsg<SvCustomMsg, SvCustomMsg, SvCustomMsg>,
query: ContractQueryMsg<SvCustomMsg>,
}
}
62 changes: 49 additions & 13 deletions examples/contracts/generic_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,32 @@ use sylvia::{contract, schemars};
#[cfg(not(feature = "library"))]
use sylvia::entry_points;

pub struct GenericContract<InstantiateT, ExecT, QueryT, MigrateT, FieldT> {
pub struct GenericContract<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT> {
_field: Item<'static, FieldT>,
_phantom: std::marker::PhantomData<(InstantiateT, ExecT, QueryT, MigrateT)>,
_phantom: std::marker::PhantomData<(
InstantiateT,
Exec1T,
Exec2T,
Exec3T,
QueryT,
MigrateT,
FieldT,
)>,
}

#[cfg_attr(not(feature = "library"), entry_points(generics<SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, String>))]
#[cfg_attr(not(feature = "library"), entry_points(generics<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, String>))]
#[contract]
#[messages(cw1 as Cw1: custom(msg, query))]
#[messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg,SvCustomMsg, SvCustomQuery, sylvia::types::SvCustomMsg> as CustomAndGeneric)]
#[messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg,SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
impl<InstantiateT, ExecT, QueryT, MigrateT, FieldT>
GenericContract<InstantiateT, ExecT, QueryT, MigrateT, FieldT>
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
GenericContract<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
where
for<'msg_de> InstantiateT: CustomMsg + Deserialize<'msg_de> + 'msg_de,
ExecT: CustomMsg + DeserializeOwned + 'static,
Exec1T: CustomMsg + DeserializeOwned + 'static,
Exec2T: CustomMsg + DeserializeOwned + 'static,
Exec3T: CustomMsg + DeserializeOwned + 'static,
QueryT: CustomMsg + DeserializeOwned + 'static,
MigrateT: CustomMsg + DeserializeOwned + 'static,
FieldT: 'static,
Expand All @@ -47,10 +57,21 @@ where
}

#[msg(exec)]
pub fn contract_execute(
pub fn contract_execute_one(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msg: ExecT,
_msg1: Exec1T,
_msg2: Exec2T,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}

#[msg(exec)]
pub fn contract_execute_two(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msg1: Exec2T,
_msg2: Exec3T,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}
Expand Down Expand Up @@ -89,8 +110,16 @@ mod tests {
#[test]
fn generic_contract() {
let app = App::<cw_multi_test::BasicApp<SvCustomMsg, SvCustomQuery>>::custom(|_, _, _| {});
let code_id: CodeId<SvCustomMsg, SvCustomMsg, SvCustomMsg, super::SvCustomMsg, String, _> =
CodeId::store_code(&app);
let code_id: CodeId<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
super::SvCustomMsg,
String,
_,
> = CodeId::store_code(&app);

let owner = "owner";

Expand All @@ -101,7 +130,14 @@ mod tests {
.call(owner)
.unwrap();

contract.contract_execute(SvCustomMsg).call(owner).unwrap();
contract
.contract_execute_one(SvCustomMsg, SvCustomMsg)
.call(owner)
.unwrap();
contract
.contract_execute_two(SvCustomMsg, SvCustomMsg)
.call(owner)
.unwrap();
contract.contract_query(SvCustomMsg).unwrap();
contract
.migrate(SvCustomMsg)
Expand Down
41 changes: 36 additions & 5 deletions examples/contracts/generic_contract/src/custom_and_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,44 @@ use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg, SvCustomQuery};
#[contract(module = crate::contract)]
#[messages(custom_and_generic as CustomAndGeneric)]
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
impl<InstantiateT, ExecT, QueryT, MigrateT, FieldT>
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
CustomAndGeneric<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
sylvia::types::SvCustomMsg,
sylvia::types::SvCustomQuery,
> for crate::contract::GenericContract<InstantiateT, ExecT, QueryT, MigrateT, FieldT>
>
for crate::contract::GenericContract<
InstantiateT,
Exec1T,
Exec2T,
Exec3T,
QueryT,
MigrateT,
FieldT,
>
{
type Error = StdError;

#[msg(exec)]
fn custom_generic_execute(
fn custom_generic_execute_one(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}

#[msg(exec)]
fn custom_generic_execute_two(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}
Expand Down Expand Up @@ -49,6 +71,8 @@ mod tests {
fn proxy_methods() {
let app = App::<cw_multi_test::BasicApp<SvCustomMsg, SvCustomQuery>>::custom(|_, _, _| {});
let code_id = CodeId::<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
sylvia::types::SvCustomMsg,
SvCustomMsg,
Expand All @@ -66,7 +90,14 @@ mod tests {
.call(owner)
.unwrap();

contract.custom_generic_execute(vec![]).call(owner).unwrap();
contract
.custom_generic_execute_one(vec![], vec![])
.call(owner)
.unwrap();
contract
.custom_generic_execute_two(vec![], vec![])
.call(owner)
.unwrap();
contract.custom_generic_query(SvCustomMsg {}).unwrap();
}
}
14 changes: 12 additions & 2 deletions examples/contracts/generic_contract/src/cw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ use sylvia::types::{ExecCtx, QueryCtx};
#[contract(module = crate::contract)]
#[messages(cw1 as Cw1)]
#[sv::custom(msg=sylvia::types::SvCustomMsg, query=sylvia::types::SvCustomQuery)]
impl<InstantiateT, ExecT, QueryT, MigrateT, FieldT> Cw1
for crate::contract::GenericContract<InstantiateT, ExecT, QueryT, MigrateT, FieldT>
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT> Cw1
for crate::contract::GenericContract<
InstantiateT,
Exec1T,
Exec2T,
Exec3T,
QueryT,
MigrateT,
FieldT,
>
{
type Error = StdError;

Expand Down Expand Up @@ -41,6 +49,8 @@ mod tests {
fn proxy_methods() {
let app = App::<cw_multi_test::BasicApp<SvCustomMsg, SvCustomQuery>>::custom(|_, _, _| {});
let code_id = CodeId::<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
sylvia::types::SvCustomMsg,
SvCustomMsg,
Expand Down
52 changes: 45 additions & 7 deletions examples/contracts/generic_contract/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,44 @@ use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg};
#[contract(module = crate::contract)]
#[messages(generic as Generic)]
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
impl<InstantiateT, ExecT, QueryT, MigrateT, FieldT> Generic<SvCustomMsg, SvCustomMsg, SvCustomMsg>
for crate::contract::GenericContract<InstantiateT, ExecT, QueryT, MigrateT, FieldT>
impl<InstantiateT, Exec1T, Exec2T, Exec3T, QueryT, MigrateT, FieldT>
Generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg>
for crate::contract::GenericContract<
InstantiateT,
Exec1T,
Exec2T,
Exec3T,
QueryT,
MigrateT,
FieldT,
>
where
for<'msg_de> InstantiateT: CustomMsg + Deserialize<'msg_de> + 'msg_de,
ExecT: CustomMsg + DeserializeOwned + 'static,
Exec1T: sylvia::types::CustomMsg + 'static,
Exec2T: sylvia::types::CustomMsg + 'static,
Exec3T: sylvia::types::CustomMsg + 'static,
QueryT: CustomMsg + DeserializeOwned + 'static,
MigrateT: CustomMsg + DeserializeOwned + 'static,
FieldT: 'static,
{
type Error = StdError;

#[msg(exec)]
fn generic_exec(
fn generic_exec_one(
&self,
_ctx: ExecCtx,
_msgs: Vec<CosmosMsg<SvCustomMsg>>,
_msgs1: Vec<CosmosMsg<SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<SvCustomMsg>>,
) -> StdResult<Response> {
Ok(Response::new())
}

#[msg(exec)]
fn generic_exec_two(
&self,
_ctx: ExecCtx,
_msgs1: Vec<CosmosMsg<SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<SvCustomMsg>>,
) -> StdResult<Response> {
Ok(Response::new())
}
Expand All @@ -37,7 +59,11 @@ where
// F.e. if we this query would return `SvCustomMsg` and we would pass
// `sylvia::types::SvCustomMsg` to the `Generic` trait paths would not match.
#[msg(query)]
fn generic_query(&self, _ctx: QueryCtx, _msg: SvCustomMsg) -> StdResult<SvCustomMsg> {
fn generic_query(
&self,
_ctx: QueryCtx,
_msg: SvCustomMsg,
) -> StdResult<sylvia::types::SvCustomMsg> {
Ok(SvCustomMsg {})
}
}
Expand All @@ -54,6 +80,8 @@ mod tests {
fn proxy_methods() {
let app = App::<cw_multi_test::BasicApp<SvCustomMsg, SvCustomQuery>>::custom(|_, _, _| {});
let code_id: CodeId<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
sylvia::types::SvCustomMsg,
SvCustomMsg,
Expand All @@ -72,7 +100,17 @@ mod tests {
.unwrap();

contract
.generic_exec(vec![CosmosMsg::Custom(SvCustomMsg {})])
.generic_exec_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();
contract
.generic_exec_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();
contract.generic_query(SvCustomMsg).unwrap();
Expand Down
30 changes: 26 additions & 4 deletions examples/contracts/generic_iface_on_contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub struct NonGenericContract;

#[cfg_attr(not(feature = "library"), entry_points)]
#[contract]
#[messages(generic<SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg,SvCustomMsg, SvCustomQuery, sylvia::types::SvCustomMsg> as CustomAndGeneric)]
#[messages(generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomMsg> as Generic: custom(msg, query))]
#[messages(custom_and_generic<SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, SvCustomMsg, sylvia::types::SvCustomMsg, SvCustomQuery> as CustomAndGeneric)]
#[messages(cw1 as Cw1: custom(msg, query))]
/// Required if interface returns generic `Response`
#[sv::custom(msg=SvCustomMsg, query=SvCustomQuery)]
Expand Down Expand Up @@ -71,7 +71,18 @@ mod tests {
.unwrap();
contract
.generic_proxy()
.generic_exec(vec![CosmosMsg::Custom(SvCustomMsg {})])
.generic_exec_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();
contract
.generic_proxy()
.generic_exec_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();

Expand All @@ -82,7 +93,18 @@ mod tests {
.unwrap();
contract
.custom_and_generic_proxy()
.custom_generic_execute(vec![CosmosMsg::Custom(SvCustomMsg {})])
.custom_generic_execute_one(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();
contract
.custom_and_generic_proxy()
.custom_generic_execute_two(
vec![CosmosMsg::Custom(SvCustomMsg {})],
vec![CosmosMsg::Custom(SvCustomMsg {})],
)
.call(owner)
.unwrap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use sylvia::types::{ExecCtx, QueryCtx, SvCustomMsg, SvCustomQuery};
#[sv::custom(msg=sylvia::types::SvCustomMsg, query=SvCustomQuery)]
impl
CustomAndGeneric<
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
Expand All @@ -18,10 +20,21 @@ impl
type Error = StdError;

#[msg(exec)]
fn custom_generic_execute(
fn custom_generic_execute_one(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}

#[msg(exec)]
fn custom_generic_execute_two(
&self,
_ctx: ExecCtx<SvCustomQuery>,
_msgs: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs1: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
_msgs2: Vec<CosmosMsg<sylvia::types::SvCustomMsg>>,
) -> StdResult<Response<SvCustomMsg>> {
Ok(Response::new())
}
Expand Down
Loading