From f29046fefd20947c640e5b714f8e4952f10ee953 Mon Sep 17 00:00:00 2001 From: tjjfvi Date: Sat, 22 Oct 2022 11:24:41 -0700 Subject: [PATCH] ... --- frame_metadata/Codec.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/frame_metadata/Codec.ts b/frame_metadata/Codec.ts index 65d6b6784..52bd84d4a 100644 --- a/frame_metadata/Codec.ts +++ b/frame_metadata/Codec.ts @@ -88,7 +88,7 @@ export function DeriveCodec(tys: M.Ty[]): DeriveCodec { }, compact(ty) { const inner = this.visit(ty.typeParam); - return compactCodecVisitor.visit(inner); + return $compact(inner); }, bitSequence() { return $.bitSequence; @@ -126,4 +126,17 @@ const compactCodecVisitor = new $.CodecVisitor<$.Codec>() .add($.u32, () => $.compactU32) .add($.u64, () => $.compactU64) .add($.u128, () => $.compactU128) - .add($.u256, () => $.compactU256); + .add($.u256, () => $.compactU256) + .add( + $.object, + (_, ...fields) => { + if (fields.length !== 1) { + // https://github.com/paritytech/parity-scale-codec/blob/75fab93/derive/src/lib.rs#L307 + throw new Error("Cannot derive Compact codec for structs with more than one key"); + } + const field = fields[0]!; + return $.object([field[0], $compact(field[1] as $.Codec)]); + }, + ); + +const $compact = (x: $.Codec): $.Codec => compactCodecVisitor.visit(x);