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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user