Rename Base -> AbstractBase (#4943)

This commit is contained in:
Jaco
2022-06-17 10:36:44 +03:00
committed by GitHub
parent ee584f62a7
commit 083e0478c3
17 changed files with 35 additions and 21 deletions
+14
View File
@@ -1,5 +1,19 @@
# CHANGELOG
## master
Contributed:
- Update `@substrate/connect` to latest (Thanks to https://github.com/tomaka)
Changes:
- Deupe all internal type property getters
- Rename `Base` type to `AbstractBase` (reflecting usage)
- Instantiate `Compact/UInt/Int` with `number` when passed
- Adjust name extraction in `PortableRegistry` (maintainability)
## 8.8.2 Jun 14, 2022
Changes:
@@ -8,7 +8,7 @@ import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types
* @name Base
* @description A type extends the Base class, when it holds a value
*/
export abstract class Base<T extends Codec> implements Codec {
export abstract class AbstractBase<T extends Codec> implements Codec {
public createdAtHash?: IU8a;
public readonly initialU8aLength?: number;
+3 -2
View File
@@ -1,5 +1,6 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { AbstractArray } from './AbstractArray';
export { AbstractInt } from './AbstractInt';
export { AbstractArray } from './Array';
export { AbstractBase } from './Base';
export { AbstractInt } from './Int';
+1 -1
View File
@@ -3,7 +3,7 @@
import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types';
import { AbstractInt } from '../abstract/AbstractInt';
import { AbstractInt } from '../abstract/Int';
/**
* @name Int
+1 -1
View File
@@ -5,7 +5,7 @@ import type { AnyTupleValue, Codec, CodecClass, Inspect, ITuple, Registry } from
import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
import { AbstractArray } from '../abstract/AbstractArray';
import { AbstractArray } from '../abstract/Array';
import { decodeU8a, mapToTypeMap, typeToConstructor } from '../utils';
type TupleType = (CodecClass | string);
+1 -1
View File
@@ -3,7 +3,7 @@
import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types';
import { AbstractInt } from '../abstract/AbstractInt';
import { AbstractInt } from '../abstract/Int';
/**
* @name UInt
+1 -1
View File
@@ -6,7 +6,7 @@ import type { Codec, CodecClass, Registry } from '../types';
import { assert, compactFromU8aLim, isU8a, logger, u8aToU8a } from '@polkadot/util';
import { AbstractArray } from '../abstract/AbstractArray';
import { AbstractArray } from '../abstract/Array';
import { decodeU8aVec, typeToConstructor } from '../utils';
const MAX_LENGTH = 64 * 1024;
+1 -1
View File
@@ -3,7 +3,7 @@
import type { Codec } from '../types';
import { AbstractArray } from '../abstract/AbstractArray';
import { AbstractArray } from '../abstract/Array';
/**
* @name VecAny
+1 -1
View File
@@ -6,7 +6,7 @@ import type { Codec, CodecClass, Inspect, Registry } from '../types';
import { isU8a, u8aConcatStrict } from '@polkadot/util';
import { AbstractArray } from '../abstract/AbstractArray';
import { AbstractArray } from '../abstract/Array';
import { decodeU8aVec, typeToConstructor } from '../utils';
import { decodeVec } from './Vec';
-1
View File
@@ -1,7 +1,6 @@
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { Base } from './Base';
export { Compact } from './Compact';
export { DoNotConstruct } from './DoNotConstruct';
export { Enum } from './Enum';
+1 -1
View File
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, IMap, Inspect, IU8a, Registry } from '
import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
import { AbstractArray } from '../abstract/AbstractArray';
import { AbstractArray } from '../abstract/Array';
import { Enum } from '../base/Enum';
import { Struct } from '../native/Struct';
import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils';
+3 -3
View File
@@ -5,7 +5,7 @@ import type { Registry } from '@polkadot/types-codec/types';
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
import { Base } from '@polkadot/types-codec';
import { AbstractBase } from '@polkadot/types-codec';
import { isBigInt, isBn, isHex, isNumber, isU8a, u8aConcat, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
@@ -38,7 +38,7 @@ function decodeU8a (registry: Registry, value: Uint8Array): GenericEthereumAccou
const [offset, length] = GenericAccountIndex.readLength(value);
return registry.createTypeUnsafe('AccountIndex', [u8aToBn(value.subarray(offset, offset + length), true)]);
return registry.createTypeUnsafe('AccountIndex', [u8aToBn(value.subarray(offset, offset + length))]);
}
function decodeAddressOrIndex (registry: Registry, value: AnyAddress): GenericEthereumAccountId | GenericAccountIndex {
@@ -61,7 +61,7 @@ function decodeAddressOrIndex (registry: Registry, value: AnyAddress): GenericEt
* we extend from Base with an AccountId/AccountIndex wrapper. Basically the Address
* is encoded as `[ <prefix-byte>, ...publicKey/...bytes ]` as per spec
*/
export class GenericEthereumLookupSource extends Base<GenericEthereumAccountId | GenericAccountIndex> {
export class GenericEthereumLookupSource extends AbstractBase<GenericEthereumAccountId | GenericAccountIndex> {
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
super(registry, decodeAddressOrIndex(registry, value));
}
+2 -2
View File
@@ -10,7 +10,7 @@ import type { CallBase, ExtrinsicPayloadValue, ICompact, IExtrinsic, IKeyringPai
import type { GenericExtrinsicEra } from './ExtrinsicEra';
import type { ExtrinsicValueV4 } from './v4/Extrinsic';
import { Base } from '@polkadot/types-codec';
import { AbstractBase } from '@polkadot/types-codec';
import { assert, compactAddLength, compactFromU8a, compactToU8a, isHex, isU8a, objectProperty, objectSpread, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import { BIT_SIGNED, BIT_UNSIGNED, DEFAULT_VERSION, UNMASK_VERSION } from './constants';
@@ -76,7 +76,7 @@ function decodeU8a (registry: Registry, value: Uint8Array, version: number): Ext
return newFromValue(registry, data.subarray(1), data[0]);
}
abstract class ExtrinsicBase<A extends AnyTuple> extends Base<ExtrinsicVx | ExtrinsicUnknown> {
abstract class ExtrinsicBase<A extends AnyTuple> extends AbstractBase<ExtrinsicVx | ExtrinsicUnknown> {
constructor (registry: Registry, value: ExtrinsicV4 | ExtrinsicUnknown, initialU8aLength?: number) {
super(registry, value, initialU8aLength);
@@ -7,7 +7,7 @@ import type { ExtrinsicPayloadV4 } from '../interfaces/extrinsics';
import type { Hash } from '../interfaces/runtime';
import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber } from '../types';
import { Base, Raw } from '@polkadot/types-codec';
import { AbstractBase, Raw } from '@polkadot/types-codec';
import { u8aToHex } from '@polkadot/util';
import { DEFAULT_VERSION } from './constants';
@@ -43,7 +43,7 @@ function decodeExtrinsicPayload (registry: Registry, value?: GenericExtrinsicPay
* A signing payload for an [[Extrinsic]]. For the final encoding, it is variable length based
* on the contents included
*/
export class GenericExtrinsicPayload extends Base<ExtrinsicPayloadVx> {
export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
constructor (registry: Registry, value?: Partial<ExtrinsicPayloadValue> | Uint8Array | string, { version }: ExtrinsicPayloadOptions = {}) {
super(registry, decodeExtrinsicPayload(registry, value as ExtrinsicPayloadValue, version));
}
+3 -3
View File
@@ -5,7 +5,7 @@ import type { Inspect, Registry } from '@polkadot/types-codec/types';
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
import { Base } from '@polkadot/types-codec';
import { AbstractBase } from '@polkadot/types-codec';
import { isBigInt, isBn, isHex, isNumber, isU8a, u8aConcat, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
@@ -38,7 +38,7 @@ function decodeU8a (registry: Registry, value: Uint8Array): GenericAccountId | G
const [offset, length] = GenericAccountIndex.readLength(value);
return registry.createTypeUnsafe('AccountIndex', [u8aToBn(value.subarray(offset, offset + length), true)]);
return registry.createTypeUnsafe('AccountIndex', [u8aToBn(value.subarray(offset, offset + length))]);
}
/** @internal */
@@ -62,7 +62,7 @@ function decodeAddressOrIndex (registry: Registry, value: AnyAddress): GenericAc
* we extend from Base with an AccountId/AccountIndex wrapper. Basically the Address
* is encoded as `[ <prefix-byte>, ...publicKey/...bytes ]` as per spec
*/
export class GenericLookupSource extends Base<GenericAccountId | GenericAccountIndex> {
export class GenericLookupSource extends AbstractBase<GenericAccountId | GenericAccountIndex> {
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
super(registry, decodeAddressOrIndex(registry, value));
}