Skip to content

Commit

Permalink
Added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiezzel committed Aug 22, 2022
1 parent 6660e1a commit 2008862
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions examples/psp22-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
1 change: 1 addition & 0 deletions examples/psp22-extension/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
15 changes: 6 additions & 9 deletions examples/psp22-extension/runtime/psp22-extension-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ where
{
let mut env = env.buf_in_buf_out();
let base_weight = <T as pallet_assets::Config>::WeightInfo::transfer();
// debug_message weight is a good approximation of the additional overhead of going from
// contract layer to substrate layer.
let overhead = <T as pallet_contracts::Config>::Schedule::get()
.host_fn_weights
.debug_message;
Expand Down Expand Up @@ -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<T, E>(env: Environment<E, InitState>) -> Result<(), DispatchError>
Expand All @@ -210,6 +209,8 @@ where
{
let mut env = env.buf_in_buf_out();
let base_weight = <T as pallet_assets::Config>::WeightInfo::transfer();
// debug_message weight is a good approximation of the additional overhead of going from
// contract layer to substrate layer.
let overhead = <T as pallet_contracts::Config>::Schedule::get()
.host_fn_weights
.debug_message;
Expand Down Expand Up @@ -244,9 +245,6 @@ where
);
DispatchError::Other("ChainExtension failed to call transfer_from")
})

// TODO: adjust weight
// env.adjust_weight(charged, actual_weight)
}

fn approve<T, E>(env: Environment<E, InitState>) -> Result<(), DispatchError>
Expand All @@ -257,6 +255,8 @@ where
{
let mut env = env.buf_in_buf_out();
let base_weight = <T as pallet_assets::Config>::WeightInfo::approve_transfer();
// debug_message weight is a good approximation of the additional overhead of going from
// contract layer to substrate layer.
let overhead = <T as pallet_contracts::Config>::Schedule::get()
.host_fn_weights
.debug_message;
Expand Down Expand Up @@ -288,9 +288,6 @@ where
);
DispatchError::Other("ChainExtension failed to call approve")
})

// TODO: adjust weight
// env.adjust_weight(charged, actual_weight)
}

fn decrease_allowance<T, E>(_env: Environment<E, InitState>) -> Result<(), DispatchError>
Expand Down

0 comments on commit 2008862

Please sign in to comment.