Skip to content

Commit

Permalink
Fix expected function signature of return_value (#2385)
Browse files Browse the repository at this point in the history
* Remove unnecessary comments

* Fix mismatching return types: `!` vs `{}`

The issue here is that in `std` the function signature of
`return_value` is different from `no_std`.

* Update `scale` deps

* Revert "Update `scale` deps"

This reverts commit 6d4c340.

* Revert "Remove unnecessary `scale` + `scale-info` deps from contracts (#2386)"

This reverts commit b86b693.
  • Loading branch information
cmichi authored Jan 30, 2025
1 parent b86b693 commit bf546be
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 47 deletions.
13 changes: 11 additions & 2 deletions crates/ink/codegen/src/generator/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ impl Dispatch<'_> {
<Self::Input as ::ink::scale::Decode>::decode(input)
.map_err(|_| ::ink::env::DispatchError::InvalidParameters)
};
#[cfg(not(feature = "std"))]
const RETURN: fn(::ink::env::ReturnFlags, Self::Output) -> ! =
|flags, output| {
::ink::env::return_value::<::ink::MessageResult::<Self::Output>>(
Expand All @@ -306,6 +307,16 @@ impl Dispatch<'_> {
&::ink::MessageResult::Ok(output),
)
};
#[cfg(feature = "std")]
const RETURN: fn(::ink::env::ReturnFlags, Self::Output) -> () =
|flags, output| {
::ink::env::return_value::<::ink::MessageResult::<Self::Output>>(
flags,
// Currently no `LangError`s are raised at this level of the
// dispatch logic so `Ok` is always returned to the caller.
&::ink::MessageResult::Ok(output),
)
};
const SELECTOR: [::core::primitive::u8; 4usize] = [ #( #selector_bytes ),* ];
const PAYABLE: ::core::primitive::bool = #payable;
const MUTATES: ::core::primitive::bool = #mutates;
Expand Down Expand Up @@ -468,7 +479,6 @@ impl Dispatch<'_> {
#[cfg(target_arch = "riscv64")]
#[::ink::polkavm_export(abi = ::ink::polkavm_derive::default_abi)]
pub extern "C" fn deploy() {
//panic!("---------------err code:\n1: _{:?}_", foo::BarPlain::Success );
internal_deploy()
}
};
Expand Down Expand Up @@ -546,7 +556,6 @@ impl Dispatch<'_> {
<<#storage_ident as ::ink::reflect::ContractMessageDecoder>::Type
as ::ink::reflect::ExecuteDispatchable>::execute_dispatchable(dispatchable)
.unwrap_or_else(|error| {
//::ink::env::debug_println!("dispatching failed");
::core::panic!("dispatching ink! message failed: {}", error)
})
}
Expand Down
5 changes: 5 additions & 0 deletions crates/primitives/src/reflect/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ pub trait DispatchableMessageInfo<const ID: u32> {
) -> Result<Self::Input, DispatchError>;

/// closure for returning per encoding todo: docs
#[cfg(not(feature = "std"))]
const RETURN: fn(ReturnFlags, Self::Output) -> !;

/// closure for returning per encoding todo: docs
#[cfg(feature = "std")]
const RETURN: fn(ReturnFlags, Self::Output) -> ();

/// Yields `true` if the dispatchable ink! message mutates the ink! storage.
const MUTATES: bool;
/// Yields `true` if the dispatchable ink! message is payable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ publish = false

[dependencies]
ink = { path = "../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] }
scale-info = { version = "2.11", default-features = false }

[dev-dependencies]
ink_e2e = { path = "../../../crates/e2e" }
Expand Down
36 changes: 21 additions & 15 deletions integration-tests/public/contract-invocation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@ authors = ["Víctor M. González <[email protected]>"]
[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
"contract1/std",
"contract2/std",
"virtual_contract/std",
"virtual_contract_ver1/std",
"virtual_contract_ver2/std",
]
ink-as-dependency = []
e2e-tests = []

[dependencies]
ink = { path = "../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
], optional = true }
contract1 = { path = "./contract1", default-features = false, features = [
"ink-as-dependency",
] }
Expand All @@ -28,21 +49,6 @@ virtual_contract_ver2 = { path = "./virtual_contract_ver2", default-features = f
[dev-dependencies]
ink_e2e = { path = "../../../crates/e2e" }

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
"contract1/std",
"contract2/std",
"virtual_contract/std",
"virtual_contract_ver1/std",
"virtual_contract_ver2/std",
]
ink-as-dependency = []
e2e-tests = []

[profile.dev]
overflow-checks = false

Expand Down
18 changes: 12 additions & 6 deletions integration-tests/public/contract-invocation/contract1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ authors = ["Víctor M. González <[email protected]>"]
[lib]
path = "lib.rs"

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std"]
ink-as-dependency = []
e2e-tests = []

[dependencies]
ink = { path = "../../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
], optional = true }

[dev-dependencies]
ink_e2e = { path = "../../../../crates/e2e" }

[features]
default = ["std"]
std = ["ink/std"]
ink-as-dependency = []
e2e-tests = []

[profile.dev]
overflow-checks = false

Expand Down
18 changes: 12 additions & 6 deletions integration-tests/public/contract-invocation/contract2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ authors = ["Víctor M. González <[email protected]>"]
[lib]
path = "lib.rs"

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std"]
ink-as-dependency = []
e2e-tests = []

[dependencies]
ink = { path = "../../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
], optional = true }

[dev-dependencies]
ink_e2e = { path = "../../../../crates/e2e" }

[features]
default = ["std"]
std = ["ink/std"]
ink-as-dependency = []
e2e-tests = []

[profile.dev]
overflow-checks = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ authors = ["Víctor M. González <[email protected]>"]
[lib]
path = "lib.rs"

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std"]
ink-as-dependency = []
e2e-tests = []

[dependencies]
ink = { path = "../../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
], optional = true }

[dev-dependencies]
ink_e2e = { path = "../../../../crates/e2e" }

[features]
default = ["std"]
std = ["ink/std"]
ink-as-dependency = []
e2e-tests = []

[profile.dev]
overflow-checks = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ authors = ["Víctor M. González <[email protected]>"]
[lib]
path = "lib.rs"

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std"]
ink-as-dependency = []
e2e-tests = []

[dependencies]
ink = { path = "../../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
], optional = true }

[dev-dependencies]
ink_e2e = { path = "../../../../crates/e2e" }

[features]
default = ["std"]
std = ["ink/std"]
ink-as-dependency = []
e2e-tests = []

[profile.dev]
overflow-checks = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ authors = ["Víctor M. González <[email protected]>"]
[lib]
path = "lib.rs"

[features]
default = ["std"]
std = ["ink/std", "scale/std", "scale-info/std"]
ink-as-dependency = []
e2e-tests = []

[dependencies]
ink = { path = "../../../../crates/ink", default-features = false }
scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
], optional = true }

[dev-dependencies]
ink_e2e = { path = "../../../../crates/e2e" }

[features]
default = ["std"]
std = ["ink/std"]
ink-as-dependency = []
e2e-tests = []

[profile.dev]
overflow-checks = false

Expand Down

0 comments on commit bf546be

Please sign in to comment.