0

I have a data structure as follows

// definition for account id is 
// pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

use primitives::{AccountId, Balance, Price};

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct Alpha{
    pub alpha: AccountId,
    pub cost: Price,
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default)]
#[scale_info(skip_type_params(T))]
pub struct Wallet{
    pub avg: Price,
    pub alphas: Vec<Alpha>,
}

and Storage Declaration

#[pallet::storage]
    #[pallet::getter(fn get_big_wallet)]
    pub type BigWallet<T: Config> = StorageDoubleMap<
        _,
        Blake2_128Concat,
        CurrencyId,
        Blake2_128Concat,
        RoundNumber,
        Wallet,
        OptionQuery,
    >;

When I tried to save data um getting the following error

let who = ensure_signed(origin)?; // this works
let mut record= Self::get_big_wallet(asset_id, round).unwrap_or_default(); // this works


let mut members= record.alpha;
let sub_len = members.len() as u128;

            let data= Alpha{
                alpa: who.clone(),
                price,
            };


Error: alpa: who.clone(),
    |                            ^^^^^^^^^^^ expected struct `AccountId32`, found associated type

How to fix this error above? How to save an account ( who ) ?

1 Answer 1

1

You are using the AccountId type from sp_primitives.
What you rather want to do is to use the AccountId from your pallet configuration which is accessible as T::AccountId or something like <T as frame_system::Config> depending on your pallet config.

use primitives::{Balance, Price};

type AccountIdOf<T> = <T as frame_system::Config>::AccountId;

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct Alpha<AccountId>{
    pub alpha: AccountId,
    pub cost: Price,
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, Default)]
pub struct Wallet<AccountId>{
    pub avg: Price,
    pub alphas: Vec<Alpha<AccountId>>,
}

// Use the wallet as:
Wallet<AccountIdOf<T>>

You can also pass in T::AccountId as generic type instead of the complete Config.

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.