1

How can I match on runtime Calls from my outer node? I essentially want to "trigger" the node once a type of extrinsic is submitted. It seems like I don't have an option to emit any kind of observable from WASM, so I'm attempting to watch the import_notification_stream from the transaction pool. This works, but now I'm struggling to unwrap the underlying call in the transaction.

let mut commands_stream = Box::pin(cloned_pool.import_notification_stream());
        while let Some(tx_hash) = commands_stream.next().await {
            log::info!("got hash for tx: {:?}", tx_hash);
            if let Some(tx) = cloned_pool.ready_transaction(&tx_hash) {
                let uxt: Block::Extrinsic = tx.data().clone();
                ... how to now convert to call and match

1 Answer 1

0

There are two ways to do this, the first one is by having a Runtime api that automtically do all the deserailisation for you than match the call like this, for example if i want to check whether an extrinsic is of a specific type i would have something like this:

    fn verify_extrinsic(extrinsic: <Block as BlockT>::Extrinsic)-> bool
        {
                if let Call::MyPallet(pallet_my_pallet::Call::<Runtime>::test_call{param1:_,param2:_}) = &extrinsic.function
                {
                    // or do some other stuff
                    false
                }else
                {
                    true
                }
        }
    }

now we update your code:

 let uxt: Block::Extrinsic = tx.data().clone();
let result = client.runtime_api().verify_extrinsic(&best_block_id, uxt.clone())
// do something with the result
 

the other way is to do manual scale decoding of the extrinsic which i think is a hustle.

Your Answer

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

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