uint icon indicating copy to clipboard operation
uint copied to clipboard

fix scale support for upcoming versions

Open pgherveou opened this issue 1 year ago • 0 comments

This PR should fix breaking changes for upcoming parity-scale-codec versions

Motivation

We have added some constraints to the HasCompact trait in https://github.com/paritytech/parity-scale-codec/pull/512 to fix MaxEncodedLen for compact fields.

/// Trait that tells you if a given type can be encoded/decoded in a compact way.
pub trait HasCompact: Sized {
	/// The compact type; this can be
-	type Type: for<'a> EncodeAsRef<'a, Self> + Decode + From<Self> + Into<Self>;
+	type Type: for<'a> EncodeAsRef<'a, Self> + Decode + From<Self> + Into<Self> + MaybeMaxEncodedLen;
}

This is so that we can fix the MaxEncodedLen derive trait for Compact field

- ty.span() => .saturating_add(<#crate_path::Compact::<#ty> as #crate_path::MaxEncodedLen>::max_encoded_len())
+ ty.span() => .saturating_add(<<#ty as #crate_path::HasCompact>::Type as #crate_path::MaxEncodedLen>::max_encoded_len())

This change breaks uint, thus this PR to attempt to fix it.

Solution

This PR implements MaxEncodedLen for CompactUint (and Encode as required) to fix the compilation issue with upcoming versions

PR Checklist

  • [ ] Added Tests
  • [ ] Added Documentation
  • [ ] Updated the changelog

pgherveou avatar Sep 12 '23 10:09 pgherveou