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 2af6f59 commit 90a4a9a
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),* > }

Check warning on line 166 in sylvia-derive/src/contract/communication/reply.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/contract/communication/reply.rs#L165-L166

Added lines #L165 - L166 were not covered by tests
} 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);

Check warning on line 172 in sylvia-derive/src/contract/communication/reply.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/contract/communication/reply.rs#L171-L172

Added lines #L171 - L172 were not covered by tests

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,)* > }

Check warning on line 537 in sylvia-derive/src/contract/mt.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/contract/mt.rs#L537

Added line #L537 was not covered by tests
} else {
quote! { #contract_ident }
};

if cfg!(feature = "sv_replies") {

Check warning on line 542 in sylvia-derive/src/contract/mt.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/contract/mt.rs#L542

Added line #L542 was not covered by tests
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() {

Check warning on line 180 in sylvia-derive/src/entry_points.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L180

Added line #L180 was not covered by tests
(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)

Check warning on line 206 in sylvia-derive/src/entry_points.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L204-L206

Added lines #L204 - L206 were not covered by tests
},
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)

Check warning on line 209 in sylvia-derive/src/entry_points.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L209

Added line #L209 was not covered by tests
},
_ => quote! {
msg.dispatch(& #contract_turbo ::new() , ( #values )).map_err(Into::into)
msg.dispatch(& #contract_turbofish ::new() , ( #values )).map_err(Into::into)

Check warning on line 212 in sylvia-derive/src/entry_points.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/entry_points.rs#L212

Added line #L212 was not covered by tests
},
};

Expand Down

0 comments on commit 90a4a9a

Please sign in to comment.