0
votes

Can anybody tell me please how to include <T as Trait>::BlockNumber and <T as Trait>::AccountId in my struct within my pallet module?

My current solution is to add a generic parameter T with a Trait bound to "Trait". Link to code.

I think the usage of that generic struct as a function parameter type in decl_module! (line 72) does lead to the following error:

error[E0277]: T doesn't implement std::fmt::Debug

-- snip --

= help: the trait std::fmt::Debug is not implemented for T

= note: required because of the requirements on the impl of std::fmt::Debug for PhysicalProof<T, [u8; 32]>

= note: required because of the requirements on the impl of std::fmt::Debug for (PhysicalProof<T, [u8; 32]>,)

= note: required by std::fmt::Debug::fmt

= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

help: consider further restricting this bound

impl<$trait_instance: $trait_name + std::fmt::Debug $(, $instance: $instantiable)?> $crate::dispatch::fmt::Debug

I have tried to implement fmt::Debug manually for T within that struct, but either that is not a solution or I am incapable of doing it correctly.

2
I'm not sure if I understood your question correctly. Can you provide a minimal reproducible example?Ibraheem Ahmed

2 Answers

0
votes

To derive Debug for as struct, all of its fields must be able to implement Debug. Right now, the compiler doesn't know if T is debuggable.

You can tell the compiler that T implements Debug by adding a Debug as a bound for type T:

#[derive(Debug)]
pub struct PhysicalProof<T, ProofData> where
    // `T` must implement `Debug`   
    T: Trait + Debug,
{
    proof: ProofData,
    date: T::BlockNumber,
}
0
votes

A suggestion from Guillaume from substrate-technical Element chat that solved the problem:

in rust the code:


/// Structure that contains the proof
#[derive(Debug)]
pub struct PhysicalProof<T, ProofData> where
  ProofData: Codec + Clone + Debug + Decode + Encode + Eq + PartialEq,
  T: Trait,
{
  proof: ProofData,
  date: T::BlockNumber,
}

Will do impl<..> Debug for PhysicalPool<...> where ..., ProofData: Debug, T: Debug this additional bounds are unwanted in your situation, but rust add them anyway. Thus when you try to use the stuct it says it doesn't implement Debug because T doesn't implement Debug.

One solution is to implmeent manually, another one would be to do:

/// Structure that contains the proof
#[derive(Debug)]
pub struct PhysicalProof<BlockNumber ProofData> where
  ProofData: Codec + Clone + Debug + Decode + Encode + Eq + PartialEq, BLockNumber: ...
{
  proof: ProofData,
  date: BlockNumber,
}