Adjust internal generic imports (#2838)
This commit is contained in:
@@ -8,7 +8,7 @@ import { Metadata } from '@polkadot/metadata';
|
||||
import rpcMetadata from '@polkadot/metadata/static';
|
||||
|
||||
import { createTypeUnsafe, TypeRegistry } from '../create';
|
||||
import AccountId from '../generic/AccountId';
|
||||
import { GenericAccountId as AccountId } from '../generic';
|
||||
import Text from '../primitive/Text';
|
||||
import { Tuple, Vec } from '.';
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import AccountIndex from '../generic/AccountIndex';
|
||||
import { GenericAccountIndex as AccountIndex } from '../generic';
|
||||
import { GenericEthereumAccountId as AccountId, GenericEthereumLookupSource as Address } from '.';
|
||||
|
||||
describe('EthereumLookupSource', (): void => {
|
||||
|
||||
@@ -8,16 +8,16 @@ import { isBigInt, isBn, isHex, isNumber, isU8a, u8aConcat, u8aToHex, u8aToU8a,
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import { Base } from '../codec/Base';
|
||||
import AccountIndex from '../generic/AccountIndex';
|
||||
import { GenericAccountIndex } from '../generic/AccountIndex';
|
||||
import { GenericEthereumAccountId } from './AccountId';
|
||||
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
type AnyAddress = BigInt | BN | GenericEthereumLookupSource | GenericEthereumAccountId | AccountIndex | number[] | Uint8Array | number | string;
|
||||
type AnyAddress = BigInt | BN | GenericEthereumLookupSource | GenericEthereumAccountId | GenericAccountIndex | number[] | Uint8Array | number | string;
|
||||
|
||||
export const ACCOUNT_ID_PREFIX = new Uint8Array([0xff]);
|
||||
|
||||
/** @internal */
|
||||
function decodeString (registry: Registry, value: string): GenericEthereumAccountId | AccountIndex {
|
||||
function decodeString (registry: Registry, value: string): GenericEthereumAccountId | GenericAccountIndex {
|
||||
const decoded = decodeAddress(value);
|
||||
|
||||
return decoded.length === 20
|
||||
@@ -26,7 +26,7 @@ function decodeString (registry: Registry, value: string): GenericEthereumAccoun
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeU8a (registry: Registry, value: Uint8Array): GenericEthereumAccountId | AccountIndex {
|
||||
function decodeU8a (registry: Registry, value: Uint8Array): GenericEthereumAccountId | GenericAccountIndex {
|
||||
// This allows us to instantiate an address with a raw publicKey. Do this first before
|
||||
// we checking the first byte, otherwise we may split an already-existent valid address
|
||||
if (value.length === 20) {
|
||||
@@ -35,7 +35,7 @@ function decodeU8a (registry: Registry, value: Uint8Array): GenericEthereumAccou
|
||||
return registry.createType('EthereumAccountId', value.subarray(1));
|
||||
}
|
||||
|
||||
const [offset, length] = AccountIndex.readLength(value);
|
||||
const [offset, length] = GenericAccountIndex.readLength(value);
|
||||
|
||||
return registry.createType('AccountIndex', u8aToBn(value.subarray(offset, offset + length), true));
|
||||
}
|
||||
@@ -48,16 +48,16 @@ function decodeU8a (registry: Registry, value: Uint8Array): GenericEthereumAccou
|
||||
* 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 | AccountIndex> {
|
||||
export class GenericEthereumLookupSource extends Base<GenericEthereumAccountId | GenericAccountIndex> {
|
||||
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
|
||||
super(registry, GenericEthereumLookupSource._decodeAddress(registry, value));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static _decodeAddress (registry: Registry, value: AnyAddress): GenericEthereumAccountId | AccountIndex {
|
||||
private static _decodeAddress (registry: Registry, value: AnyAddress): GenericEthereumAccountId | GenericAccountIndex {
|
||||
return value instanceof GenericEthereumLookupSource
|
||||
? value._raw
|
||||
: value instanceof GenericEthereumAccountId || value instanceof AccountIndex
|
||||
: value instanceof GenericEthereumAccountId || value instanceof GenericAccountIndex
|
||||
? value
|
||||
: isBn(value) || isNumber(value) || isBigInt(value)
|
||||
? registry.createType('AccountIndex', value)
|
||||
@@ -84,8 +84,8 @@ export class GenericEthereumLookupSource extends Base<GenericEthereumAccountId |
|
||||
* @description The length of the raw value, either AccountIndex or AccountId
|
||||
*/
|
||||
protected get _rawLength (): number {
|
||||
return this._raw instanceof AccountIndex
|
||||
? AccountIndex.calcLength(this._raw)
|
||||
return this._raw instanceof GenericAccountIndex
|
||||
? GenericAccountIndex.calcLength(this._raw)
|
||||
: this._raw.encodedLength;
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ export class GenericEthereumLookupSource extends Base<GenericEthereumAccountId |
|
||||
return isBare
|
||||
? encoded
|
||||
: u8aConcat(
|
||||
this._raw instanceof AccountIndex
|
||||
? AccountIndex.writeLength(encoded)
|
||||
this._raw instanceof GenericAccountIndex
|
||||
? GenericAccountIndex.writeLength(encoded)
|
||||
: ACCOUNT_ID_PREFIX,
|
||||
encoded
|
||||
);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { assert, compactAddLength, compactFromU8a, isHex, isU8a, u8aConcat, u8aT
|
||||
import { Base } from '../codec/Base';
|
||||
import { Compact } from '../codec/Compact';
|
||||
import { ExtrinsicValueV4 } from './v4/Extrinsic';
|
||||
import ExtrinsicEra from './ExtrinsicEra';
|
||||
import { GenericExtrinsicEra } from './ExtrinsicEra';
|
||||
import { BIT_SIGNED, BIT_UNSIGNED, DEFAULT_VERSION, UNMASK_VERSION } from './constants';
|
||||
|
||||
interface CreateOptions {
|
||||
@@ -66,7 +66,7 @@ abstract class ExtrinsicBase extends Base<ExtrinsicVx | ExtrinsicUnknown> {
|
||||
/**
|
||||
* @description The era for this extrinsic
|
||||
*/
|
||||
public get era (): ExtrinsicEra {
|
||||
public get era (): GenericExtrinsicEra {
|
||||
return (this._raw as ExtrinsicVx).signature.era;
|
||||
}
|
||||
|
||||
@@ -167,14 +167,14 @@ abstract class ExtrinsicBase extends Base<ExtrinsicVx | ExtrinsicUnknown> {
|
||||
* - signed, to create a transaction
|
||||
* - left as is, to create an inherent
|
||||
*/
|
||||
export default class Extrinsic extends ExtrinsicBase implements IExtrinsic {
|
||||
constructor (registry: Registry, value: Extrinsic | ExtrinsicValue | AnyU8a | Call | undefined, { version }: CreateOptions = {}) {
|
||||
super(registry, Extrinsic._decodeExtrinsic(registry, value, version));
|
||||
export class GenericExtrinsic extends ExtrinsicBase implements IExtrinsic {
|
||||
constructor (registry: Registry, value: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call | undefined, { version }: CreateOptions = {}) {
|
||||
super(registry, GenericExtrinsic._decodeExtrinsic(registry, value, version));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static _newFromValue (registry: Registry, value: any, version: number): ExtrinsicVx | ExtrinsicUnknown {
|
||||
if (value instanceof Extrinsic) {
|
||||
if (value instanceof GenericExtrinsic) {
|
||||
return value._raw;
|
||||
}
|
||||
|
||||
@@ -187,20 +187,20 @@ export default class Extrinsic extends ExtrinsicBase implements IExtrinsic {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static _decodeExtrinsic (registry: Registry, value: Extrinsic | ExtrinsicValue | AnyU8a | Call | undefined, version: number = DEFAULT_VERSION): ExtrinsicVx | ExtrinsicUnknown {
|
||||
private static _decodeExtrinsic (registry: Registry, value: GenericExtrinsic | ExtrinsicValue | AnyU8a | Call | undefined, version: number = DEFAULT_VERSION): ExtrinsicVx | ExtrinsicUnknown {
|
||||
if (isU8a(value) || Array.isArray(value) || isHex(value)) {
|
||||
return Extrinsic._decodeU8a(registry, u8aToU8a(value), version);
|
||||
return GenericExtrinsic._decodeU8a(registry, u8aToU8a(value), version);
|
||||
} else if (value instanceof registry.createClass('Call')) {
|
||||
return Extrinsic._newFromValue(registry, { method: value }, version);
|
||||
return GenericExtrinsic._newFromValue(registry, { method: value }, version);
|
||||
}
|
||||
|
||||
return Extrinsic._newFromValue(registry, value, version);
|
||||
return GenericExtrinsic._newFromValue(registry, value, version);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static _decodeU8a (registry: Registry, value: Uint8Array, version: number): ExtrinsicVx | ExtrinsicUnknown {
|
||||
if (!value.length) {
|
||||
return Extrinsic._newFromValue(registry, new Uint8Array(), version);
|
||||
return GenericExtrinsic._newFromValue(registry, new Uint8Array(), version);
|
||||
}
|
||||
|
||||
const [offset, length] = compactFromU8a(value);
|
||||
@@ -210,13 +210,13 @@ export default class Extrinsic extends ExtrinsicBase implements IExtrinsic {
|
||||
|
||||
const data = value.subarray(offset, total);
|
||||
|
||||
return Extrinsic._newFromValue(registry, data.subarray(1), data[0]);
|
||||
return GenericExtrinsic._newFromValue(registry, data.subarray(1), data[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Injects an already-generated signature into the extrinsic
|
||||
*/
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): Extrinsic {
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): GenericExtrinsic {
|
||||
(this._raw as ExtrinsicVx).addSignature(signer, signature, payload);
|
||||
|
||||
return this;
|
||||
@@ -225,7 +225,7 @@ export default class Extrinsic extends ExtrinsicBase implements IExtrinsic {
|
||||
/**
|
||||
* @description Sign the extrinsic with a specific keypair
|
||||
*/
|
||||
public sign (account: IKeyringPair, options: SignatureOptions): Extrinsic {
|
||||
public sign (account: IKeyringPair, options: SignatureOptions): GenericExtrinsic {
|
||||
(this._raw as ExtrinsicVx).sign(account, options);
|
||||
|
||||
return this;
|
||||
@@ -234,7 +234,7 @@ export default class Extrinsic extends ExtrinsicBase implements IExtrinsic {
|
||||
/**
|
||||
* @describe Adds a fake signature to the extrinsic
|
||||
*/
|
||||
public signFake (signer: Address | Uint8Array | string, options: SignatureOptions): Extrinsic {
|
||||
public signFake (signer: Address | Uint8Array | string, options: SignatureOptions): GenericExtrinsic {
|
||||
(this._raw as ExtrinsicVx).signFake(signer, options);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import ExtrinsicEra from './ExtrinsicEra';
|
||||
import { GenericExtrinsicEra as ExtrinsicEra } from '.';
|
||||
|
||||
describe('ExtrinsicEra', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -197,21 +197,21 @@ export class MortalEra extends Tuple {
|
||||
* @description
|
||||
* The era for an extrinsic, indicating either a mortal or immortal extrinsic
|
||||
*/
|
||||
export default class ExtrinsicEra extends Enum implements IExtrinsicEra {
|
||||
export class GenericExtrinsicEra extends Enum implements IExtrinsicEra {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, {
|
||||
ImmortalEra,
|
||||
MortalEra
|
||||
}, ExtrinsicEra._decodeExtrinsicEra(value as string));
|
||||
}, GenericExtrinsicEra._decodeExtrinsicEra(value as string));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
private static _decodeExtrinsicEra (value: IExtrinsicEra | MortalMethod | MortalEnumDef | ImmortalEnumDef | Uint8Array | string = new Uint8Array()): Uint8Array | Object | undefined {
|
||||
if (value instanceof ExtrinsicEra) {
|
||||
return ExtrinsicEra._decodeExtrinsicEra(value.toU8a());
|
||||
if (value instanceof GenericExtrinsicEra) {
|
||||
return GenericExtrinsicEra._decodeExtrinsicEra(value.toU8a());
|
||||
} else if (isHex(value)) {
|
||||
return ExtrinsicEra._decodeExtrinsicEra(hexToU8a(value));
|
||||
return GenericExtrinsicEra._decodeExtrinsicEra(hexToU8a(value));
|
||||
} else if (!value || isU8a(value)) {
|
||||
return (!value?.length || value[0] === 0)
|
||||
? new Uint8Array([0])
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import ExtrinsicPayload from './ExtrinsicPayload';
|
||||
import { GenericExtrinsicPayload as ExtrinsicPayload } from '.';
|
||||
|
||||
describe('ExtrinsicPayload', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Base } from '../codec/Base';
|
||||
import { Compact } from '../codec/Compact';
|
||||
import { Raw } from '../codec/Raw';
|
||||
import u32 from '../primitive/U32';
|
||||
import ExtrinsicEra from './ExtrinsicEra';
|
||||
import { GenericExtrinsicEra } from './ExtrinsicEra';
|
||||
import { DEFAULT_VERSION } from './constants';
|
||||
|
||||
interface ExtrinsicPayloadOptions {
|
||||
@@ -35,14 +35,14 @@ const VERSIONS: (keyof InterfaceTypes)[] = [
|
||||
* A signing payload for an [[Extrinsic]]. For the final encoding, it is variable length based
|
||||
* on the contents included
|
||||
*/
|
||||
export default class ExtrinsicPayload extends Base<ExtrinsicPayloadVx> {
|
||||
export class GenericExtrinsicPayload extends Base<ExtrinsicPayloadVx> {
|
||||
constructor (registry: Registry, value: Partial<ExtrinsicPayloadValue> | Uint8Array | string | undefined, { version }: ExtrinsicPayloadOptions = {}) {
|
||||
super(registry, ExtrinsicPayload.decodeExtrinsicPayload(registry, value as ExtrinsicPayloadValue, version));
|
||||
super(registry, GenericExtrinsicPayload.decodeExtrinsicPayload(registry, value as ExtrinsicPayloadValue, version));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static decodeExtrinsicPayload (registry: Registry, value: ExtrinsicPayload | ExtrinsicPayloadValue | Uint8Array | string | undefined, version: number = DEFAULT_VERSION): ExtrinsicPayloadVx {
|
||||
if (value instanceof ExtrinsicPayload) {
|
||||
public static decodeExtrinsicPayload (registry: Registry, value: GenericExtrinsicPayload | ExtrinsicPayloadValue | Uint8Array | string | undefined, version: number = DEFAULT_VERSION): ExtrinsicPayloadVx {
|
||||
if (value instanceof GenericExtrinsicPayload) {
|
||||
return value._raw;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export default class ExtrinsicPayload extends Base<ExtrinsicPayloadVx> {
|
||||
/**
|
||||
* @description The [[ExtrinsicEra]]
|
||||
*/
|
||||
public get era (): ExtrinsicEra {
|
||||
public get era (): GenericExtrinsicEra {
|
||||
return this._raw.era;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Struct } from '../codec/Struct';
|
||||
* @description
|
||||
* A default handler for payloads where the version is not known (default throw)
|
||||
*/
|
||||
export default class ExtrinsicPayloadUnknown extends Struct {
|
||||
export class GenericExtrinsicPayloadUnknown extends Struct {
|
||||
constructor (registry: Registry, value?: unknown, { version = 0 }: Partial<ExtrinsicPayloadOptions> = {}) {
|
||||
super(registry, {});
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { UNMASK_VERSION } from './constants';
|
||||
* @description
|
||||
* A default handler for extrinsics where the version is not known (default throw)
|
||||
*/
|
||||
export default class ExtrinsicUnknown extends Struct {
|
||||
export class GenericExtrinsicUnknown extends Struct {
|
||||
constructor (registry: Registry, value?: unknown, { isSigned = false, version = 0 }: Partial<ExtrinsicOptions> = {}) {
|
||||
super(registry, {});
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Metadata } from '@polkadot/metadata';
|
||||
import rpcMetadata from '@polkadot/metadata/static';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import SignerPayload from './SignerPayload';
|
||||
import { GenericSignerPayload as SignerPayload } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, rpcMetadata);
|
||||
|
||||
@@ -43,11 +43,11 @@ const _Payload = Struct.with({
|
||||
}) as unknown as Constructor<SignerPayloadType>;
|
||||
|
||||
/**
|
||||
* @name SignerPayload
|
||||
* @name GenericSignerPayload
|
||||
* @description
|
||||
* A generic signer payload that can be used for serialization between API and signer
|
||||
*/
|
||||
export default class SignerPayload extends _Payload implements ISignerPayload {
|
||||
export class GenericSignerPayload extends _Payload implements ISignerPayload {
|
||||
/**
|
||||
* @description Creates an representation of the structure as an ISignerPayload JSON
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as GenericExtrinsic } from './Extrinsic';
|
||||
export { default as GenericExtrinsicEra, MortalEra as GenericMortalEra, ImmortalEra as GenericImmortalEra } from './ExtrinsicEra';
|
||||
export { default as GenericExtrinsicPayload } from './ExtrinsicPayload';
|
||||
export { default as GenericExtrinsicPayloadUnknown } from './ExtrinsicPayloadUnknown';
|
||||
export { default as GenericExtrinsicUnknown } from './ExtrinsicUnknown';
|
||||
export { default as GenericSignerPayload } from './SignerPayload';
|
||||
export { GenericExtrinsic } from './Extrinsic';
|
||||
export { GenericExtrinsicEra, MortalEra as GenericMortalEra, ImmortalEra as GenericImmortalEra } from './ExtrinsicEra';
|
||||
export { GenericExtrinsicPayload } from './ExtrinsicPayload';
|
||||
export { GenericExtrinsicPayloadUnknown } from './ExtrinsicPayloadUnknown';
|
||||
export { GenericExtrinsicUnknown } from './ExtrinsicUnknown';
|
||||
export { GenericSignerPayload } from './SignerPayload';
|
||||
|
||||
export * from './v4';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export default {
|
||||
export const emptyCheck = {
|
||||
extra: {},
|
||||
types: {}
|
||||
};
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
import { ExtDef } from './types';
|
||||
|
||||
import EmptyCheck from './emptyCheck';
|
||||
import { emptyCheck } from './emptyCheck';
|
||||
|
||||
export default {
|
||||
LimitParathreadCommits: EmptyCheck,
|
||||
OnlyStakingAndClaims: EmptyCheck,
|
||||
PrevalidateAttests: EmptyCheck,
|
||||
RestrictFunctionality: EmptyCheck,
|
||||
TransactionCallFilter: EmptyCheck,
|
||||
ValidateDoubleVoteReports: EmptyCheck
|
||||
LimitParathreadCommits: emptyCheck,
|
||||
OnlyStakingAndClaims: emptyCheck,
|
||||
PrevalidateAttests: emptyCheck,
|
||||
RestrictFunctionality: emptyCheck,
|
||||
TransactionCallFilter: emptyCheck,
|
||||
ValidateDoubleVoteReports: emptyCheck
|
||||
} as ExtDef;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { ExtDef } from './types';
|
||||
|
||||
import EmptyCheck from './emptyCheck';
|
||||
import { emptyCheck } from './emptyCheck';
|
||||
|
||||
const CheckMortality = {
|
||||
extra: {
|
||||
@@ -21,7 +21,7 @@ export default {
|
||||
tip: 'Compact<Balance>'
|
||||
}
|
||||
},
|
||||
CheckBlockGasLimit: EmptyCheck,
|
||||
CheckBlockGasLimit: emptyCheck,
|
||||
CheckEra: CheckMortality,
|
||||
CheckGenesis: {
|
||||
extra: {
|
||||
@@ -54,7 +54,7 @@ export default {
|
||||
},
|
||||
types: {}
|
||||
},
|
||||
CheckWeight: EmptyCheck,
|
||||
LockStakingStatus: EmptyCheck,
|
||||
ValidateEquivocationReport: EmptyCheck
|
||||
CheckWeight: emptyCheck,
|
||||
LockStakingStatus: emptyCheck,
|
||||
ValidateEquivocationReport: emptyCheck
|
||||
} as ExtDef;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Metadata, extrinsicsFromMeta } from '@polkadot/metadata';
|
||||
import rpcMetadata from '@polkadot/metadata/static';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import Extrinsic from './Extrinsic';
|
||||
import { GenericExtrinsicV4 as Extrinsic } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, rpcMetadata);
|
||||
|
||||
@@ -22,18 +22,18 @@ export interface ExtrinsicValueV4 {
|
||||
* @description
|
||||
* The third generation of compact extrinsics
|
||||
*/
|
||||
export default class ExtrinsicV4 extends Struct implements IExtrinsicImpl {
|
||||
export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl {
|
||||
constructor (registry: Registry, value?: Uint8Array | ExtrinsicValueV4 | Call, { isSigned }: Partial<ExtrinsicOptions> = {}) {
|
||||
super(registry, {
|
||||
signature: 'ExtrinsicSignatureV4',
|
||||
// eslint-disable-next-line sort-keys
|
||||
method: 'Call'
|
||||
}, ExtrinsicV4.decodeExtrinsic(registry, value, isSigned));
|
||||
}, GenericExtrinsicV4.decodeExtrinsic(registry, value, isSigned));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static decodeExtrinsic (registry: Registry, value?: Call | Uint8Array | ExtrinsicValueV4, isSigned = false): ExtrinsicValueV4 {
|
||||
if (value instanceof ExtrinsicV4) {
|
||||
if (value instanceof GenericExtrinsicV4) {
|
||||
return value;
|
||||
} else if (value instanceof registry.createClass('Call')) {
|
||||
return { method: value };
|
||||
@@ -82,7 +82,7 @@ export default class ExtrinsicV4 extends Struct implements IExtrinsicImpl {
|
||||
/**
|
||||
* @description Add an [[ExtrinsicSignatureV4]] to the extrinsic (already generated)
|
||||
*/
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): ExtrinsicV4 {
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): GenericExtrinsicV4 {
|
||||
this.signature.addSignature(signer, signature, payload);
|
||||
|
||||
return this;
|
||||
@@ -91,7 +91,7 @@ export default class ExtrinsicV4 extends Struct implements IExtrinsicImpl {
|
||||
/**
|
||||
* @description Sign the extrinsic with a specific keypair
|
||||
*/
|
||||
public sign (account: IKeyringPair, options: SignatureOptions): ExtrinsicV4 {
|
||||
public sign (account: IKeyringPair, options: SignatureOptions): GenericExtrinsicV4 {
|
||||
this.signature.sign(this.method, account, options);
|
||||
|
||||
return this;
|
||||
@@ -100,7 +100,7 @@ export default class ExtrinsicV4 extends Struct implements IExtrinsicImpl {
|
||||
/**
|
||||
* @describe Adds a fake signature to the extrinsic
|
||||
*/
|
||||
public signFake (signer: Address | Uint8Array | string, options: SignatureOptions): ExtrinsicV4 {
|
||||
public signFake (signer: Address | Uint8Array | string, options: SignatureOptions): GenericExtrinsicV4 {
|
||||
this.signature.signFake(this.method, signer, options);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -17,7 +17,7 @@ import { sign } from '../util';
|
||||
* A signing payload for an [[Extrinsic]]. For the final encoding, it is variable length based
|
||||
* on the contents included
|
||||
*/
|
||||
export default class ExtrinsicPayloadV4 extends Struct {
|
||||
export class GenericExtrinsicPayloadV4 extends Struct {
|
||||
constructor (registry: Registry, value?: ExtrinsicPayloadValue | Uint8Array | string) {
|
||||
super(registry, {
|
||||
method: 'Bytes',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import ExtrinsicSignature from './ExtrinsicSignature';
|
||||
import { GenericExtrinsicSignatureV4 as ExtrinsicSignature } from '.';
|
||||
|
||||
describe('ExtrinsicSignatureV4', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -11,28 +11,28 @@ import { u8aConcat } from '@polkadot/util';
|
||||
import { Compact } from '../../codec/Compact';
|
||||
import { Struct } from '../../codec/Struct';
|
||||
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
|
||||
import ExtrinsicPayloadV4 from './ExtrinsicPayload';
|
||||
import { GenericExtrinsicPayloadV4 } from './ExtrinsicPayload';
|
||||
|
||||
/**
|
||||
* @name GenericExtrinsicSignatureV4
|
||||
* @description
|
||||
* A container for the [[Signature]] associated with a specific [[Extrinsic]]
|
||||
*/
|
||||
export default class ExtrinsicSignatureV4 extends Struct implements IExtrinsicSignature {
|
||||
constructor (registry: Registry, value: ExtrinsicSignatureV4 | Uint8Array | undefined, { isSigned }: ExtrinsicSignatureOptions = {}) {
|
||||
export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSignature {
|
||||
constructor (registry: Registry, value: GenericExtrinsicSignatureV4 | Uint8Array | undefined, { isSigned }: ExtrinsicSignatureOptions = {}) {
|
||||
super(registry, {
|
||||
signer: 'Address',
|
||||
// eslint-disable-next-line sort-keys
|
||||
signature: 'MultiSignature',
|
||||
...registry.getSignedExtensionTypes()
|
||||
}, ExtrinsicSignatureV4.decodeExtrinsicSignature(value, isSigned));
|
||||
}, GenericExtrinsicSignatureV4.decodeExtrinsicSignature(value, isSigned));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static decodeExtrinsicSignature (value: ExtrinsicSignatureV4 | Uint8Array | undefined, isSigned = false): ExtrinsicSignatureV4 | Uint8Array {
|
||||
public static decodeExtrinsicSignature (value: GenericExtrinsicSignatureV4 | Uint8Array | undefined, isSigned = false): GenericExtrinsicSignatureV4 | Uint8Array {
|
||||
if (!value) {
|
||||
return EMPTY_U8A;
|
||||
} else if (value instanceof ExtrinsicSignatureV4) {
|
||||
} else if (value instanceof GenericExtrinsicSignatureV4) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ export default class ExtrinsicSignatureV4 extends Struct implements IExtrinsicSi
|
||||
return this.get('tip') as Compact<Balance>;
|
||||
}
|
||||
|
||||
protected _injectSignature (signer: Address, signature: MultiSignature, { era, nonce, tip }: ExtrinsicPayloadV4): IExtrinsicSignature {
|
||||
protected _injectSignature (signer: Address, signature: MultiSignature, { era, nonce, tip }: GenericExtrinsicPayloadV4): IExtrinsicSignature {
|
||||
this.set('era', era);
|
||||
this.set('nonce', nonce);
|
||||
this.set('signer', signer);
|
||||
@@ -116,15 +116,15 @@ export default class ExtrinsicSignatureV4 extends Struct implements IExtrinsicSi
|
||||
return this._injectSignature(
|
||||
this.registry.createType('Address', signer),
|
||||
this.registry.createType('MultiSignature', signature),
|
||||
new ExtrinsicPayloadV4(this.registry, payload)
|
||||
new GenericExtrinsicPayloadV4(this.registry, payload)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Creates a payload from the supplied options
|
||||
*/
|
||||
public createPayload (method: Call, { blockHash, era, genesisHash, nonce, runtimeVersion: { specVersion, transactionVersion }, tip }: SignatureOptions): ExtrinsicPayloadV4 {
|
||||
return new ExtrinsicPayloadV4(this.registry, {
|
||||
public createPayload (method: Call, { blockHash, era, genesisHash, nonce, runtimeVersion: { specVersion, transactionVersion }, tip }: SignatureOptions): GenericExtrinsicPayloadV4 {
|
||||
return new GenericExtrinsicPayloadV4(this.registry, {
|
||||
blockHash,
|
||||
era: era || IMMORTAL_ERA,
|
||||
genesisHash,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as GenericExtrinsicV4 } from './Extrinsic';
|
||||
export { default as GenericExtrinsicPayloadV4 } from './ExtrinsicPayload';
|
||||
export { default as GenericExtrinsicSignatureV4 } from './ExtrinsicSignature';
|
||||
export { GenericExtrinsicV4 } from './Extrinsic';
|
||||
export { GenericExtrinsicPayloadV4 } from './ExtrinsicPayload';
|
||||
export { GenericExtrinsicSignatureV4 } from './ExtrinsicSignature';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Raw } from '../codec/Raw';
|
||||
import jsonVec from '../json/AccountIdVec.001.json';
|
||||
import AccountId from './AccountId';
|
||||
import { GenericAccountId as AccountId } from '.';
|
||||
|
||||
describe('AccountId', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -24,13 +24,13 @@ function decodeAccountId (value?: AnyU8a | AnyString): Uint8Array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name AccountId
|
||||
* @name GenericAccountId
|
||||
* @description
|
||||
* A wrapper around an AccountId/PublicKey representation. Since we are dealing with
|
||||
* underlying PublicKeys (32 bytes in length), we extend from U8aFixed which is
|
||||
* just a Uint8Array wrapper with a fixed length.
|
||||
*/
|
||||
export default class AccountId extends U8aFixed {
|
||||
export class GenericAccountId extends U8aFixed {
|
||||
constructor (registry: Registry, value?: AnyU8a) {
|
||||
const decoded = decodeAccountId(value);
|
||||
|
||||
@@ -69,7 +69,7 @@ export default class AccountId extends U8aFixed {
|
||||
* @description Returns the string representation of the value
|
||||
*/
|
||||
public toString (): string {
|
||||
return AccountId.encode(this, this.registry.chainSS58);
|
||||
return GenericAccountId.encode(this, this.registry.chainSS58);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import AccountIndex from './AccountIndex';
|
||||
import { GenericAccountIndex as AccountIndex } from '.';
|
||||
|
||||
describe('AccountIndex', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -22,7 +22,7 @@ const MAX_4BYTE = new BN(1).shln(32);
|
||||
/** @internal */
|
||||
function decodeAccountIndex (value: AnyNumber): BN | BigInt | Uint8Array | number | string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
if (value instanceof AccountIndex) {
|
||||
if (value instanceof GenericAccountIndex) {
|
||||
// `value.toBn()` on AccountIndex returns a pure BN (i.e. not an
|
||||
// AccountIndex), which has the initial `toString()` implementation.
|
||||
return value.toBn();
|
||||
@@ -34,12 +34,12 @@ function decodeAccountIndex (value: AnyNumber): BN | BigInt | Uint8Array | numbe
|
||||
}
|
||||
|
||||
/**
|
||||
* @name AccountIndex
|
||||
* @name GenericAccountIndex
|
||||
* @description
|
||||
* A wrapper around an AccountIndex, which is a shortened, variable-length encoding
|
||||
* for an Account. We extends from [[U32]] to provide the number-like properties.
|
||||
*/
|
||||
export default class AccountIndex extends U32 {
|
||||
export class GenericAccountIndex extends U32 {
|
||||
constructor (registry: Registry, value: AnyNumber = new BN(0)) {
|
||||
super(registry, decodeAccountIndex(value));
|
||||
}
|
||||
@@ -112,7 +112,7 @@ export default class AccountIndex extends U32 {
|
||||
* @description Returns the string representation of the value
|
||||
*/
|
||||
public toString (): string {
|
||||
const length = AccountIndex.calcLength(this);
|
||||
const length = GenericAccountIndex.calcLength(this);
|
||||
|
||||
return encodeAddress(this.toU8a().subarray(0, length), this.registry.chainSS58);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import metadataStatic from '@polkadot/metadata/static';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import block00300 from '../json/SignedBlock.003.00.json';
|
||||
import Block from './Block';
|
||||
import { GenericBlock as Block } from './Block';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, metadataStatic);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { Digest, DigestItem, H256, Header } from '../interfaces/runtime';
|
||||
import { AnyNumber, AnyU8a, Registry } from '../types';
|
||||
|
||||
import Extrinsic from '../extrinsic/Extrinsic';
|
||||
import { GenericExtrinsic } from '../extrinsic/Extrinsic';
|
||||
import { Struct } from '../codec/Struct';
|
||||
import { Vec } from '../codec/Vec';
|
||||
|
||||
@@ -22,11 +22,11 @@ export interface BlockValue {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Block
|
||||
* @name GenericBlock
|
||||
* @description
|
||||
* A block encoded with header and extrinsics
|
||||
*/
|
||||
export default class Block extends Struct {
|
||||
export class GenericBlock extends Struct {
|
||||
constructor (registry: Registry, value?: BlockValue | Uint8Array) {
|
||||
super(registry, {
|
||||
header: 'Header',
|
||||
@@ -45,8 +45,8 @@ export default class Block extends Struct {
|
||||
/**
|
||||
* @description The [[Extrinsic]] contained in the block
|
||||
*/
|
||||
public get extrinsics (): Vec<Extrinsic> {
|
||||
return this.get('extrinsics') as Vec<Extrinsic>;
|
||||
public get extrinsics (): Vec<GenericExtrinsic> {
|
||||
return this.get('extrinsics') as Vec<GenericExtrinsic>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Metadata } from '@polkadot/metadata';
|
||||
import metadataStatic from '@polkadot/metadata/static';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import Call from './Call';
|
||||
import { GenericCall as Call } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, metadataStatic);
|
||||
|
||||
@@ -13,7 +13,7 @@ import { U8aFixed } from '../codec/U8aFixed';
|
||||
interface DecodeMethodInput {
|
||||
args: unknown;
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
callIndex: CallIndex | Uint8Array;
|
||||
callIndex: GenericCallIndex | Uint8Array;
|
||||
}
|
||||
|
||||
interface DecodedMethod extends DecodeMethodInput {
|
||||
@@ -30,7 +30,7 @@ interface DecodedMethod extends DecodeMethodInput {
|
||||
*/
|
||||
function getArgsDef (registry: Registry, meta: FunctionMetadataLatest): ArgsDef {
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
return Call.filterOrigin(meta).reduce((result, { name, type }): ArgsDef => {
|
||||
return GenericCall.filterOrigin(meta).reduce((result, { name, type }): ArgsDef => {
|
||||
const Type = getTypeClass(registry, getTypeDef(type));
|
||||
|
||||
result[name.toString()] = Type;
|
||||
@@ -46,7 +46,7 @@ function decodeCallViaObject (registry: Registry, value: DecodedMethod, _meta?:
|
||||
|
||||
// Get the correct lookupIndex
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
const lookupIndex = callIndex instanceof CallIndex
|
||||
const lookupIndex = callIndex instanceof GenericCallIndex
|
||||
? callIndex.toU8a()
|
||||
: callIndex;
|
||||
|
||||
@@ -101,22 +101,22 @@ function decodeCall (registry: Registry, value: unknown | DecodedMethod | Uint8A
|
||||
}
|
||||
|
||||
/**
|
||||
* @name CallIndex
|
||||
* @name GenericCallIndex
|
||||
* @description
|
||||
* A wrapper around the `[sectionIndex, methodIndex]` value that uniquely identifies a method
|
||||
*/
|
||||
export class CallIndex extends U8aFixed {
|
||||
export class GenericCallIndex extends U8aFixed {
|
||||
constructor (registry: Registry, value?: AnyU8a) {
|
||||
super(registry, value, 16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Call
|
||||
* @name GenericCall
|
||||
* @description
|
||||
* Extrinsic function descriptor
|
||||
*/
|
||||
export default class Call extends Struct implements IMethod {
|
||||
export class GenericCall extends Struct implements IMethod {
|
||||
protected _meta: FunctionMetadataLatest;
|
||||
|
||||
constructor (registry: Registry, value: unknown, meta?: FunctionMetadataLatest) {
|
||||
@@ -124,7 +124,7 @@ export default class Call extends Struct implements IMethod {
|
||||
|
||||
try {
|
||||
super(registry, {
|
||||
callIndex: CallIndex,
|
||||
callIndex: GenericCallIndex,
|
||||
// eslint-disable-next-line sort-keys
|
||||
args: Struct.with(decoded.argsDef)
|
||||
}, decoded);
|
||||
@@ -174,7 +174,7 @@ export default class Call extends Struct implements IMethod {
|
||||
* @description The encoded `[sectionIndex, methodIndex]` identifier
|
||||
*/
|
||||
public get callIndex (): Uint8Array {
|
||||
return (this.get('callIndex') as CallIndex).toU8a();
|
||||
return (this.get('callIndex') as GenericCallIndex).toU8a();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import ConsensusEngineId, { CID_AURA, CID_BABE, CID_GRPA } from './ConsensusEngineId';
|
||||
import { GenericConsensusEngineId as ConsensusEngineId, CID_AURA, CID_BABE, CID_GRPA } from './ConsensusEngineId';
|
||||
|
||||
describe('ConsensusEngineId', (): void => {
|
||||
it('creates a valid id for aura', (): void => {
|
||||
|
||||
@@ -19,11 +19,11 @@ const CID_POW = 0x5f776f70; // 'pow_'
|
||||
export { CID_AURA, CID_BABE, CID_GRPA, CID_POW };
|
||||
|
||||
/**
|
||||
* @name ConsensusEngineId
|
||||
* @name GenericConsensusEngineId
|
||||
* @description
|
||||
* A 4-byte identifier (actually a [u8; 4]) identifying the engine, e.g. for Aura it would be [b'a', b'u', b'r', b'a']
|
||||
*/
|
||||
export default class ConsensusEngineId extends U32 {
|
||||
export class GenericConsensusEngineId extends U32 {
|
||||
public static idToString (input: number | BN): string {
|
||||
return bnToBn(input)
|
||||
.toArray('le')
|
||||
@@ -110,6 +110,6 @@ export default class ConsensusEngineId extends U32 {
|
||||
* @description Override the default toString to return a 4-byte string
|
||||
*/
|
||||
public toString (): string {
|
||||
return ConsensusEngineId.idToString(this as BN);
|
||||
return GenericConsensusEngineId.idToString(this as BN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,16 +63,16 @@ export class EventData extends Tuple {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Event
|
||||
* @name GenericEvent
|
||||
* @description
|
||||
* A representation of a system event. These are generated via the [[Metadata]] interfaces and
|
||||
* specific to a specific Substrate runtime
|
||||
*/
|
||||
export default class Event extends Struct {
|
||||
export class GenericEvent extends Struct {
|
||||
// Currently we _only_ decode from Uint8Array, since we expect it to
|
||||
// be used via EventRecord
|
||||
constructor (registry: Registry, _value?: Uint8Array) {
|
||||
const { DataType, value } = Event.decodeEvent(registry, _value);
|
||||
const { DataType, value } = GenericEvent.decodeEvent(registry, _value);
|
||||
|
||||
super(registry, {
|
||||
index: 'EventId',
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import AccountId from './AccountId';
|
||||
import AccountIndex from './AccountIndex';
|
||||
import LookupSource from './LookupSource';
|
||||
import { GenericAccountId as AccountId, GenericAccountIndex as AccountIndex, GenericLookupSource as LookuoSource } from '.';
|
||||
|
||||
describe('LookupSource', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
const testDecode = (type: string, input: LookupSource | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
|
||||
const testDecode = (type: string, input: LookuoSource | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const a = registry.createType('Address', input);
|
||||
|
||||
|
||||
@@ -8,16 +8,16 @@ import { isBigInt, isBn, isHex, isNumber, isU8a, u8aConcat, u8aToHex, u8aToU8a,
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import { Base } from '../codec/Base';
|
||||
import AccountId from './AccountId';
|
||||
import AccountIndex from './AccountIndex';
|
||||
import { GenericAccountId } from './AccountId';
|
||||
import { GenericAccountIndex } from './AccountIndex';
|
||||
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
type AnyAddress = BigInt | BN | LookupSource | AccountId | AccountIndex | number[] | Uint8Array | number | string;
|
||||
type AnyAddress = BigInt | BN | GenericLookupSource | GenericAccountId | GenericAccountIndex | number[] | Uint8Array | number | string;
|
||||
|
||||
export const ACCOUNT_ID_PREFIX = new Uint8Array([0xff]);
|
||||
|
||||
/** @internal */
|
||||
function decodeString (registry: Registry, value: string): AccountId | AccountIndex {
|
||||
function decodeString (registry: Registry, value: string): GenericAccountId | GenericAccountIndex {
|
||||
const decoded = decodeAddress(value);
|
||||
|
||||
return decoded.length === 32
|
||||
@@ -26,7 +26,7 @@ function decodeString (registry: Registry, value: string): AccountId | AccountIn
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeU8a (registry: Registry, value: Uint8Array): AccountId | AccountIndex {
|
||||
function decodeU8a (registry: Registry, value: Uint8Array): GenericAccountId | GenericAccountIndex {
|
||||
// This allows us to instantiate an address with a raw publicKey. Do this first before
|
||||
// we checking the first byte, otherwise we may split an already-existent valid address
|
||||
if (value.length === 32) {
|
||||
@@ -35,7 +35,7 @@ function decodeU8a (registry: Registry, value: Uint8Array): AccountId | AccountI
|
||||
return registry.createType('AccountId', value.subarray(1));
|
||||
}
|
||||
|
||||
const [offset, length] = AccountIndex.readLength(value);
|
||||
const [offset, length] = GenericAccountIndex.readLength(value);
|
||||
|
||||
return registry.createType('AccountIndex', u8aToBn(value.subarray(offset, offset + length), true));
|
||||
}
|
||||
@@ -48,16 +48,16 @@ function decodeU8a (registry: Registry, value: Uint8Array): AccountId | AccountI
|
||||
* we extend from Base with an AccountId/AccountIndex wrapper. Basically the Address
|
||||
* is encoded as `[ <prefix-byte>, ...publicKey/...bytes ]` as per spec
|
||||
*/
|
||||
export default class LookupSource extends Base<AccountId | AccountIndex> {
|
||||
export class GenericLookupSource extends Base<GenericAccountId | GenericAccountIndex> {
|
||||
constructor (registry: Registry, value: AnyAddress = new Uint8Array()) {
|
||||
super(registry, LookupSource._decodeAddress(registry, value));
|
||||
super(registry, GenericLookupSource._decodeAddress(registry, value));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
private static _decodeAddress (registry: Registry, value: AnyAddress): AccountId | AccountIndex {
|
||||
return value instanceof LookupSource
|
||||
private static _decodeAddress (registry: Registry, value: AnyAddress): GenericAccountId | GenericAccountIndex {
|
||||
return value instanceof GenericLookupSource
|
||||
? value._raw
|
||||
: value instanceof AccountId || value instanceof AccountIndex
|
||||
: value instanceof GenericAccountId || value instanceof GenericAccountIndex
|
||||
? value
|
||||
: isBn(value) || isNumber(value) || isBigInt(value)
|
||||
? registry.createType('AccountIndex', value)
|
||||
@@ -84,8 +84,8 @@ export default class LookupSource extends Base<AccountId | AccountIndex> {
|
||||
* @description The length of the raw value, either AccountIndex or AccountId
|
||||
*/
|
||||
protected get _rawLength (): number {
|
||||
return this._raw instanceof AccountIndex
|
||||
? AccountIndex.calcLength(this._raw)
|
||||
return this._raw instanceof GenericAccountIndex
|
||||
? GenericAccountIndex.calcLength(this._raw)
|
||||
: this._raw.encodedLength;
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ export default class LookupSource extends Base<AccountId | AccountIndex> {
|
||||
return isBare
|
||||
? encoded
|
||||
: u8aConcat(
|
||||
this._raw instanceof AccountIndex
|
||||
? AccountIndex.writeLength(encoded)
|
||||
this._raw instanceof GenericAccountIndex
|
||||
? GenericAccountIndex.writeLength(encoded)
|
||||
: ACCOUNT_ID_PREFIX,
|
||||
encoded
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
import { Enum } from '../codec/Enum';
|
||||
|
||||
export default class MultiAddress extends Enum {
|
||||
export class GenericMultiAddress extends Enum {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, {
|
||||
Id: 'AccountId',
|
||||
@@ -18,7 +18,7 @@ export default class MultiAddress extends Enum {
|
||||
Address32: 'H256',
|
||||
// eslint-disable-next-line sort-keys
|
||||
Address20: 'H160'
|
||||
}, MultiAddress._decodeMultiAddress(value as string));
|
||||
}, GenericMultiAddress._decodeMultiAddress(value as string));
|
||||
}
|
||||
|
||||
private static _decodeMultiAddress (value?: unknown): unknown {
|
||||
|
||||
@@ -60,11 +60,11 @@ function decodeVote (registry: Registry, value?: InputTypes): Uint8Array {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Vote
|
||||
* @name GenericVote
|
||||
* @description
|
||||
* A number of lock periods, plus a vote, one way or the other.
|
||||
*/
|
||||
export default class Vote extends U8aFixed {
|
||||
export class GenericVote extends U8aFixed {
|
||||
private _aye: boolean;
|
||||
|
||||
private _conviction: Conviction;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
|
||||
export * from '../ethereum';
|
||||
|
||||
export { default as GenericAccountId } from './AccountId';
|
||||
export { default as GenericAccountIndex } from './AccountIndex';
|
||||
export { default as GenericBlock } from './Block';
|
||||
export { default as GenericCall } from './Call';
|
||||
export { default as GenericConsensusEngineId } from './ConsensusEngineId';
|
||||
export { default as GenericEvent } from './Event';
|
||||
export { default as GenericLookupSource } from './LookupSource';
|
||||
export { default as GenericMultiAddress } from './MultiAddress';
|
||||
export { default as GenericVote } from './Vote';
|
||||
export { GenericAccountId } from './AccountId';
|
||||
export { GenericAccountIndex } from './AccountIndex';
|
||||
export { GenericBlock } from './Block';
|
||||
export { GenericCall } from './Call';
|
||||
export { GenericConsensusEngineId } from './ConsensusEngineId';
|
||||
export { GenericEvent } from './Event';
|
||||
export { GenericLookupSource } from './LookupSource';
|
||||
export { GenericMultiAddress } from './MultiAddress';
|
||||
export { GenericVote } from './Vote';
|
||||
|
||||
Reference in New Issue
Block a user