-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Forward generics to custom_generic interface
- Loading branch information
Showing
14 changed files
with
140 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
examples/contracts/generics_forwarded/src/custom_and_generic.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use cosmwasm_std::{CosmosMsg, Response, StdError, StdResult}; | ||
use custom_and_generic::CustomAndGeneric; | ||
use serde::Deserialize; | ||
use sylvia::contract; | ||
use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx, SvCustomMsg}; | ||
|
||
#[contract(module = crate::contract)] | ||
#[messages(custom_and_generic as CustomAndGeneric)] | ||
#[sv::custom(msg=CustomMsgT, query=CustomQueryT)] | ||
impl<InstantiateT, ExecT, QueryT, MigrateT, CustomMsgT, CustomQueryT, FieldT> | ||
CustomAndGeneric<ExecT, QueryT, SvCustomMsg, CustomMsgT, CustomQueryT> | ||
for crate::contract::GenericsForwardedContract< | ||
InstantiateT, | ||
ExecT, | ||
QueryT, | ||
MigrateT, | ||
CustomMsgT, | ||
CustomQueryT, | ||
FieldT, | ||
> | ||
where | ||
for<'msg_de> InstantiateT: cosmwasm_std::CustomMsg + Deserialize<'msg_de> + 'msg_de, | ||
ExecT: CustomMsg + 'static, | ||
QueryT: CustomMsg + 'static, | ||
MigrateT: CustomMsg + 'static, | ||
CustomMsgT: CustomMsg + 'static, | ||
CustomQueryT: CustomQuery + 'static, | ||
FieldT: 'static, | ||
{ | ||
type Error = StdError; | ||
|
||
#[msg(exec)] | ||
fn custom_generic_execute( | ||
&self, | ||
_ctx: ExecCtx<CustomQueryT>, | ||
_msgs: Vec<CosmosMsg<ExecT>>, | ||
) -> StdResult<Response<CustomMsgT>> { | ||
Ok(Response::new()) | ||
} | ||
|
||
#[msg(query)] | ||
fn custom_generic_query( | ||
&self, | ||
_ctx: QueryCtx<CustomQueryT>, | ||
_msg: QueryT, | ||
) -> StdResult<SvCustomMsg> { | ||
Ok(SvCustomMsg {}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::sv::test_utils::CustomAndGeneric; | ||
use crate::contract::sv::multitest_utils::CodeId; | ||
use sylvia::multitest::App; | ||
use sylvia::types::{SvCustomMsg, SvCustomQuery}; | ||
|
||
#[test] | ||
fn proxy_methods() { | ||
let app = App::<cw_multi_test::BasicApp<SvCustomMsg, SvCustomQuery>>::custom(|_, _, _| {}); | ||
let code_id = CodeId::< | ||
SvCustomMsg, | ||
sylvia::types::SvCustomMsg, | ||
SvCustomMsg, | ||
SvCustomMsg, | ||
SvCustomMsg, | ||
SvCustomQuery, | ||
String, | ||
_, | ||
>::store_code(&app); | ||
|
||
let owner = "owner"; | ||
|
||
let contract = code_id | ||
.instantiate(SvCustomMsg {}) | ||
.with_label("GenericContract") | ||
.with_admin(owner) | ||
.call(owner) | ||
.unwrap(); | ||
|
||
contract.custom_generic_execute(vec![]).call(owner).unwrap(); | ||
contract.custom_generic_query(SvCustomMsg {}).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod contract; | ||
pub mod custom_and_generic; | ||
pub mod generic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters