-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from CosmWasm/bound_querier_conversion
Bound querier conversion
- Loading branch information
Showing
6 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use proc_macro2::TokenStream; | ||
use proc_macro_error::emit_error; | ||
use quote::quote; | ||
use syn::parse::{Parse, Parser}; | ||
use syn::spanned::Spanned; | ||
use syn::ItemImpl; | ||
|
||
use crate::crate_module; | ||
use crate::parser::ContractMessageAttr; | ||
|
||
pub struct Interfaces { | ||
interfaces: Vec<ContractMessageAttr>, | ||
} | ||
|
||
impl Interfaces { | ||
pub fn new(source: &ItemImpl) -> Self { | ||
let interfaces: Vec<_> = source | ||
.attrs | ||
.iter() | ||
.filter(|attr| attr.path.is_ident("messages")) | ||
.filter_map(|attr| { | ||
let interface = match ContractMessageAttr::parse.parse2(attr.tokens.clone()) { | ||
Ok(interface) => interface, | ||
Err(err) => { | ||
emit_error!(attr.span(), err); | ||
return None; | ||
} | ||
}; | ||
|
||
Some(interface) | ||
}) | ||
.collect(); | ||
|
||
Self { interfaces } | ||
} | ||
|
||
pub fn emit_querier_from_impl(&self) -> Vec<TokenStream> { | ||
let sylvia = crate_module(); | ||
|
||
self.interfaces | ||
.iter() | ||
.map(|interface| { | ||
let ContractMessageAttr { module, .. } = interface; | ||
quote! { | ||
impl<'a, C: #sylvia ::cw_std::CustomQuery> From<&'a BoundQuerier<'a, C>> for #module ::BoundQuerier<'a, C> { | ||
fn from(querier: &'a BoundQuerier<'a, C>) -> Self { | ||
Self::borrowed(querier.contract(), querier.querier()) | ||
} | ||
} | ||
} | ||
}) | ||
.collect() | ||
} | ||
} |
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