0

I'm trying to use Ink as a programmable hook for my pallet.

TD;LR;

My pallet will store Agreement.

struct Agreement<T> {
  // ...
  pub on_approve: T::AccountId // this point to an Ink contract
}

and there is a call

#[pallet::call_index(1)]
#[pallet::weight(0{})]
pub fn approve(origin: OriginFor<T>, aggrement_id: u32) {
  let origin = ensure_signed(origin)?;
  let mut agreement = Agreement::<T>::get(aggrement_id)?;

  agreement.approve();
  // TODO: call agreement.on_success

  OK(())
}

I can call an Ink contract via pallet_contracts::Pallet::<T>::bare_call(). However, I want to ensure the contract must conform to a specific interface.

for example

#[ink::trait_definition]
pub trait MyPalletHook {
    #[ink(message)]
    fn on_success(&mut self, agreement: Agreement);
}

Is my idea reasonable? Can pre-check a smart contract code or deployed instance implement a specific trait? How to call the contract via function definition in the trait?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.