2
#![cfg_attr(not(feature = "std"), no_std)]

#[ink::contract]
mod crowd_funding {
    use ink::storage::Mapping;
    
    #[derive(scale::Decode, scale::Encode)]
    #[cfg_attr(
        feature = "std",
        derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
    )]

    pub struct IndividualFundMe {
        account_id: AccountId,
        go_fund_id: u64,
        name: String,
        reason_for_fund: String,
        amount_needed: Balance,
        amount_gotten: Balance,
        status: bool,
        donators: Vec<AccountId>
    }

    #[ink(storage)]
    pub struct CrowdFunding {
        go_funds: Mapping<AccountId, IndividualFundMe>,
        all_go_funds: Vec<IndividualFundMe>,
        successfull_go_funds: Vec<IndividualFundMe>,
        go_fund_id: u64
    }

    impl CrowdFunding {
       
        #[ink(constructor)]
        pub fn new() -> Self {
            Self {
                go_funds: Mapping::new(),
                all_go_funds: Vec::new(),
                successfull_go_funds: Vec::new(),
                go_fund_id: 1
            }
        }

        #[ink(message)]
        pub fn create_crowdfund(&mut self, _name: String, _reason_for_fund: String, _amount_needed: Balance)  {
            let new_gofund =  IndividualFundMe {
                account_id: self.env().caller(),
                go_fund_id: self.go_fund_id,
                name: _name.clone(),
                reason_for_fund: _reason_for_fund.clone(),
                amount_needed: _amount_needed,
                amount_gotten: 0,
                status: false,
                donators: Vec::new()
            };
            self.go_funds.insert(self.env().caller(), &new_gofund);
            self.all_go_funds.push(new_gofund);
            self.go_fund_id += 1;
        }
    }
}

Below is the compiler error

`IndividualFundMe` doesn't implement `Debug`
the trait `Debug` is not implemented for `IndividualFundMe`
add `#[derive(Debug)]` to `IndividualFundMe` or manually `impl Debug for IndividualFundMe`
the trait `Debug` is implemented for `Vec<T, A>`
3
  • Please paste the compile error message. Mar 29, 2023 at 11:34
  • 1
    use ink::prelude::{string::String, vec::Vec}; add this
    – Ganesh11
    Mar 29, 2023 at 11:36
  • I added this already Ganesh11 but it still complains
    – Mite
    Mar 29, 2023 at 14:37

1 Answer 1

5

You need to import: use ink::prelude::vec::Vec; in the contract's module.

You also need to import use ink::prelude::string::String; for strings.

These are the preludes that implement necessary traits to be stored.

1
  • Edited just now, you don't actually need to derive Debug, just import these preludes. Mar 29, 2023 at 16:26

Your Answer

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

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