Skip to content

Commit

Permalink
Add unstable feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cmichi committed Jan 8, 2025
1 parent e2a2342 commit e06857b
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 4 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,7 @@ jobs:
with:
# run all tests with --all-features, which will run the e2e-tests feature if present
args:
/bin/bash -c "scripts/for_all_contracts_exec.sh --path integration-tests \
--ignore public/static-buffer \
--partition ${{ matrix.partition }}/6 -- \
/bin/bash -c "scripts/for_all_contracts_exec.sh --path integration-tests --ignore public/static-buffer --partition ${{ matrix.partition }}/6 -- \
cargo +nightly test --all-features --all --manifest-path {}"

examples-custom-test:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ink_allocator = { workspace = true }
ink_storage_traits = { workspace = true }
ink_prelude = { workspace = true }
ink_primitives = { workspace = true }
ink_macro = { workspace = true }
pallet-revive-uapi = { workspace = true }

scale = { workspace = true, features = ["max-encoded-len"] }
Expand Down Expand Up @@ -92,6 +93,9 @@ std = [
# Enable contract debug messages via `debug_print!` and `debug_println!`.
ink-debug = []

# Enable functions that have are marked unstable in `pallet-revive.
unstable = []

# Disable the ink! provided global memory allocator.
no-allocator = [ "ink_allocator/no-allocator" ]

Expand Down
4 changes: 3 additions & 1 deletion crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::{
use ink_primitives::{H160, H256, U256};
use ink_storage_traits::Storable;
use pallet_revive_uapi::ReturnFlags;
use ink_macro::unstable_hostfn;

/// Returns the address of the caller of the executed contract.
///
Expand Down Expand Up @@ -353,6 +354,7 @@ where
/// This function never returns. Either the termination was successful and the
/// execution of the destroyed contract is halted. Or it failed during the termination
/// which is considered fatal and results in a trap and rollback.
#[unstable_hostfn]
pub fn terminate_contract(beneficiary: H160) -> ! {
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnvBackend::terminate_contract(instance, beneficiary)
Expand All @@ -371,7 +373,7 @@ pub fn terminate_contract(beneficiary: H160) -> ! {
///
/// - If the contract does not have sufficient free funds.
/// - If the transfer had brought the sender's total balance below the minimum balance.
/// You need to use [`terminate_contract`] in case this is your intention.
/// You need to use `terminate_contract` in case this is your intention.
pub fn transfer<E>(destination: H160, value: U256) -> Result<()>
where
E: Environment,
Expand Down
2 changes: 2 additions & 0 deletions crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::{
};
use ink_primitives::{H160, H256, U256};
use ink_storage_traits::Storable;
use ink_macro::unstable_hostfn;
pub use pallet_revive_uapi::ReturnFlags;

/// Environmental contract functionality that does not require `Environment`.
Expand Down Expand Up @@ -347,6 +348,7 @@ pub trait TypedEnvBackend: EnvBackend {
/// # Note
///
/// For more details visit: [`terminate_contract`][`crate::terminate_contract`]
#[unstable_hostfn]
fn terminate_contract(&mut self, beneficiary: H160) -> !;

/// Transfers value from the contract to the destination account ID.
Expand Down
2 changes: 2 additions & 0 deletions crates/env/src/engine/off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use ink_storage_traits::{
decode_all,
Storable,
};
use ink_macro::unstable_hostfn;
use pallet_revive_uapi::{
ReturnErrorCode,
ReturnFlags,
Expand Down Expand Up @@ -490,6 +491,7 @@ impl TypedEnvBackend for EnvInstance {
unimplemented!("off-chain environment does not support contract instantiation")
}

#[unstable_hostfn]
fn terminate_contract(&mut self, beneficiary: H160) -> ! {
self.engine.terminate(beneficiary)
}
Expand Down
2 changes: 2 additions & 0 deletions crates/env/src/engine/on_chain/pallet_revive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use ink_primitives::{
H256,
U256,
};
use ink_macro::unstable_hostfn;
use ink_storage_traits::{
decode_all,
Storable,
Expand Down Expand Up @@ -624,6 +625,7 @@ impl TypedEnvBackend for EnvInstance {
)
}

#[unstable_hostfn]
fn terminate_contract(&mut self, beneficiary: H160) -> ! {
let buffer: &mut [u8; 20] = self.scoped_buffer().take_encoded(&beneficiary)
[0..20]
Expand Down
1 change: 1 addition & 0 deletions crates/env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
html_favicon_url = "https://use.ink/crate-docs/favicon.png"
)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(
missing_docs,
bad_style,
Expand Down
3 changes: 3 additions & 0 deletions crates/ink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ no-allocator = [ "ink_env/no-allocator" ]
# Disable the ink! provided panic handler.
no-panic-handler = ["ink_env/no-panic-handler"]

# todo
unstable = ["ink_env/unstable"]

# Just for the ui tests, which use this `Cargo.toml`
# ink-as-dependency = []
11 changes: 11 additions & 0 deletions crates/ink/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,5 +1635,16 @@ pub fn scale_derive(attr: TokenStream, item: TokenStream) -> TokenStream {
}
}

#[proc_macro_attribute]
pub fn unstable_hostfn(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::Item);
let expanded = quote::quote! {
#[cfg(feature = "unstable")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
#input
};
expanded.into()
}

#[cfg(test)]
pub use contract::generate_or_err;
2 changes: 2 additions & 0 deletions crates/ink/src/env_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use ink_env::{
};
use ink_primitives::{H160, H256, U256};
use pallet_revive_uapi::ReturnErrorCode;
use ink_macro::unstable_hostfn;

/// The API behind the `self.env()` and `Self::env()` syntax in ink!.
///
Expand Down Expand Up @@ -656,6 +657,7 @@ where
/// # Note
///
/// For more details visit: [`ink_env::terminate_contract`]
#[unstable_hostfn]
pub fn terminate_contract(self, beneficiary: H160) -> ! {
ink_env::terminate_contract(beneficiary)
}
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/public/contract-terminate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ default = ["std"]
std = [
"ink/std",
]

ink = ["unstable"]
ink-as-dependency = []
e2e-tests = []
1 change: 1 addition & 0 deletions integration-tests/public/payment-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ std = [
"sp-core/std",
]

ink = ["unstable"]
ink-as-dependency = []

0 comments on commit e06857b

Please sign in to comment.