Skip to content
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

feat: BoundQuerier improve #321

Merged
merged 1 commit into from
Mar 11, 2024
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
27 changes: 15 additions & 12 deletions examples/interfaces/custom-and-generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,21 @@ mod tests {

let querier = sylvia::types::BoundQuerier::<
_,
std::marker::PhantomData<(
Empty,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
)>,
&dyn super::CustomAndGeneric<
RetT = SvCustomMsg,
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
Error = (),
ExecC = (),
QueryC = (),
>,
>::borrowed(&contract, &querier_wrapper);

let _: Result<SvCustomMsg, _> =
Expand Down
25 changes: 13 additions & 12 deletions examples/interfaces/generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,19 @@ mod tests {

let querier = sylvia::types::BoundQuerier::<
Empty,
std::marker::PhantomData<(
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
SvCustomMsg,
)>,
&dyn super::Generic<
Exec1T = SvCustomMsg,
Exec2T = SvCustomMsg,
Exec3T = SvCustomMsg,
Query1T = SvCustomMsg,
Query2T = SvCustomMsg,
Query3T = SvCustomMsg,
Sudo1T = SvCustomMsg,
Sudo2T = SvCustomMsg,
Sudo3T = SvCustomMsg,
RetT = SvCustomMsg,
Error = (),
>,
>::borrowed(&contract, &querier_wrapper);
let _: Result<SvCustomMsg, _> =
super::sv::Querier::generic_query_one(&querier, SvCustomMsg {}, SvCustomMsg {});
Expand Down
6 changes: 5 additions & 1 deletion sylvia-derive/src/associated_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl<'a> AssociatedTypes<'a> {
Self(associated_types)
}

pub fn all_names(&self) -> impl Iterator<Item = &Ident> {
self.0.iter().map(|associated| &associated.ident)
}

pub fn without_error(&self) -> impl Iterator<Item = &TraitItemType> {
self.0
.iter()
Expand Down Expand Up @@ -62,7 +66,7 @@ impl<'a> AssociatedTypes<'a> {
}
}

pub fn as_names(&self) -> impl Iterator<Item = &Ident> {
pub fn as_filtered_names(&self) -> impl Iterator<Item = &Ident> {
self.filtered().map(|associated| &associated.ident)
}

Expand Down
2 changes: 1 addition & 1 deletion sylvia-derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a> TraitInput<'a> {
custom,
} = self;
let messages = self.emit_messages();
let associated_names: Vec<_> = associated_types.as_names().collect();
let associated_names: Vec<_> = associated_types.as_filtered_names().collect();

let query_variants =
MsgVariants::new(item.as_variants(), MsgType::Query, &associated_names, &None);
Expand Down
4 changes: 3 additions & 1 deletion sylvia-derive/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ where
.map(ItemType::as_name)
.collect();

let all_generics: Vec<_> = associated_types.all_names().collect();

let assoc_types: Vec<_> = associated_types
.without_special()
.map(ItemType::as_name)
Expand All @@ -70,7 +72,7 @@ where
#(#methods_declaration)*
}

impl <'a, C: #sylvia ::cw_std::CustomQuery, #(#generics,)*> Querier for #sylvia ::types::BoundQuerier<'a, C, std::marker::PhantomData< (#(#generics,)*) > > #where_clause {
impl <'a, C: #sylvia ::cw_std::CustomQuery, #(#all_generics,)*> Querier for #sylvia ::types::BoundQuerier<'a, C, &dyn #interface_name <#( #all_generics = #all_generics,)*> > #where_clause {
#(type #generics = #generics;)*

#(#methods_trait_impl)*
Expand Down
2 changes: 1 addition & 1 deletion sylvia/tests/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ impl CounterContract<'_> {

#[cfg(test)]
mod tests {
use crate::counter::sv::test_utils::CounterProxy;
use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::{Addr, Empty, QuerierWrapper};
use sylvia::multitest::App;

use crate::counter::sv::test_utils::CounterProxy;
use crate::sv::multitest_utils::CodeId;

#[test]
Expand Down
Loading