Substrate extrinsic complex (struct) types

286 views Asked by At

I'm trying to use following struct in extrinsic parameter declaration:

pub struct PriceUpdate {
    pub source_currency: Vec<u8>,
    pub target_currency: Vec<u8>,
    pub provider: Vec<u8>,
    pub price: i64,
}

And here's the extrinsic declaration:

pub fn new_price(origin: OriginFor<T>, price_update: PriceUpdate) -> DispatchResult {

This results in compilation error:

^^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `PriceUpdate`

Can someone explain as to what are requirements for extrinsic params in respect to complex types such as structs/vecs/vecs of structs/etc? I've seen WrapperTypeEncode docs https://docs.rs/parity-scale-codec/2.2.0/parity_scale_codec/trait.WrapperTypeEncode.html but they don't spell out such information.

Many thanks!

1

There are 1 answers

0
AurevoirXavier On

Simply derive from parity-scale-codec.

use parity_scale_codec::{Encode, Decode};

#[derive(Encode, Decode)]
pub struct ...

Extrinsic is a call in pallet-level. Here, it explain that call arguments require these trait bound. https://crates.parity.io/frame_support/attr.pallet.html#call-palletcall-optional