From 1e3a1bb51c23cf824880a2fa3f45f04bc0aa8a15 Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 22 Jul 2021 14:18:31 +0300 Subject: [PATCH] Allow for type overrides via path (#3797) --- packages/types/src/generic/PortableRegistry.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/types/src/generic/PortableRegistry.ts b/packages/types/src/generic/PortableRegistry.ts index dcaf8da943..deee6e88a0 100644 --- a/packages/types/src/generic/PortableRegistry.ts +++ b/packages/types/src/generic/PortableRegistry.ts @@ -17,7 +17,16 @@ const PRIMITIVE_ALIAS: Record = { Str: 'Text' }; -const INK_PRIMITIVE_ALWAYS = ['AccountId', 'AccountIndex', 'Address', 'Balance']; +const PRIMITIVE_INK = ['AccountId', 'AccountIndex', 'Address', 'Balance']; + +// These are types where we have a specific decoding/encoding override + helpers +const PRIMITIVE_SP = [ + 'sp_core::crypto::AccountId32', + 'sp_runtime::generic::era::Era', + 'sp_runtime::multiaddress::MultiAddress', + 'pallet_democracy::vote::Vote', + 'pallet_identity::types::Data' +]; export class GenericPortableRegistry extends Struct { #typeDefs: Record = {}; @@ -88,7 +97,8 @@ export class GenericPortableRegistry extends Struct { path[0].eq('ink_env') && path[1].eq('types') ) || - INK_PRIMITIVE_ALWAYS.includes(path[path.length - 1].toString()) + PRIMITIVE_INK.includes(path[path.length - 1].toString()) || + PRIMITIVE_SP.includes(path.join('::')) ); let typeDef: TypeDef;