Hello the following code snippet is giving me headaches:
mod items;
pub use super::*;
pub use crate::roles::items::*;
pub type BalanceOf<T> = <<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type Contributors<T> = Vec<AccountIdOf<T>>;
pub type HouseIndex = u32;
pub type Bool = bool;
#[derive(Debug, PartialEq, Encode, Decode)]
pub struct Investor<T,U>{
pub account_id:T,
pub nft:U,
}
impl<T,U> Investor<T,U>{
pub fn new(acc: T,nft:U)-> Self{
Investor{
account_id: acc,
nft: nft,
}
}
}
impl<T:pallet::Config+frame_system::Config,U> Investor<T,U>{
pub fn contribute(origin:OriginFor<T>,acc:AccountIdOf<T> ,value:BalanceOf<T>) -> DispatchResult{
let c1=Contribution::new(&acc,&value);
let _who = ensure_signed(origin)?;
let _now = <frame_system::Pallet<T>>::block_number();
if ContributionsLog::<T>::contains_key(c1.account){
ContributionsLog::<T>::mutate(c1.account, |val|{
*val += *c1.amount;
})
} else {
ContributionsLog::<T>::insert(&acc,value);
ContAccounts::<T>::mutate(|val|{
val.push(acc);
})
}
//function taking contribution storage and amount as inputs here
Ok(().into())
}
}
this code is located in a mod.rs file it looks good to me, until I try to use the contribute method in my lib.rs:
impl<T: Config> Pallet<T> {
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn do_something(origin: OriginFor<T>, something: u32, acc:AccountIdOf<T> ,rent:BalanceOf<T>,cd:CID,prop:Properties,start:Option<BlockNumberOf<T>>,end:Option<BlockNumberOf<T>>) -> DispatchResult
{
let who = ensure_signed(origin)?;
let dev=Investor::new(&acc,something);
Investor::<T::AccountId,u32>::contribute(who,dev.account_id,rent);
<Something<T>>::put(dev.nft+something);
Self::deposit_event(Event::SomethingStored(something, who));
Ok(())
}
this then give me the following error:
error[E0599]: the function or associated item `contribute` exists for struct `roles::Investor<<T as frame_system::Config>::AccountId, u32>`, but its trait bounds were not satisfied
--> pallets/template/src/lib.rs:144:40
|
144 | Investor::<T::AccountId,u32>::contribute(who,dev.account_id,rent);
| ^^^^^^^^^^ function or associated item cannot be called on `roles::Investor<<T as frame_system::Config>::AccountId, u32>` due to unsatisfied trait bounds
|
::: pallets/template/src/roles/mod.rs:14:1
|
14 | pub struct Investor<T,U>{
| ------------------------ function or associated item `contribute` not found for this
|
= note: the following trait bounds were not satisfied:
`<T as frame_system::Config>::AccountId: pallet::Config`
`<T as frame_system::Config>::AccountId: frame_system::Config`
trying to implement investor as below didn't solve the problem either:
impl<T:frame_system::Config+pallet::Config,U> Investor<T,U>{
pub fn new(acc: T,nft:U)-> Self{
Investor{
account_id: acc,
nft: nft,
}
}
}
Any advice? Please?
link to the repo/lib.rs: https://github.com/Fair-Squares/fair-squares/blob/structure_template/pallets/template/src/lib.rs Kazu
cargo fmt
in order to make your code more easily readable.