Skip to content

Commit

Permalink
chore: Rename variables to be more intuitive
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Sep 19, 2024
1 parent fbffb6a commit 72ebc77
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
24 changes: 15 additions & 9 deletions sylvia-derive/src/contract/communication/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ impl<'a> ReplyData<'a> {
fn emit_match_arms(&self, contract: &Type, generics: &[&GenericParam]) -> TokenStream {
let Self { reply_id, handlers } = self;

let contract_turbo: Type = if !generics.is_empty() {
let contract_turbofish: Type = if !generics.is_empty() {
let contract_name = StripGenerics.fold_type((contract.clone()).clone());
parse_quote! { #contract_name :: < #(#generics),* > }
} else {
parse_quote! { #contract }
};

let success_match_arm = emit_success_match_arm(handlers, &contract_turbo);
let failure_match_arm = emit_failure_match_arm(handlers, &contract_turbo);
let success_match_arm = emit_success_match_arm(handlers, &contract_turbofish);
let failure_match_arm = emit_failure_match_arm(handlers, &contract_turbofish);

quote! {
#reply_id => {
Expand All @@ -185,7 +185,10 @@ impl<'a> ReplyData<'a> {
/// Emits match arm for [ReplyOn::Success].
/// In case neither [ReplyOn::Success] nor [ReplyOn::Always] is present, `Response::events`
/// and `Response::data` are forwarded in the `Response`
fn emit_success_match_arm(handlers: &[(&Ident, ReplyOn)], contract_turbo: &Type) -> TokenStream {
fn emit_success_match_arm(
handlers: &[(&Ident, ReplyOn)],
contract_turbofish: &Type,
) -> TokenStream {
let sylvia = crate_module();

match handlers
Expand All @@ -196,12 +199,12 @@ fn emit_success_match_arm(handlers: &[(&Ident, ReplyOn)], contract_turbo: &Type)
#sylvia ::cw_std::SubMsgResult::Ok(sub_msg_resp) => {
#[allow(deprecated)]
let #sylvia ::cw_std::SubMsgResponse { events, data, msg_responses} = sub_msg_resp;
#contract_turbo ::new(). #function_name ((deps, env, gas_used, events, msg_responses).into(), data, payload)
#contract_turbofish ::new(). #function_name ((deps, env, gas_used, events, msg_responses).into(), data, payload)
}
},
Some((function_name, reply_on)) if reply_on == &ReplyOn::Always => quote! {
#sylvia ::cw_std::SubMsgResult::Ok(_) => {
#contract_turbo ::new(). #function_name ((deps, env, gas_used, vec![], vec![]).into(), result, payload)
#contract_turbofish ::new(). #function_name ((deps, env, gas_used, vec![], vec![]).into(), result, payload)
}
},
_ => quote! {
Expand All @@ -222,7 +225,10 @@ fn emit_success_match_arm(handlers: &[(&Ident, ReplyOn)], contract_turbo: &Type)
/// Emits match arm for [ReplyOn::Failure].
/// In case neither [ReplyOn::Failure] nor [ReplyOn::Always] is present,
/// the error is forwarded.
fn emit_failure_match_arm(handlers: &[(&Ident, ReplyOn)], contract_turbo: &Type) -> TokenStream {
fn emit_failure_match_arm(
handlers: &[(&Ident, ReplyOn)],
contract_turbofish: &Type,
) -> TokenStream {
let sylvia = crate_module();

match handlers
Expand All @@ -231,12 +237,12 @@ fn emit_failure_match_arm(handlers: &[(&Ident, ReplyOn)], contract_turbo: &Type)
{
Some((function_name, reply_on)) if reply_on == &ReplyOn::Failure => quote! {
#sylvia ::cw_std::SubMsgResult::Err(error) => {
#contract_turbo ::new(). #function_name ((deps, env, gas_used, vec![], vec![]).into(), error, payload)
#contract_turbofish ::new(). #function_name ((deps, env, gas_used, vec![], vec![]).into(), error, payload)
}
},
Some((function_name, reply_on)) if reply_on == &ReplyOn::Always => quote! {
#sylvia ::cw_std::SubMsgResult::Err(_) => {
#contract_turbo ::new(). #function_name ((deps, env, gas_used, vec![], vec![]).into(), result, payload)
#contract_turbofish ::new(). #function_name ((deps, env, gas_used, vec![], vec![]).into(), result, payload)
}
},
_ => quote! {
Expand Down
4 changes: 2 additions & 2 deletions sylvia-derive/src/contract/mt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ impl<'a> MtHelpers<'a> {
.as_ref()
.map(|_reply| {
let contract_ident = get_ident_from_type(contract_name);
let contract_turbo = if !generic_params.is_empty() {
let contract_turbofish = if !generic_params.is_empty() {
quote! { #contract_ident ::< #(#generic_params,)* > }
} else {
quote! { #contract_ident }
};

if cfg!(feature = "sv_replies") {
quote! {
let contract = #contract_turbo ::new();
let contract = #contract_turbofish ::new();
dispatch_reply(deps, env, msg, contract).map_err(Into::into)
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions sylvia-derive/src/entry_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'a> EntryPoints<'a> {
let sylvia = crate_module();

let attr_generics = &attrs.generics;
let (contract, contract_turbo) = if attr_generics.is_empty() {
let (contract, contract_turbofish) = if attr_generics.is_empty() {
(quote! { #name }, quote! { #name })
} else {
(
Expand All @@ -202,14 +202,14 @@ impl<'a> EntryPoints<'a> {
};
let dispatch = match msg_ty {
MsgType::Reply if cfg!(feature = "sv_replies") => quote! {
let contract = #contract_turbo ::new();
let contract = #contract_turbofish ::new();
sv::dispatch_reply(deps, env, msg, contract).map_err(Into::into)
},
MsgType::Reply => quote! {
#contract_turbo ::new(). #reply((deps, env).into(), msg).map_err(Into::into)
#contract_turbofish ::new(). #reply((deps, env).into(), msg).map_err(Into::into)
},
_ => quote! {
msg.dispatch(& #contract_turbo ::new() , ( #values )).map_err(Into::into)
msg.dispatch(& #contract_turbofish ::new() , ( #values )).map_err(Into::into)
},
};

Expand Down

0 comments on commit 72ebc77

Please sign in to comment.