diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 17a12bb5602..1418ed7eaa5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -123,6 +123,8 @@ examples-fmt: cargo fmt --verbose --manifest-path ./examples/upgradeable-contracts/${contract}/Cargo.toml -- --check; done - cargo fmt --verbose --manifest-path ./examples/upgradeable-contracts/delegate-calls/upgradeable-flipper/Cargo.toml -- --check + # This file is not a part of the cargo project, so it wouldn't be formatted the usual way + - rustfmt --verbose --check ./examples/psp22-extension/runtime/psp22-extension-example.rs allow_failure: true clippy-std: diff --git a/examples/psp22-extension/README.md b/examples/psp22-extension/README.md index 6e4620964c2..96850ac8294 100644 --- a/examples/psp22-extension/README.md +++ b/examples/psp22-extension/README.md @@ -24,10 +24,10 @@ To integrate this example into Substrate you need to do two things: * In your runtime, use the code in [`psp22-extension-example.rs`](runtime/psp22-extension-example.rs) as an implementation for the trait `ChainExtension` in Substrate. - You can just copy/paste the content of that file into e.g. your `runtime/src/lib.rs`. + You can just copy/paste that file as a new module, e.g. `runtime/src/chain_extension.rs`. -* Use the implementation as the associated type `ChainExtension` of the trait - `pallet_contracts::Config`: +* In your runtime, use the implementation as the associated type `ChainExtension` of the + trait `pallet_contracts::Config`: ```rust impl pallet_contracts::Config for Runtime { … @@ -42,6 +42,9 @@ See the example contract in [`lib.rs`](lib.rs). ## Disclaimer -This is not a feature-complete or production-ready PSP22 implementation. This example -currently lacks proper error management, precise weight accounting, tests (these all -might be added at a later point). +:warning: This is not a feature-complete or production-ready PSP22 implementation. This +example currently lacks proper error management, precise weight accounting, tests (these +all might be added at a later point). + +:warning: `decrease_allowance` function is currently not implemented due to limitations +of the `assets` pallet. diff --git a/examples/psp22-extension/lib.rs b/examples/psp22-extension/lib.rs index 58891a2b395..3906e6820da 100755 --- a/examples/psp22-extension/lib.rs +++ b/examples/psp22-extension/lib.rs @@ -113,6 +113,7 @@ impl ink_env::chain_extension::FromStatusCode for Psp22ErrorCode { } } +/// An environment using default ink env types, with Psp22Extension included #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum CustomEnvironment {} diff --git a/examples/psp22-extension/runtime/psp22-extension-example.rs b/examples/psp22-extension/runtime/psp22-extension-example.rs index 113fc0f262f..817010244f2 100644 --- a/examples/psp22-extension/runtime/psp22-extension-example.rs +++ b/examples/psp22-extension/runtime/psp22-extension-example.rs @@ -163,6 +163,8 @@ where { let mut env = env.buf_in_buf_out(); let base_weight = ::WeightInfo::transfer(); + // debug_message weight is a good approximation of the additional overhead of going from + // contract layer to substrate layer. let overhead = ::Schedule::get() .host_fn_weights .debug_message; @@ -197,9 +199,6 @@ where DispatchError::Other("ChainExtension failed to call transfer") })?; Ok(()) - - // TODO: adjust weight - // env.adjust_weight(charged, actual_weight) } fn transfer_from(env: Environment) -> Result<(), DispatchError> @@ -210,6 +209,8 @@ where { let mut env = env.buf_in_buf_out(); let base_weight = ::WeightInfo::transfer(); + // debug_message weight is a good approximation of the additional overhead of going from + // contract layer to substrate layer. let overhead = ::Schedule::get() .host_fn_weights .debug_message; @@ -244,9 +245,6 @@ where ); DispatchError::Other("ChainExtension failed to call transfer_from") }) - - // TODO: adjust weight - // env.adjust_weight(charged, actual_weight) } fn approve(env: Environment) -> Result<(), DispatchError> @@ -257,6 +255,8 @@ where { let mut env = env.buf_in_buf_out(); let base_weight = ::WeightInfo::approve_transfer(); + // debug_message weight is a good approximation of the additional overhead of going from + // contract layer to substrate layer. let overhead = ::Schedule::get() .host_fn_weights .debug_message; @@ -288,9 +288,6 @@ where ); DispatchError::Other("ChainExtension failed to call approve") }) - - // TODO: adjust weight - // env.adjust_weight(charged, actual_weight) } fn decrease_allowance(_env: Environment) -> Result<(), DispatchError>