From b3538abda31b0da72c389681ce25d977932b92d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wo=C5=BAniak?= Date: Tue, 12 Nov 2024 10:01:46 +0100 Subject: [PATCH] feat: Revert adding Error to ContractApi This was potentially a breaking change --- sylvia-derive/src/contract.rs | 3 +-- sylvia-derive/src/contract/communication/api.rs | 14 ++------------ sylvia-derive/src/contract/communication/reply.rs | 8 ++++++-- sylvia/src/types.rs | 1 - 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/sylvia-derive/src/contract.rs b/sylvia-derive/src/contract.rs index f2571c76..91b66bec 100644 --- a/sylvia-derive/src/contract.rs +++ b/sylvia-derive/src/contract.rs @@ -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(); diff --git a/sylvia-derive/src/contract/communication/api.rs b/sylvia-derive/src/contract/communication/api.rs index 22fb13d6..92313ce5 100644 --- a/sylvia-derive/src/contract/communication/api.rs +++ b/sylvia-derive/src/contract/communication/api.rs @@ -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; @@ -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, @@ -70,7 +64,6 @@ impl<'a> Api<'a> { sudo_variants, generics, custom, - error, } } @@ -85,7 +78,6 @@ impl<'a> Api<'a> { sudo_variants, generics, custom, - error, } = self; let where_clause = &source.generics.where_clause; @@ -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 { @@ -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; } } } diff --git a/sylvia-derive/src/contract/communication/reply.rs b/sylvia-derive/src/contract/communication/reply.rs index ee8a190c..cf0c525c 100644 --- a/sylvia-derive/src/contract/communication/reply.rs +++ b/sylvia-derive/src/contract/communication/reply.rs @@ -17,6 +17,7 @@ pub struct Reply<'a> { source: &'a ItemImpl, generics: &'a [&'a GenericParam], reply_data: Vec>, + error: Type, } impl<'a> Reply<'a> { @@ -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, } } @@ -56,6 +60,7 @@ impl<'a> Reply<'a> { source, generics, reply_data, + error, .. } = self; @@ -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() diff --git a/sylvia/src/types.rs b/sylvia/src/types.rs index 6412a8c5..3dd4b014 100644 --- a/sylvia/src/types.rs +++ b/sylvia/src/types.rs @@ -634,5 +634,4 @@ pub trait ContractApi { type Remote<'remote>; type CustomMsg: CustomMsg; type CustomQuery: CustomQuery; - type Error: From; }