A clear explanation will be appreciated as to why Decode trait is not implemented while encode is. What are the design reason for this?
1 Answer
What? It is definetly decodable. Code from here:
impl<T: Decode, S: Get<u32>> Decode for BoundedVec<T, S> {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
let inner = Vec::<T>::decode(input)?;
if inner.len() > S::get() as usize {
return Err("BoundedVec exceeds its limit".into())
}
Ok(Self(inner, PhantomData))
}
fn skip<I: codec::Input>(input: &mut I) -> Result<(), codec::Error> {
Vec::<T>::skip(input)
}
}
and a small test:
#[test]
fn encode_decode_works() {
let bounded: BoundedVec<u32, ConstU32<7>> = bounded_vec![1, 2, 3, 4, 5, 6];
let encoded = bounded.encode();
let decoded: BoundedVec<u32, ConstU32<7>> = Decode::decode(&mut &encoded[..]).unwrap();
assert_eq!(bounded, decoded);
}
-
I Guess not the trait
Decode
is not implemented forsp_runtime::BoundedVec<<T as frame_system::Config>::AccountId, u32>
– not 0x12Dec 20, 2022 at 2:21