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: Revert adding Error to ContractApi #454

Merged
merged 1 commit into from
Nov 12, 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
3 changes: 1 addition & 2 deletions sylvia-derive/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ impl<'a> ContractInput<'a> {
item,
generics,
custom,
error,
..
} = self;
let multitest_helpers = self.emit_multitest_helpers();
let messages = self.emit_messages();
let contract_api = Api::new(item, generics, custom, error).emit();
let contract_api = Api::new(item, generics, custom).emit();
let querier = self.emit_querier();
let executor = self.emit_executor();
let reply = self.emit_reply();
Expand Down
14 changes: 2 additions & 12 deletions sylvia-derive/src/contract/communication/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::crate_module;
use crate::parser::variant_descs::AsVariantDescs;
use crate::parser::{ContractErrorAttr, Custom, MsgType};
use crate::parser::{Custom, MsgType};
use crate::types::msg_variant::MsgVariants;
use crate::utils::emit_bracketed_generics;
use proc_macro2::TokenStream;
Expand All @@ -16,16 +16,10 @@ pub struct Api<'a> {
sudo_variants: MsgVariants<'a, GenericParam>,
generics: &'a [&'a GenericParam],
custom: &'a Custom,
error: &'a ContractErrorAttr,
}

impl<'a> Api<'a> {
pub fn new(
source: &'a ItemImpl,
generics: &'a [&'a GenericParam],
custom: &'a Custom,
error: &'a ContractErrorAttr,
) -> Self {
pub fn new(source: &'a ItemImpl, generics: &'a [&'a GenericParam], custom: &'a Custom) -> Self {
let exec_variants = MsgVariants::new(
source.as_variants(),
MsgType::Exec,
Expand Down Expand Up @@ -70,7 +64,6 @@ impl<'a> Api<'a> {
sudo_variants,
generics,
custom,
error,
}
}

Expand All @@ -85,7 +78,6 @@ impl<'a> Api<'a> {
sudo_variants,
generics,
custom,
error,
} = self;

let where_clause = &source.generics.where_clause;
Expand All @@ -110,7 +102,6 @@ impl<'a> Api<'a> {
};
let custom_msg = custom.msg_or_default();
let custom_query = custom.query_or_default();
let error = &error.error;

quote! {
impl #bracket_generics #sylvia ::types::ContractApi for #contract_name #where_clause {
Expand All @@ -126,7 +117,6 @@ impl<'a> Api<'a> {
type Querier<'querier> = #sylvia ::types::BoundQuerier<'querier, #custom_query, Self >;
type CustomMsg = #custom_msg;
type CustomQuery = #custom_query;
type Error = #error;
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions sylvia-derive/src/contract/communication/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Reply<'a> {
source: &'a ItemImpl,
generics: &'a [&'a GenericParam],
reply_data: Vec<ReplyData<'a>>,
error: Type,
}

impl<'a> Reply<'a> {
Expand All @@ -26,11 +27,14 @@ impl<'a> Reply<'a> {
variants: &'a MsgVariants<'a, GenericParam>,
) -> Self {
let reply_data = variants.as_reply_data();
let parsed_attrs = ParsedSylviaAttributes::new(source.attrs.iter());
let error = parsed_attrs.error_attrs.unwrap_or_default().error;

Self {
source,
generics,
reply_data,
error,
}
}

Expand All @@ -56,6 +60,7 @@ impl<'a> Reply<'a> {
source,
generics,
reply_data,
error,
..
} = self;

Expand All @@ -65,9 +70,8 @@ impl<'a> Reply<'a> {

let custom_query = parse_quote!( < #contract as #sylvia ::types::ContractApi>::CustomQuery);
let custom_msg = parse_quote!( < #contract as #sylvia ::types::ContractApi>::CustomMsg);
let error = parse_quote!( < #contract as #sylvia ::types::ContractApi>::Error);
let ctx_params = msg_ty.emit_ctx_params(&custom_query);
let ret_type = msg_ty.emit_result_type(&custom_msg, &error);
let ret_type = msg_ty.emit_result_type(&custom_msg, error);

let match_arms = reply_data
.iter()
Expand Down
1 change: 0 additions & 1 deletion sylvia/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,5 +634,4 @@ pub trait ContractApi {
type Remote<'remote>;
type CustomMsg: CustomMsg;
type CustomQuery: CustomQuery;
type Error: From<cosmwasm_std::StdError>;
}
Loading