0

I am trying Substrate official off-chain example. I am throwing a DispatchError in my extrinsic.

#[pallet::call_index(0)]
        #[pallet::weight({0})]
        pub fn submit_price(origin: OriginFor<T>, is_ocw: bool) -> DispatchResultWithPostInfo {
            // Retrieve sender of the transaction.
            let who = ensure_signed(origin)?;
            ensure!(true == false, Error::<T>::NoneValue);
            // Add the price to the on-chain list.
            Self::add_price(Some(who), price);
            Ok(().into())
        }


Here is off-chain worker code:

fn offchain_worker(_block_number: BlockNumberFor<T>) {
            log::info!("Hello from pallet-ocw.");
            let signer = Signer::<T, T::AuthorityId>::all_accounts();
            if !signer.can_sign() {
                log::error!("No local accounts available");
                return
            }

                let results = signer.send_signed_transaction(|_account| {
                    Call:: submit_price { is_ocw: true }
                });

                for (acc, res) in &results {
                    match res {
                        Ok(()) => log::info!("Executed Successfully:  {:?}", acc.id),
                        Err(e) => log::error!("[{:?}] Failed to submit transaction: {:?}", acc.id, e),
                    }
                }


        }

It always prints Executed Successfully. Ideally it should print error log. Please let me know if I am missing anything.

1 Answer 1

0

If you take a look into the code, you will find that it finally calls sp_io::offchain::submit_transaction. The result means submitting to the pool successfully. You should not print "Executed Successfully".

1
  • What if extrinsic dispatch error, does OCW deduct that error?
    – Boleng
    Commented Jun 28 at 3:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.