Skip to content

Commit

Permalink
Revert "Optimise deny_payment. Use eerywhere semantic of deny. (#1267)"
Browse files Browse the repository at this point in the history
This reverts commit 1bfccc7.
  • Loading branch information
agryaznov committed Jun 5, 2022
1 parent 80d302e commit 0a96173
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
19 changes: 7 additions & 12 deletions crates/lang/codegen/src/generator/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ impl Dispatch<'_> {
}
}
};
let any_constructor_accept_payment =
self.any_constructor_accepts_payment_expr(constructor_spans);

let constructor_execute = (0..count_constructors).map(|index| {
let constructor_span = constructor_spans[index];
Expand All @@ -545,8 +543,9 @@ impl Dispatch<'_> {
}>>::IDS[#index]
}>>::CALLABLE
);
let deny_payment = quote_spanned!(constructor_span=>
!<#storage_ident as ::ink_lang::reflect::DispatchableConstructorInfo<{
let accepts_payment = quote_spanned!(constructor_span=>
false ||
<#storage_ident as ::ink_lang::reflect::DispatchableConstructorInfo<{
<#storage_ident as ::ink_lang::reflect::ContractDispatchableConstructors<{
<#storage_ident as ::ink_lang::reflect::ContractAmountDispatchables>::CONSTRUCTORS
}>>::IDS[#index]
Expand All @@ -555,12 +554,10 @@ impl Dispatch<'_> {

quote_spanned!(constructor_span=>
Self::#constructor_ident(input) => {
if #any_constructor_accept_payment && #deny_payment {
::ink_lang::codegen::deny_payment::<
<#storage_ident as ::ink_lang::reflect::ContractEnv>::Env>()?;
}

::ink_lang::codegen::execute_constructor::<#storage_ident, _, _>(
::ink_lang::codegen::ExecuteConstructorConfig {
payable: #accepts_payment,
},
move || { #constructor_callable(input) }
)
}
Expand Down Expand Up @@ -695,8 +692,6 @@ impl Dispatch<'_> {
}
}
};
let any_message_accept_payment =
self.any_message_accepts_payment_expr(message_spans);

let message_execute = (0..count_messages).map(|index| {
let message_span = message_spans[index];
Expand Down Expand Up @@ -734,7 +729,7 @@ impl Dispatch<'_> {
Self::#message_ident(input) => {
use ::core::default::Default;

if #any_message_accept_payment && #deny_payment {
if #deny_payment {
::ink_lang::codegen::deny_payment::<
<#storage_ident as ::ink_lang::reflect::ContractEnv>::Env>()?;
}
Expand Down
15 changes: 14 additions & 1 deletion crates/lang/src/codegen/dispatch/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,33 @@ where
Ok(())
}

/// Configuration for execution of ink! constructor.
#[derive(Debug, Copy, Clone)]
pub struct ExecuteConstructorConfig {
/// Yields `true` if the ink! constructor accepts payment.
pub payable: bool,
}

/// Executes the given ink! constructor.
///
/// # Note
///
/// The closure is supposed to already contain all the arguments that the real
/// constructor message requires and forwards them.
#[inline]
pub fn execute_constructor<Contract, F, R>(f: F) -> Result<(), DispatchError>
pub fn execute_constructor<Contract, F, R>(
config: ExecuteConstructorConfig,
f: F,
) -> Result<(), DispatchError>
where
Contract: SpreadLayout + ContractRootKey + ContractEnv,
F: FnOnce() -> R,
<private::Seal<R> as ConstructorReturnType<Contract>>::ReturnValue: scale::Encode,
private::Seal<R>: ConstructorReturnType<Contract>,
{
if !config.payable {
deny_payment::<<Contract as ContractEnv>::Env>()?;
}
let result = ManuallyDrop::new(private::Seal(f()));
match result.as_result() {
Ok(contract) => {
Expand Down
1 change: 1 addition & 0 deletions crates/lang/src/codegen/dispatch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub use self::{
execute_constructor,
initialize_contract,
ContractRootKey,
ExecuteConstructorConfig,
},
info::ContractCallBuilder,
type_check::{
Expand Down
1 change: 1 addition & 0 deletions crates/lang/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub use self::{
ContractRootKey,
DispatchInput,
DispatchOutput,
ExecuteConstructorConfig,
},
env::{
Env,
Expand Down

0 comments on commit 0a96173

Please sign in to comment.