Revert all recent $ renames (#5429)
* Revert "[CI Skip] bump/beta 9.11.4-6-x" This reverts commit7ee4f7aaf8. * Revert "Rename Code .registry to .$registry (#5428)" This reverts commitdd6826fadd. * Revert "[CI Skip] bump/beta 9.11.4-5-x" This reverts commitabc68bf2e2. * Revert "Convert encodedLength to $encodedLength (#5426)" This reverts commitccab89304b. * Revert "[CI Skip] bump/beta 9.11.4-4-x" This reverts commit044465eee4. * Revert "Rename inspect() to inspectU8a() (#5425)" This reverts commit42af205546. * Revert "[CI Skip] bump/beta 9.11.4-3-x" This reverts commit545ad50097. * Revert "Move .isEmpty to $isEmpty (#5424)" This reverts commit6f19084a4d. * Revert "[CI Skip] bump/beta 9.11.4-2-x" This reverts commit4688291ecf. * Revert "Warn on deprecated getter usage (#5423)" This reverts commitda1cf9d64e. * Revert "[CI Skip] bump/beta 9.11.4-1-x" This reverts commit96a3ef51f0. * Revert "Revert "[CI Skip] bump/beta 9.11.4-1-x"" This reverts commit 2eca0730a630d587878f12c141e21ea631dcdd19. * Revert "Revert "[CI Skip] bump/beta 9.11.4-2-x"" This reverts commit 66284b40692071aa03a1064997c9402fc0b0987c. * Revert "Revert "[CI Skip] bump/beta 9.11.4-3-x"" This reverts commit 9b820eaefccdb7b51d893000e5480d11e5195e22. * Revert "Revert "[CI Skip] bump/beta 9.11.4-4-x"" This reverts commit cb5149adf98a5eefd8da61b8793707f85deb7c09. * Revert "Revert "[CI Skip] bump/beta 9.11.4-5-x"" This reverts commit 489a64439860fefba163695ec36b319dcb1eeddc. * Revert "Revert "[CI Skip] bump/beta 9.11.4-6-x"" This reverts commit 34a0fd4e2784a1b40ea8e06534d1f39328250e7a. * Adjust linebreaks * Adjust isStorageFallback naming * Fix build
This commit is contained in:
+1
-5
@@ -2,13 +2,9 @@
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
- **Breaking change** The `Codec.inspect()` call has been renamed to `Codec.inspectU8a()`. This should not only have a minor impact on (very limited) users since the functionality is not used in general operation, but rather only in specialized tools that wish the inspect the actual bytes encoding.
|
|
||||||
|
|
||||||
Changes:
|
Changes:
|
||||||
|
|
||||||
- Add `$isStorageFallback` on the `Codec` interface. (`true` if entry was created from a metadata fallback value from an empty storage item)
|
- Add `isStorageFallback` on the `Codec` interface. (`true` if entry was created from a metadata fallback value from an empty storage item)
|
||||||
- Prefix `isEmpty/initialU8aLength/createdAtHash` with `$` on the `Codec` interface, e.g. `$isEmpty`. (The original interface getters has been marked as deprecated, aill warn, but is available)
|
|
||||||
- Rename `inspect()` to `inspectU8a()` on `Codec` interfaces
|
|
||||||
|
|
||||||
|
|
||||||
## 9.11.3 Jan 15, 2023
|
## 9.11.3 Jan 15, 2023
|
||||||
|
|||||||
@@ -76,17 +76,11 @@ function parseJson (json: Record<string, unknown>, chainProperties?: ChainProper
|
|||||||
|
|
||||||
export class Abi {
|
export class Abi {
|
||||||
readonly events: AbiEvent[];
|
readonly events: AbiEvent[];
|
||||||
|
|
||||||
readonly constructors: AbiConstructor[];
|
readonly constructors: AbiConstructor[];
|
||||||
|
|
||||||
readonly info: ContractProjectInfo;
|
readonly info: ContractProjectInfo;
|
||||||
|
|
||||||
readonly json: Record<string, unknown>;
|
readonly json: Record<string, unknown>;
|
||||||
|
|
||||||
readonly messages: AbiMessage[];
|
readonly messages: AbiMessage[];
|
||||||
|
|
||||||
readonly metadata: ContractMetadataLatest;
|
readonly metadata: ContractMetadataLatest;
|
||||||
|
|
||||||
readonly registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
constructor (abiJson: Record<string, unknown> | string, chainProperties?: ChainProperties) {
|
constructor (abiJson: Record<string, unknown> | string, chainProperties?: ChainProperties) {
|
||||||
@@ -239,7 +233,7 @@ export class Abi {
|
|||||||
return args.map(({ type: { lookupName, type } }): Codec => {
|
return args.map(({ type: { lookupName, type } }): Codec => {
|
||||||
const value = this.registry.createType(lookupName || type, data.subarray(offset));
|
const value = this.registry.createType(lookupName || type, data.subarray(offset));
|
||||||
|
|
||||||
offset += value.$encodedLength;
|
offset += value.encodedLength;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,11 +12,9 @@ import { Abi } from '../Abi';
|
|||||||
|
|
||||||
export abstract class Base<ApiType extends ApiTypes> {
|
export abstract class Base<ApiType extends ApiTypes> {
|
||||||
readonly abi: Abi;
|
readonly abi: Abi;
|
||||||
|
|
||||||
readonly api: ApiBase<ApiType>;
|
readonly api: ApiBase<ApiType>;
|
||||||
|
|
||||||
protected readonly _decorateMethod: DecorateMethod<ApiType>;
|
protected readonly _decorateMethod: DecorateMethod<ApiType>;
|
||||||
|
|
||||||
protected readonly _isWeightV1: boolean;
|
protected readonly _isWeightV1: boolean;
|
||||||
|
|
||||||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<R
|
|||||||
|
|
||||||
const nonce = (infoOrTuple as AccountInfo).nonce || (infoOrTuple as [Index, AccountData])[0];
|
const nonce = (infoOrTuple as AccountInfo).nonce || (infoOrTuple as [Index, AccountData])[0];
|
||||||
|
|
||||||
if (!data || data.$isEmpty) {
|
if (!data || data.isEmpty) {
|
||||||
return [
|
return [
|
||||||
nonce,
|
nonce,
|
||||||
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]]
|
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]]
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export function getBlock (instanceId: string, api: DeriveApi): (hash: Uint8Array
|
|||||||
])
|
])
|
||||||
),
|
),
|
||||||
map(([signedBlock, events, [, validators, author]]) =>
|
map(([signedBlock, events, [, validators, author]]) =>
|
||||||
createSignedBlockExtended(events.$registry, signedBlock, events, validators, author)
|
createSignedBlockExtended(events.registry, signedBlock, events, validators, author)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export function getHeader (instanceId: string, api: DeriveApi): (blockHash: Uint
|
|||||||
getAuthorDetails(header, queryAt)
|
getAuthorDetails(header, queryAt)
|
||||||
),
|
),
|
||||||
map(([header, validators, author]) =>
|
map(([header, validators, author]) =>
|
||||||
createHeaderExtended((validators || header).$registry, header, validators, author)
|
createHeaderExtended((validators || header).registry, header, validators, author)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export function subscribeFinalizedBlocks (instanceId: string, api: DeriveApi): (
|
|||||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||||
api.derive.chain.subscribeFinalizedHeads().pipe(
|
api.derive.chain.subscribeFinalizedHeads().pipe(
|
||||||
switchMap((header) =>
|
switchMap((header) =>
|
||||||
api.derive.chain.getBlock(header.$createdAtHash || header.hash)
|
api.derive.chain.getBlock(header.createdAtHash || header.hash)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export function subscribeFinalizedHeads (instanceId: string, api: DeriveApi): ()
|
|||||||
const endHash = prevHash;
|
const endHash = prevHash;
|
||||||
const startHash = header.parentHash;
|
const startHash = header.parentHash;
|
||||||
|
|
||||||
prevHash = header.$createdAtHash = header.hash;
|
prevHash = header.createdAtHash = header.hash;
|
||||||
|
|
||||||
return endHash === null || startHash.eq(endHash)
|
return endHash === null || startHash.eq(endHash)
|
||||||
? of(header)
|
? of(header)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export function subscribeNewBlocks (instanceId: string, api: DeriveApi): () => O
|
|||||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||||
api.derive.chain.subscribeNewHeads().pipe(
|
api.derive.chain.subscribeNewHeads().pipe(
|
||||||
switchMap((header) =>
|
switchMap((header) =>
|
||||||
api.derive.chain.getBlock(header.$createdAtHash || header.hash)
|
api.derive.chain.getBlock(header.createdAtHash || header.hash)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ export function subscribeNewHeads (instanceId: string, api: DeriveApi): () => Ob
|
|||||||
getAuthorDetails(header, queryAt)
|
getAuthorDetails(header, queryAt)
|
||||||
),
|
),
|
||||||
map(([header, validators, author]): HeaderExtended => {
|
map(([header, validators, author]): HeaderExtended => {
|
||||||
header.$createdAtHash = header.hash;
|
header.createdAtHash = header.hash;
|
||||||
|
|
||||||
return createHeaderExtended(header.$registry, header, validators, author);
|
return createHeaderExtended(header.registry, header, validators, author);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function _getUpdates (api: DeriveApi, paraId: string | number | BN): Observable<
|
|||||||
added = added.concat(...changes.added);
|
added = added.concat(...changes.added);
|
||||||
removed = removed.concat(...changes.removed);
|
removed = removed.concat(...changes.removed);
|
||||||
|
|
||||||
return of({ added, addedDelta: changes.added, blockHash: events.$createdAtHash?.toHex() || '-', removed, removedDelta: changes.removed });
|
return of({ added, addedDelta: changes.added, blockHash: events.createdAtHash?.toHex() || '-', removed, removedDelta: changes.removed });
|
||||||
}
|
}
|
||||||
|
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
@@ -52,7 +52,7 @@ function _eventTriggerAll (api: DeriveApi, paraId: string | number | BN): Observ
|
|||||||
);
|
);
|
||||||
|
|
||||||
return items.length
|
return items.length
|
||||||
? of(events.$createdAtHash?.toHex() || '-')
|
? of(events.createdAtHash?.toHex() || '-')
|
||||||
: EMPTY;
|
: EMPTY;
|
||||||
}),
|
}),
|
||||||
startWith('-')
|
startWith('-')
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ export function extractContributed (paraId: string | number | BN, events: Vec<Fr
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}, { added, blockHash: events.$createdAtHash?.toHex() || '-', removed });
|
}, { added, blockHash: events.createdAtHash?.toHex() || '-', removed });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ function isNewDepositors (depositors: ITuple<[Vec<AccountId>, Balance]> | ITuple
|
|||||||
function parse ([proposals, images, optDepositors]: Result): DeriveProposal[] {
|
function parse ([proposals, images, optDepositors]: Result): DeriveProposal[] {
|
||||||
return proposals
|
return proposals
|
||||||
.filter(([, , proposer], index): boolean =>
|
.filter(([, , proposer], index): boolean =>
|
||||||
!!(optDepositors[index]?.isSome) && !proposer.$isEmpty
|
!!(optDepositors[index]?.isSome) && !proposer.isEmpty
|
||||||
)
|
)
|
||||||
.map(([index, hash, proposer], proposalIndex): DeriveProposal => {
|
.map(([index, hash, proposer], proposalIndex): DeriveProposal => {
|
||||||
const depositors = optDepositors[proposalIndex].unwrap();
|
const depositors = optDepositors[proposalIndex].unwrap();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function mapResult ([result, validators, heartbeats, numBlocks]: [DeriveHeartbea
|
|||||||
validators.forEach((validator, index): void => {
|
validators.forEach((validator, index): void => {
|
||||||
const validatorId = validator.toString();
|
const validatorId = validator.toString();
|
||||||
const blockCount = numBlocks[index];
|
const blockCount = numBlocks[index];
|
||||||
const hasMessage = !heartbeats[index].$isEmpty;
|
const hasMessage = !heartbeats[index].isEmpty;
|
||||||
const prev = result[validatorId];
|
const prev = result[validatorId];
|
||||||
|
|
||||||
if (!prev || prev.hasMessage !== hasMessage || !prev.blockCount.eq(blockCount)) {
|
if (!prev || prev.hasMessage !== hasMessage || !prev.blockCount.eq(blockCount)) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ function signingHeader (api: DeriveApi): Observable<Header> {
|
|||||||
switchMap((header) =>
|
switchMap((header) =>
|
||||||
// check for chains at genesis (until block 1 is produced, e.g. 6s), since
|
// check for chains at genesis (until block 1 is produced, e.g. 6s), since
|
||||||
// we do need to allow transactions at chain start (also dev/seal chains)
|
// we do need to allow transactions at chain start (also dev/seal chains)
|
||||||
header.parentHash.$isEmpty
|
header.parentHash.isEmpty
|
||||||
? of(header)
|
? of(header)
|
||||||
// in the case of the current block, we use the parent to minimize the
|
// in the case of the current block, we use the parent to minimize the
|
||||||
// impact of forks on the system, but not completely remove it
|
// impact of forks on the system, but not completely remove it
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export function createHeaderExtended (registry: Registry, header?: Header, valid
|
|||||||
super(registry, header);
|
super(registry, header);
|
||||||
|
|
||||||
this.#author = author || extractAuthor(this.digest, validators || []);
|
this.#author = author || extractAuthor(this.digest, validators || []);
|
||||||
this.$createdAtHash = header?.$createdAtHash;
|
this.createdAtHash = header?.createdAtHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export function createSignedBlockExtended (registry: Registry, block?: SignedBlo
|
|||||||
this.#author = author || extractAuthor(this.block.header.digest, validators || []);
|
this.#author = author || extractAuthor(this.block.header.digest, validators || []);
|
||||||
this.#events = events || ([] as EventRecord[]);
|
this.#events = events || ([] as EventRecord[]);
|
||||||
this.#extrinsics = mapExtrinsics(this.block.extrinsics, this.#events);
|
this.#extrinsics = mapExtrinsics(this.block.extrinsics, this.#events);
|
||||||
this.$createdAtHash = block?.$createdAtHash;
|
this.createdAtHash = block?.createdAtHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -712,7 +712,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
|||||||
decorated.sizeAt = decorateMethod((blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<u64> =>
|
decorated.sizeAt = decorateMethod((blockHash: Hash | Uint8Array | string, ...args: unknown[]): Observable<u64> =>
|
||||||
getQueryAt(blockHash).pipe(
|
getQueryAt(blockHash).pipe(
|
||||||
switchMap((q) =>
|
switchMap((q) =>
|
||||||
this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.$registry), blockHash))));
|
this._rpcCore.state.getStorageSize(getArgs(args, q.creator.meta.registry), blockHash))));
|
||||||
|
|
||||||
// .keys() & .entries() only available on map types
|
// .keys() & .entries() only available on map types
|
||||||
if (creator.iterKey && creator.meta.type.isMap) {
|
if (creator.iterKey && creator.meta.type.isMap) {
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
|||||||
: await firstValueFrom(this._rpcCore.chain.getHeader.raw(blockHash))
|
: await firstValueFrom(this._rpcCore.chain.getHeader.raw(blockHash))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (header.parentHash.$isEmpty) {
|
if (header.parentHash.isEmpty) {
|
||||||
throw new Error('Unable to retrieve header and parent from supplied hash');
|
throw new Error('Unable to retrieve header and parent from supplied hash');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
|
|||||||
first(),
|
first(),
|
||||||
switchMap((signingInfo): Observable<RuntimeDispatchInfo> => {
|
switchMap((signingInfo): Observable<RuntimeDispatchInfo> => {
|
||||||
// setup our options (same way as in signAndSend)
|
// setup our options (same way as in signAndSend)
|
||||||
const eraOptions = makeEraOptions(api, this.$registry, allOptions, signingInfo);
|
const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo);
|
||||||
const signOptions = makeSignOptions(api, eraOptions, {});
|
const signOptions = makeSignOptions(api, eraOptions, {});
|
||||||
const u8a = this.isSigned
|
const u8a = this.isSigned
|
||||||
? api.tx(this).signFake(address, signOptions).toU8a()
|
? api.tx(this).signFake(address, signOptions).toU8a()
|
||||||
@@ -244,7 +244,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
|
|||||||
return api.derive.tx.signingInfo(address, options.nonce, options.era).pipe(
|
return api.derive.tx.signingInfo(address, options.nonce, options.era).pipe(
|
||||||
first(),
|
first(),
|
||||||
mergeMap(async (signingInfo): Promise<UpdateInfo> => {
|
mergeMap(async (signingInfo): Promise<UpdateInfo> => {
|
||||||
const eraOptions = makeEraOptions(api, this.$registry, options, signingInfo);
|
const eraOptions = makeEraOptions(api, this.registry, options, signingInfo);
|
||||||
let updateId = -1;
|
let updateId = -1;
|
||||||
|
|
||||||
if (isKeyringPair(account)) {
|
if (isKeyringPair(account)) {
|
||||||
@@ -316,7 +316,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
|
|||||||
throw new Error('No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
|
throw new Error('No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = this.$registry.createTypeUnsafe<SignerPayload>('SignerPayload', [objectSpread({}, options, {
|
const payload = this.registry.createTypeUnsafe<SignerPayload>('SignerPayload', [objectSpread({}, options, {
|
||||||
address,
|
address,
|
||||||
blockNumber: header ? header.number : 0,
|
blockNumber: header ? header.number : 0,
|
||||||
method: this.method
|
method: this.method
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
|
|||||||
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
||||||
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
||||||
}, {});
|
}, {});
|
||||||
const { $registry: registry, lookup, pallets } = meta.asLatest;
|
const { lookup, pallets, registry } = meta.asLatest;
|
||||||
|
|
||||||
const modules = pallets
|
const modules = pallets
|
||||||
.filter(({ constants }) => constants.length > 0)
|
.filter(({ constants }) => constants.length > 0)
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
|
|||||||
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
||||||
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
||||||
}, {});
|
}, {});
|
||||||
const { $registry: registry, lookup, pallets } = meta.asLatest;
|
const { lookup, pallets, registry } = meta.asLatest;
|
||||||
const modules = pallets
|
const modules = pallets
|
||||||
.filter(({ events }) => events.isSome)
|
.filter(({ events }) => events.isSome)
|
||||||
.map(({ events, name }) => ({
|
.map(({ events, name }) => ({
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ function generateRegistry (registry: Registry, filtered: [PortableType, TypeDef]
|
|||||||
|
|
||||||
function generateLookup (destDir: string, entries: [string, HexString][]): void {
|
function generateLookup (destDir: string, entries: [string, HexString][]): void {
|
||||||
entries.reduce<string[]>((exclude, [subPath, staticMeta]): string[] => {
|
entries.reduce<string[]>((exclude, [subPath, staticMeta]): string[] => {
|
||||||
const { $registry: registry, lookup } = initMeta(staticMeta).metadata.asLatest;
|
const { lookup, registry } = initMeta(staticMeta).metadata.asLatest;
|
||||||
const filtered = getFilteredTypes(lookup, exclude);
|
const filtered = getFilteredTypes(lookup, exclude);
|
||||||
|
|
||||||
generateLookupDefs(registry, filtered, destDir, subPath);
|
generateLookupDefs(registry, filtered, destDir, subPath);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export function generateCallTypes (meta: Metadata, dest: string, extraTypes: Ext
|
|||||||
|
|
||||||
// find the system.Version in metadata
|
// find the system.Version in metadata
|
||||||
let apis: Apis | null = null;
|
let apis: Apis | null = null;
|
||||||
const { $registry: registry, pallets } = meta.asLatest;
|
const { pallets, registry } = meta.asLatest;
|
||||||
const sysp = pallets.find(({ name }) => name.eq('System'));
|
const sysp = pallets.find(({ name }) => name.eq('System'));
|
||||||
|
|
||||||
if (sysp) {
|
if (sysp) {
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ function addConstants ({ lookup, pallets }: MetadataLatest): string {
|
|||||||
description: DESC_CONSTANTS,
|
description: DESC_CONSTANTS,
|
||||||
sections: pallets
|
sections: pallets
|
||||||
.sort(sortByName)
|
.sort(sortByName)
|
||||||
.filter(({ constants }) => !constants.$isEmpty)
|
.filter(({ constants }) => !constants.isEmpty)
|
||||||
.map(({ constants, name }) => {
|
.map(({ constants, name }) => {
|
||||||
const sectionName = stringLowerFirst(name);
|
const sectionName = stringLowerFirst(name);
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ function addConstants ({ lookup, pallets }: MetadataLatest): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
function addStorage ({ $registry: registry, lookup, pallets }: MetadataLatest): string {
|
function addStorage ({ lookup, pallets, registry }: MetadataLatest): string {
|
||||||
const { substrate } = getSubstrateStorage(registry);
|
const { substrate } = getSubstrateStorage(registry);
|
||||||
const moduleSections = pallets
|
const moduleSections = pallets
|
||||||
.sort(sortByName)
|
.sort(sortByName)
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ export function getSimilarTypes (registry: Registry, definitions: Record<string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (isChildClass(Enum, Clazz)) {
|
} else if (isChildClass(Enum, Clazz)) {
|
||||||
const { $isBasic, defKeys } = new (Clazz as Constructor)(registry) as Enum;
|
const { defKeys, isBasic } = new (Clazz as Constructor)(registry) as Enum;
|
||||||
const keys = defKeys.filter((v) => !v.startsWith('__Unused'));
|
const keys = defKeys.filter((v) => !v.startsWith('__Unused'));
|
||||||
|
|
||||||
if ($isBasic) {
|
if (isBasic) {
|
||||||
possibleTypes.push(arrayToStrType(keys), 'number');
|
possibleTypes.push(arrayToStrType(keys), 'number');
|
||||||
} else {
|
} else {
|
||||||
// TODO We don't really want any here, these should be expanded
|
// TODO We don't really want any here, these should be expanded
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, Inspect, IU8a, IVec, Registry } from '../types';
|
|||||||
|
|
||||||
import { compactToU8a, u8aConcatStrict, u8aToHex } from '@polkadot/util';
|
import { compactToU8a, u8aConcatStrict, u8aToHex } from '@polkadot/util';
|
||||||
|
|
||||||
import { compareArray, warnGet } from '../utils';
|
import { compareArray } from '../utils/compareArray';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name AbstractArray
|
* @name AbstractArray
|
||||||
@@ -16,10 +16,11 @@ import { compareArray, warnGet } from '../utils';
|
|||||||
* @noInheritDoc
|
* @noInheritDoc
|
||||||
*/
|
*/
|
||||||
export abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
|
export abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
|
||||||
public $createdAtHash?: IU8a;
|
readonly registry: Registry;
|
||||||
public $initialU8aLength?: number;
|
|
||||||
public $isStorageFallback?: boolean;
|
public createdAtHash?: IU8a;
|
||||||
readonly $registry: Registry;
|
public initialU8aLength?: number;
|
||||||
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description This ensures that operators such as clice, filter, map, etc. return
|
* @description This ensures that operators such as clice, filter, map, etc. return
|
||||||
@@ -32,44 +33,19 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
|||||||
protected constructor (registry: Registry, length: number) {
|
protected constructor (registry: Registry, length: number) {
|
||||||
super(length);
|
super(length);
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
// We need to loop through all entries since they may have a variable length themselves,
|
// We need to loop through all entries since they may have a variable length themselves,
|
||||||
// e.g. when a Vec or Compact is contained withing, it has a variable length based on data
|
// e.g. when a Vec or Compact is contained withing, it has a variable length based on data
|
||||||
let total = compactToU8a(this.length).length;
|
let total = compactToU8a(this.length).length;
|
||||||
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
total += this[i].$encodedLength;
|
total += this[i].encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
@@ -79,13 +55,13 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.length === 0;
|
return this.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +83,7 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
inner: this.inspectInner(),
|
inner: this.inspectInner(),
|
||||||
outer: [compactToU8a(this.length)]
|
outer: [compactToU8a(this.length)]
|
||||||
@@ -118,7 +94,7 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
|||||||
const inner = new Array<Inspect>(this.length);
|
const inner = new Array<Inspect>(this.length);
|
||||||
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
inner[i] = this[i].inspectU8a();
|
inner[i] = this[i].inspect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return inner;
|
return inner;
|
||||||
|
|||||||
@@ -4,55 +4,29 @@
|
|||||||
import type { HexString } from '@polkadot/util/types';
|
import type { HexString } from '@polkadot/util/types';
|
||||||
import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types';
|
import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Base
|
* @name Base
|
||||||
* @description A type extends the Base class, when it holds a value
|
* @description A type extends the Base class, when it holds a value
|
||||||
*/
|
*/
|
||||||
export abstract class AbstractBase<T extends Codec> implements Codec {
|
export abstract class AbstractBase<T extends Codec> implements Codec {
|
||||||
public $createdAtHash?: IU8a;
|
readonly registry: Registry;
|
||||||
public $initialU8aLength?: number;
|
|
||||||
public $isStorageFallback?: boolean;
|
public createdAtHash?: IU8a;
|
||||||
readonly $registry: Registry;
|
public initialU8aLength?: number;
|
||||||
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #raw: T;
|
readonly #raw: T;
|
||||||
|
|
||||||
protected constructor (registry: Registry, value: T, initialU8aLength?: number) {
|
protected constructor (registry: Registry, value: T, initialU8aLength?: number) {
|
||||||
this.$initialU8aLength = initialU8aLength;
|
this.initialU8aLength = initialU8aLength;
|
||||||
this.#raw = value;
|
this.#raw = value;
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return this.toU8a().length;
|
return this.toU8a().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +34,7 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
public get inner (): T {
|
public get inner (): T {
|
||||||
@@ -70,8 +44,8 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
|
|||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.#raw.$isEmpty;
|
return this.#raw.isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,8 +58,8 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return this.#raw.inspectU8a();
|
return this.#raw.inspect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from
|
|||||||
|
|
||||||
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util';
|
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
export const DEFAULT_UINT_BITS = 64;
|
export const DEFAULT_UINT_BITS = 64;
|
||||||
|
|
||||||
// Maximum allowed integer for JS is 2^53 - 1, set limit at 52
|
// Maximum allowed integer for JS is 2^53 - 1, set limit at 52
|
||||||
@@ -74,12 +72,13 @@ function decodeAbstractInt (value: Exclude<AnyNumber, Uint8Array> | Record<strin
|
|||||||
* @noInheritDoc
|
* @noInheritDoc
|
||||||
*/
|
*/
|
||||||
export abstract class AbstractInt extends BN implements INumber {
|
export abstract class AbstractInt extends BN implements INumber {
|
||||||
public $createdAtHash?: IU8a;
|
readonly registry: Registry;
|
||||||
readonly $encodedLength: number;
|
readonly encodedLength: number;
|
||||||
public $initialU8aLength?: number;
|
readonly isUnsigned: boolean;
|
||||||
public $isStorageFallback?: boolean;
|
|
||||||
readonly $isUnsigned: boolean;
|
public createdAtHash?: IU8a;
|
||||||
readonly $registry: Registry;
|
public initialU8aLength?: number;
|
||||||
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #bitLength: UIntBitLength;
|
readonly #bitLength: UIntBitLength;
|
||||||
|
|
||||||
@@ -96,10 +95,11 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
: decodeAbstractInt(value, isSigned)
|
: decodeAbstractInt(value, isSigned)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.#bitLength = bitLength;
|
this.#bitLength = bitLength;
|
||||||
this.$encodedLength = this.$initialU8aLength = this.#bitLength / 8;
|
this.encodedLength = this.#bitLength / 8;
|
||||||
this.$isUnsigned = !isSigned;
|
this.initialU8aLength = this.#bitLength / 8;
|
||||||
|
this.isUnsigned = !isSigned;
|
||||||
|
|
||||||
const isNegative = this.isNeg();
|
const isNegative = this.isNeg();
|
||||||
const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
|
const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
|
||||||
@@ -111,47 +111,17 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isUnsigned instead. This getter will be removed in a future version */
|
|
||||||
public get isUnsigned (): boolean {
|
|
||||||
return warnGet(this, 'isUnsigned');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is a zero value (align elsewhere)
|
* @description Checks if the value is a zero value (align elsewhere)
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.isZero();
|
return this.isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +141,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
// number and BN inputs (no `.eqn` needed) - numbers will be converted
|
// number and BN inputs (no `.eqn` needed) - numbers will be converted
|
||||||
return super.eq(
|
return super.eq(
|
||||||
isHex(other)
|
isHex(other)
|
||||||
? hexToBn(other.toString(), { isLe: false, isNegative: !this.$isUnsigned })
|
? hexToBn(other.toString(), { isLe: false, isNegative: !this.isUnsigned })
|
||||||
: bnToBn(other as string)
|
: bnToBn(other as string)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -179,7 +149,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [this.toU8a()]
|
outer: [this.toU8a()]
|
||||||
};
|
};
|
||||||
@@ -216,7 +186,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
return bnToHex(this, {
|
return bnToHex(this, {
|
||||||
bitLength: this.bitLength(),
|
bitLength: this.bitLength(),
|
||||||
isLe,
|
isLe,
|
||||||
isNegative: !this.$isUnsigned
|
isNegative: !this.isUnsigned
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +202,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
? 'everything'
|
? 'everything'
|
||||||
// FIXME In the case of multiples we need some way of detecting which instance this belongs
|
// FIXME In the case of multiples we need some way of detecting which instance this belongs
|
||||||
// to. as it stands we will always format (incorrectly) against the first token defined
|
// to. as it stands we will always format (incorrectly) against the first token defined
|
||||||
: formatBalance(this, { decimals: this.$registry.chainDecimals[0], withSi: true, withUnit: this.$registry.chainTokens[0] });
|
: formatBalance(this, { decimals: this.registry.chainDecimals[0], withSi: true, withUnit: this.registry.chainTokens[0] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const [, divisor] = FORMATTERS.find(([type]) => type === rawType) || [];
|
const [, divisor] = FORMATTERS.find(([type]) => type === rawType) || [];
|
||||||
@@ -271,9 +241,9 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
// NOTE In the case of balances, which have a special meaning on the UI
|
// NOTE In the case of balances, which have a special meaning on the UI
|
||||||
// and can be interpreted differently, return a specific value for it so
|
// and can be interpreted differently, return a specific value for it so
|
||||||
// underlying it always matches (no matter which length it actually is)
|
// underlying it always matches (no matter which length it actually is)
|
||||||
return this instanceof this.$registry.createClassUnsafe('Balance')
|
return this instanceof this.registry.createClassUnsafe('Balance')
|
||||||
? 'Balance'
|
? 'Balance'
|
||||||
: `${this.$isUnsigned ? 'u' : 'i'}${this.bitLength()}`;
|
: `${this.isUnsigned ? 'u' : 'i'}${this.bitLength()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,7 +264,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
|||||||
return bnToU8a(this, {
|
return bnToU8a(this, {
|
||||||
bitLength: this.bitLength(),
|
bitLength: this.bitLength(),
|
||||||
isLe: true,
|
isLe: true,
|
||||||
isNegative: !this.$isUnsigned
|
isNegative: !this.isUnsigned
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,6 @@ const CompactU32 = Compact.with(U32);
|
|||||||
describe('Compact', (): void => {
|
describe('Compact', (): void => {
|
||||||
const registry = new TypeRegistry();
|
const registry = new TypeRegistry();
|
||||||
|
|
||||||
describe('@deprecated', (): void => {
|
|
||||||
it('warns on createdAtHash usage', () => {
|
|
||||||
// eslint-disable-next-line deprecation/deprecation
|
|
||||||
expect(new Compact(registry, 'u128').createdAtHash).not.toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('warns on initialU8aLength usage', () => {
|
|
||||||
// eslint-disable-next-line deprecation/deprecation
|
|
||||||
expect(new Compact(registry, 'u128').initialU8aLength).toEqual(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('constructor', (): void => {
|
describe('constructor', (): void => {
|
||||||
it('fails on > MAX_SAFE_INTEGER', (): void => {
|
it('fails on > MAX_SAFE_INTEGER', (): void => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
||||||
@@ -44,19 +32,19 @@ describe('Compact', (): void => {
|
|||||||
|
|
||||||
it('has the correct encodedLength for constructor values (string BlockNumber)', (): void => {
|
it('has the correct encodedLength for constructor values (string BlockNumber)', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new (Compact.with('BlockNumber'))(registry, 0xfffffff9).$encodedLength
|
new (Compact.with('BlockNumber'))(registry, 0xfffffff9).encodedLength
|
||||||
).toEqual(5);
|
).toEqual(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has the correct encodedLength for constructor values (class BlockNumber)', (): void => {
|
it('has the correct encodedLength for constructor values (class BlockNumber)', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new (Compact.with(registry.createClass('BlockNumber')))(registry, 0xfffffff9).$encodedLength
|
new (Compact.with(registry.createClass('BlockNumber')))(registry, 0xfffffff9).encodedLength
|
||||||
).toEqual(5);
|
).toEqual(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has the correct encodedLength for constructor values (u32)', (): void => {
|
it('has the correct encodedLength for constructor values (u32)', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new (Compact.with(U32))(registry, 0xffff9).$encodedLength
|
new (Compact.with(U32))(registry, 0xffff9).encodedLength
|
||||||
).toEqual(4);
|
).toEqual(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,7 +86,7 @@ describe('Compact', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new (Compact.with(U32))(registry, 0xffff).inspectU8a()
|
new (Compact.with(U32))(registry, 0xffff).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([254, 255, 3, 0])]
|
outer: [new Uint8Array([254, 255, 3, 0])]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type { AnyJson, AnyNumber, CodecClass, ICompact, Inspect, INumber, IU8a,
|
|||||||
|
|
||||||
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
|
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { typeToConstructor, warnGet } from '../utils';
|
import { typeToConstructor } from '../utils';
|
||||||
|
|
||||||
interface Options<T> {
|
interface Options<T> {
|
||||||
definition?: CodecClass<T>;
|
definition?: CodecClass<T>;
|
||||||
@@ -47,49 +47,25 @@ function decodeCompact<T extends INumber> (registry: Registry, Type: CodecClass<
|
|||||||
* a number and making the compact representation thereof
|
* a number and making the compact representation thereof
|
||||||
*/
|
*/
|
||||||
export class Compact<T extends INumber> implements ICompact<T> {
|
export class Compact<T extends INumber> implements ICompact<T> {
|
||||||
public $createdAtHash?: IU8a;
|
readonly registry: Registry;
|
||||||
public $initialU8aLength?: number;
|
|
||||||
public $isStorageFallback?: boolean;
|
public createdAtHash?: IU8a;
|
||||||
readonly $registry: Registry;
|
public initialU8aLength?: number;
|
||||||
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #Type: CodecClass<T>;
|
readonly #Type: CodecClass<T>;
|
||||||
readonly #raw: T;
|
readonly #raw: T;
|
||||||
|
|
||||||
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
|
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
||||||
|
|
||||||
const [raw, decodedLength] = decodeCompact<T>(registry, this.#Type, value);
|
const [raw, decodedLength] = decodeCompact<T>(registry, this.#Type, value);
|
||||||
|
|
||||||
this.$initialU8aLength = decodedLength;
|
this.initialU8aLength = decodedLength;
|
||||||
this.#raw = raw;
|
this.#raw = raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static with<O extends INumber> (Type: CodecClass<O> | string): CodecClass<Compact<O>> {
|
public static with<O extends INumber> (Type: CodecClass<O> | string): CodecClass<Compact<O>> {
|
||||||
let definition: CodecClass<O> | undefined;
|
let definition: CodecClass<O> | undefined;
|
||||||
|
|
||||||
@@ -107,7 +83,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return this.toU8a().length;
|
return this.toU8a().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,14 +91,14 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.#raw.$isEmpty;
|
return this.#raw.isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,7 +122,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [this.toU8a()]
|
outer: [this.toU8a()]
|
||||||
};
|
};
|
||||||
@@ -205,7 +181,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
|||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public toRawType (): string {
|
public toRawType (): string {
|
||||||
return `Compact<${this.$registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,53 +4,26 @@
|
|||||||
import type { HexString } from '@polkadot/util/types';
|
import type { HexString } from '@polkadot/util/types';
|
||||||
import type { AnyJson, Codec, CodecClass, Inspect, IU8a, Registry } from '../types';
|
import type { AnyJson, Codec, CodecClass, Inspect, IU8a, Registry } from '../types';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name DoNotConstruct
|
* @name DoNotConstruct
|
||||||
* @description
|
* @description
|
||||||
* An unknown type that fails on construction with the type info
|
* An unknown type that fails on construction with the type info
|
||||||
*/
|
*/
|
||||||
export class DoNotConstruct implements Codec {
|
export class DoNotConstruct implements Codec {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
#neverError: Error;
|
#neverError: Error;
|
||||||
|
|
||||||
constructor (registry: Registry, typeName = 'DoNotConstruct') {
|
constructor (registry: Registry, typeName = 'DoNotConstruct') {
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
||||||
|
|
||||||
throw this.#neverError;
|
throw this.#neverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static with (typeName?: string): CodecClass {
|
public static with (typeName?: string): CodecClass {
|
||||||
return class extends DoNotConstruct {
|
return class extends DoNotConstruct {
|
||||||
constructor (registry: Registry) {
|
constructor (registry: Registry) {
|
||||||
@@ -62,7 +35,7 @@ export class DoNotConstruct implements Codec {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
throw this.#neverError;
|
throw this.#neverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +49,7 @@ export class DoNotConstruct implements Codec {
|
|||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value (always true)
|
* @description Checks if the value is an empty value (always true)
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
throw this.#neverError;
|
throw this.#neverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +57,7 @@ export class DoNotConstruct implements Codec {
|
|||||||
throw this.#neverError;
|
throw this.#neverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
throw this.#neverError;
|
throw this.#neverError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ describe('Enum', (): void => {
|
|||||||
it('has isNone set, with correct index (i.e. no values are used)', (): void => {
|
it('has isNone set, with correct index (i.e. no values are used)', (): void => {
|
||||||
const test = new Enum(registry, ['foo', 'bar'], 1);
|
const test = new Enum(registry, ['foo', 'bar'], 1);
|
||||||
|
|
||||||
expect(test.$isNone).toBe(true);
|
expect(test.isNone).toBe(true);
|
||||||
expect(test.index).toEqual(1);
|
expect(test.index).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ describe('Enum', (): void => {
|
|||||||
registry,
|
registry,
|
||||||
{ Text, U32 },
|
{ Text, U32 },
|
||||||
'0x0134120000'
|
'0x0134120000'
|
||||||
).inspectU8a()
|
).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([0x01]), new Uint8Array([0x34, 0x12, 0x00, 0x00])]
|
outer: [new Uint8Array([0x01]), new Uint8Array([0x34, 0x12, 0x00, 0x00])]
|
||||||
});
|
});
|
||||||
@@ -430,7 +430,7 @@ describe('Enum', (): void => {
|
|||||||
const test = new Test(registry, 123, 1);
|
const test = new Test(registry, 123, 1);
|
||||||
|
|
||||||
expect(test.toHex()).toEqual('0x017b000000');
|
expect(test.toHex()).toEqual('0x017b000000');
|
||||||
expect(test.$encodedLength).toEqual(1 + 4);
|
expect(test.encodedLength).toEqual(1 + 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('encodes a single entry correctly', (): void => {
|
it('encodes a single entry correctly', (): void => {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, IEnum, Inspect, IU8a, Registry } from
|
|||||||
|
|
||||||
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { mapToTypeMap, typesToMap, warnGet } from '../utils';
|
import { mapToTypeMap, typesToMap } from '../utils';
|
||||||
import { Null } from './Null';
|
import { Null } from './Null';
|
||||||
|
|
||||||
// export interface, this is used in Enum.with, so required as public by TS
|
// export interface, this is used in Enum.with, so required as public by TS
|
||||||
@@ -183,16 +183,16 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: unknown, index?:
|
|||||||
* an extension to enum where the value type is determined by the actual index.
|
* an extension to enum where the value type is determined by the actual index.
|
||||||
*/
|
*/
|
||||||
export class Enum implements IEnum {
|
export class Enum implements IEnum {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
readonly $isBasic: boolean;
|
public isStorageFallback?: boolean;
|
||||||
public $isStorageFallback?: boolean;
|
|
||||||
|
|
||||||
readonly #def: TypesDef;
|
readonly #def: TypesDef;
|
||||||
readonly #entryIndex: number;
|
readonly #entryIndex: number;
|
||||||
readonly #indexes: number[];
|
readonly #indexes: number[];
|
||||||
|
readonly #isBasic: boolean;
|
||||||
readonly #isIndexed: boolean;
|
readonly #isIndexed: boolean;
|
||||||
readonly #raw: Codec;
|
readonly #raw: Codec;
|
||||||
|
|
||||||
@@ -204,55 +204,19 @@ export class Enum implements IEnum {
|
|||||||
? createFromU8a(registry, def, value[0], value.subarray(1))
|
? createFromU8a(registry, def, value[0], value.subarray(1))
|
||||||
: decodeEnum(registry, def, value, index);
|
: decodeEnum(registry, def, value, index);
|
||||||
|
|
||||||
this.$isBasic = isBasic;
|
this.registry = registry;
|
||||||
|
|
||||||
this.$registry = registry;
|
|
||||||
this.#def = def;
|
this.#def = def;
|
||||||
|
this.#isBasic = isBasic;
|
||||||
this.#isIndexed = isIndexed;
|
this.#isIndexed = isIndexed;
|
||||||
this.#indexes = Object.values(def).map(({ index }) => index);
|
this.#indexes = Object.values(def).map(({ index }) => index);
|
||||||
this.#entryIndex = this.#indexes.indexOf(decoded.index);
|
this.#entryIndex = this.#indexes.indexOf(decoded.index);
|
||||||
this.#raw = decoded.value;
|
this.#raw = decoded.value;
|
||||||
|
|
||||||
if (this.#raw.$initialU8aLength) {
|
if (this.#raw.initialU8aLength) {
|
||||||
this.$initialU8aLength = 1 + this.#raw.$initialU8aLength;
|
this.initialU8aLength = 1 + this.#raw.initialU8aLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isBasic instead. This getter will be removed in a future version */
|
|
||||||
public get isBasic (): boolean {
|
|
||||||
return warnGet(this, 'isBasic');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isNone instead. This getter will be removed in a future version */
|
|
||||||
public get isNone (): boolean {
|
|
||||||
return warnGet(this, 'isNone');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static with (Types: Record<string, string | CodecClass> | Record<string, number> | string[]): EnumCodecClass<Enum> {
|
public static with (Types: Record<string, string | CodecClass> | Record<string, number> | string[]): EnumCodecClass<Enum> {
|
||||||
let definition: Definition | undefined;
|
let definition: Definition | undefined;
|
||||||
|
|
||||||
@@ -297,15 +261,15 @@ export class Enum implements IEnum {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return 1 + this.#raw.$encodedLength;
|
return 1 + this.#raw.encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -322,17 +286,24 @@ export class Enum implements IEnum {
|
|||||||
return this.#raw;
|
return this.#raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description true if this is a basic enum (no values)
|
||||||
|
*/
|
||||||
|
public get isBasic (): boolean {
|
||||||
|
return this.#isBasic;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.#raw.$isEmpty;
|
return this.#raw.isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the Enum points to a [[Null]] type
|
* @description Checks if the Enum points to a [[Null]] type
|
||||||
*/
|
*/
|
||||||
public get $isNone (): boolean {
|
public get isNone (): boolean {
|
||||||
return this.#raw instanceof Null;
|
return this.#raw instanceof Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,7 +344,7 @@ export class Enum implements IEnum {
|
|||||||
return !this.toU8a().some((entry, index) => entry !== other[index]);
|
return !this.toU8a().some((entry, index) => entry !== other[index]);
|
||||||
} else if (isNumber(other)) {
|
} else if (isNumber(other)) {
|
||||||
return this.toNumber() === other;
|
return this.toNumber() === other;
|
||||||
} else if (this.$isBasic && isString(other)) {
|
} else if (this.#isBasic && isString(other)) {
|
||||||
return this.type === other;
|
return this.type === other;
|
||||||
} else if (isHex(other)) {
|
} else if (isHex(other)) {
|
||||||
return this.toHex() === other;
|
return this.toHex() === other;
|
||||||
@@ -390,12 +361,12 @@ export class Enum implements IEnum {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
if (this.$isBasic) {
|
if (this.#isBasic) {
|
||||||
return { outer: [new Uint8Array([this.index])] };
|
return { outer: [new Uint8Array([this.index])] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const { inner, outer = [] } = this.#raw.inspectU8a();
|
const { inner, outer = [] } = this.#raw.inspect();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inner,
|
inner,
|
||||||
@@ -414,7 +385,7 @@ export class Enum implements IEnum {
|
|||||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||||
*/
|
*/
|
||||||
public toHuman (isExtended?: boolean): AnyJson {
|
public toHuman (isExtended?: boolean): AnyJson {
|
||||||
return this.$isBasic || this.$isNone
|
return this.#isBasic || this.isNone
|
||||||
? this.type
|
? this.type
|
||||||
: { [this.type]: this.#raw.toHuman(isExtended) };
|
: { [this.type]: this.#raw.toHuman(isExtended) };
|
||||||
}
|
}
|
||||||
@@ -423,7 +394,7 @@ export class Enum implements IEnum {
|
|||||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||||
*/
|
*/
|
||||||
public toJSON (): AnyJson {
|
public toJSON (): AnyJson {
|
||||||
return this.$isBasic
|
return this.#isBasic
|
||||||
? this.type
|
? this.type
|
||||||
: { [stringCamelCase(this.type)]: this.#raw.toJSON() };
|
: { [stringCamelCase(this.type)]: this.#raw.toJSON() };
|
||||||
}
|
}
|
||||||
@@ -439,7 +410,7 @@ export class Enum implements IEnum {
|
|||||||
* @description Converts the value in a best-fit primitive form
|
* @description Converts the value in a best-fit primitive form
|
||||||
*/
|
*/
|
||||||
public toPrimitive (): AnyJson {
|
public toPrimitive (): AnyJson {
|
||||||
return this.$isBasic
|
return this.#isBasic
|
||||||
? this.type
|
? this.type
|
||||||
: { [stringCamelCase(this.type)]: this.#raw.toPrimitive() };
|
: { [stringCamelCase(this.type)]: this.#raw.toPrimitive() };
|
||||||
}
|
}
|
||||||
@@ -448,7 +419,7 @@ export class Enum implements IEnum {
|
|||||||
* @description Returns a raw struct representation of the enum types
|
* @description Returns a raw struct representation of the enum types
|
||||||
*/
|
*/
|
||||||
protected _toRawStruct (): string[] | Record<string, string | number> {
|
protected _toRawStruct (): string[] | Record<string, string | number> {
|
||||||
if (this.$isBasic) {
|
if (this.#isBasic) {
|
||||||
return this.#isIndexed
|
return this.#isIndexed
|
||||||
? this.defKeys.reduce((out: Record<string, number>, key, index): Record<string, number> => {
|
? this.defKeys.reduce((out: Record<string, number>, key, index): Record<string, number> => {
|
||||||
out[key] = this.#indexes[index];
|
out[key] = this.#indexes[index];
|
||||||
@@ -460,7 +431,7 @@ export class Enum implements IEnum {
|
|||||||
|
|
||||||
const entries = Object.entries(this.#def);
|
const entries = Object.entries(this.#def);
|
||||||
|
|
||||||
return typesToMap(this.$registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => {
|
return typesToMap(this.registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => {
|
||||||
out[0][i] = Type;
|
out[0][i] = Type;
|
||||||
out[1][i] = key;
|
out[1][i] = key;
|
||||||
|
|
||||||
@@ -479,7 +450,7 @@ export class Enum implements IEnum {
|
|||||||
* @description Returns the string representation of the value
|
* @description Returns the string representation of the value
|
||||||
*/
|
*/
|
||||||
public toString (): string {
|
public toString (): string {
|
||||||
return this.$isNone
|
return this.isNone
|
||||||
? this.type
|
? this.type
|
||||||
: stringify(this.toJSON());
|
: stringify(this.toJSON());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ describe('Int', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new Int(registry, '0x12', 16).inspectU8a()
|
new Int(registry, '0x12', 16).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([0x12, 0x00])]
|
outer: [new Uint8Array([0x12, 0x00])]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ describe('Null', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('isEmpty', (): void => {
|
it('isEmpty', (): void => {
|
||||||
expect(new Null(registry).$isEmpty).toBe(true);
|
expect(new Null(registry).isEmpty).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has an empty hex', (): void => {
|
it('has an empty hex', (): void => {
|
||||||
|
|||||||
@@ -6,48 +6,22 @@ import type { Codec, Inspect, IU8a, Registry } from '../types';
|
|||||||
|
|
||||||
import { isNull } from '@polkadot/util';
|
import { isNull } from '@polkadot/util';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Null
|
* @name Null
|
||||||
* @description
|
* @description
|
||||||
* Implements a type that does not contain anything (apart from `null`)
|
* Implements a type that does not contain anything (apart from `null`)
|
||||||
*/
|
*/
|
||||||
export class Null implements Codec {
|
export class Null implements Codec {
|
||||||
public $createdAtHash?: IU8a;
|
readonly encodedLength = 0;
|
||||||
readonly $encodedLength = 0;
|
readonly isEmpty = true;
|
||||||
public $initialU8aLength = 0;
|
readonly registry: Registry;
|
||||||
public $isStorageFallback?: boolean;
|
|
||||||
readonly $isEmpty = true;
|
public createdAtHash?: IU8a;
|
||||||
readonly $registry: Registry;
|
public initialU8aLength = 0;
|
||||||
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
constructor (registry: Registry) {
|
constructor (registry: Registry) {
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +41,7 @@ export class Null implements Codec {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ describe('Option', (): void => {
|
|||||||
].forEach((test): void => {
|
].forEach((test): void => {
|
||||||
expect(test.isSome).toBe(true);
|
expect(test.isSome).toBe(true);
|
||||||
expect(test.isNone).toBe(false);
|
expect(test.isNone).toBe(false);
|
||||||
expect(test.$isEmpty).toBe(false);
|
expect(test.isEmpty).toBe(false);
|
||||||
expect(test.toU8a()).toEqual(new Uint8Array([1]));
|
expect(test.toU8a()).toEqual(new Uint8Array([1]));
|
||||||
expect(test.unwrap().toHex()).toEqual('0x');
|
expect(test.unwrap().toHex()).toEqual('0x');
|
||||||
});
|
});
|
||||||
@@ -198,7 +198,7 @@ describe('Option', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new Option(registry, U32, '1234').inspectU8a()
|
new Option(registry, U32, '1234').inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([0x01]), new Uint8Array([210, 4, 0, 0])]
|
outer: [new Uint8Array([0x01]), new Uint8Array([210, 4, 0, 0])]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, Inspect, IOption, IU8a, Registry } fro
|
|||||||
|
|
||||||
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
||||||
|
|
||||||
import { typeToConstructor, warnGet } from '../utils';
|
import { typeToConstructor } from '../utils';
|
||||||
import { Null } from './Null';
|
import { Null } from './Null';
|
||||||
|
|
||||||
interface Options<T> {
|
interface Options<T> {
|
||||||
@@ -66,11 +66,11 @@ function decodeOption (registry: Registry, Type: CodecClass, value?: unknown): C
|
|||||||
* with a value if/as required/found.
|
* with a value if/as required/found.
|
||||||
*/
|
*/
|
||||||
export class Option<T extends Codec> implements IOption<T> {
|
export class Option<T extends Codec> implements IOption<T> {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #Type: CodecClass<T>;
|
readonly #Type: CodecClass<T>;
|
||||||
readonly #raw: T;
|
readonly #raw: T;
|
||||||
@@ -83,40 +83,15 @@ export class Option<T extends Codec> implements IOption<T> {
|
|||||||
: new Type(registry, value.subarray(1))
|
: new Type(registry, value.subarray(1))
|
||||||
: decodeOption(registry, Type, value);
|
: decodeOption(registry, Type, value);
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.#Type = Type;
|
this.#Type = Type;
|
||||||
this.#raw = decoded as T;
|
this.#raw = decoded as T;
|
||||||
|
|
||||||
if (decoded?.$initialU8aLength) {
|
if (decoded?.initialU8aLength) {
|
||||||
this.$initialU8aLength = 1 + decoded.$initialU8aLength;
|
this.initialU8aLength = 1 + decoded.initialU8aLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Option<O>> {
|
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Option<O>> {
|
||||||
let definition: CodecClass<O> | undefined;
|
let definition: CodecClass<O> | undefined;
|
||||||
|
|
||||||
@@ -136,22 +111,22 @@ export class Option<T extends Codec> implements IOption<T> {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
// boolean byte (has value, doesn't have) along with wrapped length
|
// boolean byte (has value, doesn't have) along with wrapped length
|
||||||
return 1 + this.#raw.$encodedLength;
|
return 1 + this.#raw.encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the Option has no value
|
* @description Checks if the Option has no value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.isNone;
|
return this.isNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,12 +165,12 @@ export class Option<T extends Codec> implements IOption<T> {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
if (this.isNone) {
|
if (this.isNone) {
|
||||||
return { outer: [new Uint8Array([0])] };
|
return { outer: [new Uint8Array([0])] };
|
||||||
}
|
}
|
||||||
|
|
||||||
const { inner, outer = [] } = this.#raw.inspectU8a();
|
const { inner, outer = [] } = this.#raw.inspect();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inner,
|
inner,
|
||||||
@@ -243,7 +218,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
|||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public toRawType (isBare?: boolean): string {
|
public toRawType (isBare?: boolean): string {
|
||||||
const wrapped = this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType();
|
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
|
||||||
|
|
||||||
return isBare
|
return isBare
|
||||||
? wrapped
|
? wrapped
|
||||||
@@ -266,7 +241,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
|||||||
return this.#raw.toU8a(true);
|
return this.#raw.toU8a(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
const u8a = new Uint8Array(this.$encodedLength);
|
const u8a = new Uint8Array(this.encodedLength);
|
||||||
|
|
||||||
if (this.isSome) {
|
if (this.isSome) {
|
||||||
u8a.set([1]);
|
u8a.set([1]);
|
||||||
@@ -304,6 +279,6 @@ export class Option<T extends Codec> implements IOption<T> {
|
|||||||
public unwrapOrDefault (): T {
|
public unwrapOrDefault (): T {
|
||||||
return this.isSome
|
return this.isSome
|
||||||
? this.unwrap()
|
? this.unwrap()
|
||||||
: new this.#Type(this.$registry);
|
: new this.#Type(this.registry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export class Result<O extends Codec, E extends Codec> extends Enum implements IR
|
|||||||
* @description Checks if the Result has no value
|
* @description Checks if the Result has no value
|
||||||
*/
|
*/
|
||||||
public override get isEmpty (): boolean {
|
public override get isEmpty (): boolean {
|
||||||
return this.isOk && this.value.$isEmpty;
|
return this.isOk && this.value.isEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ describe('Tuple', (): void => {
|
|||||||
const INPUT = '0xcc0200000000';
|
const INPUT = '0xcc0200000000';
|
||||||
const test = registry.createType('(u32, [u32; 0], u16)', INPUT);
|
const test = registry.createType('(u32, [u32; 0], u16)', INPUT);
|
||||||
|
|
||||||
expect(test.$encodedLength).toEqual(4 + 0 + 2);
|
expect(test.encodedLength).toEqual(4 + 0 + 2);
|
||||||
expect(test.toHex()).toEqual(INPUT);
|
expect(test.toHex()).toEqual(INPUT);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -123,7 +123,7 @@ describe('Tuple', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
tuple.inspectU8a()
|
tuple.inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ outer: [new Uint8Array([7 << 2]), stringToU8a('bazzing')] },
|
{ outer: [new Uint8Array([7 << 2]), stringToU8a('bazzing')] },
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
|||||||
|
|
||||||
super(registry, Classes[0].length);
|
super(registry, Classes[0].length);
|
||||||
|
|
||||||
this.$initialU8aLength = (
|
this.initialU8aLength = (
|
||||||
isU8a(value)
|
isU8a(value)
|
||||||
? decodeU8a(registry, this, value, Classes)
|
? decodeU8a(registry, this, value, Classes)
|
||||||
: decodeTuple(registry, this, value, Classes)
|
: decodeTuple(registry, this, value, Classes)
|
||||||
@@ -93,11 +93,11 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
total += this[i].$encodedLength;
|
total += this[i].encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
@@ -109,13 +109,13 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
|||||||
public get Types (): string[] {
|
public get Types (): string[] {
|
||||||
return this.#Types[1].length
|
return this.#Types[1].length
|
||||||
? this.#Types[1]
|
? this.#Types[1]
|
||||||
: this.#Types[0].map((T) => new T(this.$registry).toRawType());
|
: this.#Types[0].map((T) => new T(this.registry).toRawType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public override inspectU8a (): Inspect {
|
public override inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
inner: this.inspectInner()
|
inner: this.inspectInner()
|
||||||
};
|
};
|
||||||
@@ -126,7 +126,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
|||||||
*/
|
*/
|
||||||
public toRawType (): string {
|
public toRawType (): string {
|
||||||
const types = this.#Types[0].map((T) =>
|
const types = this.#Types[0].map((T) =>
|
||||||
this.$registry.getClassName(T) || new T(this.$registry).toRawType()
|
this.registry.getClassName(T) || new T(this.registry).toRawType()
|
||||||
);
|
);
|
||||||
|
|
||||||
return `(${types.join(',')})`;
|
return `(${types.join(',')})`;
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ describe('UInt', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new UInt(registry, '0x12', 16).inspectU8a()
|
new UInt(registry, '0x12', 16).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([0x12, 0x00])]
|
outer: [new Uint8Array([0x12, 0x00])]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ describe('Vec', (): void => {
|
|||||||
];
|
];
|
||||||
const vec = registry.createType('Vec<AccountId>', addrs);
|
const vec = registry.createType('Vec<AccountId>', addrs);
|
||||||
|
|
||||||
expect(vec.inspectU8a()).toEqual({
|
expect(vec.inspect()).toEqual({
|
||||||
inner: addrs.map((a) => ({
|
inner: addrs.map((a) => ({
|
||||||
outer: [decodeAddress(a)]
|
outer: [decodeAddress(a)]
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
|
|||||||
|
|
||||||
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
|
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
|
||||||
|
|
||||||
this.$initialU8aLength = (
|
this.initialU8aLength = (
|
||||||
isU8a(decodeFrom)
|
isU8a(decodeFrom)
|
||||||
? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type)
|
? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type)
|
||||||
: decodeVec(registry, this, decodeFrom, startAt, this.#Type)
|
: decodeVec(registry, this, decodeFrom, startAt, this.#Type)
|
||||||
@@ -115,7 +115,7 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
|
|||||||
// convert type first, this removes overhead from the eq
|
// convert type first, this removes overhead from the eq
|
||||||
const other = _other instanceof this.#Type
|
const other = _other instanceof this.#Type
|
||||||
? _other
|
? _other
|
||||||
: new this.#Type(this.$registry, _other);
|
: new this.#Type(this.registry, _other);
|
||||||
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
if (other.eq(this[i])) {
|
if (other.eq(this[i])) {
|
||||||
@@ -130,6 +130,6 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
|
|||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public toRawType (): string {
|
public toRawType (): string {
|
||||||
return `Vec<${this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType()}>`;
|
return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,19 +50,19 @@ describe('VecFixed', (): void => {
|
|||||||
it('has empty Uint8Array when length is 0', (): void => {
|
it('has empty Uint8Array when length is 0', (): void => {
|
||||||
const test = new (VecFixed.with(Text, 0))(registry);
|
const test = new (VecFixed.with(Text, 0))(registry);
|
||||||
|
|
||||||
expect(test.$encodedLength).toEqual(0);
|
expect(test.encodedLength).toEqual(0);
|
||||||
expect(test.toU8a()).toEqual(new Uint8Array([]));
|
expect(test.toU8a()).toEqual(new Uint8Array([]));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has equivalent to 1 Uint8Array when length is 1', (): void => {
|
it('has equivalent to 1 Uint8Array when length is 1', (): void => {
|
||||||
const test = new (VecFixed.with(Text, 1))(registry, ['hello']);
|
const test = new (VecFixed.with(Text, 1))(registry, ['hello']);
|
||||||
|
|
||||||
expect(test.$encodedLength).toEqual(1 + 5);
|
expect(test.encodedLength).toEqual(1 + 5);
|
||||||
expect(test.toU8a()).toEqual(new Uint8Array([20, 104, 101, 108, 108, 111]));
|
expect(test.toU8a()).toEqual(new Uint8Array([20, 104, 101, 108, 108, 111]));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(test.inspectU8a()).toEqual({
|
expect(test.inspect()).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
||||||
{ outer: [new Uint8Array([1 << 2]), stringToU8a('2')] },
|
{ outer: [new Uint8Array([1 << 2]), stringToU8a('2')] },
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
|||||||
|
|
||||||
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
|
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
|
||||||
|
|
||||||
this.$initialU8aLength = (
|
this.initialU8aLength = (
|
||||||
isU8a(value)
|
isU8a(value)
|
||||||
? decodeU8aVec(registry, this, value, 0, this.#Type)
|
? decodeU8aVec(registry, this, value, 0, this.#Type)
|
||||||
: decodeVec(registry, this, value, 0, this.#Type)
|
: decodeVec(registry, this, value, 0, this.#Type)
|
||||||
@@ -57,17 +57,17 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
|||||||
* @description The type for the items
|
* @description The type for the items
|
||||||
*/
|
*/
|
||||||
public get Type (): string {
|
public get Type (): string {
|
||||||
return new this.#Type(this.$registry).toRawType();
|
return new this.#Type(this.registry).toRawType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
for (let i = 0; i < this.length; i++) {
|
||||||
total += this[i].$encodedLength;
|
total += this[i].encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
@@ -76,7 +76,7 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public override inspectU8a (): Inspect {
|
public override inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
inner: this.inspectInner()
|
inner: this.inspectInner()
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ describe('BTreeMap', (): void => {
|
|||||||
it('correctly encodes length', (): void => {
|
it('correctly encodes length', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new (
|
new (
|
||||||
BTreeMap.with(Text, U32))(registry, mockU32TextMap).$encodedLength
|
BTreeMap.with(Text, U32))(registry, mockU32TextMap).encodedLength
|
||||||
).toEqual(13);
|
).toEqual(13);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ describe('BTreeMap', (): void => {
|
|||||||
[new Text(registry, '1'), new Text(registry, 'foo')],
|
[new Text(registry, '1'), new Text(registry, 'foo')],
|
||||||
[new Text(registry, '2'), new Text(registry, 'bar')],
|
[new Text(registry, '2'), new Text(registry, 'bar')],
|
||||||
[new Text(registry, '3'), new Text(registry, 'baz')]
|
[new Text(registry, '3'), new Text(registry, 'baz')]
|
||||||
])).inspectU8a()
|
])).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ describe('BTreeSet', (): void => {
|
|||||||
it('correctly encodes length', (): void => {
|
it('correctly encodes length', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new (
|
new (
|
||||||
BTreeSet.with(U32))(registry, mockU32Set).$encodedLength
|
BTreeSet.with(U32))(registry, mockU32Set).encodedLength
|
||||||
).toEqual(17);
|
).toEqual(17);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -139,10 +139,10 @@ describe('BTreeSet', (): void => {
|
|||||||
|
|
||||||
// only the length byte
|
// only the length byte
|
||||||
expect(none.toHex()).toEqual('0x00');
|
expect(none.toHex()).toEqual('0x00');
|
||||||
expect(none.$encodedLength).toEqual(1);
|
expect(none.encodedLength).toEqual(1);
|
||||||
expect(
|
expect(
|
||||||
(new (BTreeSet.with(U32))(registry, none.toHex())).$initialU8aLength
|
(new (BTreeSet.with(U32))(registry, none.toHex())).initialU8aLength
|
||||||
).toEqual(none.$encodedLength);
|
).toEqual(none.encodedLength);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly encodes/decodes filled', (): void => {
|
it('correctly encodes/decodes filled', (): void => {
|
||||||
@@ -150,10 +150,10 @@ describe('BTreeSet', (): void => {
|
|||||||
|
|
||||||
// length byte + 2 values, 2 << 2 with u32 values
|
// length byte + 2 values, 2 << 2 with u32 values
|
||||||
expect(some.toHex()).toEqual('0x080100000002000000');
|
expect(some.toHex()).toEqual('0x080100000002000000');
|
||||||
expect(some.$encodedLength).toEqual(1 + (4 * 2));
|
expect(some.encodedLength).toEqual(1 + (4 * 2));
|
||||||
expect(
|
expect(
|
||||||
(new (BTreeSet.with(U32))(registry, some.toHex())).$initialU8aLength
|
(new (BTreeSet.with(U32))(registry, some.toHex())).initialU8aLength
|
||||||
).toEqual(some.$encodedLength);
|
).toEqual(some.encodedLength);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ describe('BTreeSet', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new (BTreeSet.with(U32))(registry, [1, 2, 3, 4]).inspectU8a()
|
new (BTreeSet.with(U32))(registry, [1, 2, 3, 4]).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ outer: [new Uint8Array([1, 0, 0, 0])] },
|
{ outer: [new Uint8Array([1, 0, 0, 0])] },
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, Inspect, ISet, IU8a, Registry } from '
|
|||||||
|
|
||||||
import { compactFromU8aLim, compactToU8a, isHex, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
import { compactFromU8aLim, compactToU8a, isHex, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { compareSet, decodeU8aVec, sortSet, typeToConstructor, warnGet } from '../utils';
|
import { compareSet, decodeU8aVec, sortSet, typeToConstructor } from '../utils';
|
||||||
|
|
||||||
const l = logger('BTreeSet');
|
const l = logger('BTreeSet');
|
||||||
|
|
||||||
@@ -70,11 +70,11 @@ function decodeSet<V extends Codec> (registry: Registry, valType: CodecClass<V>
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V> {
|
export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V> {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #ValClass: CodecClass<V>;
|
readonly #ValClass: CodecClass<V>;
|
||||||
|
|
||||||
@@ -83,36 +83,11 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
|||||||
|
|
||||||
super(sortSet(values));
|
super(sortSet(values));
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.$initialU8aLength = decodedLength;
|
this.initialU8aLength = decodedLength;
|
||||||
this.#ValClass = ValClass;
|
this.#ValClass = ValClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static with<V extends Codec> (valType: CodecClass<V> | string): CodecClass<BTreeSet<V>> {
|
public static with<V extends Codec> (valType: CodecClass<V> | string): CodecClass<BTreeSet<V>> {
|
||||||
return class extends BTreeSet<V> {
|
return class extends BTreeSet<V> {
|
||||||
constructor (registry: Registry, value?: Uint8Array | string | Set<any>) {
|
constructor (registry: Registry, value?: Uint8Array | string | Set<any>) {
|
||||||
@@ -124,11 +99,11 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
let len = compactToU8a(this.size).length;
|
let len = compactToU8a(this.size).length;
|
||||||
|
|
||||||
for (const v of this.values()) {
|
for (const v of this.values()) {
|
||||||
len += v.$encodedLength;
|
len += v.encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
@@ -138,13 +113,13 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
|||||||
* @description Returns a hash of the value
|
* @description Returns a hash of the value
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.size === 0;
|
return this.size === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,11 +140,11 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
const inner = new Array<Inspect>();
|
const inner = new Array<Inspect>();
|
||||||
|
|
||||||
for (const v of this.values()) {
|
for (const v of this.values()) {
|
||||||
inner.push(v.inspectU8a());
|
inner.push(v.inspect());
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -215,7 +190,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
|||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public toRawType (): string {
|
public toRawType (): string {
|
||||||
return `BTreeSet<${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`;
|
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ describe('BitVec', (): void => {
|
|||||||
|
|
||||||
it('has the right encodedLength', (): void => {
|
it('has the right encodedLength', (): void => {
|
||||||
expect(
|
expect(
|
||||||
bitvec.$encodedLength
|
bitvec.encodedLength
|
||||||
).toEqual((test.length - 2) / 2);
|
).toEqual((test.length - 2) / 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ describe('BitVec', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new BitVec(registry, '0x0837').inspectU8a()
|
new BitVec(registry, '0x0837').inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([0]), new Uint8Array([0x08, 0x37])]
|
outer: [new Uint8Array([0]), new Uint8Array([0x08, 0x37])]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,14 +60,14 @@ export class BitVec extends Raw {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
return this.length + compactToU8a(this.#decodedLength).length;
|
return this.length + compactToU8a(this.#decodedLength).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public override inspectU8a (): Inspect {
|
public override inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [compactToU8a(this.#decodedLength), super.toU8a()]
|
outer: [compactToU8a(this.#decodedLength), super.toU8a()]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ describe('Bytes', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new Bytes(registry, '0x12345678').inspectU8a()
|
new Bytes(registry, '0x12345678').inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([4 << 2]), new Uint8Array([0x12, 0x34, 0x56, 0x78])]
|
outer: [new Uint8Array([4 << 2]), new Uint8Array([0x12, 0x34, 0x56, 0x78])]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,14 +50,14 @@ export class Bytes extends Raw {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
return this.length + compactToU8a(this.length).length;
|
return this.length + compactToU8a(this.length).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public override inspectU8a (isBare?: boolean): Inspect {
|
public override inspect (isBare?: boolean): Inspect {
|
||||||
const clength = compactToU8a(this.length);
|
const clength = compactToU8a(this.length);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ describe('HashMap', (): void => {
|
|||||||
new (HashMap.with(Text, Text))(registry, new Map([
|
new (HashMap.with(Text, Text))(registry, new Map([
|
||||||
[new Text(registry, '1'), new Text(registry, 'foo')],
|
[new Text(registry, '1'), new Text(registry, 'foo')],
|
||||||
[new Text(registry, '2'), new Text(registry, 'bar')]
|
[new Text(registry, '2'), new Text(registry, 'bar')]
|
||||||
])).inspectU8a()
|
])).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export class Linkage<T extends Codec> extends Struct {
|
|||||||
public override toU8a (): Uint8Array {
|
public override toU8a (): Uint8Array {
|
||||||
// As part of a storage query (where these appear), in the case of empty, the values
|
// As part of a storage query (where these appear), in the case of empty, the values
|
||||||
// are NOT populated by the node - follow the same logic, leaving it empty
|
// are NOT populated by the node - follow the same logic, leaving it empty
|
||||||
return this.$isEmpty
|
return this.isEmpty
|
||||||
? EMPTY
|
? EMPTY
|
||||||
: super.toU8a();
|
: super.toU8a();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,10 +81,10 @@ describe('CodecMap', (): void => {
|
|||||||
|
|
||||||
// only the length byte
|
// only the length byte
|
||||||
expect(none.toHex()).toEqual('0x00');
|
expect(none.toHex()).toEqual('0x00');
|
||||||
expect(none.$encodedLength).toEqual(1);
|
expect(none.encodedLength).toEqual(1);
|
||||||
expect(
|
expect(
|
||||||
new CodecMap(registry, Text, Text, none.toHex()).$initialU8aLength
|
new CodecMap(registry, Text, Text, none.toHex()).initialU8aLength
|
||||||
).toEqual(none.$encodedLength);
|
).toEqual(none.encodedLength);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('correctly encodes/decodes filled', (): void => {
|
it('correctly encodes/decodes filled', (): void => {
|
||||||
@@ -95,10 +95,10 @@ describe('CodecMap', (): void => {
|
|||||||
|
|
||||||
// length byte + 2 values, 2 << 2 with Text values
|
// length byte + 2 values, 2 << 2 with Text values
|
||||||
expect(some.toHex()).toEqual('0x0804310c666f6f04320c626172');
|
expect(some.toHex()).toEqual('0x0804310c666f6f04320c626172');
|
||||||
expect(some.$encodedLength).toEqual(1 + ((1 + 1) * 2) + ((1 + 3) * 2));
|
expect(some.encodedLength).toEqual(1 + ((1 + 1) * 2) + ((1 + 3) * 2));
|
||||||
expect(
|
expect(
|
||||||
new CodecMap(registry, Text, Text, some.toHex()).$initialU8aLength
|
new CodecMap(registry, Text, Text, some.toHex()).initialU8aLength
|
||||||
).toEqual(some.$encodedLength);
|
).toEqual(some.encodedLength);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ describe('CodecMap', (): void => {
|
|||||||
new CodecMap(registry, Text, Text, new Map([
|
new CodecMap(registry, Text, Text, new Map([
|
||||||
[new Text(registry, '1'), new Text(registry, 'foo')],
|
[new Text(registry, '1'), new Text(registry, 'foo')],
|
||||||
[new Text(registry, '2'), new Text(registry, 'bar')]
|
[new Text(registry, '2'), new Text(registry, 'bar')]
|
||||||
])).inspectU8a()
|
])).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
{ outer: [new Uint8Array([1 << 2]), stringToU8a('1')] },
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { AbstractArray } from '../abstract/Array';
|
|||||||
import { Enum } from '../base/Enum';
|
import { Enum } from '../base/Enum';
|
||||||
import { Raw } from '../native/Raw';
|
import { Raw } from '../native/Raw';
|
||||||
import { Struct } from '../native/Struct';
|
import { Struct } from '../native/Struct';
|
||||||
import { compareMap, decodeU8a, sortMap, typeToConstructor, warnGet } from '../utils';
|
import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils';
|
||||||
|
|
||||||
const l = logger('Map');
|
const l = logger('Map');
|
||||||
|
|
||||||
@@ -94,11 +94,11 @@ function decodeMap<K extends Codec, V extends Codec> (registry: Registry, keyTyp
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements IMap<K, V> {
|
export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements IMap<K, V> {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #KeyClass: CodecClass<K>;
|
readonly #KeyClass: CodecClass<K>;
|
||||||
readonly #ValClass: CodecClass<V>;
|
readonly #ValClass: CodecClass<V>;
|
||||||
@@ -109,46 +109,21 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
|||||||
|
|
||||||
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.$initialU8aLength = decodedLength;
|
this.initialU8aLength = decodedLength;
|
||||||
this.#KeyClass = KeyClass;
|
this.#KeyClass = KeyClass;
|
||||||
this.#ValClass = ValClass;
|
this.#ValClass = ValClass;
|
||||||
this.#type = type;
|
this.#type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
let len = compactToU8a(this.size).length;
|
let len = compactToU8a(this.size).length;
|
||||||
|
|
||||||
for (const [k, v] of this.entries()) {
|
for (const [k, v] of this.entries()) {
|
||||||
len += k.$encodedLength + v.$encodedLength;
|
len += k.encodedLength + v.encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
@@ -158,13 +133,13 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
|||||||
* @description Returns a hash of the value
|
* @description Returns a hash of the value
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.size === 0;
|
return this.size === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,12 +153,12 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
const inner = new Array<Inspect>();
|
const inner = new Array<Inspect>();
|
||||||
|
|
||||||
for (const [k, v] of this.entries()) {
|
for (const [k, v] of this.entries()) {
|
||||||
inner.push(k.inspectU8a());
|
inner.push(k.inspect());
|
||||||
inner.push(v.inspectU8a());
|
inner.push(v.inspect());
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -250,7 +225,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
|||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public toRawType (): string {
|
public toRawType (): string {
|
||||||
return `${this.#type}<${this.$registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.$registry).toRawType()},${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`;
|
return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ describe('OptionBool', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(new OptionBool(registry, true).inspectU8a()).toEqual({
|
expect(new OptionBool(registry, true).inspect()).toEqual({
|
||||||
outer: [new Uint8Array([1])]
|
outer: [new Uint8Array([1])]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ export class OptionBool extends Option<Bool> {
|
|||||||
: value
|
: value
|
||||||
);
|
);
|
||||||
|
|
||||||
this.$initialU8aLength = 1;
|
this.initialU8aLength = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ export class OptionBool extends Option<Bool> {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public override inspectU8a (): Inspect {
|
public override inspect (): Inspect {
|
||||||
return { outer: [this.toU8a()] };
|
return { outer: [this.toU8a()] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ describe('Range', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(range.inspectU8a()).toEqual({
|
expect(range.inspect()).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ outer: [new Uint8Array([1, 0, 0, 0])] },
|
{ outer: [new Uint8Array([1, 0, 0, 0])] },
|
||||||
{ outer: [new Uint8Array([2, 0, 0, 0])] }
|
{ outer: [new Uint8Array([2, 0, 0, 0])] }
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ describe('Type', (): void => {
|
|||||||
const u8a = new Type(registry, original).toU8a();
|
const u8a = new Type(registry, original).toU8a();
|
||||||
const decoded = new Type(registry, u8a);
|
const decoded = new Type(registry, u8a);
|
||||||
|
|
||||||
expect(decoded.$encodedLength).toEqual(original.length + 1); // extra byte for length
|
expect(decoded.encodedLength).toEqual(original.length + 1); // extra byte for length
|
||||||
expect(decoded.toString()).toEqual(expected);
|
expect(decoded.toString()).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ describe('U8aFixed', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(u8a.inspectU8a()).toEqual({
|
expect(u8a.inspect()).toEqual({
|
||||||
outer: [new Uint8Array([1, 2, 3, 4])]
|
outer: [new Uint8Array([1, 2, 3, 4])]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ describe('WrapperKeepOpaque', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect (non-decodable)', (): void => {
|
it('has a sane inspect (non-decodable)', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new ClazzUSize(registry, u8au32).inspectU8a()
|
new ClazzUSize(registry, u8au32).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([4 << 2]), new Uint8Array([0x87, 0xd6, 0x12, 0x00])]
|
outer: [new Uint8Array([4 << 2]), new Uint8Array([0x87, 0xd6, 0x12, 0x00])]
|
||||||
});
|
});
|
||||||
@@ -60,7 +60,7 @@ describe('WrapperKeepOpaque', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect (decodable)', (): void => {
|
it('has a sane inspect (decodable)', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new ClazzU32(registry, u8au32).inspectU8a()
|
new ClazzU32(registry, u8au32).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [{ outer: [new Uint8Array([0x87, 0xd6, 0x12, 0x00])] }],
|
inner: [{ outer: [new Uint8Array([0x87, 0xd6, 0x12, 0x00])] }],
|
||||||
outer: [new Uint8Array([4 << 2])]
|
outer: [new Uint8Array([4 << 2])]
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public override inspectU8a (): Inspect {
|
public override inspect (): Inspect {
|
||||||
return this.#decoded
|
return this.#decoded
|
||||||
? {
|
? {
|
||||||
inner: [this.#decoded.inspectU8a()],
|
inner: [this.#decoded.inspect()],
|
||||||
outer: [compactToU8a(this.length)]
|
outer: [compactToU8a(this.length)]
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
@@ -103,7 +103,7 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
|||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public override toRawType (): string {
|
public override toRawType (): string {
|
||||||
return `${this.#opaqueName}<${this.$registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.$registry).toRawType())}>`;
|
return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ describe('WrapperOpaque', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new WrapperOpaque(registry, 'u32', '0x78563412').inspectU8a()
|
new WrapperOpaque(registry, 'u32', '0x78563412').inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [{ outer: [new Uint8Array([0x78, 0x56, 0x34, 0x12])] }],
|
inner: [{ outer: [new Uint8Array([0x78, 0x56, 0x34, 0x12])] }],
|
||||||
outer: [new Uint8Array([4 << 2])]
|
outer: [new Uint8Array([4 << 2])]
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ describe('Bool', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly encodes length', (): void => {
|
it('correctly encodes length', (): void => {
|
||||||
expect(new Bool(registry, true).$encodedLength).toEqual(1);
|
expect(new Bool(registry, true).encodedLength).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('utils', (): void => {
|
describe('utils', (): void => {
|
||||||
@@ -58,13 +58,13 @@ describe('Bool', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has sane isEmpty aligning with the rest', (): void => {
|
it('has sane isEmpty aligning with the rest', (): void => {
|
||||||
expect(new Bool(registry).$isEmpty).toBe(true);
|
expect(new Bool(registry).isEmpty).toBe(true);
|
||||||
expect(new Bool(registry, false).$isEmpty).toBe(true);
|
expect(new Bool(registry, false).isEmpty).toBe(true);
|
||||||
expect(new Bool(registry, true).$isEmpty).toBe(false);
|
expect(new Bool(registry, true).isEmpty).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(new Bool(registry, true).inspectU8a()).toEqual({
|
expect(new Bool(registry, true).inspect()).toEqual({
|
||||||
outer: [new Uint8Array([1])]
|
outer: [new Uint8Array([1])]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import type { AnyBool, Codec, Inspect, IU8a, Registry } from '../types';
|
|||||||
|
|
||||||
import { isU8a, u8aToHex } from '@polkadot/util';
|
import { isU8a, u8aToHex } from '@polkadot/util';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name bool
|
* @name bool
|
||||||
* @description
|
* @description
|
||||||
@@ -15,12 +13,11 @@ import { warnGet } from '../utils';
|
|||||||
* @noInheritDoc
|
* @noInheritDoc
|
||||||
*/
|
*/
|
||||||
export class bool extends Boolean implements Codec {
|
export class bool extends Boolean implements Codec {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
readonly $encodedLength = 1;
|
public initialU8aLength = 1;
|
||||||
public $initialU8aLength = 1;
|
public isStorageFallback?: boolean;
|
||||||
public $isStorageFallback?: boolean;
|
|
||||||
|
|
||||||
constructor (registry: Registry, value: bool | AnyBool | Uint8Array | number = false) {
|
constructor (registry: Registry, value: bool | AnyBool | Uint8Array | number = false) {
|
||||||
super(
|
super(
|
||||||
@@ -31,45 +28,27 @@ export class bool extends Boolean implements Codec {
|
|||||||
: !!value
|
: !!value
|
||||||
);
|
);
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
/**
|
||||||
public get createdAtHash (): IU8a | undefined {
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
return warnGet(this, 'createdAtHash');
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return warnGet(this, 'encodedLength');
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value (true when it wraps false/default)
|
* @description Checks if the value is an empty value (true when it wraps false/default)
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.isFalse;
|
return this.isFalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +80,7 @@ export class bool extends Boolean implements Codec {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [this.toU8a()]
|
outer: [this.toU8a()]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ describe('Date', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(new CodecDate(registry, 3).inspectU8a()).toEqual({
|
expect(new CodecDate(registry, 3).inspect()).toEqual({
|
||||||
outer: [new Uint8Array([3, 0, 0, 0, 0, 0, 0, 0])]
|
outer: [new Uint8Array([3, 0, 0, 0, 0, 0, 0, 0])]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from
|
|||||||
|
|
||||||
import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
|
import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
const BITLENGTH: UIntBitLength = 64;
|
const BITLENGTH: UIntBitLength = 64;
|
||||||
const U8A_OPTS = { bitLength: BITLENGTH, isLe: true };
|
const U8A_OPTS = { bitLength: BITLENGTH, isLe: true };
|
||||||
|
|
||||||
@@ -36,55 +34,36 @@ function decodeDate (value: CodecDate | Date | AnyNumber): Date {
|
|||||||
* @noInheritDoc
|
* @noInheritDoc
|
||||||
*/
|
*/
|
||||||
export class CodecDate extends Date implements INumber {
|
export class CodecDate extends Date implements INumber {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
readonly $encodedLength = BITLENGTH / 8;
|
public initialU8aLength = BITLENGTH / 8;
|
||||||
public $initialU8aLength = BITLENGTH / 8;
|
public isStorageFallback?: boolean;
|
||||||
public $isStorageFallback?: boolean;
|
|
||||||
|
|
||||||
constructor (registry: Registry, value: CodecDate | Date | AnyNumber = 0) {
|
constructor (registry: Registry, value: CodecDate | Date | AnyNumber = 0) {
|
||||||
super(decodeDate(value));
|
super(decodeDate(value));
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
/**
|
||||||
public get createdAtHash (): IU8a | undefined {
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
return warnGet(this, 'createdAtHash');
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return warnGet(this, 'encodedLength');
|
return BITLENGTH / 8;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.getTime() === 0;
|
return this.getTime() === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +84,7 @@ export class CodecDate extends Date implements INumber {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [this.toU8a()]
|
outer: [this.toU8a()]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe('Float', (): void => {
|
|||||||
|
|
||||||
it('triggers isEmpty on 0', (): void => {
|
it('triggers isEmpty on 0', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new F32(registry, 0).$isEmpty
|
new F32(registry, 0).isEmpty
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import type { AnyFloat, CodecClass, IFloat, Inspect, IU8a, Registry } from '../t
|
|||||||
|
|
||||||
import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
bitLength?: 32 | 64;
|
bitLength?: 32 | 64;
|
||||||
}
|
}
|
||||||
@@ -21,11 +19,12 @@ interface Options {
|
|||||||
* in some eth_* RPCs
|
* in some eth_* RPCs
|
||||||
*/
|
*/
|
||||||
export class Float extends Number implements IFloat {
|
export class Float extends Number implements IFloat {
|
||||||
public $createdAtHash?: IU8a;
|
readonly encodedLength: number;
|
||||||
readonly $encodedLength: number;
|
readonly registry: Registry;
|
||||||
public $initialU8aLength?: number;
|
|
||||||
public $isStorageFallback?: boolean;
|
public createdAtHash?: IU8a;
|
||||||
readonly $registry: Registry;
|
public initialU8aLength?: number;
|
||||||
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #bitLength: 32 | 64;
|
readonly #bitLength: 32 | 64;
|
||||||
|
|
||||||
@@ -39,34 +38,9 @@ export class Float extends Number implements IFloat {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.#bitLength = bitLength;
|
this.#bitLength = bitLength;
|
||||||
this.$encodedLength = bitLength / 8;
|
this.encodedLength = bitLength / 8;
|
||||||
this.$initialU8aLength = this.$encodedLength;
|
this.initialU8aLength = this.encodedLength;
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static with (bitLength: 32 | 64): CodecClass<Float> {
|
public static with (bitLength: 32 | 64): CodecClass<Float> {
|
||||||
@@ -81,13 +55,13 @@ export class Float extends Number implements IFloat {
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns true if the type wraps an empty/default all-0 value
|
* @description Returns true if the type wraps an empty/default all-0 value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
get isEmpty (): boolean {
|
||||||
return this.valueOf() === 0;
|
return this.valueOf() === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +75,7 @@ export class Float extends Number implements IFloat {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [this.toU8a()]
|
outer: [this.toU8a()]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, Inspect, IU8a, Registry } from '../types';
|
|||||||
|
|
||||||
import { isFunction, objectProperties, stringify } from '@polkadot/util';
|
import { isFunction, objectProperties, stringify } from '@polkadot/util';
|
||||||
|
|
||||||
import { compareMap, warnGet } from '../utils';
|
import { compareMap } from '../utils';
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
|
function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
|
||||||
@@ -22,59 +22,40 @@ function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
|
|||||||
* @noInheritDoc
|
* @noInheritDoc
|
||||||
*/
|
*/
|
||||||
export class Json extends Map<string, any> implements Codec {
|
export class Json extends Map<string, any> implements Codec {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
readonly $encodedLength = 0;
|
public initialU8aLength?: number;
|
||||||
public $initialU8aLength?: number;
|
public isStorageFallback?: boolean;
|
||||||
public $isStorageFallback?: boolean;
|
|
||||||
|
|
||||||
constructor (registry: Registry, value?: Record<string, unknown> | null) {
|
constructor (registry: Registry, value?: Record<string, unknown> | null) {
|
||||||
const decoded = decodeJson(value);
|
const decoded = decodeJson(value);
|
||||||
|
|
||||||
super(decoded);
|
super(decoded);
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
|
|
||||||
objectProperties(this, decoded.map(([k]) => k), (k) => this.get(k));
|
objectProperties(this, decoded.map(([k]) => k), (k) => this.get(k));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
/**
|
||||||
public get createdAtHash (): IU8a | undefined {
|
* @description Always 0, never encodes as a Uint8Array
|
||||||
return warnGet(this, 'createdAtHash');
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return warnGet(this, 'encodedLength');
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return [...this.keys()].length === 0;
|
return [...this.keys()].length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +76,7 @@ export class Json extends Map<string, any> implements Codec {
|
|||||||
/**
|
/**
|
||||||
* @description Unimplemented, will throw
|
* @description Unimplemented, will throw
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
throw new Error('Unimplemented');
|
throw new Error('Unimplemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ describe('Raw', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('correctly encodes length', (): void => {
|
it('correctly encodes length', (): void => {
|
||||||
expect(u8a.$encodedLength).toEqual(5);
|
expect(u8a.encodedLength).toEqual(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('allows wrapping of a pre-existing instance', (): void => {
|
it('allows wrapping of a pre-existing instance', (): void => {
|
||||||
@@ -98,7 +98,7 @@ describe('Raw', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new Raw(registry, [1, 2, 3, 4, 5]).inspectU8a()
|
new Raw(registry, [1, 2, 3, 4, 5]).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([1, 2, 3, 4, 5])]
|
outer: [new Uint8Array([1, 2, 3, 4, 5])]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import type { AnyJson, AnyU8a, Inspect, IU8a, Registry } from '../types';
|
|||||||
|
|
||||||
import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
|
import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Raw
|
* @name Raw
|
||||||
* @description
|
* @description
|
||||||
@@ -18,11 +16,11 @@ import { warnGet } from '../utils';
|
|||||||
* @noInheritDoc
|
* @noInheritDoc
|
||||||
*/
|
*/
|
||||||
export class Raw extends Uint8Array implements IU8a {
|
export class Raw extends Uint8Array implements IU8a {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description This ensures that operators such as clice, filter, map, etc. return
|
* @description This ensures that operators such as clice, filter, map, etc. return
|
||||||
@@ -35,39 +33,14 @@ export class Raw extends Uint8Array implements IU8a {
|
|||||||
constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) {
|
constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) {
|
||||||
super(u8aToU8a(value));
|
super(u8aToU8a(value));
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.$initialU8aLength = initialU8aLength;
|
this.initialU8aLength = initialU8aLength;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return this.length;
|
return this.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +48,7 @@ export class Raw extends Uint8Array implements IU8a {
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,7 +61,7 @@ export class Raw extends Uint8Array implements IU8a {
|
|||||||
/**
|
/**
|
||||||
* @description Returns true if the type wraps an empty/default all-0 value
|
* @description Returns true if the type wraps an empty/default all-0 value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return !this.length || isUndefined(this.find((b) => !!b));
|
return !this.length || isUndefined(this.find((b) => !!b));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +94,7 @@ export class Raw extends Uint8Array implements IU8a {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [this.toU8a()]
|
outer: [this.toU8a()]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ describe('Set', (): void => {
|
|||||||
it('constructs via an string[]', (): void => {
|
it('constructs via an string[]', (): void => {
|
||||||
const set = new CodecSet(registry, SET_ROLES, ['full', 'authority']);
|
const set = new CodecSet(registry, SET_ROLES, ['full', 'authority']);
|
||||||
|
|
||||||
expect(set.$isEmpty).toEqual(false);
|
expect(set.isEmpty).toEqual(false);
|
||||||
expect(set.toString()).toEqual(
|
expect(set.toString()).toEqual(
|
||||||
'[full, authority]'
|
'[full, authority]'
|
||||||
);
|
);
|
||||||
@@ -97,7 +97,7 @@ describe('Set', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(set.inspectU8a()).toEqual({
|
expect(set.inspect()).toEqual({
|
||||||
outer: [new Uint8Array([SET_ROLES.full | SET_ROLES.authority])]
|
outer: [new Uint8Array([SET_ROLES.full | SET_ROLES.authority])]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { CodecClass, Inspect, ISet, IU8a, Registry } from '../types';
|
|||||||
|
|
||||||
import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
|
import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { compareArray, warnGet } from '../utils';
|
import { compareArray } from '../utils';
|
||||||
|
|
||||||
type SetValues = Record<string, number | BN>;
|
type SetValues = Record<string, number | BN>;
|
||||||
|
|
||||||
@@ -92,11 +92,11 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
|
|||||||
* a bitwise representation of the values.
|
* a bitwise representation of the values.
|
||||||
*/
|
*/
|
||||||
export class CodecSet extends Set<string> implements ISet<string> {
|
export class CodecSet extends Set<string> implements ISet<string> {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #allowed: SetValues;
|
readonly #allowed: SetValues;
|
||||||
readonly #byteLength: number;
|
readonly #byteLength: number;
|
||||||
@@ -104,36 +104,11 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
|||||||
constructor (registry: Registry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength = 8) {
|
constructor (registry: Registry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength = 8) {
|
||||||
super(decodeSet(setValues, value, bitLength));
|
super(decodeSet(setValues, value, bitLength));
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.#allowed = setValues;
|
this.#allowed = setValues;
|
||||||
this.#byteLength = bitLength / 8;
|
this.#byteLength = bitLength / 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static with (values: SetValues, bitLength?: number): CodecClass<CodecSet> {
|
public static with (values: SetValues, bitLength?: number): CodecClass<CodecSet> {
|
||||||
return class extends CodecSet {
|
return class extends CodecSet {
|
||||||
static {
|
static {
|
||||||
@@ -158,7 +133,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return this.#byteLength;
|
return this.#byteLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,13 +141,13 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description true is the Set contains no values
|
* @description true is the Set contains no values
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.size === 0;
|
return this.size === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +200,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
return {
|
return {
|
||||||
outer: [this.toU8a()]
|
outer: [this.toU8a()]
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ describe('Struct', (): void => {
|
|||||||
txt: Text,
|
txt: Text,
|
||||||
u32: U32
|
u32: U32
|
||||||
})
|
})
|
||||||
)(registry, { foo: 'bazzing', bar: 69 }).$encodedLength
|
)(registry, { foo: 'bazzing', bar: 69 }).encodedLength
|
||||||
).toEqual(5);
|
).toEqual(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -380,7 +380,7 @@ describe('Struct', (): void => {
|
|||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new Struct(registry, def, val).inspectU8a()
|
new Struct(registry, def, val).inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Regi
|
|||||||
|
|
||||||
import { isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
import { isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||||
|
|
||||||
import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap, warnGet } from '../utils';
|
import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from '../utils';
|
||||||
|
|
||||||
type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
|
type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
|
||||||
|
|
||||||
@@ -103,11 +103,11 @@ export class Struct<
|
|||||||
V extends { [K in keyof S]: any } = { [K in keyof S]: any },
|
V extends { [K in keyof S]: any } = { [K in keyof S]: any },
|
||||||
// type names, mapped by key, name of Class in S
|
// type names, mapped by key, name of Class in S
|
||||||
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
|
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
readonly #jsonMap: Map<keyof S, string>;
|
readonly #jsonMap: Map<keyof S, string>;
|
||||||
readonly #Types: Definition;
|
readonly #Types: Definition;
|
||||||
@@ -122,37 +122,12 @@ export class Struct<
|
|||||||
|
|
||||||
super(decoded);
|
super(decoded);
|
||||||
|
|
||||||
this.$initialU8aLength = decodedLength;
|
this.initialU8aLength = decodedLength;
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.#jsonMap = jsonMap;
|
this.#jsonMap = jsonMap;
|
||||||
this.#Types = typeMap;
|
this.#Types = typeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
|
||||||
|
|
||||||
public static with<S extends TypesDef> (Types: S, jsonMap?: Map<string, string>): CodecClass<Struct<S>> {
|
public static with<S extends TypesDef> (Types: S, jsonMap?: Map<string, string>): CodecClass<Struct<S>> {
|
||||||
let definition: Definition | undefined;
|
let definition: Definition | undefined;
|
||||||
|
|
||||||
@@ -185,9 +160,9 @@ export class Struct<
|
|||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
for (const v of this.values()) {
|
for (const v of this.values()) {
|
||||||
if (!v.$isEmpty) {
|
if (!v.isEmpty) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,11 +173,11 @@ export class Struct<
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
for (const v of this.values()) {
|
for (const v of this.values()) {
|
||||||
total += v.$encodedLength;
|
total += v.encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
@@ -212,7 +187,7 @@ export class Struct<
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,7 +198,7 @@ export class Struct<
|
|||||||
const [Types, keys] = this.#Types;
|
const [Types, keys] = this.#Types;
|
||||||
|
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
result[keys[i]] = new Types[i](this.$registry).toRawType();
|
result[keys[i]] = new Types[i](this.registry).toRawType();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result as E;
|
return result as E;
|
||||||
@@ -261,12 +236,12 @@ export class Struct<
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (isBare?: BareOpts): Inspect {
|
public inspect (isBare?: BareOpts): Inspect {
|
||||||
const inner = new Array<Inspect>();
|
const inner = new Array<Inspect>();
|
||||||
|
|
||||||
for (const [k, v] of this.entries()) {
|
for (const [k, v] of this.entries()) {
|
||||||
inner.push({
|
inner.push({
|
||||||
...v.inspectU8a(
|
...v.inspect(
|
||||||
!isBare || isBoolean(isBare)
|
!isBare || isBoolean(isBare)
|
||||||
? isBare
|
? isBare
|
||||||
: isBare[k]
|
: isBare[k]
|
||||||
@@ -345,7 +320,7 @@ export class Struct<
|
|||||||
* @description Returns the base runtime type name for this instance
|
* @description Returns the base runtime type name for this instance
|
||||||
*/
|
*/
|
||||||
public toRawType (): string {
|
public toRawType (): string {
|
||||||
return stringify(typesToMap(this.$registry, this.#Types));
|
return stringify(typesToMap(this.registry, this.#Types));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -59,20 +59,20 @@ describe('Text', (): void => {
|
|||||||
it('calulates the length & encoded length correctly for ASCII', (): void => {
|
it('calulates the length & encoded length correctly for ASCII', (): void => {
|
||||||
const test = new Text(registry, 'abcde');
|
const test = new Text(registry, 'abcde');
|
||||||
|
|
||||||
expect(test.$encodedLength).toEqual(6);
|
expect(test.encodedLength).toEqual(6);
|
||||||
expect(test).toHaveLength(5);
|
expect(test).toHaveLength(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calulates the length & encoded length correctly for non-ASCII', (): void => {
|
it('calulates the length & encoded length correctly for non-ASCII', (): void => {
|
||||||
const test = new Text(registry, '中文');
|
const test = new Text(registry, '中文');
|
||||||
|
|
||||||
expect(test.$encodedLength).toEqual(7);
|
expect(test.encodedLength).toEqual(7);
|
||||||
expect(test).toHaveLength(2);
|
expect(test).toHaveLength(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
expect(
|
expect(
|
||||||
new Text(registry, 'abcde').inspectU8a()
|
new Text(registry, 'abcde').inspect()
|
||||||
).toEqual({
|
).toEqual({
|
||||||
outer: [new Uint8Array([5 << 2]), stringToU8a('abcde')]
|
outer: [new Uint8Array([5 << 2]), stringToU8a('abcde')]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import type { AnyString, AnyU8a, Inspect, IText, IU8a, Registry } from '../types
|
|||||||
|
|
||||||
import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
||||||
|
|
||||||
import { warnGet } from '../utils';
|
|
||||||
import { Raw } from './Raw';
|
import { Raw } from './Raw';
|
||||||
|
|
||||||
const MAX_LENGTH = 128 * 1024;
|
const MAX_LENGTH = 128 * 1024;
|
||||||
@@ -50,11 +49,11 @@ function decodeText (value?: null | AnyString | AnyU8a | { toString: () => strin
|
|||||||
* @noInheritDoc
|
* @noInheritDoc
|
||||||
*/
|
*/
|
||||||
export class Text extends String implements IText {
|
export class Text extends String implements IText {
|
||||||
readonly $registry: Registry;
|
readonly registry: Registry;
|
||||||
|
|
||||||
public $createdAtHash?: IU8a;
|
public createdAtHash?: IU8a;
|
||||||
public $initialU8aLength?: number;
|
public initialU8aLength?: number;
|
||||||
public $isStorageFallback?: boolean;
|
public isStorageFallback?: boolean;
|
||||||
|
|
||||||
#override: string | null = null;
|
#override: string | null = null;
|
||||||
|
|
||||||
@@ -63,39 +62,14 @@ export class Text extends String implements IText {
|
|||||||
|
|
||||||
super(str);
|
super(str);
|
||||||
|
|
||||||
this.$registry = registry;
|
this.registry = registry;
|
||||||
this.$initialU8aLength = decodedLength;
|
this.initialU8aLength = decodedLength;
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
public get encodedLength (): number {
|
|
||||||
return warnGet(this, 'encodedLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
public get initialU8aLength (): number | undefined {
|
|
||||||
return warnGet(this, 'initialU8aLength');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version */
|
|
||||||
public get isEmpty (): boolean {
|
|
||||||
return warnGet(this, 'isEmpty');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
|
||||||
public get registry (): Registry {
|
|
||||||
return warnGet(this, 'registry');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public get $encodedLength (): number {
|
public get encodedLength (): number {
|
||||||
return this.toU8a().length;
|
return this.toU8a().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +77,13 @@ export class Text extends String implements IText {
|
|||||||
* @description returns a hash of the contents
|
* @description returns a hash of the contents
|
||||||
*/
|
*/
|
||||||
public get hash (): IU8a {
|
public get hash (): IU8a {
|
||||||
return this.$registry.hash(this.toU8a());
|
return this.registry.hash(this.toU8a());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Checks if the value is an empty value
|
* @description Checks if the value is an empty value
|
||||||
*/
|
*/
|
||||||
public get $isEmpty (): boolean {
|
public get isEmpty (): boolean {
|
||||||
return this.length === 0;
|
return this.length === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +107,7 @@ export class Text extends String implements IText {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
public inspectU8a (): Inspect {
|
public inspect (): Inspect {
|
||||||
const value = stringToU8a(super.toString());
|
const value = stringToU8a(super.toString());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -14,23 +14,6 @@ export interface Inspect {
|
|||||||
outer?: Uint8Array[];
|
outer?: Uint8Array[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CodecDeprecated {
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
readonly createdAtHash: IU8a | undefined;
|
|
||||||
|
|
||||||
/** @deprecated Use $encodedLength instead. This getter will be removed in a future version. */
|
|
||||||
readonly encodedLength: number;
|
|
||||||
|
|
||||||
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
|
|
||||||
readonly initialU8aLength: number | undefined;
|
|
||||||
|
|
||||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version. */
|
|
||||||
readonly isEmpty: boolean;
|
|
||||||
|
|
||||||
/** @deprecated Use $registry instead. This getter will be removed in a future version. */
|
|
||||||
readonly registry: Registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Codec
|
* @name Codec
|
||||||
* @description
|
* @description
|
||||||
@@ -39,32 +22,20 @@ interface CodecDeprecated {
|
|||||||
* with getters and functions. The Codec Base is however required for operating
|
* with getters and functions. The Codec Base is however required for operating
|
||||||
* as an encoding/decoding layer
|
* as an encoding/decoding layer
|
||||||
*/
|
*/
|
||||||
export interface Codec extends CodecDeprecated {
|
export interface Codec {
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description
|
||||||
* The block at which this value was retrieved/created (set to non-empty when
|
* The block at which this value was retrieved/created (set to non-empty when
|
||||||
* retrieved from storage)
|
* retrieved from storage)
|
||||||
*/
|
*/
|
||||||
$createdAtHash?: IU8a;
|
createdAtHash?: IU8a;
|
||||||
|
|
||||||
/**
|
|
||||||
* @description
|
|
||||||
* The length of the value when encoded as a Uint8Array (which is the SCALE representation)
|
|
||||||
*/
|
|
||||||
readonly $encodedLength: number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description
|
||||||
* The length of the initial encoded value (Only available when the value was
|
* The length of the initial encoded value (Only available when the value was
|
||||||
* constructed from a Uint8Array input)
|
* constructed from a Uint8Array input)
|
||||||
*/
|
*/
|
||||||
$initialU8aLength?: number;
|
initialU8aLength?: number;
|
||||||
|
|
||||||
/**
|
|
||||||
* @description
|
|
||||||
* Checks if the value is an empty value, with the internal bytes all-zero
|
|
||||||
*/
|
|
||||||
$isEmpty: boolean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description
|
||||||
@@ -76,20 +47,28 @@ export interface Codec extends CodecDeprecated {
|
|||||||
* any empty storage item should erturn the default. (This is the same as the
|
* any empty storage item should erturn the default. (This is the same as the
|
||||||
* implementation on the Substrate runtime)
|
* implementation on the Substrate runtime)
|
||||||
*/
|
*/
|
||||||
$isStorageFallback?: boolean;
|
isStorageFallback?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
* The type registry associated with this object, as available when this type
|
*/
|
||||||
* was initially created.
|
readonly encodedLength: number;
|
||||||
*/
|
|
||||||
readonly $registry: Registry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns a hash of the value
|
* @description Returns a hash of the value
|
||||||
*/
|
*/
|
||||||
readonly hash: IU8a;
|
readonly hash: IU8a;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Checks if the value is an empty value
|
||||||
|
*/
|
||||||
|
readonly isEmpty: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description The registry associated with this object
|
||||||
|
*/
|
||||||
|
readonly registry: Registry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Compares the value of the input to see if there is a match
|
* @description Compares the value of the input to see if there is a match
|
||||||
*/
|
*/
|
||||||
@@ -98,7 +77,7 @@ export interface Codec extends CodecDeprecated {
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
inspectU8a (isBare?: BareOpts): Inspect;
|
inspect (isBare?: BareOpts): Inspect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ export interface ICompact<T extends INumber = INumber> extends Codec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IEnum extends Codec {
|
export interface IEnum extends Codec {
|
||||||
readonly $isBasic: boolean;
|
|
||||||
|
|
||||||
readonly defIndexes: number[];
|
readonly defIndexes: number[];
|
||||||
readonly defKeys: string[];
|
readonly defKeys: string[];
|
||||||
readonly index: number;
|
readonly index: number;
|
||||||
|
readonly isBasic: boolean;
|
||||||
readonly type: string;
|
readonly type: string;
|
||||||
readonly value: Codec;
|
readonly value: Codec;
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export interface Registry {
|
|||||||
readonly chainSS58: number | undefined;
|
readonly chainSS58: number | undefined;
|
||||||
readonly chainTokens: string[];
|
readonly chainTokens: string[];
|
||||||
|
|
||||||
$createdAtHash?: IU8a;
|
createdAtHash?: IU8a;
|
||||||
|
|
||||||
findMetaCall (callIndex: Uint8Array): CallFunction;
|
findMetaCall (callIndex: Uint8Array): CallFunction;
|
||||||
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN } | { error: BN | Uint8Array, index: BN }): RegistryError;
|
findMetaError (errorIndex: Uint8Array | { error: BN, index: BN } | { error: BN | Uint8Array, index: BN }): RegistryError;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export function decodeU8a <T extends Codec = Codec> (registry: Registry, result:
|
|||||||
while (i < count) {
|
while (i < count) {
|
||||||
const value = new Types[i](registry, u8a.subarray(offset));
|
const value = new Types[i](registry, u8a.subarray(offset));
|
||||||
|
|
||||||
offset += value.$initialU8aLength || value.$encodedLength;
|
offset += value.initialU8aLength || value.encodedLength;
|
||||||
result[i] = value;
|
result[i] = value;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ export function decodeU8aStruct (registry: Registry, result: [string, Codec][],
|
|||||||
while (i < count) {
|
while (i < count) {
|
||||||
const value = new Types[i](registry, u8a.subarray(offset));
|
const value = new Types[i](registry, u8a.subarray(offset));
|
||||||
|
|
||||||
offset += value.$initialU8aLength || value.$encodedLength;
|
offset += value.initialU8aLength || value.encodedLength;
|
||||||
result[i] = [keys[i], value];
|
result[i] = [keys[i], value];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ export function decodeU8aVec <T extends Codec = Codec> (registry: Registry, resu
|
|||||||
while (i < count) {
|
while (i < count) {
|
||||||
const value = new Type(registry, u8a.subarray(offset));
|
const value = new Type(registry, u8a.subarray(offset));
|
||||||
|
|
||||||
offset += value.$initialU8aLength || value.$encodedLength;
|
offset += value.initialU8aLength || value.encodedLength;
|
||||||
result[i] = value;
|
result[i] = value;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,3 @@ export { typeToConstructor } from './typeToConstructor';
|
|||||||
export { sanitize } from './sanitize';
|
export { sanitize } from './sanitize';
|
||||||
export { sortAsc, sortSet, sortMap } from './sortValues';
|
export { sortAsc, sortSet, sortMap } from './sortValues';
|
||||||
export { typesToMap } from './typesToMap';
|
export { typesToMap } from './typesToMap';
|
||||||
export { warnGet } from './warnGet';
|
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
type Getters = 'createdAtHash' | 'encodedLength' | 'hash' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned' | 'registry';
|
|
||||||
|
|
||||||
const hasWarned: Record<string, boolean> = {};
|
|
||||||
|
|
||||||
/** @description Warns (once, per class) on the use of a deprecated interface */
|
|
||||||
export function warnGet <T> (obj: Record<string, any>, name: Getters): T {
|
|
||||||
const clazz = `${obj.constructor?.name || 'Codec'}`;
|
|
||||||
const check = `${clazz}.${name}`;
|
|
||||||
const pass = `$${name}`;
|
|
||||||
|
|
||||||
if (!hasWarned[check]) {
|
|
||||||
hasWarned[check] = true;
|
|
||||||
|
|
||||||
console.warn(`Use ${clazz}.${pass} instead. The use of ${check} is deprecated and will be removed in a future version.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return obj[pass] as T;
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,7 @@ function checkInstance (created: Codec, matcher: Uint8Array): void {
|
|||||||
) ||
|
) ||
|
||||||
(
|
(
|
||||||
// when the created is empty and matcher is also empty, let it slide...
|
// when the created is empty and matcher is also empty, let it slide...
|
||||||
created.$isEmpty &&
|
created.isEmpty &&
|
||||||
matcher.every((v) => !v)
|
matcher.every((v) => !v)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -54,11 +54,11 @@ function initType<T extends Codec> (registry: Registry, Type: CodecClass, params
|
|||||||
isPedantic && checkPedantic(created, params);
|
isPedantic && checkPedantic(created, params);
|
||||||
|
|
||||||
if (blockHash) {
|
if (blockHash) {
|
||||||
created.$createdAtHash = createTypeUnsafe<IU8a>(registry, 'BlockHash', [blockHash]);
|
created.createdAtHash = createTypeUnsafe<IU8a>(registry, 'BlockHash', [blockHash]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFallback) {
|
if (isFallback) {
|
||||||
created.$isStorageFallback = true;
|
created.isStorageFallback = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return created as T;
|
return created as T;
|
||||||
|
|||||||
@@ -98,4 +98,4 @@ const tt9 = registry.createType('(u32, (u32, u64), Vec<u8>, Vec<(u32, u64)>, [u8
|
|||||||
// tuple with nested fixed
|
// tuple with nested fixed
|
||||||
const tta = registry.createType('([u8;32], [u16;5])');
|
const tta = registry.createType('([u8;32], [u16;5])');
|
||||||
|
|
||||||
assert(tt1[2].bitLength() && tt2.bitLength() && tt4[3].bitLength() && tt5.$isEmpty && tt6[1].toHuman() && tt7.toHuman() && tt8.toHuman() && tt9.toHuman() && tta[1][1].bitLength(), 'All ok');
|
assert(tt1[2].bitLength() && tt2.bitLength() && tt4[3].bitLength() && tt5.isEmpty && tt6[1].toHuman() && tt7.toHuman() && tt8.toHuman() && tt9.toHuman() && tta[1][1].bitLength(), 'All ok');
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe('createType', (): void => {
|
|||||||
|
|
||||||
expect(f64.toRawType()).toEqual('Fixed64');
|
expect(f64.toRawType()).toEqual('Fixed64');
|
||||||
expect(f64.bitLength()).toEqual(64);
|
expect(f64.bitLength()).toEqual(64);
|
||||||
expect(f64.$isUnsigned).toBe(false);
|
expect(f64.isUnsigned).toBe(false);
|
||||||
expect(f64 instanceof Int).toBe(true);
|
expect(f64 instanceof Int).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import type { ExtDef } from '../extrinsic/signedExtensions/types';
|
|||||||
import type { ChainProperties, DispatchErrorModule, DispatchErrorModuleU8, DispatchErrorModuleU8a, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
|
import type { ChainProperties, DispatchErrorModule, DispatchErrorModuleU8, DispatchErrorModuleU8a, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
|
||||||
import type { CallFunction, CodecHasher, Definitions, DetectCodec, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types';
|
import type { CallFunction, CodecHasher, Definitions, DetectCodec, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types';
|
||||||
|
|
||||||
import { DoNotConstruct, Json, Raw, warnGet } from '@polkadot/types-codec';
|
import { DoNotConstruct, Json, Raw } from '@polkadot/types-codec';
|
||||||
import { constructTypeClass, createClassUnsafe, createTypeUnsafe } from '@polkadot/types-create';
|
import { constructTypeClass, createClassUnsafe, createTypeUnsafe } from '@polkadot/types-create';
|
||||||
import { assertReturn, BN_ZERO, formatBalance, isFunction, isNumber, isString, isU8a, lazyMethod, logger, objectSpread, stringCamelCase, stringify } from '@polkadot/util';
|
import { assertReturn, BN_ZERO, formatBalance, isFunction, isNumber, isString, isU8a, lazyMethod, logger, objectSpread, stringCamelCase, stringify } from '@polkadot/util';
|
||||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||||
@@ -186,7 +186,7 @@ export class TypeRegistry implements Registry {
|
|||||||
readonly #metadataEvents: Record<string, Record<string, CodecClass<GenericEventData>>> = {};
|
readonly #metadataEvents: Record<string, Record<string, CodecClass<GenericEventData>>> = {};
|
||||||
readonly #moduleMap: Record<string, string[]> = {};
|
readonly #moduleMap: Record<string, string[]> = {};
|
||||||
|
|
||||||
public $createdAtHash?: Hash;
|
public createdAtHash?: Hash;
|
||||||
|
|
||||||
constructor (createdAtHash?: Hash | Uint8Array | string) {
|
constructor (createdAtHash?: Hash | Uint8Array | string) {
|
||||||
this.#knownDefaults = objectSpread({ Json, Metadata, PortableRegistry, Raw }, baseTypes);
|
this.#knownDefaults = objectSpread({ Json, Metadata, PortableRegistry, Raw }, baseTypes);
|
||||||
@@ -199,15 +199,10 @@ export class TypeRegistry implements Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (createdAtHash) {
|
if (createdAtHash) {
|
||||||
this.$createdAtHash = this.createType('BlockHash', createdAtHash);
|
this.createdAtHash = this.createType('BlockHash', createdAtHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
|
||||||
public get createdAtHash (): IU8a | undefined {
|
|
||||||
return warnGet(this, 'createdAtHash');
|
|
||||||
}
|
|
||||||
|
|
||||||
public get chainDecimals (): number[] {
|
public get chainDecimals (): number[] {
|
||||||
if (this.#chainProperties?.tokenDecimals.isSome) {
|
if (this.#chainProperties?.tokenDecimals.isSome) {
|
||||||
const allDecimals = this.#chainProperties.tokenDecimals.unwrap();
|
const allDecimals = this.#chainProperties.tokenDecimals.unwrap();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ describe('EthereumAccountId', (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('is empty by default', (): void => {
|
it('is empty by default', (): void => {
|
||||||
expect(id.$isEmpty).toBe(true);
|
expect(id.isEmpty).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('equals the empty address', (): void => {
|
it('equals the empty address', (): void => {
|
||||||
@@ -77,7 +77,7 @@ describe('EthereumAccountId', (): void => {
|
|||||||
]));
|
]));
|
||||||
|
|
||||||
it('decodes to a non-empty value', (): void => {
|
it('decodes to a non-empty value', (): void => {
|
||||||
expect(registry.createType('EthereumAccountId', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887').$isEmpty).toBe(false);
|
expect(registry.createType('EthereumAccountId', '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887').isEmpty).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export class GenericEthereumLookupSource extends AbstractBase<GenericEthereumAcc
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
const rawLength = this._rawLength;
|
const rawLength = this._rawLength;
|
||||||
|
|
||||||
return rawLength + (
|
return rawLength + (
|
||||||
@@ -86,7 +86,7 @@ export class GenericEthereumLookupSource extends AbstractBase<GenericEthereumAcc
|
|||||||
protected get _rawLength (): number {
|
protected get _rawLength (): number {
|
||||||
return this.inner instanceof GenericAccountIndex
|
return this.inner instanceof GenericAccountIndex
|
||||||
? GenericAccountIndex.calcLength(this.inner)
|
? GenericAccountIndex.calcLength(this.inner)
|
||||||
: this.inner.$encodedLength;
|
: this.inner.encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ abstract class ExtrinsicBase<A extends AnyTuple> extends AbstractBase<ExtrinsicV
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
return this.toU8a().length;
|
return this.toU8a().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,13 +266,13 @@ export class GenericExtrinsic<A extends AnyTuple = AnyTuple> extends ExtrinsicBa
|
|||||||
/**
|
/**
|
||||||
* @description Returns a breakdown of the hex encoding for this Codec
|
* @description Returns a breakdown of the hex encoding for this Codec
|
||||||
*/
|
*/
|
||||||
override inspectU8a (): Inspect {
|
override inspect (): Inspect {
|
||||||
const encoded = u8aConcat(...this.toU8aInner());
|
const encoded = u8aConcat(...this.toU8aInner());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inner: this.isSigned
|
inner: this.isSigned
|
||||||
? this.inner.inspectU8a().inner
|
? this.inner.inspect().inner
|
||||||
: this.inner.method.inspectU8a().inner,
|
: this.inner.method.inspect().inner,
|
||||||
outer: [compactToU8a(encoded.length), new Uint8Array([this.version])]
|
outer: [compactToU8a(encoded.length), new Uint8Array([this.version])]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ export class MortalEra extends Tuple {
|
|||||||
/**
|
/**
|
||||||
* @description Encoded length for mortals occupy 2 bytes, different from the actual Tuple since it is encoded. This is a shortcut fro `toU8a().length`
|
* @description Encoded length for mortals occupy 2 bytes, different from the actual Tuple since it is encoded. This is a shortcut fro `toU8a().length`
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,10 +247,10 @@ export class GenericExtrinsicEra extends Enum implements IExtrinsicEra {
|
|||||||
/**
|
/**
|
||||||
* @description Override the encoded length method
|
* @description Override the encoded length method
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
return this.isImmortalEra
|
return this.isImmortalEra
|
||||||
? this.asImmortalEra.$encodedLength
|
? this.asImmortalEra.encodedLength
|
||||||
: this.asMortalEra.$encodedLength;
|
: this.asMortalEra.encodedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ describe('ExtrinsicPayload', (): void => {
|
|||||||
const a = new ExtrinsicPayload(registry, TEST, { version: 4 });
|
const a = new ExtrinsicPayload(registry, TEST, { version: 4 });
|
||||||
const b = new ExtrinsicPayload(registry, a.toU8a(), { version: 4 });
|
const b = new ExtrinsicPayload(registry, a.toU8a(), { version: 4 });
|
||||||
|
|
||||||
expect(a.inspectU8a()).toEqual(b.inspectU8a());
|
expect(a.inspect()).toEqual(b.inspect());
|
||||||
expect(a.toJSON()).toEqual(b.toJSON());
|
expect(a.toJSON()).toEqual(b.toJSON());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ describe('ExtrinsicPayload', (): void => {
|
|||||||
const a = new ExtrinsicPayload(registry, TEST, { version: 4 });
|
const a = new ExtrinsicPayload(registry, TEST, { version: 4 });
|
||||||
const b = new ExtrinsicPayload(registry, a.toHex(), { version: 4 });
|
const b = new ExtrinsicPayload(registry, a.toHex(), { version: 4 });
|
||||||
|
|
||||||
expect(a.inspectU8a()).toEqual(b.inspectU8a());
|
expect(a.inspect()).toEqual(b.inspect());
|
||||||
expect(a.toJSON()).toEqual(b.toJSON());
|
expect(a.toJSON()).toEqual(b.toJSON());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
|
|||||||
*/
|
*/
|
||||||
public get genesisHash (): BlockHash {
|
public get genesisHash (): BlockHash {
|
||||||
// NOTE only v3+
|
// NOTE only v3+
|
||||||
return this.inner.genesisHash || this.$registry.createTypeUnsafe('Hash', []);
|
return this.inner.genesisHash || this.registry.createTypeUnsafe('Hash', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,7 +89,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
|
|||||||
*/
|
*/
|
||||||
public get specVersion (): INumber {
|
public get specVersion (): INumber {
|
||||||
// NOTE only v3+
|
// NOTE only v3+
|
||||||
return this.inner.specVersion || this.$registry.createTypeUnsafe('u32', []);
|
return this.inner.specVersion || this.registry.createTypeUnsafe('u32', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +97,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
|
|||||||
*/
|
*/
|
||||||
public get tip (): ICompact<INumber> {
|
public get tip (): ICompact<INumber> {
|
||||||
// NOTE from v2+
|
// NOTE from v2+
|
||||||
return this.inner.tip || this.$registry.createTypeUnsafe('Compact<Balance>', []);
|
return this.inner.tip || this.registry.createTypeUnsafe('Compact<Balance>', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +105,7 @@ export class GenericExtrinsicPayload extends AbstractBase<ExtrinsicPayloadVx> {
|
|||||||
*/
|
*/
|
||||||
public get transactionVersion (): INumber {
|
public get transactionVersion (): INumber {
|
||||||
// NOTE only v4+
|
// NOTE only v4+
|
||||||
return this.inner.transactionVersion || this.$registry.createTypeUnsafe('u32', []);
|
return this.inner.transactionVersion || this.registry.createTypeUnsafe('u32', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
|
|||||||
public toRaw (): SignerPayloadRaw {
|
public toRaw (): SignerPayloadRaw {
|
||||||
const payload = this.toPayload();
|
const payload = this.toPayload();
|
||||||
const data = u8aToHex(
|
const data = u8aToHex(
|
||||||
this.$registry
|
this.registry
|
||||||
.createTypeUnsafe('ExtrinsicPayload', [payload, { version: payload.version }])
|
.createTypeUnsafe('ExtrinsicPayload', [payload, { version: payload.version }])
|
||||||
// NOTE Explicitly pass the bare flag so the method is encoded un-prefixed (non-decodable, for signing only)
|
// NOTE Explicitly pass the bare flag so the method is encoded un-prefixed (non-decodable, for signing only)
|
||||||
.toU8a({ method: true })
|
.toU8a({ method: true })
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl {
|
|||||||
} else if (isU8a(value)) {
|
} else if (isU8a(value)) {
|
||||||
// here we decode manually since we need to pull through the version information
|
// here we decode manually since we need to pull through the version information
|
||||||
const signature = registry.createTypeUnsafe<ExtrinsicSignatureV4>('ExtrinsicSignatureV4', [value, { isSigned }]);
|
const signature = registry.createTypeUnsafe<ExtrinsicSignatureV4>('ExtrinsicSignatureV4', [value, { isSigned }]);
|
||||||
const method = registry.createTypeUnsafe<Call>('Call', [value.subarray(signature.$encodedLength)]);
|
const method = registry.createTypeUnsafe<Call>('Call', [value.subarray(signature.encodedLength)]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
method,
|
method,
|
||||||
@@ -54,7 +54,7 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl {
|
|||||||
/**
|
/**
|
||||||
* @description The length of the value when encoded as a Uint8Array
|
* @description The length of the value when encoded as a Uint8Array
|
||||||
*/
|
*/
|
||||||
public override get $encodedLength (): number {
|
public override get encodedLength (): number {
|
||||||
return this.toU8a().length;
|
return this.toU8a().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe('ExtrinsicPayload', (): void => {
|
|||||||
it('has a sane inspect', (): void => {
|
it('has a sane inspect', (): void => {
|
||||||
// we don't expect this to fail, however it is actually a good
|
// we don't expect this to fail, however it is actually a good
|
||||||
// reference for the ordering in base Substrate
|
// reference for the ordering in base Substrate
|
||||||
expect(new ExtrinsicPayload(registry, { method: tx.timestamp.set(0).toHex() } as never).inspectU8a()).toEqual({
|
expect(new ExtrinsicPayload(registry, { method: tx.timestamp.set(0).toHex() } as never).inspect()).toEqual({
|
||||||
inner: [
|
inner: [
|
||||||
{ name: 'method', outer: [new Uint8Array([3, 0, 0])] },
|
{ name: 'method', outer: [new Uint8Array([3, 0, 0])] },
|
||||||
{ name: 'era', outer: [new Uint8Array([0]), new Uint8Array([0])] },
|
{ name: 'era', outer: [new Uint8Array([0]), new Uint8Array([0])] },
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user