Add $isStorageFallback on Codec interface (#5421)

* Add $isStorageFallback on Codec interface

* Rename in CHANGELOG

* Update specs with new naming

* Small formatting adjustments

* Abstract values

* Adjust initialU8a expectation

* Mark old interface as deprecated (& type to never)

* Adjust @deprecated comments

* Add deprecated interfaces to all
This commit is contained in:
Jaco
2023-01-18 21:58:06 +02:00
committed by GitHub
parent 263fce1e7d
commit 923f569d77
42 changed files with 261 additions and 156 deletions
+11 -3
View File
@@ -44,13 +44,21 @@ function checkPedantic (created: Codec, [value]: unknown[]): void {
// Initializes a type with a value. This also checks for fallbacks and in the cases
// where isPedantic is specified (storage decoding), also check the format/structure
function initType<T extends Codec> (registry: Registry, Type: CodecClass, params: unknown[] = [], { blockHash, isOptional, isPedantic }: CreateOptions = {}): T {
const created = new (isOptional ? Option.with(Type) : Type)(registry, ...params);
function initType<T extends Codec> (registry: Registry, Type: CodecClass, params: unknown[] = [], { blockHash, isFallback, isOptional, isPedantic }: CreateOptions = {}): T {
const created = new (
isOptional
? Option.with(Type)
: Type
)(registry, ...params);
isPedantic && checkPedantic(created, params);
if (blockHash) {
created.createdAtHash = createTypeUnsafe<IU8a>(registry, 'Hash', [blockHash]);
created.$createdAtHash = createTypeUnsafe<IU8a>(registry, 'BlockHash', [blockHash]);
}
if (isFallback) {
created.$isStorageFallback = true;
}
return created as T;