1

ChainExtension will return Result<RetVal, DispatchError>. (As you can see in the bottom pircutre)

  • When ChainExtension implementation returns Ok(RetVal::Converging(1)) and handle that status code 1 on ink! contract side like below, then Extrinsic itself will be shown as success even if dispatch failed.

impl ink_env::chain_extension::FromStatusCode for ContractErrorCode {
    fn from_status_code(status_code: u32) -> Result<(), Self> {
        match status_code {
            0 => Ok(()),
            1 => Err(Self::Failed),
            _ => panic!("encountered unknown status code"),
        }
    }
}

(What I did for experiments was ignore Error(DispatchError) and return Ok(RetVal::Converging(1)) instead so that ink! can handle status code 1.) enter image description here

  • When it returns DispatchError (Extrinsic itself fail), ink! smart contract cannot handle it and return its failure reason with #[message] functions' returned value. for e.g. Result<(), ContractError> (here ContractError reflects DispatchError's reason and perhaps we'd like to show it on UI).

The question is What is the appropriate way for ink! smart contract messages to handle DispatchError (from ChainExtension) and return it as its returned value?


enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.