rmrk-team / rmrk-substrate

[WIP] RMRK Substrate pallets
https://rmrk.app
Other
74 stars 36 forks source link

Add a restriction handler in function transfer #237

Closed Index0011 closed 1 year ago

Index0011 commented 1 year ago

Now the function transfer has no limitation that anyone could transfer items in any condition, now we have such a scene that we need to checkout if the transfer action satisfy some limitation, then to allow the transfer continue. If we can add a handler in RMRK- trait so that we can implement our custom pre-check handler?

HashWarlock commented 1 year ago

To add context here on potential solution, we can create a custom handler:

trait CheckAllowTransferFn {
    fn check(...) -> bool;
}

impl CheckAllowTransferFn for () {
    return true;
}

trait Config {
    // ...
    type CheckAllowTransfer: CheckAllowTransferFn;
}

This allows for downstream to implement the handler default impl of CheckAllowTransferFn in their runtimes to satisfy their use case. Example:

fn transfer() {
    if !T::CheckAllowTransfer::check() {
        return Err;
    }
    // ...
    // ...
}