Convert RPC classes to primitive classes or /srml types (#1192)
* Convert RPC classes to primitive classes or /srml types * Lint passes... lokking at tests next. * Tests pass. * Types with basic docs (lots of work here) * Update StorageKey.spec.ts * Add injector to metadata doc generation * Fix import
This commit is contained in:
@@ -6,7 +6,7 @@ import { Observable } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/primitive/AccountIndex';
|
||||
import { AccountId, AccountIndex, Vector } from '@polkadot/types';
|
||||
import { AccountId, AccountIndex, Vec } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -30,7 +30,7 @@ export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | s
|
||||
? _accountIndex
|
||||
: new AccountIndex(_accountIndex);
|
||||
|
||||
return (querySection.enumSet<Vector<AccountId>>(accountIndex.div(ENUMSET_SIZE)))
|
||||
return (querySection.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)))
|
||||
.pipe(
|
||||
startWith([]),
|
||||
map((accounts): AccountId | undefined =>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, AccountIndex, Address, Vector } from '@polkadot/types';
|
||||
import { AccountId, AccountIndex, Address, Vec } from '@polkadot/types';
|
||||
|
||||
import { idAndIndex } from '../accounts/idAndIndex';
|
||||
import { DerivedBalances } from '../types';
|
||||
@@ -17,7 +17,7 @@ export function votingBalancesNominatorsFor (api: ApiInterfaceRx): (address: Acc
|
||||
return idAndIndex(api)(address).pipe(
|
||||
switchMap(([accountId]): Observable<AccountId[]> =>
|
||||
accountId
|
||||
? (api.query.staking.nominatorsFor<Vector<AccountId>>(accountId))
|
||||
? (api.query.staking.nominatorsFor<Vec<AccountId>>(accountId))
|
||||
: of([] as AccountId[])
|
||||
),
|
||||
switchMap(votingBalances(api)),
|
||||
|
||||
@@ -8,7 +8,7 @@ import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option, Vector } from '@polkadot/types';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { ReferendumInfoExtended } from '../type';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -19,7 +19,7 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) =
|
||||
return (
|
||||
!ids || !ids.length
|
||||
? of([] as Option<ReferendumInfo>[])
|
||||
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<Vector<Option<ReferendumInfo>>>
|
||||
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<Vec<Option<ReferendumInfo>>>
|
||||
).pipe(
|
||||
map((infos): Option<ReferendumInfoExtended>[] =>
|
||||
ids.map((id, index): Option<ReferendumInfoExtended> =>
|
||||
|
||||
@@ -8,7 +8,7 @@ import BN from 'bn.js';
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vector, Vote, createType } from '@polkadot/types';
|
||||
import { AccountId, Vec, Vote, createType } from '@polkadot/types';
|
||||
|
||||
import { DerivedBalances, DerivedReferendumVote } from '../types';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -17,8 +17,8 @@ import { votingBalances } from '../balances/votingBalances';
|
||||
|
||||
export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | number) => Observable<DerivedReferendumVote[]> {
|
||||
return (referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
(api.query.democracy.votersFor<Vector<AccountId>>(referendumId)).pipe(
|
||||
switchMap((votersFor): Observable<[Vector<AccountId>, Vote[], DerivedBalances[]]> =>
|
||||
(api.query.democracy.votersFor<Vec<AccountId>>(referendumId)).pipe(
|
||||
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> =>
|
||||
combineLatest([
|
||||
of(votersFor),
|
||||
votes(api)(referendumId as BN, votersFor),
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vector, Vote } from '@polkadot/types';
|
||||
import { AccountId, Vec, Vote } from '@polkadot/types';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
@@ -19,6 +19,6 @@ export function votes (api: ApiInterfaceRx): (referendumId: BN, accountIds?: Acc
|
||||
[referendumId, accountId]
|
||||
)
|
||||
)
|
||||
) as Observable<Vector<Vote>>).pipe(drr());
|
||||
) as Observable<Vec<Vote>>).pipe(drr());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AccountId, Vector } from '@polkadot/types';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { switchMap, map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -27,11 +27,11 @@ export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observabl
|
||||
return (who: AccountId): Observable<boolean[][]> =>
|
||||
(api.query.elections.nextVoterSet<SetIndex>())
|
||||
.pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vector<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi([...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [who.toString(), i])) as any as Observable<Vector<ApprovalFlag>[]>
|
||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
|
||||
api.query.elections.approvalsOf.multi([...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] => [who.toString(), i])) as any as Observable<Vec<ApprovalFlag>[]>
|
||||
),
|
||||
map((votes: Vector<ApprovalFlag>[]): boolean[][] =>
|
||||
votes.map((flags: Vector<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags))
|
||||
map((votes: Vec<ApprovalFlag>[]): boolean[][] =>
|
||||
votes.map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags))
|
||||
),
|
||||
drr()
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@ import { ApprovalFlag, SetIndex } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { AccountId, Vector } from '@polkadot/types';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
||||
import { drr } from '../util/drr';
|
||||
@@ -25,9 +25,9 @@ import { drr } from '../util/drr';
|
||||
*/
|
||||
export function approvalsOfAt (api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> {
|
||||
return (who: AccountId, at: SetIndex): Observable<boolean[]> =>
|
||||
(api.query.elections.approvalsOf<Vector<ApprovalFlag>>([who.toString(), at]))
|
||||
(api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]))
|
||||
.pipe(
|
||||
map((flags: Vector<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
|
||||
map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { SetIndex } from '@polkadot/types/srml/elections/types';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vector, Option, createType } from '@polkadot/types';
|
||||
import { AccountId, Vec, Option, createType } from '@polkadot/types';
|
||||
import { DerivedVoterPositions } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@@ -28,11 +28,11 @@ import { drr } from '../util/drr';
|
||||
export function voterPositions (api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> {
|
||||
return (): Observable<DerivedVoterPositions> =>
|
||||
api.query.elections.nextVoterSet<SetIndex>().pipe(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vector<Option<AccountId>>[]]> => combineLatest(
|
||||
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest(
|
||||
of(api.consts.elections.voterSetSize) as any as Observable<BN>,
|
||||
api.query.elections.voters.multi([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i])) as any as Observable<Vector<Option<AccountId>>[]>
|
||||
api.query.elections.voters.multi([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i])) as any as Observable<Vec<Option<AccountId>>[]>
|
||||
)),
|
||||
map((result: [BN, Vector<Option<AccountId>>[]]): DerivedVoterPositions => {
|
||||
map((result: [BN, Vec<Option<AccountId>>[]]): DerivedVoterPositions => {
|
||||
const [setSize, voters] = result;
|
||||
return voters.reduce((result: DerivedVoterPositions, vec, setIndex): DerivedVoterPositions => {
|
||||
vec.forEach((e, index): void => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Vector } from '@polkadot/types';
|
||||
import { AccountId, Vec } from '@polkadot/types';
|
||||
import { DerivedVoterPositions } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -23,12 +23,12 @@ import { voterPositions } from './voterPositions';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function voters (api: ApiInterfaceRx): () => Observable<Vector<AccountId>> {
|
||||
return (): Observable<Vector<AccountId>> =>
|
||||
export function voters (api: ApiInterfaceRx): () => Observable<Vec<AccountId>> {
|
||||
return (): Observable<Vec<AccountId>> =>
|
||||
voterPositions(api)().pipe(
|
||||
map(
|
||||
(voterPositions: DerivedVoterPositions): Vector<AccountId> =>
|
||||
new Vector(
|
||||
(voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
||||
new Vec(
|
||||
AccountId,
|
||||
Object.entries(voterPositions)
|
||||
.sort((a, b): 0 | 1 | -1 => a[1].globalIndex.cmp(b[1].globalIndex))
|
||||
|
||||
@@ -12,7 +12,7 @@ import { DerivedStaking, DerivedUnlocking } from '../types';
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { createType, AccountId, Option, Tuple, Vector } from '@polkadot/types';
|
||||
import { createType, AccountId, Option, Tuple, Vec } from '@polkadot/types';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
@@ -74,7 +74,7 @@ function redeemableSum (stakingLedger: StakingLedger | undefined, eraLength: BN,
|
||||
.reduce((curr, prev): BN => curr.add(prev.value.unwrap()), new BN(0));
|
||||
}
|
||||
|
||||
function unwrapSessionIds (stashId: AccountId, validatorIds: AccountId[], auraIds: AccountId[], nextKeys: Option<AccountId> | Vector<Tuple>): { nextSessionId?: AccountId; sessionId?: AccountId } {
|
||||
function unwrapSessionIds (stashId: AccountId, validatorIds: AccountId[], auraIds: AccountId[], nextKeys: Option<AccountId> | Vec<Tuple>): { nextSessionId?: AccountId; sessionId?: AccountId } {
|
||||
// for 2.x we have a Vec<(ValidatorId,Keys)> of the keys
|
||||
if (Array.isArray(nextKeys)) {
|
||||
const validatorIdx = validatorIds.indexOf(stashId);
|
||||
@@ -111,7 +111,7 @@ function withStashController (api: ApiInterfaceRx, accountId: AccountId, control
|
||||
// FIXME while we have 2.x and 1.x support, don't add this to .multi -
|
||||
// should be added when only 2.x
|
||||
api.query.aura && api.query.aura.authorities
|
||||
? api.query.aura.authorities<Vector<AccountId>>()
|
||||
? api.query.aura.authorities<Vec<AccountId>>()
|
||||
: of([] as AccountId[]),
|
||||
api.queryMulti([
|
||||
api.query.session.queuedKeys
|
||||
@@ -124,7 +124,7 @@ function withStashController (api: ApiInterfaceRx, accountId: AccountId, control
|
||||
[api.query.staking.stakers, stashId],
|
||||
[api.query.staking.validators, stashId]
|
||||
])
|
||||
]) as Observable<[BN, BlockNumber, AccountId[], [Option<AccountId> | Vector<Tuple>, AccountId[], Option<StakingLedger>, [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
]) as Observable<[BN, BlockNumber, AccountId[], [Option<AccountId> | Vec<Tuple>, AccountId[], Option<StakingLedger>, [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
).pipe(
|
||||
map(([eraLength, bestNumber, auraIds, [nextKeys, validatorIds, _stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]]): DerivedStaking => {
|
||||
const stakingLedger = _stakingLedger.unwrapOr(null) || undefined;
|
||||
@@ -159,7 +159,7 @@ function withControllerLedger (api: ApiInterfaceRx, accountId: AccountId, stakin
|
||||
// FIXME while we have 2.x and 1.x support, don't add this to .multi -
|
||||
// should be added when only 2.x
|
||||
api.query.aura && api.query.aura.authorities
|
||||
? api.query.aura.authorities<Vector<AccountId>>()
|
||||
? api.query.aura.authorities<Vec<AccountId>>()
|
||||
: of([] as AccountId[]),
|
||||
api.queryMulti([
|
||||
api.query.session.queuedKeys
|
||||
@@ -171,7 +171,7 @@ function withControllerLedger (api: ApiInterfaceRx, accountId: AccountId, stakin
|
||||
[api.query.staking.stakers, stashId],
|
||||
[api.query.staking.validators, stashId]
|
||||
])
|
||||
]) as Observable<[AccountId[], [Option<AccountId> | Vector<Tuple>, AccountId[], [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
]) as Observable<[AccountId[], [Option<AccountId> | Vec<Tuple>, AccountId[], [AccountId[]], RewardDestination, Exposure, [ValidatorPrefs]]]>
|
||||
).pipe(
|
||||
map(([auraIds, [nextKeys, validatorIds, [nominators], rewardDestination, stakers, [validatorPrefs]]]): DerivedStaking => {
|
||||
const { nextSessionId, sessionId } = unwrapSessionIds(stashId, validatorIds, auraIds, nextKeys);
|
||||
|
||||
@@ -25,27 +25,27 @@ export default class HeaderExtended extends Header {
|
||||
|
||||
// extract from the substrate 2.0 PreRuntime digest
|
||||
if (pitem) {
|
||||
const preRuntime = pitem.asPreRuntime;
|
||||
const [engine, data] = pitem.asPreRuntime;
|
||||
|
||||
if (preRuntime.engine.isAura) {
|
||||
slot = preRuntime.slot;
|
||||
if (engine.isAura) {
|
||||
slot = engine.extractSlot(data);
|
||||
}
|
||||
} else {
|
||||
const [citem] = header.digest.logsWith('Consensus');
|
||||
|
||||
// extract author from the consensus (substrate 1.0, digest)
|
||||
if (citem) {
|
||||
const consensus = citem.asConsensus;
|
||||
const [engine, data] = citem.asConsensus;
|
||||
|
||||
if (consensus.engine.isAura) {
|
||||
slot = consensus.slot;
|
||||
if (engine.isAura) {
|
||||
slot = engine.extractSlot(data);
|
||||
}
|
||||
} else {
|
||||
const [sitem] = header.digest.logsWith('SealV0');
|
||||
|
||||
// extract author from the seal (pre substrate 1.0, backwards compat)
|
||||
if (sitem) {
|
||||
slot = sitem.asSealV0.slot;
|
||||
slot = sitem.asSealV0[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
import { ApprovalFlag } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Vector } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
export function approvalFlagToBool (flags: Vector<ApprovalFlag>): boolean[] {
|
||||
export function approvalFlagToBool (flags: Vec<ApprovalFlag>): boolean[] {
|
||||
const bools: boolean[] = [];
|
||||
for (const flag of flags) {
|
||||
for (const bit of [...Array(flag.bitLength())].map((_, i): number => i)) {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
import { ApprovalFlag } from '@polkadot/types/srml/elections/types';
|
||||
|
||||
import { Vector } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
export function approvalFlagsToBools (flags: Vector<ApprovalFlag>): boolean[] {
|
||||
export function approvalFlagsToBools (flags: Vec<ApprovalFlag>): boolean[] {
|
||||
const bools: boolean[] = [];
|
||||
|
||||
flags.forEach((flag: ApprovalFlag): void => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ClassOf, Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/v6/static';
|
||||
import json from '@polkadot/types/Metadata/static';
|
||||
import { injectDefinitions } from '@polkadot/types/srml';
|
||||
|
||||
import fromMetadata from '../fromMetadata';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v6/static';
|
||||
import metadataRpc from '@polkadot/types/Metadata/static';
|
||||
|
||||
import fromMetadata from './fromMetadata';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v6/static';
|
||||
import metadataRpc from '@polkadot/types/Metadata/static';
|
||||
import { ModulesWithMethods } from '@polkadot/types/primitive/Method';
|
||||
|
||||
import fromMetadata from './fromMetadata';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/v6/static';
|
||||
import json from '@polkadot/types/Metadata/static';
|
||||
import { injectDefinitions } from '@polkadot/types/srml';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
|
||||
@@ -2,9 +2,15 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { injectDefinitions } from '@polkadot/types/srml';
|
||||
|
||||
import { storage } from './storage';
|
||||
|
||||
describe('storage', (): void => {
|
||||
beforeEach((): void => {
|
||||
injectDefinitions();
|
||||
});
|
||||
|
||||
it('should return well known keys', (): void => {
|
||||
expect(typeof storage.substrate).toBe('object');
|
||||
|
||||
|
||||
@@ -2,9 +2,15 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { injectDefinitions } from '@polkadot/types/srml';
|
||||
|
||||
import { authorityCount, authorityPrefix, changesTrieConfig, childStorageKeyPrefix, code, extrinsicIndex, heapPages } from './substrate';
|
||||
|
||||
describe('substrate', (): void => {
|
||||
beforeEach((): void => {
|
||||
injectDefinitions();
|
||||
});
|
||||
|
||||
// @deprecated: The ':auth:' (authorityPrefix) and ':auth:len' (authorityCount) storage keys
|
||||
// have been removed in https://github.com/paritytech/substrate/pull/2802
|
||||
it('authorityCount should return the correct storage key', (): void => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { Text, Vector } from '@polkadot/types';
|
||||
import { Text, Vec } from '@polkadot/types';
|
||||
|
||||
import createFunction from './createFunction';
|
||||
|
||||
@@ -18,7 +18,7 @@ const createRuntimeFunction = (method: string, key: string, { documentation, typ
|
||||
createFunction(
|
||||
{
|
||||
meta: {
|
||||
documentation: new Vector(Text, [documentation]),
|
||||
documentation: new Vec(Text, [documentation]),
|
||||
modifier: new StorageEntryModifier(1), // default
|
||||
type: new StorageEntryType(type, 0),
|
||||
toJSON: (): any => key
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v6/static';
|
||||
import metadataRpc from '@polkadot/types/Metadata/static';
|
||||
|
||||
import fromMetadata from './fromMetadata';
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
||||
import { Hash } from '@polkadot/types/srml/types';
|
||||
import { Hash, RuntimeVersion, SignedBlock } from '@polkadot/types/srml/types';
|
||||
import { AnyFunction, Codec, CodecArg, RegistryTypes } from '@polkadot/types/types';
|
||||
import {
|
||||
ApiInterfaceRx, ApiInterfaceEvents, ApiOptions, ApiTypes, DecorateMethodOptions,
|
||||
@@ -23,7 +23,7 @@ import { Storage } from '@polkadot/api-metadata/storage/types';
|
||||
import storageFromMeta from '@polkadot/api-metadata/storage/fromMetadata';
|
||||
import RpcCore from '@polkadot/rpc-core';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { Event, getTypeRegistry, Metadata, Method, RuntimeVersion, SignedBlock, Null, U64 } from '@polkadot/types';
|
||||
import { Event, getTypeRegistry, Metadata, Method, Null, u64 } from '@polkadot/types';
|
||||
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/primitive/Extrinsic/constants';
|
||||
import { MethodFunction, ModulesWithMethods } from '@polkadot/types/primitive/Method';
|
||||
@@ -697,7 +697,7 @@ export default abstract class ApiBase<ApiType> {
|
||||
);
|
||||
|
||||
decorated.size = decorateMethod(
|
||||
(arg1?: CodecArg, arg2?: CodecArg): Observable<U64> =>
|
||||
(arg1?: CodecArg, arg2?: CodecArg): Observable<u64> =>
|
||||
this._rpcCore.state.getStorageSize(
|
||||
creator.meta.type.isDoubleMap
|
||||
? [creator, [arg1, arg2]]
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { Balance, BlockNumber, Hash, Index } from '@polkadot/types/srml/types';
|
||||
import { SignerPayload as ISignerPayload } from './types';
|
||||
|
||||
import { Address, ClassOf, Compact, ExtrinsicEra, Struct, U8, Method } from '@polkadot/types';
|
||||
import { Address, ClassOf, Compact, ExtrinsicEra, Struct, u8, Method } from '@polkadot/types';
|
||||
|
||||
export interface SignerPayloadType {
|
||||
address: Address;
|
||||
@@ -16,7 +16,7 @@ export interface SignerPayloadType {
|
||||
method: Method;
|
||||
nonce: Compact<Index>;
|
||||
tip: Compact<Balance>;
|
||||
version: U8;
|
||||
version: u8;
|
||||
}
|
||||
|
||||
export default class SignerPayload extends Struct.with({
|
||||
@@ -28,7 +28,7 @@ export default class SignerPayload extends Struct.with({
|
||||
method: Method,
|
||||
nonce: ClassOf('Compact<Index>'),
|
||||
tip: ClassOf('Compact<Balance>'),
|
||||
version: U8
|
||||
version: u8
|
||||
}) {
|
||||
/**
|
||||
* @description Returns this as a SignerPayloadType. This works since the Struct.with injects all the getters automatically (just ensure the 2 definitiona are matching)
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Hash, Index } from '@polkadot/types/srml/types';
|
||||
import { ExtrinsicStatus, EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/srml/types';
|
||||
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types';
|
||||
import { ApiInterfaceRx, ApiTypes } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators';
|
||||
import { createType, AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Header, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types';
|
||||
import { createType, AccountId, Address, getTypeRegistry, Header, Method, Vec, ExtrinsicEra } from '@polkadot/types';
|
||||
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import filterEvents from './util/filterEvents';
|
||||
@@ -135,7 +135,7 @@ export default function createSubmittableExtrinsic<ApiType> (
|
||||
|
||||
return combineLatest([
|
||||
api.rpc.chain.getBlock(blockHash) as Observable<SignedBlock>,
|
||||
api.query.system.events.at(blockHash) as Observable<Vector<EventRecord>>
|
||||
api.query.system.events.at(blockHash) as Observable<Vec<EventRecord>>
|
||||
]).pipe(
|
||||
map(([signedBlock, allEvents]): SubmittableResult => {
|
||||
const result = new SubmittableResult({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Hash } from '@polkadot/types/srml/types';
|
||||
import { Hash, RuntimeVersion } from '@polkadot/types/srml/types';
|
||||
import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
||||
import { DeriveCustom } from '@polkadot/api-derive';
|
||||
import { Constants } from '@polkadot/api-metadata/consts/types';
|
||||
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
||||
import { RuntimeVersion, u64 as U64 } from '@polkadot/types';
|
||||
import { u64 } from '@polkadot/types';
|
||||
import { MethodFunction } from '@polkadot/types/primitive/Method';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
|
||||
@@ -107,7 +107,7 @@ export interface StorageEntryObservable {
|
||||
hash: (arg1?: CodecArg, arg2?: CodecArg) => Observable<Hash>;
|
||||
key: (arg1?: CodecArg, arg2?: CodecArg) => string;
|
||||
multi: <T extends Codec>(args: (CodecArg[] | CodecArg)[]) => Observable<T[]>;
|
||||
size: (arg1?: CodecArg, arg2?: CodecArg) => Observable<U64>;
|
||||
size: (arg1?: CodecArg, arg2?: CodecArg) => Observable<u64>;
|
||||
}
|
||||
|
||||
export interface StorageEntryPromiseOverloads {
|
||||
@@ -129,7 +129,7 @@ export interface StorageEntryPromise extends StorageEntryPromiseOverloads {
|
||||
hash: (arg1?: CodecArg, arg2?: CodecArg) => Promise<Hash>;
|
||||
key: (arg1?: CodecArg, arg2?: CodecArg) => string;
|
||||
multi: StorageEntryPromiseMulti;
|
||||
size: (arg1?: CodecArg, arg2?: CodecArg) => Promise<U64>;
|
||||
size: (arg1?: CodecArg, arg2?: CodecArg) => Promise<u64>;
|
||||
}
|
||||
|
||||
export type QueryableStorageEntry<ApiType> =
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { EventRecord, SignedBlock, U8a } from '@polkadot/types';
|
||||
import { EventRecord, SignedBlock } from '@polkadot/types/srml/types';
|
||||
|
||||
import { U8a } from '@polkadot/types';
|
||||
|
||||
import l from './logging';
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SignedBlock } from '@polkadot/types/srml/types';
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Extrinsic, SignedBlock } from '@polkadot/types';
|
||||
import { Extrinsic } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { EventRecord } from '@polkadot/types/srml/types';
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { AccountId, ClassOf, EventRecord, Header, Option, Vector } from '@polkadot/types';
|
||||
import { AccountId, ClassOf, Header, Option, Vec } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -72,13 +74,13 @@ describeE2E({
|
||||
|
||||
it('makes a query at a latest block (specified)', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const events = await api.query.system.events.at(header.hash) as Vector<EventRecord>;
|
||||
const events = await api.query.system.events.at(header.hash) as Vec<EventRecord>;
|
||||
|
||||
expect(events.length).not.toEqual(0);
|
||||
});
|
||||
|
||||
it('subscribes to events', (done): Promise<() => void> => {
|
||||
return api.query.system.events((events: Vector<EventRecord>): void => {
|
||||
return api.query.system.events((events: Vec<EventRecord>): void => {
|
||||
expect(events).not.toHaveLength(0);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import BN from 'bn.js';
|
||||
import { DerivedBalances } from '@polkadot/api-derive/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Header, Option, U32, createType } from '@polkadot/types';
|
||||
import { Header, Option, u32, createType } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -65,7 +65,7 @@ describeE2E({
|
||||
|
||||
it('subscribes to queries (default)', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.query.staking.minimumValidatorCount((defaultCount: U32): void => {
|
||||
api.query.staking.minimumValidatorCount((defaultCount: u32): void => {
|
||||
expect(defaultCount.toNumber()).toBe(1);
|
||||
|
||||
done();
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Hash, SessionIndex } from '@polkadot/types/srml/types';
|
||||
import { EventRecord, Hash, SessionIndex } from '@polkadot/types/srml/types';
|
||||
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { EventRecord, Header, Option, Vector, createType } from '@polkadot/types';
|
||||
import { Header, Option, Vec, createType } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -80,7 +80,7 @@ describeE2E()('Promise e2e queries', (wsUrl): void => {
|
||||
|
||||
it('makes a query at a latest block (specified)', async (): Promise<void> => {
|
||||
const header = await api.rpc.chain.getHeader() as Header;
|
||||
const events = await api.query.system.events.at(header.hash) as Vector<EventRecord>;
|
||||
const events = await api.query.system.events.at(header.hash) as Vec<EventRecord>;
|
||||
|
||||
expect(events.length).not.toEqual(0);
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Hash, Index } from '@polkadot/types/srml/types';
|
||||
import { EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/srml/types';
|
||||
|
||||
import Keyring from '@polkadot/keyring';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
import { randomAsHex } from '@polkadot/util-crypto';
|
||||
import { EventRecord, ExtrinsicEra, Header, SignedBlock } from '@polkadot/types';
|
||||
import { ExtrinsicEra, Header } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SignedBlock, StorageChangeSet } from '@polkadot/types/srml/types';
|
||||
|
||||
import storage from '@polkadot/api-metadata/storage/static';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { ClassOf, SignedBlock, StorageChangeSet } from '@polkadot/types';
|
||||
import { ClassOf } from '@polkadot/types';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
|
||||
@@ -42,7 +44,7 @@ describe.skip('e2e Alexander - Polkadot', (): void => {
|
||||
.getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df')
|
||||
.subscribe((block: SignedBlock): void => {
|
||||
expect(block).toBeDefined();
|
||||
expect(block).toBeInstanceOf(SignedBlock);
|
||||
expect(block).toBeInstanceOf(ClassOf('SignedBlock'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -52,7 +54,7 @@ describe.skip('e2e Alexander - Polkadot', (): void => {
|
||||
.getBlock('0x53416d53a4b1dfcae9165a89d193608e4aa770414f02267f5b2c4015a2e66091')
|
||||
.subscribe((block: SignedBlock): void => {
|
||||
expect(block).toBeDefined();
|
||||
expect(block).toBeInstanceOf(SignedBlock);
|
||||
expect(block).toBeInstanceOf(ClassOf('SignedBlock'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ChainProperties, Extrinsic, Vector } from '@polkadot/types';
|
||||
import { ChainProperties } from '@polkadot/types/srml/types';
|
||||
|
||||
import { ClassOf, Extrinsic, Vec } from '@polkadot/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
@@ -18,8 +20,8 @@ describe.skip('e2e basics', (): void => {
|
||||
it('retrieves the pending extrinsics', (done): void => {
|
||||
rpc.author
|
||||
.pendingExtrinsics()
|
||||
.subscribe((extrinsics: Vector<Extrinsic>): void => {
|
||||
expect(extrinsics).toBeInstanceOf(Vector);
|
||||
.subscribe((extrinsics: Vec<Extrinsic>): void => {
|
||||
expect(extrinsics).toBeInstanceOf(Vec);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -28,7 +30,7 @@ describe.skip('e2e basics', (): void => {
|
||||
rpc.system
|
||||
.properties()
|
||||
.subscribe((properties: ChainProperties): void => {
|
||||
expect(properties).toBeInstanceOf(ChainProperties);
|
||||
expect(properties).toBeInstanceOf(ClassOf('ChainProperties'));
|
||||
console.log('properties', properties);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Header, RuntimeVersion } from '@polkadot/types';
|
||||
import { RuntimeVersion } from '@polkadot/types/srml/types';
|
||||
|
||||
import { ClassOf, Header } from '@polkadot/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
@@ -33,7 +35,7 @@ describe.skip('e2e chain', (): void => {
|
||||
rpc.chain
|
||||
.getRuntimeVersion()
|
||||
.subscribe((version: RuntimeVersion): void => {
|
||||
expect(version).toBeInstanceOf(RuntimeVersion);
|
||||
expect(version).toBeInstanceOf(ClassOf('RuntimeVersion'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Balance, Hash } from '@polkadot/types/srml/types';
|
||||
import { Balance, Hash, StorageData } from '@polkadot/types/srml/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -14,7 +14,7 @@ import { Abi } from '@polkadot/api-contract';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Bytes, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types';
|
||||
import { Bytes, Metadata, Moment, StorageKey } from '@polkadot/types';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
import flipperAbi from '../../../../api-contract/test/contracts/flipper.json';
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { StorageChangeSet } from '@polkadot/types';
|
||||
import { StorageChangeSet } from '@polkadot/types/srml/types';
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import storage from '@polkadot/api-metadata/storage/static';
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { injectDefinitions } from '@polkadot/types/srml';
|
||||
import rpcMetadataV3 from '@polkadot/types/Metadata/v3/static';
|
||||
import rpcMetadataV4 from '@polkadot/types/Metadata/v4/static';
|
||||
import rpcMetadataV5 from '@polkadot/types/Metadata/v5/static';
|
||||
import rpcMetadataV6 from '@polkadot/types/Metadata/v6/static';
|
||||
import rpcMetadataV6 from '@polkadot/types/Metadata/static';
|
||||
import rpcMetadataV7 from '@polkadot/types/Metadata/v7/static';
|
||||
|
||||
import Api from '.';
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
||||
import { RpcSection, RpcMethod } from '@polkadot/jsonrpc/types';
|
||||
import { StorageChangeSet, StorageData } from '@polkadot/types/srml/types';
|
||||
import { AnyJson, Codec } from '@polkadot/types/types';
|
||||
import { RpcInterface, RpcInterfaceMethod, RpcInterfaceSection } from './types';
|
||||
|
||||
@@ -11,7 +12,7 @@ import memoizee from 'memoizee';
|
||||
import { combineLatest, from, Observable, Observer, of, throwError } from 'rxjs';
|
||||
import { catchError, map, publishReplay, refCount, switchMap } from 'rxjs/operators';
|
||||
import interfaces from '@polkadot/jsonrpc';
|
||||
import { Option, StorageChangeSet, StorageData, StorageKey, Vector, createClass, createType } from '@polkadot/types';
|
||||
import { ClassOf, Option, StorageKey, Vec, createClass, createType } from '@polkadot/types';
|
||||
import { ExtError, assert, isFunction, isNull, isNumber, logger } from '@polkadot/util';
|
||||
|
||||
const l = logger('rpc-core');
|
||||
@@ -277,13 +278,13 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
throw error;
|
||||
}
|
||||
} else if (method.type === 'StorageChangeSet') {
|
||||
} else if ((method.type as string) === 'StorageChangeSet') {
|
||||
// multiple return values (via state.storage subscription), decode the values
|
||||
// one at a time, all based on the query types. Three values can be returned -
|
||||
// - Base - There is a valid value, non-empty
|
||||
// - null - The storage key is empty (but in the resultset)
|
||||
// - undefined - The storage value is not in the resultset
|
||||
return (params[0] as Vector<StorageKey>).reduce((results, key: StorageKey): (Codec | undefined)[] => {
|
||||
return (params[0] as Vec<StorageKey>).reduce((results, key: StorageKey): (Codec | undefined)[] => {
|
||||
try {
|
||||
results.push(this.formatStorageSet(key, base as StorageChangeSet));
|
||||
} catch (error) {
|
||||
@@ -323,9 +324,9 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
// see if we have a result value for this specific key, fallback to the cache value
|
||||
// when the value in the set is not available, or is null/empty.
|
||||
const { value } = base.changes.find(({ key, value }): boolean =>
|
||||
const [, value] = base.changes.find(([key, value]): boolean =>
|
||||
value.isSome && key.toHex() === hexKey
|
||||
) || { value: this._storageCache.get(hexKey) || new Option<StorageData>(StorageData, null) };
|
||||
) || [null, this._storageCache.get(hexKey) || new Option<StorageData>(ClassOf('StorageData'), null)];
|
||||
|
||||
// store the retrieved result - the only issue with this cache is that there is no
|
||||
// clearning of it, so very long running processes (not just a couple of hours, longer)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { ProviderInterface, ProviderInterfaceEmitted, ProviderInterfaceEmitCb } from '../types';
|
||||
import { MockStateSubscriptions, MockStateSubscriptionCallback, MockStateDb } from './types';
|
||||
|
||||
@@ -11,10 +12,9 @@ import EventEmitter from 'eventemitter3';
|
||||
import interfaces from '@polkadot/jsonrpc';
|
||||
import testKeyring from '@polkadot/keyring/testing';
|
||||
import storage from '@polkadot/api-metadata/storage/static';
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import rpcMetadata from '@polkadot/types/Metadata/static';
|
||||
import rpcSignedBlock from '@polkadot/types/json/SignedBlock.004.immortal.json';
|
||||
import { Header, RuntimeVersion, SignedBlock } from '@polkadot/types';
|
||||
import { createType, Header } from '@polkadot/types';
|
||||
import { bnToU8a, logger, u8aToHex } from '@polkadot/util';
|
||||
import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
@@ -48,10 +48,10 @@ export default class Mock implements ProviderInterface {
|
||||
|
||||
private requests: Record<string, (...params: any[]) => string> = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
chain_getBlock: (hash: string): any => new SignedBlock(rpcSignedBlock.result).toJSON(),
|
||||
chain_getBlock: (hash: string): any => createType('SignedBlock', rpcSignedBlock.result).toJSON(),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
chain_getBlockHash: (blockNumber: number): string => '0x1234',
|
||||
chain_getRuntimeVersion: (): string => new RuntimeVersion().toHex(),
|
||||
chain_getRuntimeVersion: (): string => createType('RuntimeVersion').toHex(),
|
||||
state_getStorage: (storage: MockStateDb, params: any[]): string => {
|
||||
return u8aToHex(
|
||||
storage[(params[0] as string)]
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CodecTypes } from '@polkadot/types/classes';
|
||||
// import { CodecTypes } from '@polkadot/types/classes';
|
||||
|
||||
type PubSub = [string, string, string];
|
||||
|
||||
export interface RpcParam {
|
||||
isOptional: boolean;
|
||||
name: string;
|
||||
type: CodecTypes;
|
||||
type: string; // CodecTypes;
|
||||
}
|
||||
|
||||
export interface RpcMethodOpt {
|
||||
@@ -20,7 +20,7 @@ export interface RpcMethodOpt {
|
||||
isSubscription?: boolean;
|
||||
params: RpcParam[];
|
||||
pubsub?: PubSub;
|
||||
type: CodecTypes;
|
||||
type: string; // CodecTypes;
|
||||
}
|
||||
|
||||
export interface RpcMethod {
|
||||
@@ -34,7 +34,7 @@ export interface RpcMethod {
|
||||
params: RpcParam[];
|
||||
pubsub: PubSub;
|
||||
section: string;
|
||||
type: CodecTypes;
|
||||
type: string; // CodecTypes;
|
||||
}
|
||||
|
||||
export interface RpcSection {
|
||||
|
||||
@@ -23,8 +23,8 @@ These are the base types of the codec. They are typically not used directly, but
|
||||
| [[U8a]] | A basic wrapper around Uint8Array. It will consume the full Uint8Array as passed to it |
|
||||
| [[U8aFixed]] | A U8a that manages a a sequence of bytes up to the specified bitLength |
|
||||
| [[UInt]] | A generic unsigned integer codec. It handles the encoding and decoding of Little Endian encoded numbers in Substrate |
|
||||
| [[Vector]] | This manages codec arrays. Internally it keeps track of the length (as decoded) |
|
||||
| [[VectorAny]] | This manages codec arrays, assuming that the inputs are already of type Codec |
|
||||
| [[Vec]] | This manages codec arrays. Internally it keeps track of the length (as decoded) |
|
||||
| [[VecAny]] | This manages codec arrays, assuming that the inputs are already of type Codec |
|
||||
|
||||
|
||||
## Primitive types
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Vector } from '../codec';
|
||||
import { Vec } from '../codec';
|
||||
import { Codec } from '../types';
|
||||
|
||||
export interface MetadataInterface<Modules extends Codec> extends Codec {
|
||||
modules: Vector<Modules>;
|
||||
modules: Vec<Modules>;
|
||||
getUniqTypes (throwError: boolean): string[];
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ export default function validateTypes (types: string[], throwError: boolean): vo
|
||||
|
||||
case TypeDefInfo.Compact:
|
||||
case TypeDefInfo.Option:
|
||||
case TypeDefInfo.Vector:
|
||||
case TypeDefInfo.Vec:
|
||||
return extractTypes([(decoded.sub as TypeDef).type]);
|
||||
|
||||
case TypeDefInfo.VectorFixed:
|
||||
case TypeDefInfo.VecFixed:
|
||||
return extractTypes([(decoded.ext as TypeDefExtVecFixed).type]);
|
||||
|
||||
case TypeDefInfo.Tuple:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import U16 from '../../primitive/U16';
|
||||
|
||||
@@ -42,15 +42,15 @@ export class OuterDispatchMetadata extends Struct {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
name: Text,
|
||||
calls: Vector.with(OuterDispatchCall)
|
||||
calls: Vec.with(OuterDispatchCall)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[OuterDispathCall]] wrapped
|
||||
*/
|
||||
public get calls (): Vector<OuterDispatchCall> {
|
||||
return this.get('calls') as Vector<OuterDispatchCall>;
|
||||
public get calls (): Vec<OuterDispatchCall> {
|
||||
return this.get('calls') as Vec<OuterDispatchCall>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import Struct from '../../codec/Struct';
|
||||
import Tuple from '../../codec/Tuple';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
|
||||
@@ -12,38 +12,38 @@ export class EventMetadata extends Struct {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
name: Text,
|
||||
args: Vector.with(Type),
|
||||
documentation: Vector.with(Text)
|
||||
args: Vec.with(Type),
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The arguments of [[Type]]
|
||||
*/
|
||||
public get args (): Vector<Type> {
|
||||
return this.get('args') as Vector<Type>;
|
||||
public get args (): Vec<Type> {
|
||||
return this.get('args') as Vec<Type>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The arguments of [[Type]]
|
||||
* @deprecated Use `.args` instead
|
||||
*/
|
||||
public get arguments (): Vector<Type> {
|
||||
public get arguments (): Vec<Type> {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
@@ -59,15 +59,15 @@ export class OuterEventEventMetadata extends Tuple {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
Text,
|
||||
'Vec<EventMetadata>': Vector.with(EventMetadata)
|
||||
'Vec<EventMetadata>': Vec.with(EventMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[EventMetadata]]
|
||||
*/
|
||||
public get events (): Vector<EventMetadata> {
|
||||
return this[1] as Vector<EventMetadata>;
|
||||
public get events (): Vec<EventMetadata> {
|
||||
return this[1] as Vec<EventMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,15 +82,15 @@ export class OuterEventMetadata extends Struct {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
name: Text,
|
||||
events: Vector.with(OuterEventEventMetadata)
|
||||
events: Vec.with(OuterEventEventMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[OuterEventEventMetadata]]
|
||||
*/
|
||||
public get events (): Vector<OuterEventEventMetadata> {
|
||||
return this.get('events') as Vector<OuterEventEventMetadata>;
|
||||
public get events (): Vec<OuterEventEventMetadata> {
|
||||
return this.get('events') as Vec<OuterEventEventMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@ import { hexToU8a, isHex, isU8a } from '@polkadot/util';
|
||||
|
||||
import Compact from '../../codec/Compact';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
import { OuterDispatchMetadata, OuterDispatchCall } from './Calls';
|
||||
import { OuterEventMetadata, OuterEventEventMetadata } from './Events';
|
||||
@@ -25,7 +25,7 @@ export default class MetadataV0 extends Struct implements MetadataInterface<Runt
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
outerEvent: OuterEventMetadata,
|
||||
modules: Vector.with(RuntimeModuleMetadata),
|
||||
modules: Vec.with(RuntimeModuleMetadata),
|
||||
outerDispatch: OuterDispatchMetadata
|
||||
}, MetadataV0.decodeMetadata(value));
|
||||
}
|
||||
@@ -55,22 +55,22 @@ export default class MetadataV0 extends Struct implements MetadataInterface<Runt
|
||||
/**
|
||||
* @description Wrapped [[OuterDispatchCall]]
|
||||
*/
|
||||
public get calls (): Vector<OuterDispatchCall> {
|
||||
public get calls (): Vec<OuterDispatchCall> {
|
||||
return (this.get('outerDispatch') as OuterDispatchMetadata).calls;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Wrapped [[OuterEventEventMetadata]]
|
||||
*/
|
||||
public get events (): Vector<OuterEventEventMetadata> {
|
||||
public get events (): Vec<OuterEventEventMetadata> {
|
||||
return (this.get('outerEvent') as OuterEventMetadata).events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Wrapped [[RuntimeModuleMetadata]]
|
||||
*/
|
||||
public get modules (): Vector<RuntimeModuleMetadata> {
|
||||
return this.get('modules') as Vector<RuntimeModuleMetadata>;
|
||||
public get modules (): Vec<RuntimeModuleMetadata> {
|
||||
return this.get('modules') as Vec<RuntimeModuleMetadata>;
|
||||
}
|
||||
|
||||
private get argNames (): string[][][] {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
import U16 from '../../primitive/U16';
|
||||
@@ -39,38 +39,38 @@ export class FunctionMetadata extends Struct {
|
||||
super({
|
||||
id: U16,
|
||||
name: Text,
|
||||
args: Vector.with(FunctionArgumentMetadata),
|
||||
documentation: Vector.with(Text)
|
||||
args: Vec.with(FunctionArgumentMetadata),
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The arguments of [[Type]]
|
||||
*/
|
||||
public get args (): Vector<FunctionArgumentMetadata> {
|
||||
return this.get('args') as Vector<FunctionArgumentMetadata>;
|
||||
public get args (): Vec<FunctionArgumentMetadata> {
|
||||
return this.get('args') as Vec<FunctionArgumentMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[FunctionArgumentMetadata]] for arguments
|
||||
* @deprecated Use `.args` instead
|
||||
*/
|
||||
public get arguments (): Vector<FunctionArgumentMetadata> {
|
||||
return this.get('arguments') as Vector<FunctionArgumentMetadata>;
|
||||
public get arguments (): Vec<FunctionArgumentMetadata> {
|
||||
return this.get('arguments') as Vec<FunctionArgumentMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
@@ -93,15 +93,15 @@ export class CallMetadata extends Struct {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
name: Text,
|
||||
functions: Vector.with(FunctionMetadata)
|
||||
functions: Vec.with(FunctionMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The functions available as [[FunctionMetadata]]
|
||||
*/
|
||||
public get functions (): Vector<FunctionMetadata> {
|
||||
return this.get('functions') as Vector<FunctionMetadata>;
|
||||
public get functions (): Vec<FunctionMetadata> {
|
||||
return this.get('functions') as Vec<FunctionMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@ import { assert } from '@polkadot/util';
|
||||
|
||||
import Enum from '../../codec/Enum';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Bytes from '../../primitive/Bytes';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
@@ -131,7 +131,7 @@ export interface StorageFunctionMetadataValue {
|
||||
modifier: StorageFunctionModifier | AnyNumber;
|
||||
type: StorageFunctionType;
|
||||
fallback: Bytes;
|
||||
documentation: Vector<Text> | string[];
|
||||
documentation: Vec<Text> | string[];
|
||||
}
|
||||
|
||||
export class StorageFunctionMetadata extends Struct {
|
||||
@@ -141,7 +141,7 @@ export class StorageFunctionMetadata extends Struct {
|
||||
modifier: StorageFunctionModifier,
|
||||
type: StorageFunctionType,
|
||||
fallback: Bytes,
|
||||
documentation: Vector.with(Text)
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -163,15 +163,15 @@ export class StorageFunctionMetadata extends Struct {
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
@@ -201,15 +201,15 @@ export class StorageMetadata extends Struct {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
prefix: Text,
|
||||
functions: Vector.with(StorageFunctionMetadata)
|
||||
functions: Vec.with(StorageFunctionMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[StorageFunctionMetadata]] for the section
|
||||
*/
|
||||
public get functions (): Vector<StorageFunctionMetadata> {
|
||||
return this.get('functions') as Vector<StorageFunctionMetadata>;
|
||||
public get functions (): Vec<StorageFunctionMetadata> {
|
||||
return this.get('functions') as Vec<StorageFunctionMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { stringUpperFirst } from '@polkadot/util';
|
||||
|
||||
import { Option, Vector } from '../../codec';
|
||||
import { Option, Vec } from '../../codec';
|
||||
import MetadataV0 from './Metadata';
|
||||
import { RuntimeModuleMetadata } from './Modules';
|
||||
import { Text } from '../../primitive';
|
||||
@@ -16,23 +16,23 @@ import { StorageFunctionMetadata } from '../v1/Storage';
|
||||
|
||||
function toV1Calls (modul: RuntimeModuleMetadata): Option<FunctionMetadata> {
|
||||
return modul.module.call.functions.length === 0
|
||||
? new Option(Vector.with(FunctionMetadata))
|
||||
: new Option(Vector.with(FunctionMetadata), modul.module.call.functions);
|
||||
? new Option(Vec.with(FunctionMetadata))
|
||||
: new Option(Vec.with(FunctionMetadata), modul.module.call.functions);
|
||||
}
|
||||
|
||||
function toV1Events (metadataV0: MetadataV0, prefix: Text): Option<EventMetadata> {
|
||||
const events = metadataV0.events.find((event): boolean => event.name.eq(prefix));
|
||||
|
||||
return events
|
||||
? new Option(Vector.with(EventMetadata), events.events)
|
||||
: new Option(Vector.with(EventMetadata));
|
||||
? new Option(Vec.with(EventMetadata), events.events)
|
||||
: new Option(Vec.with(EventMetadata));
|
||||
}
|
||||
|
||||
function toV1Storage (modul: RuntimeModuleMetadata): Option<StorageFunctionMetadata> {
|
||||
return modul.storage.isNone
|
||||
? new Option(Vector.with(StorageFunctionMetadata))
|
||||
? new Option(Vec.with(StorageFunctionMetadata))
|
||||
: new Option(
|
||||
Vector.with(StorageFunctionMetadata),
|
||||
Vec.with(StorageFunctionMetadata),
|
||||
modul.storage.unwrap().functions
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
|
||||
@@ -39,30 +39,30 @@ export class FunctionMetadata extends Struct {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
name: Text,
|
||||
args: Vector.with(FunctionArgumentMetadata),
|
||||
documentation: Vector.with(Text)
|
||||
args: Vec.with(FunctionArgumentMetadata),
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[FunctionArgumentMetadata]] for arguments
|
||||
*/
|
||||
public get args (): Vector<FunctionArgumentMetadata> {
|
||||
return this.get('args') as Vector<FunctionArgumentMetadata>;
|
||||
public get args (): Vec<FunctionArgumentMetadata> {
|
||||
return this.get('args') as Vec<FunctionArgumentMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
@@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct {
|
||||
super({
|
||||
name: Text,
|
||||
prefix: Text,
|
||||
storage: Option.with(Vector.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata))
|
||||
storage: Option.with(Vec.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vec.with(FunctionMetadata)),
|
||||
events: Option.with(Vec.with(EventMetadata))
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
public get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
public get calls (): Option<Vec<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vec<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
public get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
public get events (): Option<Vec<EventMetadata>> {
|
||||
return this.get('events') as Option<Vec<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct {
|
||||
/**
|
||||
* @description the associated module storage
|
||||
*/
|
||||
public get storage (): Option<Vector<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vector<StorageFunctionMetadata>>;
|
||||
public get storage (): Option<Vec<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct {
|
||||
export default class MetadataV1 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
modules: Vec.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
public get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
public get modules (): Vec<ModuleMetadata> {
|
||||
return this.get('modules') as Vec<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames (): string[][][] {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
@@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct {
|
||||
super({
|
||||
name: Text,
|
||||
prefix: Text,
|
||||
storage: Option.with(Vector.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata))
|
||||
storage: Option.with(Vec.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vec.with(FunctionMetadata)),
|
||||
events: Option.with(Vec.with(EventMetadata))
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
public get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
public get calls (): Option<Vec<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vec<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
public get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
public get events (): Option<Vec<EventMetadata>> {
|
||||
return this.get('events') as Option<Vec<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct {
|
||||
/**
|
||||
* @description the associated module storage
|
||||
*/
|
||||
public get storage (): Option<Vector<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vector<StorageFunctionMetadata>>;
|
||||
public get storage (): Option<Vec<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct {
|
||||
export default class MetadataV2 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
modules: Vec.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
public get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
public get modules (): Vec<ModuleMetadata> {
|
||||
return this.get('modules') as Vec<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames (): string[][][] {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { assert } from '@polkadot/util';
|
||||
|
||||
import Enum from '../../codec/Enum';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Bool from '../../primitive/Bool';
|
||||
import Bytes from '../../primitive/Bytes';
|
||||
import Text from '../../primitive/Text';
|
||||
@@ -113,7 +113,7 @@ export interface StorageFunctionMetadataValue {
|
||||
modifier: StorageFunctionModifier | AnyNumber;
|
||||
type: StorageFunctionType;
|
||||
fallback: Bytes;
|
||||
documentation: Vector<Text> | string[];
|
||||
documentation: Vec<Text> | string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +128,7 @@ export class StorageFunctionMetadata extends Struct {
|
||||
modifier: StorageFunctionModifier,
|
||||
type: StorageFunctionType,
|
||||
fallback: Bytes,
|
||||
documentation: Vector.with(Text)
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -143,15 +143,15 @@ export class StorageFunctionMetadata extends Struct {
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
@@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct {
|
||||
super({
|
||||
name: Text,
|
||||
prefix: Text,
|
||||
storage: Option.with(Vector.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata))
|
||||
storage: Option.with(Vec.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vec.with(FunctionMetadata)),
|
||||
events: Option.with(Vec.with(EventMetadata))
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
public get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
public get calls (): Option<Vec<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vec<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
public get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
public get events (): Option<Vec<EventMetadata>> {
|
||||
return this.get('events') as Option<Vec<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct {
|
||||
/**
|
||||
* @description the associated module storage
|
||||
*/
|
||||
public get storage (): Option<Vector<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vector<StorageFunctionMetadata>>;
|
||||
public get storage (): Option<Vec<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct {
|
||||
export default class MetadataV3 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
modules: Vec.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
public get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
public get modules (): Vec<ModuleMetadata> {
|
||||
return this.get('modules') as Vec<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames (): string[][][] {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { assert } from '@polkadot/util';
|
||||
|
||||
import Enum from '../../codec/Enum';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Bytes from '../../primitive/Bytes';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
@@ -146,7 +146,7 @@ export interface StorageFunctionMetadataValue {
|
||||
modifier: StorageFunctionModifier | AnyNumber;
|
||||
type: StorageFunctionType;
|
||||
fallback: Bytes;
|
||||
documentation: Vector<Text> | string[];
|
||||
documentation: Vec<Text> | string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +161,7 @@ export class StorageFunctionMetadata extends Struct {
|
||||
modifier: StorageFunctionModifier,
|
||||
type: StorageFunctionType,
|
||||
fallback: Bytes,
|
||||
documentation: Vector.with(Text)
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -176,15 +176,15 @@ export class StorageFunctionMetadata extends Struct {
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Option, Vector } from '../../codec';
|
||||
import { Option, Vec } from '../../codec';
|
||||
import MetadataV3 from './Metadata';
|
||||
import StorageHasher from '../../primitive/StorageHasher';
|
||||
import MetadataV4 from '../v4';
|
||||
@@ -57,7 +57,7 @@ export default function toV4 (metadataV3: MetadataV3): MetadataV4 {
|
||||
prefix: modul.prefix,
|
||||
storage: modul.storage.isSome
|
||||
? new Option(
|
||||
Vector.with(StorageFunctionMetadata),
|
||||
Vec.with(StorageFunctionMetadata),
|
||||
modul.storage.unwrap().map(toV4StorageFunction)
|
||||
)
|
||||
: undefined,
|
||||
|
||||
@@ -6,7 +6,7 @@ import { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
@@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct {
|
||||
super({
|
||||
name: Text,
|
||||
prefix: Text,
|
||||
storage: Option.with(Vector.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata))
|
||||
storage: Option.with(Vec.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vec.with(FunctionMetadata)),
|
||||
events: Option.with(Vec.with(EventMetadata))
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
public get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
public get calls (): Option<Vec<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vec<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
public get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
public get events (): Option<Vec<EventMetadata>> {
|
||||
return this.get('events') as Option<Vec<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct {
|
||||
/**
|
||||
* @description the associated module storage
|
||||
*/
|
||||
public get storage (): Option<Vector<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vector<StorageFunctionMetadata>>;
|
||||
public get storage (): Option<Vec<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct {
|
||||
export default class MetadataV4 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
modules: Vec.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
public get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
public get modules (): Vec<ModuleMetadata> {
|
||||
return this.get('modules') as Vec<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames (): string[][][] {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { assert } from '@polkadot/util';
|
||||
|
||||
import Enum from '../../codec/Enum';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Bool from '../../primitive/Bool';
|
||||
import Bytes from '../../primitive/Bytes';
|
||||
import StorageHasher from '../../primitive/StorageHasher';
|
||||
@@ -190,7 +190,7 @@ export interface StorageFunctionMetadataValue {
|
||||
modifier: StorageFunctionModifier | AnyNumber;
|
||||
type: StorageFunctionType;
|
||||
fallback: Bytes;
|
||||
documentation: Vector<Text> | string[];
|
||||
documentation: Vec<Text> | string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +205,7 @@ export class StorageFunctionMetadata extends Struct {
|
||||
modifier: StorageFunctionModifier,
|
||||
type: StorageFunctionType,
|
||||
fallback: Bytes,
|
||||
documentation: Vector.with(Text)
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -227,15 +227,15 @@ export class StorageFunctionMetadata extends Struct {
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Option, Vector } from '../../codec';
|
||||
import { Option, Vec } from '../../codec';
|
||||
import Text from '../../primitive/Text';
|
||||
import MetadataV4 from './Metadata';
|
||||
import StorageHasher from '../../primitive/StorageHasher';
|
||||
@@ -67,7 +67,7 @@ export default function toV5 (metadataV4: MetadataV4): MetadataV5 {
|
||||
prefix: modul.prefix,
|
||||
storage: modul.storage.isSome
|
||||
? new Option(
|
||||
Vector.with(StorageFunctionMetadata),
|
||||
Vec.with(StorageFunctionMetadata),
|
||||
modul.storage.unwrap().map(toV5StorageFunction)
|
||||
)
|
||||
: undefined,
|
||||
|
||||
@@ -6,7 +6,7 @@ import { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
@@ -24,24 +24,24 @@ export class ModuleMetadata extends Struct {
|
||||
super({
|
||||
name: Text,
|
||||
prefix: Text,
|
||||
storage: Option.with(Vector.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata))
|
||||
storage: Option.with(Vec.with(StorageFunctionMetadata)),
|
||||
calls: Option.with(Vec.with(FunctionMetadata)),
|
||||
events: Option.with(Vec.with(EventMetadata))
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
public get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
public get calls (): Option<Vec<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vec<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
public get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
public get events (): Option<Vec<EventMetadata>> {
|
||||
return this.get('events') as Option<Vec<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +61,8 @@ export class ModuleMetadata extends Struct {
|
||||
/**
|
||||
* @description the associated module storage
|
||||
*/
|
||||
public get storage (): Option<Vector<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vector<StorageFunctionMetadata>>;
|
||||
public get storage (): Option<Vec<StorageFunctionMetadata>> {
|
||||
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ export class ModuleMetadata extends Struct {
|
||||
export default class MetadataV5 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
modules: Vec.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
public get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
public get modules (): Vec<ModuleMetadata> {
|
||||
return this.get('modules') as Vec<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames (): string[][][] {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { assert } from '@polkadot/util';
|
||||
|
||||
import Enum from '../../codec/Enum';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Bytes from '../../primitive/Bytes';
|
||||
import StorageHasher from '../../primitive/StorageHasher';
|
||||
import Text from '../../primitive/Text';
|
||||
@@ -151,7 +151,7 @@ export interface StorageFunctionMetadataValue {
|
||||
modifier: StorageFunctionModifier | AnyNumber;
|
||||
type: StorageFunctionType;
|
||||
fallback: Bytes;
|
||||
documentation: Vector<Text> | string[];
|
||||
documentation: Vec<Text> | string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +166,7 @@ export class StorageFunctionMetadata extends Struct {
|
||||
modifier: StorageFunctionModifier,
|
||||
type: StorageFunctionType,
|
||||
fallback: Bytes,
|
||||
documentation: Vector.with(Text)
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -188,15 +188,15 @@ export class StorageFunctionMetadata extends Struct {
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Text]] documentation
|
||||
* @deprecated Use `.documentation` instead.
|
||||
*/
|
||||
public get docs (): Vector<Text> {
|
||||
public get docs (): Vec<Text> {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import Bytes from '../../primitive/Bytes';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
|
||||
export class ModuleConstantMetadata extends Struct {
|
||||
public constructor (value?: any) {
|
||||
@@ -14,7 +14,7 @@ export class ModuleConstantMetadata extends Struct {
|
||||
name: Text,
|
||||
type: Type,
|
||||
value: Bytes,
|
||||
documentation: Vector.with(Text)
|
||||
documentation: Vec.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export class ModuleConstantMetadata extends Struct {
|
||||
/**
|
||||
* @description The documentation
|
||||
*/
|
||||
public get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
public get documentation (): Vec<Text> {
|
||||
return this.get('documentation') as Vec<Text>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
@@ -25,32 +25,32 @@ export class ModuleMetadata extends Struct {
|
||||
super({
|
||||
name: Text,
|
||||
prefix: Text,
|
||||
storage: Option.with(Vector.with(StorageEntryMetadata)),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata)),
|
||||
constants: Vector.with(ModuleConstantMetadata)
|
||||
storage: Option.with(Vec.with(StorageEntryMetadata)),
|
||||
calls: Option.with(Vec.with(FunctionMetadata)),
|
||||
events: Option.with(Vec.with(EventMetadata)),
|
||||
constants: Vec.with(ModuleConstantMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
public get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
public get calls (): Option<Vec<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vec<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module constants
|
||||
*/
|
||||
public get constants (): Vector<ModuleConstantMetadata> {
|
||||
return this.get('constants') as Vector<ModuleConstantMetadata>;
|
||||
public get constants (): Vec<ModuleConstantMetadata> {
|
||||
return this.get('constants') as Vec<ModuleConstantMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
public get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
public get events (): Option<Vec<EventMetadata>> {
|
||||
return this.get('events') as Option<Vec<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,8 +70,8 @@ export class ModuleMetadata extends Struct {
|
||||
/**
|
||||
* @description the associated module storage
|
||||
*/
|
||||
public get storage (): Option<Vector<StorageEntryMetadata>> {
|
||||
return this.get('storage') as Option<Vector<StorageEntryMetadata>>;
|
||||
public get storage (): Option<Vec<StorageEntryMetadata>> {
|
||||
return this.get('storage') as Option<Vec<StorageEntryMetadata>>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,15 +83,15 @@ export class ModuleMetadata extends Struct {
|
||||
export default class MetadataV6 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
modules: Vec.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
public get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
public get modules (): Vec<ModuleMetadata> {
|
||||
return this.get('modules') as Vec<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames (): string[][][] {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
@@ -25,31 +25,31 @@ export class ModuleMetadata extends Struct {
|
||||
super({
|
||||
name: Text,
|
||||
storage: Option.with(StorageMetadata),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata)),
|
||||
constants: Vector.with(ModuleConstantMetadata)
|
||||
calls: Option.with(Vec.with(FunctionMetadata)),
|
||||
events: Option.with(Vec.with(EventMetadata)),
|
||||
constants: Vec.with(ModuleConstantMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
public get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
public get calls (): Option<Vec<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vec<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module constants
|
||||
*/
|
||||
public get constants (): Vector<ModuleConstantMetadata> {
|
||||
return this.get('constants') as Vector<ModuleConstantMetadata>;
|
||||
public get constants (): Vec<ModuleConstantMetadata> {
|
||||
return this.get('constants') as Vec<ModuleConstantMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
public get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
public get events (): Option<Vec<EventMetadata>> {
|
||||
return this.get('events') as Option<Vec<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,15 +82,15 @@ export class ModuleMetadata extends Struct {
|
||||
export default class MetadataV7 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
public constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
modules: Vec.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
public get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
public get modules (): Vec<ModuleMetadata> {
|
||||
return this.get('modules') as Vec<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames (): string[][][] {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Vec from '../../codec/Vec';
|
||||
import Text from '../../primitive/Text';
|
||||
|
||||
import { DoubleMapType, MapType, PlainType, StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryModifier, StorageEntryType } from '../v6/Storage';
|
||||
@@ -24,15 +24,15 @@ export class StorageMetadata extends Struct {
|
||||
super({
|
||||
prefix: Text,
|
||||
// NOTE renamed to items from entries (since Struct already has entries from Map)
|
||||
items: Vector.with(StorageEntryMetadata)
|
||||
items: Vec.with(StorageEntryMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the storage entries
|
||||
*/
|
||||
public get items (): Vector<StorageEntryMetadata> {
|
||||
return this.get('items') as Vector<StorageEntryMetadata>;
|
||||
public get items (): Vec<StorageEntryMetadata> {
|
||||
return this.get('items') as Vec<StorageEntryMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,7 +104,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
|
||||
);
|
||||
}
|
||||
|
||||
// Below are methods that we override. When we do a `new Vector(...).map()`,
|
||||
// Below are methods that we override. When we do a `new Vec(...).map()`,
|
||||
// we want it to return an Array. We only override the methods that return a
|
||||
// new instance.
|
||||
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyNumber, Constructor } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString } from '@polkadot/util';
|
||||
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
|
||||
|
||||
import Moment from '../primitive/Moment';
|
||||
import { AnyNumber, Constructor } from '../types';
|
||||
import AbstractInt, { UIntBitLength } from './AbstractInt';
|
||||
import { UIntBitLength } from './AbstractInt';
|
||||
import UInt from './UInt';
|
||||
import Base from './Base';
|
||||
|
||||
// List of codec types that are compact-encodable
|
||||
export const COMPACT_ENCODABLE = [AbstractInt, Moment];
|
||||
export type CompactEncodable = AbstractInt | Moment; // FIXME is there a way to do it not-manually from the array?
|
||||
export const COMPACT_ENCODABLE = [UInt, Moment];
|
||||
export type CompactEncodable = UInt | Moment; // FIXME is there a way to do it not-manually from the array?
|
||||
|
||||
/**
|
||||
* @name Compact
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Struct, Option, Tuple, Vector } from '.';
|
||||
import { Struct, Option, Tuple, Vec } from '.';
|
||||
import { Constructor, Codec } from '../types';
|
||||
|
||||
type TypeWithValues = [Constructor, any[]];
|
||||
@@ -35,8 +35,8 @@ export default class Linkage<T extends Codec> extends Struct {
|
||||
export class LinkageResult extends Tuple {
|
||||
public constructor ([TypeKey, keys]: TypeWithValues, [TypeValue, values]: TypeWithValues) {
|
||||
super({
|
||||
Keys: Vector.with(TypeKey),
|
||||
Values: Vector.with(TypeValue)
|
||||
Keys: Vec.with(TypeKey),
|
||||
Values: Vec.with(TypeValue)
|
||||
}, [keys, values]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { injectDefinitions } from '../srml';
|
||||
import Option from './Option';
|
||||
import Bytes from '../primitive/Bytes';
|
||||
import U32 from '../primitive/U32';
|
||||
@@ -23,6 +24,10 @@ const testEncode = (to: string, expected: any): void =>
|
||||
});
|
||||
|
||||
describe('Option', (): void => {
|
||||
beforeEach((): void => {
|
||||
injectDefinitions();
|
||||
});
|
||||
|
||||
it('converts undefined/null to empty', (): void => {
|
||||
expect(new Option(Text, undefined).isNone).toBe(true);
|
||||
expect(new Option(Text, null).isNone).toBe(true);
|
||||
|
||||
@@ -9,7 +9,7 @@ import U32 from '../primitive/U32';
|
||||
import { injectDefinitions } from '../srml';
|
||||
import { CodecTo } from '../types';
|
||||
import Struct from './Struct';
|
||||
import Vector from './Vector';
|
||||
import Vec from './Vec';
|
||||
|
||||
describe('Struct', (): void => {
|
||||
beforeEach((): void => {
|
||||
@@ -66,7 +66,7 @@ describe('Struct', (): void => {
|
||||
|
||||
it('decodes a more complicated type', (): void => {
|
||||
const s = new Struct({
|
||||
foo: Vector.with(Struct.with({
|
||||
foo: Vec.with(Struct.with({
|
||||
bar: Text
|
||||
}))
|
||||
}, { foo: [{ bar: 1 }, { bar: 2 }] });
|
||||
@@ -198,7 +198,7 @@ describe('Struct', (): void => {
|
||||
compactNumber: ClassOf('Compact<BlockNumber>'),
|
||||
optionNumber: ClassOf('Option<BlockNumber>'),
|
||||
counter: U32,
|
||||
vector: Vector.with(AccountId)
|
||||
vector: Vec.with(AccountId)
|
||||
}).toRawType()
|
||||
).toEqual(JSON.stringify({
|
||||
accountId: 'AccountId',
|
||||
|
||||
@@ -11,14 +11,14 @@ import AccountId from '../primitive/AccountId';
|
||||
import Method from '../primitive/Method';
|
||||
import Text from '../primitive/Text';
|
||||
import createType from './createType';
|
||||
import Vector from './Vector';
|
||||
import Vec from './Vec';
|
||||
import Tuple from './Tuple';
|
||||
|
||||
describe('Vector', (): void => {
|
||||
let vector: Vector<Codec>;
|
||||
describe('Vec', (): void => {
|
||||
let vector: Vec<Codec>;
|
||||
|
||||
beforeEach((): void => {
|
||||
vector = new Vector(Text, ['1', '23', '345', '4567', new Text('56789')]);
|
||||
vector = new Vec(Text, ['1', '23', '345', '4567', new Text('56789')]);
|
||||
|
||||
Method.injectMethods(extrinsics);
|
||||
});
|
||||
@@ -44,7 +44,7 @@ describe('Vector', (): void => {
|
||||
|
||||
it('allows contruction via JSON', (): void => {
|
||||
expect(
|
||||
new Vector(Text, ['6', '7']).toJSON()
|
||||
new Vec(Text, ['6', '7']).toJSON()
|
||||
).toEqual(['6', '7']);
|
||||
});
|
||||
|
||||
@@ -56,7 +56,7 @@ describe('Vector', (): void => {
|
||||
const test = createType('Vec<(PropIndex, Proposal, AccountId)>', new Uint8Array([
|
||||
4, 10, 0, 0, 0, 0, 3, 80, 123, 10, 9, 34, 48, 120, 52, 50, 34, 58, 32, 34, 48, 120, 52, 51, 34, 10, 125, 10, 209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79
|
||||
]));
|
||||
const first = (test as Vector<Codec>)[0] as Tuple;
|
||||
const first = (test as Vec<Codec>)[0] as Tuple;
|
||||
|
||||
expect((first[0] as PropIndex).toNumber()).toEqual(10);
|
||||
expect((first[1] as Proposal).callIndex).toEqual(new Uint8Array([0, 3]));
|
||||
@@ -118,7 +118,7 @@ describe('Vector', (): void => {
|
||||
});
|
||||
|
||||
describe('utils', (): void => {
|
||||
const vec = new Vector(Text, ['123', '456']);
|
||||
const vec = new Vec(Text, ['123', '456']);
|
||||
|
||||
it('compares against codec types', (): void => {
|
||||
expect(vec.eq([new Text('123'), new Text('456')])).toBe(true);
|
||||
@@ -130,7 +130,7 @@ describe('Vector', (): void => {
|
||||
|
||||
it('finds the index of an value', (): void => {
|
||||
const myId = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
const vec = new Vector(AccountId, [
|
||||
const vec = new Vec(AccountId, [
|
||||
'5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw', '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty', '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
|
||||
]);
|
||||
|
||||
@@ -12,24 +12,24 @@ import AbstractArray from './AbstractArray';
|
||||
const MAX_LENGTH = 32768;
|
||||
|
||||
/**
|
||||
* @name Vector
|
||||
* @name Vec
|
||||
* @description
|
||||
* This manages codec arrays. Internally it keeps track of the length (as decoded) and allows
|
||||
* construction with the passed `Type` in the constructor. It is an extension to Array, providing
|
||||
* specific encoding/decoding on top of the base type.
|
||||
*/
|
||||
export default class Vector<T extends Codec> extends AbstractArray<T> {
|
||||
export default class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
private _Type: Constructor<T>;
|
||||
|
||||
public constructor (Type: Constructor<T>, value: Vector<any> | Uint8Array | string | any[] = [] as any[]) {
|
||||
public constructor (Type: Constructor<T>, value: Vec<any> | Uint8Array | string | any[] = [] as any[]) {
|
||||
super(
|
||||
...Vector.decodeVector(Type, value)
|
||||
...Vec.decodeVec(Type, value)
|
||||
);
|
||||
|
||||
this._Type = Type;
|
||||
}
|
||||
|
||||
public static decodeVector<T extends Codec> (Type: Constructor<T>, value: Vector<any> | Uint8Array | string | any[]): T[] {
|
||||
public static decodeVec<T extends Codec> (Type: Constructor<T>, value: Vec<any> | Uint8Array | string | any[]): T[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((entry, index): T => {
|
||||
try {
|
||||
@@ -37,7 +37,7 @@ export default class Vector<T extends Codec> extends AbstractArray<T> {
|
||||
? entry
|
||||
: new Type(entry);
|
||||
} catch (error) {
|
||||
console.error(`Unable to decode Vector on index ${index}`, error.message);
|
||||
console.error(`Unable to decode Vec on index ${index}`, error.message);
|
||||
|
||||
throw error;
|
||||
}
|
||||
@@ -47,19 +47,19 @@ export default class Vector<T extends Codec> extends AbstractArray<T> {
|
||||
const u8a = u8aToU8a(value);
|
||||
const [offset, length] = Compact.decodeU8a(u8a);
|
||||
|
||||
assert(length.lten(MAX_LENGTH), `Vector length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
assert(length.lten(MAX_LENGTH), `Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
|
||||
return decodeU8a(u8a.subarray(offset), new Array(length.toNumber()).fill(Type)) as T[];
|
||||
}
|
||||
|
||||
public static with<O extends Codec> (Type: Constructor<O>): Constructor<Vector<O>> {
|
||||
return class extends Vector<O> {
|
||||
public static with<O extends Codec> (Type: Constructor<O>): Constructor<Vec<O>> {
|
||||
return class extends Vec<O> {
|
||||
public constructor (value?: any[]) {
|
||||
super(Type, value);
|
||||
}
|
||||
|
||||
public static Fallback = Type.Fallback
|
||||
? Vector.with(Type.Fallback)
|
||||
? Vec.with(Type.Fallback)
|
||||
: undefined;
|
||||
};
|
||||
}
|
||||
@@ -6,13 +6,13 @@ import { Codec } from '../types';
|
||||
import AbstractArray from './AbstractArray';
|
||||
|
||||
/**
|
||||
* @name VectorAny
|
||||
* @name VecAny
|
||||
* @description
|
||||
* This manages codec arrays, assuming that the inputs are already of type Codec. Unlike
|
||||
* a vector, this can be used to manage array-like structures with variable arguments of
|
||||
* any types
|
||||
*/
|
||||
export default class VectorAny<T extends Codec> extends AbstractArray<T> {
|
||||
export default class VecAny<T extends Codec> extends AbstractArray<T> {
|
||||
/**
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
@@ -7,26 +7,26 @@ import { Codec, Constructor } from '../types';
|
||||
import { assert, isU8a, u8aConcat, compactToU8a } from '@polkadot/util';
|
||||
|
||||
import AbstractArray from './AbstractArray';
|
||||
import Vector from './Vector';
|
||||
import Vec from './Vec';
|
||||
|
||||
/**
|
||||
* @name VectorFixed
|
||||
* @name VecFixed
|
||||
* @description
|
||||
* This manages codec arrays of a fixed length
|
||||
*/
|
||||
export default class VectorFixed<T extends Codec> extends AbstractArray<T> {
|
||||
export default class VecFixed<T extends Codec> extends AbstractArray<T> {
|
||||
private _Type: Constructor<T>;
|
||||
|
||||
public constructor (Type: Constructor<T>, length: number, value: VectorFixed<any> | Uint8Array | string | any[] = [] as any[]) {
|
||||
public constructor (Type: Constructor<T>, length: number, value: VecFixed<any> | Uint8Array | string | any[] = [] as any[]) {
|
||||
super(
|
||||
...VectorFixed.decodeVectorFixed(Type, length, value)
|
||||
...VecFixed.decodeVecFixed(Type, length, value)
|
||||
);
|
||||
|
||||
this._Type = Type;
|
||||
}
|
||||
|
||||
public static decodeVectorFixed<T extends Codec> (Type: Constructor<T>, allocLength: number, value: VectorFixed<any> | Uint8Array | string | any[]): T[] {
|
||||
const values = Vector.decodeVector(
|
||||
public static decodeVecFixed<T extends Codec> (Type: Constructor<T>, allocLength: number, value: VecFixed<any> | Uint8Array | string | any[]): T[] {
|
||||
const values = Vec.decodeVec(
|
||||
Type,
|
||||
isU8a(value)
|
||||
? u8aConcat(compactToU8a(allocLength), value)
|
||||
@@ -42,14 +42,14 @@ export default class VectorFixed<T extends Codec> extends AbstractArray<T> {
|
||||
return values;
|
||||
}
|
||||
|
||||
public static with<O extends Codec> (Type: Constructor<O>, length: number): Constructor<VectorFixed<O>> {
|
||||
return class extends VectorFixed<O> {
|
||||
public static with<O extends Codec> (Type: Constructor<O>, length: number): Constructor<VecFixed<O>> {
|
||||
return class extends VecFixed<O> {
|
||||
public constructor (value?: any[]) {
|
||||
super(Type, length, value);
|
||||
}
|
||||
|
||||
public static Fallback = Type.Fallback
|
||||
? VectorFixed.with(Type.Fallback, length)
|
||||
? VecFixed.with(Type.Fallback, length)
|
||||
: undefined;
|
||||
};
|
||||
}
|
||||
@@ -86,7 +86,7 @@ describe('getTypeValue', (): void => {
|
||||
}
|
||||
},
|
||||
{
|
||||
info: TypeDefInfo.Vector,
|
||||
info: TypeDefInfo.Vec,
|
||||
type: 'Vec<u64>',
|
||||
sub: {
|
||||
info: TypeDefInfo.Plain,
|
||||
@@ -118,7 +118,7 @@ describe('getTypeValue', (): void => {
|
||||
type: 'Text'
|
||||
},
|
||||
{
|
||||
info: TypeDefInfo.Vector,
|
||||
info: TypeDefInfo.Vec,
|
||||
type: 'Vec<(Bool, u128)>',
|
||||
sub: {
|
||||
info: TypeDefInfo.Tuple,
|
||||
@@ -145,7 +145,7 @@ describe('getTypeValue', (): void => {
|
||||
expect(
|
||||
getTypeDef('Vec<(PropIndex, Proposal, AccountId)>')
|
||||
).toEqual({
|
||||
info: TypeDefInfo.Vector,
|
||||
info: TypeDefInfo.Vec,
|
||||
type: 'Vec<(PropIndex, Proposal, AccountId)>',
|
||||
sub: {
|
||||
info: TypeDefInfo.Tuple,
|
||||
|
||||
@@ -8,7 +8,6 @@ import { assert } from '@polkadot/util';
|
||||
import { InterfaceRegistry } from '../interfaceRegistry';
|
||||
import { Codec, Constructor } from '../types';
|
||||
import Null from '../primitive/Null';
|
||||
import StorageData from '../primitive/StorageData';
|
||||
import Text from '../primitive/Text';
|
||||
import Compact from './Compact';
|
||||
import Enum from './Enum';
|
||||
@@ -19,8 +18,8 @@ import Struct from './Struct';
|
||||
import Tuple from './Tuple';
|
||||
import U8aFixed, { BitLength as U8aFixedBitLength } from './U8aFixed';
|
||||
import UInt from './UInt';
|
||||
import Vector from './Vector';
|
||||
import VectorFixed from './VectorFixed';
|
||||
import Vec from './Vec';
|
||||
import VecFixed from './VecFixed';
|
||||
import getRegistry from './typeRegistry';
|
||||
|
||||
export enum TypeDefInfo {
|
||||
@@ -33,8 +32,8 @@ export enum TypeDefInfo {
|
||||
Set,
|
||||
Struct,
|
||||
Tuple,
|
||||
Vector,
|
||||
VectorFixed,
|
||||
Vec,
|
||||
VecFixed,
|
||||
// anything not full supported (keep this as the last entry)
|
||||
Null
|
||||
}
|
||||
@@ -114,11 +113,10 @@ function _decodeEnum (value: TypeDef, details: string[] | Record<string, string>
|
||||
name,
|
||||
type: 'Null'
|
||||
}))
|
||||
: Object.entries(details).map(([name, type]): TypeDef => ({
|
||||
info: TypeDefInfo.Plain,
|
||||
name,
|
||||
type: type || 'Null'
|
||||
}));
|
||||
: Object.entries(details).map(([name, type]): TypeDef =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
getTypeDef(type || 'Null', name)
|
||||
);
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -169,7 +167,7 @@ export function getTypeDef (_type: Text | string, name?: string): TypeDef {
|
||||
// as a first round, only u8 via u8aFixed, we can add more support
|
||||
assert(vecLen <= 256, `${type}: Only support for [Type; <length>], where length <= 256`);
|
||||
|
||||
value.info = TypeDefInfo.VectorFixed;
|
||||
value.info = TypeDefInfo.VecFixed;
|
||||
value.ext = { length: vecLen, type: vecType } as unknown as TypeDefExtVecFixed;
|
||||
} else if (startingWith(type, '{', '}')) {
|
||||
const parsed = JSON.parse(type);
|
||||
@@ -190,7 +188,7 @@ export function getTypeDef (_type: Text | string, name?: string): TypeDef {
|
||||
value.info = TypeDefInfo.Option;
|
||||
value.sub = getTypeDef(subType);
|
||||
} else if (startingWith(type, 'Vec<', '>')) {
|
||||
value.info = TypeDefInfo.Vector;
|
||||
value.info = TypeDefInfo.Vec;
|
||||
value.sub = getTypeDef(subType);
|
||||
} else if (startingWith(type, 'Linkage<', '>')) {
|
||||
value.info = TypeDefInfo.Linkage;
|
||||
@@ -284,13 +282,13 @@ export function getTypeClass<T extends Codec = Codec> (value: TypeDef, Fallback?
|
||||
(value.sub as TypeDef[]).map((Type): Constructor<Codec> => getTypeClass(Type))
|
||||
) as unknown as Constructor<T>;
|
||||
|
||||
case TypeDefInfo.Vector:
|
||||
assert(value.sub && !Array.isArray(value.sub), 'Expected subtype for Vector');
|
||||
return Vector.with(
|
||||
case TypeDefInfo.Vec:
|
||||
assert(value.sub && !Array.isArray(value.sub), 'Expected subtype for Vec');
|
||||
return Vec.with(
|
||||
getTypeClass<Codec>(value.sub as TypeDef)
|
||||
) as unknown as Constructor<T>;
|
||||
|
||||
case TypeDefInfo.VectorFixed:
|
||||
case TypeDefInfo.VecFixed:
|
||||
assert(value.ext, 'Expected length & type information for fixed vector');
|
||||
|
||||
const ext = value.ext as TypeDefExtVecFixed;
|
||||
@@ -298,7 +296,7 @@ export function getTypeClass<T extends Codec = Codec> (value: TypeDef, Fallback?
|
||||
return (
|
||||
ext.type === 'u8'
|
||||
? U8aFixed.with((ext.length * 8) as U8aFixedBitLength)
|
||||
: VectorFixed.with(createClass<Codec>(ext.type), ext.length)
|
||||
: VecFixed.with(createClass<Codec>(ext.type), ext.length)
|
||||
) as unknown as Constructor<T>;
|
||||
|
||||
case TypeDefInfo.Linkage:
|
||||
@@ -340,7 +338,7 @@ function initType<T extends Codec = Codec, K extends Text | string = Text | stri
|
||||
assert(
|
||||
inHex === crHex || // check that the hex matches, if matching, all-ok
|
||||
(
|
||||
(value instanceof StorageData) && // input is from storage
|
||||
(value instanceof ClassOf('StorageData')) && // input is from storage
|
||||
(created instanceof Uint8Array) && // we are a variable-lneght structure
|
||||
(value.toU8a(true).toString() === created.toU8a().toString()) // strip the input length
|
||||
),
|
||||
|
||||
@@ -16,8 +16,7 @@ export { default as Set } from './Set';
|
||||
export { default as Struct } from './Struct';
|
||||
export { default as StructAny } from './StructAny';
|
||||
export { default as Tuple } from './Tuple';
|
||||
export { default as Vector } from './Vector';
|
||||
export { default as VectorAny } from './VectorAny';
|
||||
export { default as Vec, default as Vector } from './Vec';
|
||||
|
||||
// Convenience base classes, used as "anything of this type" bases
|
||||
export { default as U8a } from './U8a';
|
||||
|
||||
@@ -10,4 +10,3 @@
|
||||
*/
|
||||
export { default as Metadata } from './Metadata';
|
||||
export * from './primitive';
|
||||
export * from './rpc';
|
||||
|
||||
@@ -1,215 +1,190 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
// Auto-generated via `yarn build:srmlTs`, do not edit
|
||||
|
||||
import { Compact, Option, Vector } from './codec';
|
||||
import { AccountId, AccountIndex, Address, Bool, Bytes, Data, Event, EventIndex, EventRecord, EventRecord0to76, Extrinsic, ExtrinsicEra, Fixed64, H160, H256, H512, I128, I16, I256, I32, I64, I8, ImmortalEra, KeyValue, Method, Moment, MomentOf, MortalEra, Null, Origin, Phantom, SignaturePayload, StorageData, StorageHasher, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, USize, Vote, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
import { Compact, Option, Vec } from './codec';
|
||||
import { AccountId, AccountIndex, Address, Block, Bool, Bytes, ConsensusEngineId, Data, Digest, DigestItem, Event, Extrinsic, ExtrinsicEra, Fixed64, H160, H256, H512, Header, I128, I16, I256, I32, I64, I8, ImmortalEra, Method, Moment, MortalEra, Null, Origin, SignaturePayload, StorageHasher, StorageKey, Text, Type, U128, U16, U256, U32, U64, U8, Vote, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
|
||||
export interface InterfaceRegistry {
|
||||
AccountId: AccountId;
|
||||
'Option<AccountId>': Option<AccountId>;
|
||||
'Vec<AccountId>': Vector<AccountId>;
|
||||
'Vec<AccountId>': Vec<AccountId>;
|
||||
AccountIndex: AccountIndex;
|
||||
'Compact<AccountIndex>': Compact<AccountIndex>;
|
||||
'Option<AccountIndex>': Option<AccountIndex>;
|
||||
'Vec<AccountIndex>': Vector<AccountIndex>;
|
||||
'Vec<AccountIndex>': Vec<AccountIndex>;
|
||||
Address: Address;
|
||||
'Option<Address>': Option<Address>;
|
||||
'Vec<Address>': Vector<Address>;
|
||||
'Vec<Address>': Vec<Address>;
|
||||
Event: Event;
|
||||
'Option<Event>': Option<Event>;
|
||||
'Vec<Event>': Vector<Event>;
|
||||
EventIndex: EventIndex;
|
||||
'Compact<EventIndex>': Compact<EventIndex>;
|
||||
'Option<EventIndex>': Option<EventIndex>;
|
||||
'Vec<EventIndex>': Vector<EventIndex>;
|
||||
EventRecord: EventRecord;
|
||||
'Option<EventRecord>': Option<EventRecord>;
|
||||
'Vec<EventRecord>': Vector<EventRecord>;
|
||||
EventRecord0to76: EventRecord0to76;
|
||||
'Option<EventRecord0to76>': Option<EventRecord0to76>;
|
||||
'Vec<EventRecord0to76>': Vector<EventRecord0to76>;
|
||||
'Vec<Event>': Vec<Event>;
|
||||
Block: Block;
|
||||
'Option<Block>': Option<Block>;
|
||||
'Vec<Block>': Vec<Block>;
|
||||
Bool: Bool;
|
||||
'Option<Bool>': Option<Bool>;
|
||||
'Vec<Bool>': Vector<Bool>;
|
||||
'Vec<Bool>': Vec<Bool>;
|
||||
bool: bool;
|
||||
'Option<bool>': Option<bool>;
|
||||
'Vec<bool>': Vector<bool>;
|
||||
'Vec<bool>': Vec<bool>;
|
||||
Bytes: Bytes;
|
||||
'Option<Bytes>': Option<Bytes>;
|
||||
'Vec<Bytes>': Vector<Bytes>;
|
||||
'Vec<Bytes>': Vec<Bytes>;
|
||||
ConsensusEngineId: ConsensusEngineId;
|
||||
'Compact<ConsensusEngineId>': Compact<ConsensusEngineId>;
|
||||
'Option<ConsensusEngineId>': Option<ConsensusEngineId>;
|
||||
'Vec<ConsensusEngineId>': Vec<ConsensusEngineId>;
|
||||
Data: Data;
|
||||
'Option<Data>': Option<Data>;
|
||||
'Vec<Data>': Vector<Data>;
|
||||
'Vec<Data>': Vec<Data>;
|
||||
Digest: Digest;
|
||||
'Option<Digest>': Option<Digest>;
|
||||
'Vec<Digest>': Vec<Digest>;
|
||||
DigestItem: DigestItem;
|
||||
'Option<DigestItem>': Option<DigestItem>;
|
||||
'Vec<DigestItem>': Vec<DigestItem>;
|
||||
H160: H160;
|
||||
'Option<H160>': Option<H160>;
|
||||
'Vec<H160>': Vector<H160>;
|
||||
'Vec<H160>': Vec<H160>;
|
||||
H256: H256;
|
||||
'Option<H256>': Option<H256>;
|
||||
'Vec<H256>': Vector<H256>;
|
||||
'Vec<H256>': Vec<H256>;
|
||||
H512: H512;
|
||||
'Option<H512>': Option<H512>;
|
||||
'Vec<H512>': Vector<H512>;
|
||||
I8: I8;
|
||||
'Compact<I8>': Compact<I8>;
|
||||
'Option<I8>': Option<I8>;
|
||||
'Vec<I8>': Vector<I8>;
|
||||
'Vec<H512>': Vec<H512>;
|
||||
Header: Header;
|
||||
'Option<Header>': Option<Header>;
|
||||
'Vec<Header>': Vec<Header>;
|
||||
i8: i8;
|
||||
'Compact<i8>': Compact<i8>;
|
||||
'Option<i8>': Option<i8>;
|
||||
'Vec<i8>': Vector<i8>;
|
||||
I16: I16;
|
||||
'Compact<I16>': Compact<I16>;
|
||||
'Option<I16>': Option<I16>;
|
||||
'Vec<I16>': Vector<I16>;
|
||||
'Vec<i8>': Vec<i8>;
|
||||
I8: I8;
|
||||
'Option<I8>': Option<I8>;
|
||||
'Vec<I8>': Vec<I8>;
|
||||
i16: i16;
|
||||
'Compact<i16>': Compact<i16>;
|
||||
'Option<i16>': Option<i16>;
|
||||
'Vec<i16>': Vector<i16>;
|
||||
I32: I32;
|
||||
'Compact<I32>': Compact<I32>;
|
||||
'Option<I32>': Option<I32>;
|
||||
'Vec<I32>': Vector<I32>;
|
||||
'Vec<i16>': Vec<i16>;
|
||||
I16: I16;
|
||||
'Option<I16>': Option<I16>;
|
||||
'Vec<I16>': Vec<I16>;
|
||||
i32: i32;
|
||||
'Compact<i32>': Compact<i32>;
|
||||
'Option<i32>': Option<i32>;
|
||||
'Vec<i32>': Vector<i32>;
|
||||
I64: I64;
|
||||
'Compact<I64>': Compact<I64>;
|
||||
'Option<I64>': Option<I64>;
|
||||
'Vec<I64>': Vector<I64>;
|
||||
'Vec<i32>': Vec<i32>;
|
||||
I32: I32;
|
||||
'Option<I32>': Option<I32>;
|
||||
'Vec<I32>': Vec<I32>;
|
||||
i64: i64;
|
||||
'Compact<i64>': Compact<i64>;
|
||||
'Option<i64>': Option<i64>;
|
||||
'Vec<i64>': Vector<i64>;
|
||||
'Vec<i64>': Vec<i64>;
|
||||
I64: I64;
|
||||
'Option<I64>': Option<I64>;
|
||||
'Vec<I64>': Vec<I64>;
|
||||
Fixed64: Fixed64;
|
||||
'Compact<Fixed64>': Compact<Fixed64>;
|
||||
'Option<Fixed64>': Option<Fixed64>;
|
||||
'Vec<Fixed64>': Vector<Fixed64>;
|
||||
I128: I128;
|
||||
'Compact<I128>': Compact<I128>;
|
||||
'Option<I128>': Option<I128>;
|
||||
'Vec<I128>': Vector<I128>;
|
||||
'Vec<Fixed64>': Vec<Fixed64>;
|
||||
i128: i128;
|
||||
'Compact<i128>': Compact<i128>;
|
||||
'Option<i128>': Option<i128>;
|
||||
'Vec<i128>': Vector<i128>;
|
||||
I256: I256;
|
||||
'Compact<I256>': Compact<I256>;
|
||||
'Option<I256>': Option<I256>;
|
||||
'Vec<I256>': Vector<I256>;
|
||||
'Vec<i128>': Vec<i128>;
|
||||
I128: I128;
|
||||
'Option<I128>': Option<I128>;
|
||||
'Vec<I128>': Vec<I128>;
|
||||
i256: i256;
|
||||
'Compact<i256>': Compact<i256>;
|
||||
'Option<i256>': Option<i256>;
|
||||
'Vec<i256>': Vector<i256>;
|
||||
KeyValue: KeyValue;
|
||||
'Option<KeyValue>': Option<KeyValue>;
|
||||
'Vec<KeyValue>': Vector<KeyValue>;
|
||||
'Vec<i256>': Vec<i256>;
|
||||
I256: I256;
|
||||
'Option<I256>': Option<I256>;
|
||||
'Vec<I256>': Vec<I256>;
|
||||
Method: Method;
|
||||
'Option<Method>': Option<Method>;
|
||||
'Vec<Method>': Vector<Method>;
|
||||
'Vec<Method>': Vec<Method>;
|
||||
Moment: Moment;
|
||||
'Option<Moment>': Option<Moment>;
|
||||
'Vec<Moment>': Vector<Moment>;
|
||||
MomentOf: MomentOf;
|
||||
'Compact<MomentOf>': Compact<MomentOf>;
|
||||
'Option<MomentOf>': Option<MomentOf>;
|
||||
'Vec<MomentOf>': Vector<MomentOf>;
|
||||
'Vec<Moment>': Vec<Moment>;
|
||||
Null: Null;
|
||||
'Option<Null>': Option<Null>;
|
||||
'Vec<Null>': Vector<Null>;
|
||||
Phantom: Phantom;
|
||||
'Option<Phantom>': Option<Phantom>;
|
||||
'Vec<Phantom>': Vector<Phantom>;
|
||||
'Vec<Null>': Vec<Null>;
|
||||
Origin: Origin;
|
||||
'Option<Origin>': Option<Origin>;
|
||||
'Vec<Origin>': Vector<Origin>;
|
||||
StorageData: StorageData;
|
||||
'Option<StorageData>': Option<StorageData>;
|
||||
'Vec<StorageData>': Vector<StorageData>;
|
||||
'Vec<Origin>': Vec<Origin>;
|
||||
StorageHasher: StorageHasher;
|
||||
'Option<StorageHasher>': Option<StorageHasher>;
|
||||
'Vec<StorageHasher>': Vector<StorageHasher>;
|
||||
'Vec<StorageHasher>': Vec<StorageHasher>;
|
||||
StorageKey: StorageKey;
|
||||
'Option<StorageKey>': Option<StorageKey>;
|
||||
'Vec<StorageKey>': Vector<StorageKey>;
|
||||
'Vec<StorageKey>': Vec<StorageKey>;
|
||||
Text: Text;
|
||||
'Option<Text>': Option<Text>;
|
||||
'Vec<Text>': Vector<Text>;
|
||||
'Vec<Text>': Vec<Text>;
|
||||
Type: Type;
|
||||
'Option<Type>': Option<Type>;
|
||||
'Vec<Type>': Vector<Type>;
|
||||
U8: U8;
|
||||
'Compact<U8>': Compact<U8>;
|
||||
'Option<U8>': Option<U8>;
|
||||
'Vec<U8>': Vector<U8>;
|
||||
'Vec<Type>': Vec<Type>;
|
||||
u8: u8;
|
||||
'Compact<u8>': Compact<u8>;
|
||||
'Option<u8>': Option<u8>;
|
||||
'Vec<u8>': Vector<u8>;
|
||||
U16: U16;
|
||||
'Compact<U16>': Compact<U16>;
|
||||
'Option<U16>': Option<U16>;
|
||||
'Vec<U16>': Vector<U16>;
|
||||
'Vec<u8>': Vec<u8>;
|
||||
U8: U8;
|
||||
'Compact<U8>': Compact<U8>;
|
||||
'Option<U8>': Option<U8>;
|
||||
'Vec<U8>': Vec<U8>;
|
||||
u16: u16;
|
||||
'Compact<u16>': Compact<u16>;
|
||||
'Option<u16>': Option<u16>;
|
||||
'Vec<u16>': Vector<u16>;
|
||||
U32: U32;
|
||||
'Compact<U32>': Compact<U32>;
|
||||
'Option<U32>': Option<U32>;
|
||||
'Vec<U32>': Vector<U32>;
|
||||
'Vec<u16>': Vec<u16>;
|
||||
U16: U16;
|
||||
'Compact<U16>': Compact<U16>;
|
||||
'Option<U16>': Option<U16>;
|
||||
'Vec<U16>': Vec<U16>;
|
||||
u32: u32;
|
||||
'Compact<u32>': Compact<u32>;
|
||||
'Option<u32>': Option<u32>;
|
||||
'Vec<u32>': Vector<u32>;
|
||||
U64: U64;
|
||||
'Compact<U64>': Compact<U64>;
|
||||
'Option<U64>': Option<U64>;
|
||||
'Vec<U64>': Vector<U64>;
|
||||
'Vec<u32>': Vec<u32>;
|
||||
U32: U32;
|
||||
'Compact<U32>': Compact<U32>;
|
||||
'Option<U32>': Option<U32>;
|
||||
'Vec<U32>': Vec<U32>;
|
||||
u64: u64;
|
||||
'Compact<u64>': Compact<u64>;
|
||||
'Option<u64>': Option<u64>;
|
||||
'Vec<u64>': Vector<u64>;
|
||||
U128: U128;
|
||||
'Compact<U128>': Compact<U128>;
|
||||
'Option<U128>': Option<U128>;
|
||||
'Vec<U128>': Vector<U128>;
|
||||
'Vec<u64>': Vec<u64>;
|
||||
U64: U64;
|
||||
'Compact<U64>': Compact<U64>;
|
||||
'Option<U64>': Option<U64>;
|
||||
'Vec<U64>': Vec<U64>;
|
||||
u128: u128;
|
||||
'Compact<u128>': Compact<u128>;
|
||||
'Option<u128>': Option<u128>;
|
||||
'Vec<u128>': Vector<u128>;
|
||||
U256: U256;
|
||||
'Compact<U256>': Compact<U256>;
|
||||
'Option<U256>': Option<U256>;
|
||||
'Vec<U256>': Vector<U256>;
|
||||
'Vec<u128>': Vec<u128>;
|
||||
U128: U128;
|
||||
'Compact<U128>': Compact<U128>;
|
||||
'Option<U128>': Option<U128>;
|
||||
'Vec<U128>': Vec<U128>;
|
||||
u256: u256;
|
||||
'Compact<u256>': Compact<u256>;
|
||||
'Option<u256>': Option<u256>;
|
||||
'Vec<u256>': Vector<u256>;
|
||||
USize: USize;
|
||||
'Compact<USize>': Compact<USize>;
|
||||
'Option<USize>': Option<USize>;
|
||||
'Vec<USize>': Vector<USize>;
|
||||
'Vec<u256>': Vec<u256>;
|
||||
U256: U256;
|
||||
'Compact<U256>': Compact<U256>;
|
||||
'Option<U256>': Option<U256>;
|
||||
'Vec<U256>': Vec<U256>;
|
||||
usize: usize;
|
||||
'Compact<usize>': Compact<usize>;
|
||||
'Option<usize>': Option<usize>;
|
||||
'Vec<usize>': Vector<usize>;
|
||||
'Vec<usize>': Vec<usize>;
|
||||
Vote: Vote;
|
||||
'Option<Vote>': Option<Vote>;
|
||||
'Vec<Vote>': Vector<Vote>;
|
||||
'Vec<Vote>': Vec<Vote>;
|
||||
Extrinsic: Extrinsic;
|
||||
'Option<Extrinsic>': Option<Extrinsic>;
|
||||
'Vec<Extrinsic>': Vector<Extrinsic>;
|
||||
'Vec<Extrinsic>': Vec<Extrinsic>;
|
||||
ExtrinsicEra: ExtrinsicEra;
|
||||
'Option<ExtrinsicEra>': Option<ExtrinsicEra>;
|
||||
'Vec<ExtrinsicEra>': Vector<ExtrinsicEra>;
|
||||
'Vec<ExtrinsicEra>': Vec<ExtrinsicEra>;
|
||||
MortalEra: MortalEra;
|
||||
'Option<MortalEra>': Option<MortalEra>;
|
||||
'Vec<MortalEra>': Vector<MortalEra>;
|
||||
'Vec<MortalEra>': Vec<MortalEra>;
|
||||
ImmortalEra: ImmortalEra;
|
||||
'Option<ImmortalEra>': Option<ImmortalEra>;
|
||||
'Vec<ImmortalEra>': Vector<ImmortalEra>;
|
||||
'Vec<ImmortalEra>': Vec<ImmortalEra>;
|
||||
SignaturePayload: SignaturePayload;
|
||||
'Option<SignaturePayload>': Option<SignaturePayload>;
|
||||
'Vec<SignaturePayload>': Vector<SignaturePayload>;
|
||||
'Vec<SignaturePayload>': Vec<SignaturePayload>;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
|
||||
import { setAddressPrefix } from '@polkadot/util-crypto';
|
||||
|
||||
import createType from '../codec/createType';
|
||||
import U8a from '../codec/U8a';
|
||||
import Vector from '../codec/Vector';
|
||||
import Vec from '../codec/Vec';
|
||||
import jsonVec from '../json/AccountIdVec.001.json';
|
||||
import { injectDefinitions } from '../srml';
|
||||
import AccountId from './AccountId';
|
||||
import StorageData from './StorageData';
|
||||
|
||||
describe('AccountId', (): void => {
|
||||
beforeEach((): void => {
|
||||
injectDefinitions();
|
||||
});
|
||||
|
||||
describe('defaults', (): void => {
|
||||
const id = new AccountId();
|
||||
|
||||
@@ -85,8 +90,8 @@ describe('AccountId', (): void => {
|
||||
it('has the correct entries', (): void => {
|
||||
setAddressPrefix(68);
|
||||
|
||||
const data = new StorageData(jsonVec.params.result.changes[0][1]);
|
||||
const list = new Vector(AccountId, data).map((accountId): string => accountId.toString());
|
||||
const data = createType('StorageData', jsonVec.params.result.changes[0][1]);
|
||||
const list = new Vec(AccountId, data).map((accountId): string => accountId.toString());
|
||||
|
||||
expect(list).toEqual([
|
||||
'7qVJujLF3EDbZt5WfQXWvueFedMS4Vfk2Hb4GyR8jwksTLup',
|
||||
|
||||
@@ -5,11 +5,13 @@
|
||||
import extrinsics from '@polkadot/api-metadata/extrinsics/static';
|
||||
|
||||
import block00300 from '../json/SignedBlock.003.00.json';
|
||||
import Method from '../primitive/Method';
|
||||
import { injectDefinitions } from '../srml';
|
||||
import Method from './Method';
|
||||
import Block from './Block';
|
||||
|
||||
describe('Block', (): void => {
|
||||
beforeEach((): void => {
|
||||
injectDefinitions();
|
||||
Method.injectMethods(extrinsics);
|
||||
});
|
||||
|
||||
@@ -8,9 +8,9 @@ import { AnyU8a } from '../types';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import createType, { ClassOf } from '../codec/createType';
|
||||
import Extrinsic from '../primitive/Extrinsic/Extrinsic';
|
||||
import Extrinsic from './Extrinsic/Extrinsic';
|
||||
import Struct from '../codec/Struct';
|
||||
import Vector from '../codec/Vector';
|
||||
import Vec from '../codec/Vec';
|
||||
import Header, { HeaderValue } from './Header';
|
||||
|
||||
export interface BlockValue {
|
||||
@@ -27,7 +27,7 @@ export default class Block extends Struct {
|
||||
public constructor (value?: BlockValue | Uint8Array) {
|
||||
super({
|
||||
header: Header,
|
||||
extrinsics: ClassOf<Vector<Extrinsic>>('Vec<Extrinsic>')
|
||||
extrinsics: ClassOf('Vec<Extrinsic>')
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ export default class Block extends Struct {
|
||||
/**
|
||||
* @description The [[Extrinsic]] contained in the block
|
||||
*/
|
||||
public get extrinsics (): Vector<Extrinsic> {
|
||||
return this.get('extrinsics') as Vector<Extrinsic>;
|
||||
public get extrinsics (): Vec<Extrinsic> {
|
||||
return this.get('extrinsics') as Vec<Extrinsic>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2,10 +2,15 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import createType from '../codec/createType';
|
||||
import { injectDefinitions } from '../srml';
|
||||
import Bytes from './Bytes';
|
||||
import StorageData from './StorageData';
|
||||
|
||||
describe('Bytes', (): void => {
|
||||
beforeEach((): void => {
|
||||
injectDefinitions();
|
||||
});
|
||||
|
||||
const CODE = new Uint8Array([0x14, 0x3a, 0x63, 0x6f, 0x64, 0x65]);
|
||||
|
||||
describe('construction', (): void => {
|
||||
@@ -30,7 +35,7 @@ describe('Bytes', (): void => {
|
||||
it('creates via storagedata (no prefix)', (): void => {
|
||||
expect(
|
||||
new Bytes(
|
||||
new StorageData('0x3a636f6465')
|
||||
createType('StorageData', '0x3a636f6465')
|
||||
).toU8a()
|
||||
).toEqual(CODE);
|
||||
});
|
||||
@@ -38,7 +43,7 @@ describe('Bytes', (): void => {
|
||||
it('creates via storagedata (with length prefix)', (): void => {
|
||||
expect(
|
||||
new Bytes(
|
||||
new StorageData('0x143a636f6465')
|
||||
createType('StorageData', '0x143a636f6465')
|
||||
).toU8a()
|
||||
).toEqual(CODE);
|
||||
});
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyU8a } from '../types';
|
||||
|
||||
import { assert, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { AnyU8a } from '../types';
|
||||
import { ClassOf } from '../codec/createType';
|
||||
import Compact from '../codec/Compact';
|
||||
import U8a from '../codec/U8a';
|
||||
|
||||
@@ -13,7 +15,7 @@ import U8a from '../codec/U8a';
|
||||
* @description
|
||||
* A Bytes wrapper for Vec<u8>. The significant difference between this and a normal Uint8Array
|
||||
* is that this version allows for length-encoding. (i.e. it is a variable-item codec, the same
|
||||
* as what is found in [[Text]] and [[Vector]])
|
||||
* as what is found in [[Text]] and [[Vec]])
|
||||
*/
|
||||
export default class Bytes extends U8a {
|
||||
public constructor (value?: AnyU8a) {
|
||||
@@ -21,18 +23,13 @@ export default class Bytes extends U8a {
|
||||
}
|
||||
|
||||
private static decodeBytes (value?: AnyU8a): Uint8Array | undefined {
|
||||
// FIXME Cyclic dependency, however needed for the StoreageData check below. In a perfect
|
||||
// world, we should probably be checking Bytes - however as a first step, check against
|
||||
// StorageData to cater for the _specific_ problematic case
|
||||
const StorageData = require('./StorageData').default;
|
||||
|
||||
if (Array.isArray(value) || isString(value)) {
|
||||
const u8a = u8aToU8a(value);
|
||||
|
||||
return Bytes.decodeBytes(
|
||||
Compact.addLengthPrefix(u8a)
|
||||
);
|
||||
} else if (value instanceof StorageData) {
|
||||
} else if (value instanceof ClassOf('StorageData')) {
|
||||
// Here we cater for the actual StorageData that _could_ have a length prefix. In the
|
||||
// case of `:code` it is not added, for others it is
|
||||
const u8a = value as Uint8Array;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { assert, bnToBn } from '@polkadot/util';
|
||||
|
||||
import Bytes from './Bytes';
|
||||
import U32 from './U32';
|
||||
import U64 from './U64';
|
||||
|
||||
const CID_AURA = 0x61727561; // 'aura'
|
||||
const CID_BABE = 0x65626162; // 'babe'
|
||||
const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1)
|
||||
|
||||
export { CID_AURA, CID_BABE, CID_GRPA };
|
||||
|
||||
/**
|
||||
* @name ConsensusEngineId
|
||||
* @description
|
||||
* A 4-byte identifier (actually a [u8; 4]) identifying the engine, e.g. for Aura it would be [b'a', b'u', b'r', b'a']
|
||||
*/
|
||||
export default class ConsensusEngineId extends U32 {
|
||||
public static idToString (input: number | BN): string {
|
||||
return bnToBn(input)
|
||||
.toArray('le')
|
||||
.map((code): string => String.fromCharCode(code))
|
||||
.join('');
|
||||
}
|
||||
|
||||
public static stringToId (input: string): number {
|
||||
return input
|
||||
.split('')
|
||||
.reverse()
|
||||
.reduce((result, char): number => (result * 256) + char.charCodeAt(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if the engine matches aura
|
||||
*/
|
||||
public get isAura (): boolean {
|
||||
return this.eq(CID_AURA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` is the engine matches babe
|
||||
*/
|
||||
public get isBabe (): boolean {
|
||||
return this.eq(CID_BABE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` is the engine matches grandpa
|
||||
*/
|
||||
public get isGrandpa (): boolean {
|
||||
return this.eq(CID_GRPA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From the input bytes, decode into an aura-tuple
|
||||
*/
|
||||
public extractSlot (bytes: Bytes): U64 {
|
||||
assert(this.isAura, 'Invalid engine for asAura conversion');
|
||||
|
||||
return new U64(
|
||||
// no compact prefix, only use the correct number of supplied bytes
|
||||
bytes.toU8a(true).subarray(0, 8)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Override the default toString to return a 4-byte string
|
||||
*/
|
||||
public toString (): string {
|
||||
return ConsensusEngineId.idToString(this as BN);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
import { injectDefinitions } from '../srml';
|
||||
import json3 from '../json/Header.003.json';
|
||||
import block1 from '../json/SignedBlock.003.00.json';
|
||||
import Digest, { ConsensusEngineId, CID_AURA, CID_BABE, CID_GRPA } from './Digest';
|
||||
import ConsensusEngineId, { CID_AURA, CID_BABE, CID_GRPA } from './ConsensusEngineId';
|
||||
import Digest from './Digest';
|
||||
|
||||
describe('Digest', (): void => {
|
||||
beforeEach((): void => {
|
||||
@@ -0,0 +1,194 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AuthorityId } from '../srml/consensus/types';
|
||||
import { Hash } from '../srml/runtime/types';
|
||||
import { Consensus, PreRuntime, Seal, SealV0 } from '../srml/rpc/types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { ClassOf } from '../codec/createType';
|
||||
import Enum from '../codec/Enum';
|
||||
import Struct from '../codec/Struct';
|
||||
import Vec from '../codec/Vec';
|
||||
import Bytes from './Bytes';
|
||||
|
||||
/**
|
||||
* @name DigestItem
|
||||
* @description
|
||||
* A [[Enum]] the specifies the specific item in the logs of a [[Digest]]
|
||||
*/
|
||||
export class DigestItem extends Enum {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
Other: ClassOf('Bytes'), // 0
|
||||
AuthoritiesChange: ClassOf('Vec<AuthorityId>'), // 1
|
||||
ChangesTrieRoot: ClassOf('Hash'), // 2
|
||||
SealV0: ClassOf('SealV0'), // 3
|
||||
Consensus: ClassOf('Consensus'), // 4
|
||||
Seal: ClassOf('Seal'), // 5
|
||||
PreRuntime: ClassOf('PreRuntime') // 6
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[Vec<AuthorityId>]]
|
||||
*/
|
||||
public get asAuthoritiesChange (): Vec<AuthorityId> {
|
||||
assert(this.isAuthoritiesChange, `Cannot convert '${this.type}' via asAuthoritiesChange`);
|
||||
|
||||
return this.value as Vec<AuthorityId>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[ChangesTrieRoot]]
|
||||
*/
|
||||
public get asChangesTrieRoot (): Hash {
|
||||
assert(this.isChangesTrieRoot, `Cannot convert '${this.type}' via asChangesTrieRoot`);
|
||||
|
||||
return this.value as Hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desciption Retuns the item as a [[Consensus]]
|
||||
*/
|
||||
public get asConsensus (): Consensus {
|
||||
assert(this.isConsensus, `Cannot convert '${this.type}' via asConsensus`);
|
||||
|
||||
return this.value as Consensus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[Bytes]]
|
||||
*/
|
||||
public get asOther (): Bytes {
|
||||
assert(this.isOther, `Cannot convert '${this.type}' via asOther`);
|
||||
|
||||
return this.value as Bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[PreRuntime]]
|
||||
*/
|
||||
public get asPreRuntime (): PreRuntime {
|
||||
assert(this.isPreRuntime, `Cannot convert '${this.type}' via asPreRuntime`);
|
||||
|
||||
return this.value as PreRuntime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[Seal]]
|
||||
*/
|
||||
public get asSeal (): Seal {
|
||||
assert(this.isSeal, `Cannot convert '${this.type}' via asSeal`);
|
||||
|
||||
return this.value as Seal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[SealV0]]
|
||||
*/
|
||||
public get asSealV0 (): SealV0 {
|
||||
assert(this.isSealV0, `Cannot convert '${this.type}' via asSealV0`);
|
||||
|
||||
return this.value as SealV0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[AuthoritiesChange]]
|
||||
*/
|
||||
public get isAuthoritiesChange (): boolean {
|
||||
return this.type === 'AuthoritiesChange';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[ChangesTrieRoot]]
|
||||
*/
|
||||
public get isChangesTrieRoot (): boolean {
|
||||
return this.type === 'ChangesTrieRoot';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[Consensus]]
|
||||
*/
|
||||
public get isConsensus (): boolean {
|
||||
return this.type === 'Consensus';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[Other]]
|
||||
*/
|
||||
public get isOther (): boolean {
|
||||
return this.type === 'Other';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[PreRuntime]]
|
||||
*/
|
||||
public get isPreRuntime (): boolean {
|
||||
return this.type === 'PreRuntime';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[Seal]]
|
||||
*/
|
||||
public get isSeal (): boolean {
|
||||
return this.type === 'Seal';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[SealV0]]
|
||||
*/
|
||||
public get isSealV0 (): boolean {
|
||||
return this.type === 'SealV0';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers. For logs, we overrides to produce the hex version (sligning with substrate gives in actual JSON responses)
|
||||
*/
|
||||
public toJSON (): string {
|
||||
return this.toHex();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the type of engine
|
||||
*/
|
||||
public get type (): string {
|
||||
return super.type;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Digest
|
||||
* @description
|
||||
* A [[Header]] Digest
|
||||
*/
|
||||
export default class Digest extends Struct {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
logs: Vec.with(DigestItem)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[DigestItem]] logs
|
||||
*/
|
||||
public get logs (): Vec<DigestItem> {
|
||||
return this.get('logs') as Vec<DigestItem>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned.
|
||||
*/
|
||||
public logsWith (...include: string[]): Vec<DigestItem> {
|
||||
return this.logs.filter(({ type }): boolean => include.includes(type)) as Vec<DigestItem>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution.
|
||||
*/
|
||||
public logsWithout (...exclude: string[]): Vec<DigestItem> {
|
||||
return this.logs.filter(({ type }): boolean => !exclude.includes(type)) as Vec<DigestItem>;
|
||||
}
|
||||
}
|
||||
@@ -2,30 +2,21 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { EventId } from '../srml/system/types';
|
||||
import { Constructor, Codec } from '../types';
|
||||
|
||||
import { assert, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { ClassOf, TypeDef, getTypeClass, getTypeDef } from '../codec/createType';
|
||||
import Struct from '../codec/Struct';
|
||||
import Tuple from '../codec/Tuple';
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
import { TypeDef, getTypeClass, getTypeDef } from '../codec/createType';
|
||||
import Metadata from '../Metadata';
|
||||
import { EventMetadata as EventMetadataV7 } from '../Metadata/v7/Events';
|
||||
import Null from './Null';
|
||||
import U32 from './U32';
|
||||
import Unconstructable from './Unconstructable';
|
||||
|
||||
const EventTypes: Record<string, Constructor<EventData>> = {};
|
||||
|
||||
/**
|
||||
* @name EventIndex
|
||||
* @description
|
||||
* The Substrate EventIndex representation as a [[U32]].
|
||||
*/
|
||||
export class EventIndex extends U32 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name EventData
|
||||
* @description
|
||||
@@ -78,18 +69,6 @@ export class EventData extends Tuple {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name EventId
|
||||
* @description
|
||||
* This follows the same approach as in [[Method]], we have the `[sectionIndex, methodIndex]` pairing
|
||||
* that indicates the actual event fired
|
||||
*/
|
||||
export class EventId extends U8aFixed {
|
||||
public constructor (value?: any) {
|
||||
super(value, 16);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Event
|
||||
* @description
|
||||
@@ -103,7 +82,7 @@ export default class Event extends Struct {
|
||||
const { DataType, value } = Event.decodeEvent(_value);
|
||||
|
||||
super({
|
||||
index: EventId,
|
||||
index: ClassOf('EventId'),
|
||||
data: DataType
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -3,114 +3,12 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Hash } from '../srml/runtime/types';
|
||||
import { Phase } from '../srml/system/types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import createType, { ClassOf } from '../codec/createType';
|
||||
import Enum from '../codec/Enum';
|
||||
import { ClassOf } from '../codec/createType';
|
||||
import Struct from '../codec/Struct';
|
||||
import Vector from '../codec/Vector';
|
||||
import Vec from '../codec/Vec';
|
||||
import Event from './Event';
|
||||
import Null from './Null';
|
||||
import U32 from './U32';
|
||||
|
||||
/**
|
||||
* @name ApplyExtrinsic
|
||||
* @description
|
||||
* The [[Phase]] where the extrinsic is applied
|
||||
*/
|
||||
export class ApplyExtrinsic extends U32 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Finalization
|
||||
* @description
|
||||
* The [[Phase]] where the extrinsic is being Finalized
|
||||
*/
|
||||
export class Finalization extends Null {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Phase
|
||||
* @description
|
||||
* An [[Enum]] that indicates the specific phase where the [[EventRecord]] was generated
|
||||
*/
|
||||
export class Phase extends Enum {
|
||||
public constructor (value: any, index?: number) {
|
||||
super({
|
||||
ApplyExtrinsic,
|
||||
Finalization
|
||||
}, value, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[ApplyExtrinsic]]
|
||||
*/
|
||||
public get asApplyExtrinsic (): ApplyExtrinsic {
|
||||
assert(this.isApplyExtrinsic, `Cannot convert '${this.type}' via asApplyExtrinsic`);
|
||||
|
||||
return this.value as ApplyExtrinsic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[Finalization]]
|
||||
*/
|
||||
public get asFinalization (): Finalization {
|
||||
assert(this.isFinalization, `Cannot convert '${this.type}' via asFinalization`);
|
||||
|
||||
return this.value as Finalization;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description true when this is a ApplyExtrinsic
|
||||
*/
|
||||
public get isApplyExtrinsic (): boolean {
|
||||
return this.type === 'ApplyExtrinsic';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description true when this is a ApplyExtrinsic
|
||||
*/
|
||||
public get isFinalization (): boolean {
|
||||
return this.type === 'Finalization';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name EventRecord_0_76
|
||||
* @description
|
||||
* A record for an [[Event]] (as specified by [[Metadata]]) with the specific [[Phase]] of
|
||||
* application.
|
||||
*/
|
||||
export class EventRecord0to76 extends Struct {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
phase: Phase,
|
||||
event: Event
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Event]] this record refers to
|
||||
*/
|
||||
public get event (): Event {
|
||||
return this.get('event') as Event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Phase]] where the event was generated
|
||||
*/
|
||||
public get phase (): Phase {
|
||||
return this.get('phase') as Phase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Hash]] topics for this event (empty, compat)
|
||||
*/
|
||||
public get topics (): Vector<Hash> {
|
||||
return createType('Vec<Hash>', []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name EventRecord
|
||||
@@ -121,13 +19,14 @@ export class EventRecord0to76 extends Struct {
|
||||
export default class EventRecord extends Struct {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
phase: Phase,
|
||||
phase: ClassOf('Phase'),
|
||||
event: Event,
|
||||
topics: ClassOf('Vec<Hash>')
|
||||
}, value);
|
||||
}
|
||||
|
||||
public static Fallback = EventRecord0to76;
|
||||
// TODO We want these injected by createType
|
||||
public static Fallback = ClassOf('EventRecord0to76');
|
||||
|
||||
/**
|
||||
* @description The [[Event]] this record refers to
|
||||
@@ -146,7 +45,7 @@ export default class EventRecord extends Struct {
|
||||
/**
|
||||
* @description The [[Hash]] topics for this event
|
||||
*/
|
||||
public get topics (): Vector<Hash> {
|
||||
return this.get('topics') as Vector<Hash>;
|
||||
public get topics (): Vec<Hash> {
|
||||
return this.get('topics') as Vec<Hash>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export default class Header extends Struct {
|
||||
number: ClassOf('Compact<BlockNumber>'),
|
||||
stateRoot: ClassOf('Hash'),
|
||||
extrinsicsRoot: ClassOf('Hash'),
|
||||
digest: Digest
|
||||
digest: ClassOf('Digest')
|
||||
}, value || {});
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import KeyValue, { KeyValueOption } from './KeyValue';
|
||||
|
||||
describe('KeyValue', (): void => {
|
||||
it('decodes KeyValue from u8a', (): void => {
|
||||
expect(
|
||||
new KeyValue(
|
||||
Uint8Array.from([
|
||||
4 << 2,
|
||||
0x11, 0x22, 0x33, 0x44,
|
||||
9 << 2,
|
||||
0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11
|
||||
])
|
||||
).toJSON()
|
||||
).toEqual(['0x11223344', '0x998877665544332211']);
|
||||
});
|
||||
|
||||
it('encodes KeyValue from JSON', (): void => {
|
||||
expect(
|
||||
new KeyValue(['0x11223344', '0x998877665544332211']).toU8a()
|
||||
).toEqual(
|
||||
new Uint8Array([
|
||||
4 << 2,
|
||||
0x11, 0x22, 0x33, 0x44,
|
||||
9 << 2,
|
||||
0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('exposes the properties for key/value', (): void => {
|
||||
const kv = new KeyValue(['0x11223344', '0x998877665544332211']);
|
||||
|
||||
expect(kv.key.toHex()).toEqual('0x11223344');
|
||||
expect(kv.value.toHex()).toEqual('0x998877665544332211');
|
||||
});
|
||||
});
|
||||
|
||||
describe('KeyValueOption', (): void => {
|
||||
it('exposes the properties for key/value', (): void => {
|
||||
const kv = new KeyValueOption([
|
||||
'0x11223344'
|
||||
]);
|
||||
|
||||
expect(kv.key.toHex()).toEqual('0x11223344');
|
||||
expect(kv.value.isNone).toEqual(true);
|
||||
});
|
||||
});
|
||||
@@ -1,75 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyU8a } from '../types';
|
||||
|
||||
import Option from '../codec/Option';
|
||||
import Tuple from '../codec/Tuple';
|
||||
import StorageData from './StorageData';
|
||||
import StorageKey from './StorageKey';
|
||||
|
||||
type KeyValueValue = [AnyU8a, AnyU8a];
|
||||
|
||||
/**
|
||||
* @name KeyValue
|
||||
* @description
|
||||
* KeyValue structure. Since most of the keys and resultant values in Subtrate are
|
||||
* hashed and/or encoded, this does not wrap [[Text]], but rather a [[Bytes]]
|
||||
* for the keys and values. (Not to be confused with the KeyValue in [[Metadata]], that
|
||||
* is actually for Maps, whereas this is a representation of actual storage values)
|
||||
*/
|
||||
export default class KeyValue extends Tuple {
|
||||
public constructor (value?: KeyValueValue | Uint8Array) {
|
||||
super({
|
||||
key: StorageKey,
|
||||
value: StorageData
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[StorageKey]]
|
||||
*/
|
||||
public get key (): StorageKey {
|
||||
return this[0] as StorageKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[StorageData]]
|
||||
*/
|
||||
public get value (): StorageData {
|
||||
return this[1] as StorageData;
|
||||
}
|
||||
}
|
||||
|
||||
export type KeyValueOptionValue = [AnyU8a, AnyU8a?];
|
||||
|
||||
/**
|
||||
* @name KeyValueOption
|
||||
* @description
|
||||
* A key/value change. This is similar to the [[KeyValue]] structure,
|
||||
* however in this case the value could be optional. Here it extends
|
||||
* from a [[Tuple]], indicating the use inside areas such as [[StorageChangeSet]]
|
||||
*/
|
||||
export class KeyValueOption extends Tuple {
|
||||
public constructor (value?: KeyValueOptionValue | Uint8Array) {
|
||||
super({
|
||||
StorageKey,
|
||||
'Option<StorageData>': Option.with(StorageData)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[StorageKey]]
|
||||
*/
|
||||
public get key (): StorageKey {
|
||||
return this[0] as StorageKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Option]] [[StorageData]]
|
||||
*/
|
||||
public get value (): Option<StorageData> {
|
||||
return this[1] as Option<StorageData>;
|
||||
}
|
||||
}
|
||||
@@ -131,11 +131,3 @@ export default class Moment extends Date implements Codec {
|
||||
return bnToU8a(this.toNumber(), BITLENGTH, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name MomentOf
|
||||
* @description
|
||||
* The Substrate MomentOf representation as a [[Moment]].
|
||||
*/
|
||||
export class MomentOf extends Moment {
|
||||
}
|
||||
|
||||
@@ -69,14 +69,3 @@ export default class Null implements Codec {
|
||||
return new Uint8Array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Phantom
|
||||
* @description
|
||||
* Implements a type that does not contain anything (apart from `null`)
|
||||
*/
|
||||
export class Phantom extends Null {
|
||||
public toRawType (): string {
|
||||
return 'Phantom';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Bytes from './Bytes';
|
||||
|
||||
/**
|
||||
* @name StorageData
|
||||
* @description
|
||||
* Data retrieved via Storage queries and data for key-value pairs
|
||||
*/
|
||||
export default class StorageData extends Bytes {
|
||||
}
|
||||
@@ -13,37 +13,38 @@
|
||||
export { default as AccountId } from './AccountId';
|
||||
export { default as AccountIndex } from './AccountIndex';
|
||||
export { default as Address } from './Address';
|
||||
export { default as Event, EventIndex } from './Event';
|
||||
export { default as EventRecord, EventRecord0to76 } from './EventRecord';
|
||||
export { default as Event } from './Event';
|
||||
export { default as Block } from './Block';
|
||||
export { default as Bool, default as bool } from './Bool';
|
||||
export { default as Bytes } from './Bytes';
|
||||
export { default as ConsensusEngineId } from './ConsensusEngineId';
|
||||
export { default as Data } from './Data';
|
||||
export { default as Digest, DigestItem } from './Digest';
|
||||
export * from './Extrinsic';
|
||||
export { default as H160 } from './H160';
|
||||
export { default as H256 } from './H256';
|
||||
export { default as H512 } from './H512';
|
||||
export { default as I8, default as i8 } from './I8';
|
||||
export { default as I16, default as i16 } from './I16';
|
||||
export { default as I32, default as i32 } from './I32';
|
||||
export { default as I64, default as i64 } from './I64';
|
||||
export { default as Header } from './Header';
|
||||
export { default as i8, default as I8 } from './I8';
|
||||
export { default as i16, default as I16 } from './I16';
|
||||
export { default as i32, default as I32 } from './I32';
|
||||
export { default as i64, default as I64 } from './I64';
|
||||
export { default as Fixed64 } from './I64Fixed';
|
||||
export { default as I128, default as i128 } from './I128';
|
||||
export { default as I256, default as i256 } from './I256';
|
||||
export { default as KeyValue } from './KeyValue';
|
||||
export { default as i128, default as I128 } from './I128';
|
||||
export { default as i256, default as I256 } from './I256';
|
||||
export { default as Method } from './Method';
|
||||
export { default as Moment, MomentOf } from './Moment';
|
||||
export { default as Null, Phantom } from './Null';
|
||||
export { default as Moment } from './Moment';
|
||||
export { default as Null } from './Null';
|
||||
export { default as Origin } from './Origin';
|
||||
export { default as StorageData } from './StorageData';
|
||||
export { default as StorageHasher } from './StorageHasher';
|
||||
export { default as StorageKey } from './StorageKey';
|
||||
export { default as Text } from './Text';
|
||||
export { default as Type } from './Type';
|
||||
export { default as U8, default as u8 } from './U8';
|
||||
export { default as U16, default as u16 } from './U16';
|
||||
export { default as U32, default as u32 } from './U32';
|
||||
export { default as U64, default as u64 } from './U64';
|
||||
export { default as U128, default as u128 } from './U128';
|
||||
export { default as U256, default as u256 } from './U256';
|
||||
export { default as USize, default as usize } from './USize';
|
||||
export { default as u8, default as U8 } from './U8';
|
||||
export { default as u16, default as U16 } from './U16';
|
||||
export { default as u32, default as U32 } from './U32';
|
||||
export { default as u64, default as U64 } from './U64';
|
||||
export { default as u128, default as U128 } from './U128';
|
||||
export { default as u256, default as U256 } from './U256';
|
||||
export { default as usize } from './USize';
|
||||
export { default as Vote } from './Vote';
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import ChainProperties from './ChainProperties';
|
||||
|
||||
describe('ChainProperties', (): void => {
|
||||
it('decodes from a null value', (): void => {
|
||||
expect(
|
||||
[...new ChainProperties(null).entries()]
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('decodes from an actual object', (): void => {
|
||||
expect(
|
||||
[...new ChainProperties({
|
||||
decimals: 15,
|
||||
tokenSymbol: 'BBQ'
|
||||
}).entries()]
|
||||
).toEqual([['decimals', 15], ['tokenSymbol', 'BBQ']]);
|
||||
});
|
||||
|
||||
it('checks equality', (): void => {
|
||||
expect(
|
||||
new ChainProperties({
|
||||
decimals: 15,
|
||||
tokenSymbol: 'BBQ'
|
||||
}).eq([['tokenSymbol', 'BBQ'], ['decimals', 15]])
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,26 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import StructAny from '../codec/StructAny';
|
||||
|
||||
/**
|
||||
* @name ChainProperties
|
||||
* @description
|
||||
* Wraps the properties retrieved from the chain via the `system.properties` RPC call.
|
||||
*/
|
||||
export default class ChainProperties extends StructAny {
|
||||
/**
|
||||
* @description The token decimals, if defined (de-facto standard only)
|
||||
*/
|
||||
public get tokenDecimals (): number | undefined {
|
||||
return this.get('tokenDecimals');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The token system, if defined (de-facto standard only)
|
||||
*/
|
||||
public get tokenSymbol (): string | undefined {
|
||||
return this.get('tokenSymbol');
|
||||
}
|
||||
}
|
||||
@@ -1,415 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Hash, Signature } from '../srml/runtime/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { assert, bnToBn } from '@polkadot/util';
|
||||
|
||||
import Enum from '../codec/Enum';
|
||||
import Struct from '../codec/Struct';
|
||||
import Tuple from '../codec/Tuple';
|
||||
import Vector from '../codec/Vector';
|
||||
import Bytes from '../primitive/Bytes';
|
||||
import U32 from '../primitive/U32';
|
||||
import U64 from '../primitive/U64';
|
||||
|
||||
// Should import AuthorityId (however, move these to generated types)
|
||||
import AuthorityId from '../primitive/AccountId';
|
||||
import { ClassOf } from '../codec';
|
||||
|
||||
const CID_AURA = 0x61727561; // 'aura'
|
||||
const CID_BABE = 0x65626162; // 'babe'
|
||||
const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1)
|
||||
|
||||
export { CID_AURA, CID_BABE, CID_GRPA };
|
||||
|
||||
/**
|
||||
* @name AuthoritiesChange
|
||||
* @description
|
||||
* Log for Authories changed
|
||||
*/
|
||||
export class AuthoritiesChange extends Vector.with(AuthorityId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name ConsensusEngineId
|
||||
* @description
|
||||
* A 4-byte identifier (actually a [u8; 4]) identifying the engine, e.g. for Aura it would be [b'a', b'u', b'r', b'a']
|
||||
*/
|
||||
export class ConsensusEngineId extends U32 {
|
||||
public static idToString (input: number | BN): string {
|
||||
return bnToBn(input)
|
||||
.toArray('le')
|
||||
.map((code): string => String.fromCharCode(code))
|
||||
.join('');
|
||||
}
|
||||
|
||||
public static stringToId (input: string): number {
|
||||
return input
|
||||
.split('')
|
||||
.reverse()
|
||||
.reduce((result, char): number => (result * 256) + char.charCodeAt(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if the engine matches aura
|
||||
*/
|
||||
public get isAura (): boolean {
|
||||
return this.eq(CID_AURA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` is the engine matches babe
|
||||
*/
|
||||
public get isBabe (): boolean {
|
||||
return this.eq(CID_BABE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` is the engine matches grandpa
|
||||
*/
|
||||
public get isGrandpa (): boolean {
|
||||
return this.eq(CID_GRPA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From the input bytes, decode into an aura-tuple
|
||||
*/
|
||||
public extractSlot (bytes: Bytes): U64 {
|
||||
assert(this.isAura, 'Invalid engine for asAura conversion');
|
||||
|
||||
return new U64(
|
||||
// no compact prefix, only use the correct number of supplied bytes
|
||||
bytes.toU8a(true).subarray(0, 8)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Override the default toString to return a 4-byte string
|
||||
*/
|
||||
public toString (): string {
|
||||
return ConsensusEngineId.idToString(this as BN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Consensus
|
||||
* @description
|
||||
* Log item indicating consensus
|
||||
*/
|
||||
export class Consensus extends Tuple {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
ConsensusEngineId,
|
||||
Bytes
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped engine [[ConsensusEngineId]]
|
||||
*/
|
||||
public get engine (): ConsensusEngineId {
|
||||
return this[0] as ConsensusEngineId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[Bytes]]
|
||||
*/
|
||||
public get data (): Bytes {
|
||||
return this[1] as Bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The slot extracted from the raw data (fails on non-Aura)
|
||||
*/
|
||||
public get slot (): U64 {
|
||||
return this.engine.extractSlot(this.data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name SealV0
|
||||
* @description
|
||||
* Log item indicating a sealing event. This has been replaced in later versions with a renamed [[Seal]], we however have kept compatibility with the old version
|
||||
*/
|
||||
export class SealV0 extends Tuple {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
U64,
|
||||
Signature: ClassOf<Signature>('Signature')
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[Signature]]
|
||||
*/
|
||||
public get signature (): Signature {
|
||||
return this[1] as Signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[U64]] slot
|
||||
*/
|
||||
public get slot (): U64 {
|
||||
return this[0] as U64;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Seal
|
||||
* @description
|
||||
* Log item indicating a sealing event.
|
||||
*/
|
||||
export class Seal extends Tuple {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
ConsensusEngineId,
|
||||
Bytes
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[Bytes]]
|
||||
*/
|
||||
public get data (): Bytes {
|
||||
return this[1] as Bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[U64]] slot
|
||||
*/
|
||||
public get slot (): U64 {
|
||||
return this[0] as U64;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Other
|
||||
* @description
|
||||
* Log item that is just a stream of [[Bytes]]
|
||||
*/
|
||||
export class Other extends Bytes {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name PreRuntime
|
||||
* @description
|
||||
* These are messages from the consensus engine to the runtime, although the consensus engine the consensus engine can (and should) read them itself to avoid ode and state duplication.
|
||||
*/
|
||||
export class PreRuntime extends Tuple {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
ConsensusEngineId,
|
||||
Bytes
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[ConsensusEngineId]]
|
||||
*/
|
||||
public get engine (): ConsensusEngineId {
|
||||
return this[0] as ConsensusEngineId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The wrapped [[Bytes]]
|
||||
*/
|
||||
public get data (): Bytes {
|
||||
return this[1] as Bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The slot extracted from the raw data (fails on non-Aura)
|
||||
*/
|
||||
public get slot (): U64 {
|
||||
return this.engine.extractSlot(this.data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name DigestItem
|
||||
* @description
|
||||
* A [[Enum]] the specifies the specific item in the logs of a [[Digest]]
|
||||
*/
|
||||
export class DigestItem extends Enum {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
Other, // 0
|
||||
AuthoritiesChange, // 1
|
||||
ChangesTrieRoot: ClassOf<Hash>('Hash'), // 2
|
||||
SealV0, // 3
|
||||
Consensus, // 4
|
||||
Seal, // 5
|
||||
PreRuntime // 6
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[AuthoritiesChange]]
|
||||
*/
|
||||
public get asAuthoritiesChange (): AuthoritiesChange {
|
||||
assert(this.isAuthoritiesChange, `Cannot convert '${this.type}' via asAuthoritiesChange`);
|
||||
|
||||
return this.value as AuthoritiesChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[ChangesTrieRoot]]
|
||||
*/
|
||||
public get asChangesTrieRoot (): Hash {
|
||||
assert(this.isChangesTrieRoot, `Cannot convert '${this.type}' via asChangesTrieRoot`);
|
||||
|
||||
return this.value as Hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @desciption Retuns the item as a [[Consensus]]
|
||||
*/
|
||||
public get asConsensus (): Consensus {
|
||||
assert(this.isConsensus, `Cannot convert '${this.type}' via asConsensus`);
|
||||
|
||||
return this.value as Consensus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[Other]]
|
||||
*/
|
||||
public get asOther (): Other {
|
||||
assert(this.isOther, `Cannot convert '${this.type}' via asOther`);
|
||||
|
||||
return this.value as Other;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[PreRuntime]]
|
||||
*/
|
||||
public get asPreRuntime (): PreRuntime {
|
||||
assert(this.isPreRuntime, `Cannot convert '${this.type}' via asPreRuntime`);
|
||||
|
||||
return this.value as PreRuntime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[Seal]]
|
||||
*/
|
||||
public get asSeal (): Seal {
|
||||
assert(this.isSeal, `Cannot convert '${this.type}' via asSeal`);
|
||||
|
||||
return this.value as Seal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the item as a [[SealV0]]
|
||||
*/
|
||||
public get asSealV0 (): SealV0 {
|
||||
assert(this.isSealV0, `Cannot convert '${this.type}' via asSealV0`);
|
||||
|
||||
return this.value as SealV0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[AuthoritiesChange]]
|
||||
*/
|
||||
public get isAuthoritiesChange (): boolean {
|
||||
return this.type === 'AuthoritiesChange';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[ChangesTrieRoot]]
|
||||
*/
|
||||
public get isChangesTrieRoot (): boolean {
|
||||
return this.type === 'ChangesTrieRoot';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[Consensus]]
|
||||
*/
|
||||
public get isConsensus (): boolean {
|
||||
return this.type === 'Consensus';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[Other]]
|
||||
*/
|
||||
public get isOther (): boolean {
|
||||
return this.type === 'Other';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[PreRuntime]]
|
||||
*/
|
||||
public get isPreRuntime (): boolean {
|
||||
return this.type === 'PreRuntime';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[Seal]]
|
||||
*/
|
||||
public get isSeal (): boolean {
|
||||
return this.type === 'Seal';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true on [[SealV0]]
|
||||
*/
|
||||
public get isSealV0 (): boolean {
|
||||
return this.type === 'SealV0';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers. For logs, we overrides to produce the hex version (sligning with substrate gives in actual JSON responses)
|
||||
*/
|
||||
public toJSON (): string {
|
||||
return this.toHex();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the type of engine
|
||||
*/
|
||||
public get type (): string {
|
||||
return super.type;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Digest
|
||||
* @description
|
||||
* A [[Header]] Digest
|
||||
*/
|
||||
export default class Digest extends Struct {
|
||||
public constructor (value: any) {
|
||||
super({
|
||||
logs: Vector.with(DigestItem)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[DigestItem]] logs
|
||||
*/
|
||||
public get logs (): Vector<DigestItem> {
|
||||
return this.get('logs') as Vector<DigestItem>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned.
|
||||
*/
|
||||
public logsWith (...include: string[]): Vector<DigestItem> {
|
||||
return this.logs.filter(({ type }): boolean => include.includes(type)) as Vector<DigestItem>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution.
|
||||
*/
|
||||
public logsWithout (...exclude: string[]): Vector<DigestItem> {
|
||||
return this.logs.filter(({ type }): boolean => !exclude.includes(type)) as Vector<DigestItem>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name DigestOf
|
||||
* @description
|
||||
* A [[Header]] Digest
|
||||
*/
|
||||
export class DigestOf extends Digest { }
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user