Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d7be67499 | ||
|
|
7804794233 | ||
|
|
c7a68a4e05 | ||
|
|
811f9f7868 | ||
|
|
d9acf1cfea | ||
|
|
0967dbba6b | ||
|
|
025a745258 | ||
|
|
88eb4fd6e5 | ||
|
|
0dcdffd59c | ||
|
|
1f39ad264a | ||
|
|
e357a08118 | ||
|
|
d6b2b4a1a3 | ||
|
|
47f2ee725f | ||
|
|
1028e14761 | ||
|
|
5fdefa9e58 | ||
|
|
80209da5c5 | ||
|
|
bbdf0e3192 | ||
|
|
9ee1c0bf13 | ||
|
|
5490947384 | ||
|
|
b1788be796 | ||
|
|
f4ec312656 | ||
|
|
e1057603fc | ||
|
|
0268e398c1 | ||
|
|
757d45b39e | ||
|
|
4f57a5a611 | ||
|
|
987896e323 | ||
|
|
1b9d3bf38e | ||
|
|
b8a0f39da4 | ||
|
|
e4e20f8a88 | ||
|
|
131729e438 | ||
|
|
4672439bce | ||
|
|
0b11fc98b9 | ||
|
|
ece0a4b19a | ||
|
|
1dac7e3f1b | ||
|
|
3e1c93d4a8 | ||
|
|
19e9af02d8 | ||
|
|
2200cc2fab | ||
|
|
33990b6d02 | ||
|
|
333313fd6a | ||
|
|
33fd09c053 | ||
|
|
7dadac7344 | ||
|
|
340554a659 | ||
|
|
236ad16406 | ||
|
|
aae4671db5 | ||
|
|
d0f9eb7d03 | ||
|
|
d6106b3253 | ||
|
|
9740c282d8 | ||
|
|
f65b5c77ec | ||
|
|
0f920ee77d | ||
|
|
62d1415d1b | ||
|
|
f8792e09c9 | ||
|
|
8d4b03d066 | ||
|
|
5d3c728cf0 | ||
|
|
04340de6ae | ||
|
|
d709a5b3be | ||
|
|
1d3dfc77a3 | ||
|
|
a72d33ad24 | ||
|
|
e4948ef579 | ||
|
|
f9812585b8 |
@@ -1,5 +1,47 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 3.2.1 Dec 27, 2020
|
||||
|
||||
Upgrade priority: Low. Recommended for users of parachains.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Adjust metadata `.asV12` type signature (Thanks to https://github.com/yjhmelody)
|
||||
|
||||
Changes:
|
||||
|
||||
- Add `api.{errors, events, query, tx}.<section>.<name>.is(...)`
|
||||
- Remove support for staking pre Substrate 2.0
|
||||
- Add all frontier types & RPCs
|
||||
- Support `AccountInfo` with new provider/consumer refCount structure
|
||||
- Additional Cumulus parachain types
|
||||
- Consistently format number JSON based on bitLength
|
||||
- Cleanup metadata -> api dependencies
|
||||
- Update `@polkadot/util` to 5.2.1
|
||||
|
||||
|
||||
## 3.1.1 Dec 20, 2020
|
||||
|
||||
Upgrade priority: Low. Recommended for users of parachains.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Additional parachain types (Thanks to https://github.com/joelamouche)
|
||||
- Support for multi queries with `HttpProvider` (Thanks to https://github.com/ianhe8x)
|
||||
- Configurable error logging with `createTypeUnsafe` (Thanks to https://github.com/dvdplm)
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust core type creation, removing storage duplication
|
||||
- Update parachain types to support Rococo v1
|
||||
- Adjust bounties derive to cater for new Substrate namespaces (& move to bounties)
|
||||
- Mark `detectPackage` as known side-effect
|
||||
- Add `detectPackage` to `@polkadot/metadata` (a number of requests on this)
|
||||
- Adjust x-rxjs wrapper to expose all methods, incl. Node.js esm fixes
|
||||
- Update to latest Substrate static metadata
|
||||
- Update `@polkadot/util` to 5.1.1
|
||||
|
||||
|
||||
## 3.0.1 Dec 14, 2020
|
||||
|
||||
Upgrade priority: Low. Recommended for the next Kusama/Polkadot upgrades due to additional types and those following chains following Substrate master closely.
|
||||
|
||||
+2
-2
@@ -28,11 +28,11 @@
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/register": "^7.12.10",
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/dev": "^0.61.2",
|
||||
"@polkadot/dev": "^0.61.16",
|
||||
"@polkadot/ts": "^0.3.58",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.19",
|
||||
"copyfiles": "^2.4.1"
|
||||
},
|
||||
"version": "3.0.1"
|
||||
"version": "3.2.1"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"sideEffects": false,
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
@@ -13,10 +14,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/api": "3.0.1",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/x-rxjs": "3.0.1",
|
||||
"@polkadot/api": "3.2.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"@polkadot/x-rxjs": "3.2.1",
|
||||
"bn.js": "^4.11.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base';
|
||||
import type { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base';
|
||||
|
||||
export type BlueprintSubmittableResult = BaseBlueprintSubmittableResult<'promise'>;
|
||||
export type CodeSubmittableResult = BaseCodeSubmittableResult<'promise'>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base';
|
||||
import type { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base';
|
||||
|
||||
export type BlueprintSubmittableResult = BaseBlueprintSubmittableResult<'promise'>;
|
||||
export type CodeSubmittableResult = BaseCodeSubmittableResult<'promise'>;
|
||||
|
||||
@@ -17,7 +17,7 @@ type ContractEvents = 'CodeStored' | 'ContractExecution' | 'Instantiated';
|
||||
type TOptions = BlueprintOptions | ContractOptions;
|
||||
|
||||
export function formatData (registry: Registry, data: Raw, { type }: TypeDef): Codec {
|
||||
return createTypeUnsafe(registry, type, [data], true);
|
||||
return createTypeUnsafe(registry, type, [data], { isPedantic: true });
|
||||
}
|
||||
|
||||
export function applyOnEvent <T> (result: SubmittableResult, type: ContractEvents, fn: (records: EventRecord[]) => T): T | undefined {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"sideEffects": false,
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
@@ -13,16 +14,16 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/api": "3.0.1",
|
||||
"@polkadot/rpc-core": "3.0.1",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/util-crypto": "^5.0.1",
|
||||
"@polkadot/x-rxjs": "3.0.1",
|
||||
"@polkadot/api": "3.2.1",
|
||||
"@polkadot/rpc-core": "3.2.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"@polkadot/util-crypto": "^5.2.2",
|
||||
"@polkadot/x-rxjs": "3.2.1",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^5.0.1",
|
||||
"@polkadot/rpc-provider": "3.0.1"
|
||||
"@polkadot/keyring": "^5.2.2",
|
||||
"@polkadot/rpc-provider": "3.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,40 +2,16 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Option, Vec } from '@polkadot/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId, AccountIndex, BalanceOf } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map, startWith } from '@polkadot/x-rxjs/operators';
|
||||
import { map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function queryEnumSet (api: ApiInterfaceRx, _accountIndex: AccountIndex | string): Observable<AccountId | undefined> {
|
||||
const accountIndex = _accountIndex instanceof api.registry.createClass('AccountIndex')
|
||||
? _accountIndex
|
||||
: api.registry.createType('AccountIndex', _accountIndex);
|
||||
|
||||
return api.query.indices.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)).pipe(
|
||||
startWith([]),
|
||||
map((accounts): AccountId | undefined =>
|
||||
(accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// current
|
||||
function query (api: ApiInterfaceRx, accountIndex: AccountIndex | string): Observable<AccountId | undefined> {
|
||||
return api.query.indices.accounts<Option<ITuple<[AccountId, BalanceOf]>>>(accountIndex).pipe(
|
||||
map((optResult): AccountId | undefined =>
|
||||
optResult.unwrapOr([])[0]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name indexToId
|
||||
* @param {( AccountIndex | string )} accountIndex - An accounts index in different formats.
|
||||
@@ -52,9 +28,11 @@ function query (api: ApiInterfaceRx, accountIndex: AccountIndex | string): Obser
|
||||
export function indexToId (instanceId: string, api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
||||
return memo(instanceId, (accountIndex: AccountIndex | string): Observable<AccountId | undefined> =>
|
||||
api.query.indices
|
||||
? isFunction(api.query.indices.accounts)
|
||||
? query(api, accountIndex)
|
||||
: queryEnumSet(api, accountIndex)
|
||||
? api.query.indices.accounts<Option<ITuple<[AccountId, BalanceOf]>>>(accountIndex).pipe(
|
||||
map((optResult): AccountId | undefined =>
|
||||
optResult.unwrapOr([])[0]
|
||||
)
|
||||
)
|
||||
: of(undefined)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,47 +2,17 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Vec } from '@polkadot/types';
|
||||
import type { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
import type { AccountIndex } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { AccountIndexes } from '../types';
|
||||
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map, startWith, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
import { map, startWith } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
const enumsetSize = ENUMSET_SIZE.toNumber();
|
||||
|
||||
let indicesCache: AccountIndexes | null = null;
|
||||
|
||||
function queryEnumSet (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
return api.query.indices.nextEnumSet<AccountIndex>().pipe(
|
||||
// use the nextEnumSet (which is a counter of the number of sets) to construct
|
||||
// a range of values to query [0, 1, 2, ...]. Retrieve the full enum set for the
|
||||
// specific index - each query can return up to ENUMSET_SIZE (64) records, each
|
||||
// containing an AccountId
|
||||
switchMap((next: AccountIndex): Observable<Vec<AccountId>[]> =>
|
||||
api.query.indices.enumSet.multi<Vec<AccountId>>([...Array(next.toNumber() + 1).keys()])
|
||||
),
|
||||
map((all: AccountId[][]): AccountIndexes =>
|
||||
all.reduce((indexes: AccountIndexes, list, outerIndex): AccountIndexes => {
|
||||
(list || []).forEach((accountId, innerIndex): void => {
|
||||
// re-create the index based on position 0 is [0][0] and likewise
|
||||
// 64 (0..63 in first) is [1][0] (the first index value in set 2)
|
||||
const index = (outerIndex * enumsetSize) + innerIndex;
|
||||
|
||||
indexes[accountId.toString()] = api.registry.createType('AccountIndex', index);
|
||||
});
|
||||
|
||||
return indexes;
|
||||
}, {})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function queryAccounts (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
return api.query.indices.accounts.entries().pipe(
|
||||
map((entries): AccountIndexes =>
|
||||
@@ -78,9 +48,7 @@ export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observa
|
||||
? of(indicesCache)
|
||||
: (
|
||||
api.query.indices
|
||||
? isFunction(api.query.indices.accounts)
|
||||
? queryAccounts(api).pipe(startWith({}))
|
||||
: queryEnumSet(api).pipe(startWith({}))
|
||||
? queryAccounts(api).pipe(startWith({}))
|
||||
: of({} as AccountIndexes)
|
||||
).pipe(
|
||||
map((indices): AccountIndexes => {
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
@@ -6,12 +6,12 @@ import type { Bytes, Option, StorageKey } from '@polkadot/types';
|
||||
import type { Bounty, BountyIndex } from '@polkadot/types/interfaces';
|
||||
import type { Codec, InterfaceTypes } from '@polkadot/types/types';
|
||||
|
||||
import { bounties } from '@polkadot/api-derive/treasury/bounties';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
|
||||
import { BountyFactory } from '../../test/bountyFactory';
|
||||
import { BytesFactory } from '../../test/bytesFactory';
|
||||
import { createApiWithAugmentations } from '../../test/helpers';
|
||||
import { bounties } from '.';
|
||||
|
||||
const DEFAULT_PROPOSER = '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM';
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { DeriveBounties } from '@polkadot/api-derive/types';
|
||||
import type { Bytes, Option } from '@polkadot/types';
|
||||
import type { Bounty, BountyIndex } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { memo } from '@polkadot/api-derive/util';
|
||||
import { combineLatest } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
type Result = [Option<Bounty>[], Option<Bytes>[]];
|
||||
|
||||
function parseResult ([maybeBounties, maybeDescriptions]: Result): DeriveBounties {
|
||||
const bounties: DeriveBounties = [];
|
||||
|
||||
maybeBounties.forEach((bounty, index) => {
|
||||
if (bounty.isSome) {
|
||||
bounties.push({ bounty: bounty.unwrap(), description: maybeDescriptions[index].unwrapOrDefault().toUtf8() });
|
||||
}
|
||||
});
|
||||
|
||||
return bounties;
|
||||
}
|
||||
|
||||
export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveBounties> {
|
||||
const bountyBase = api.query.bounties
|
||||
? api.query.bounties
|
||||
: api.query.treasury;
|
||||
|
||||
return memo(instanceId, (): Observable<DeriveBounties> =>
|
||||
bountyBase.bountyCount<BountyIndex>().pipe(
|
||||
switchMap(() => bountyBase.bounties.keys()),
|
||||
switchMap((keys): Observable<Result> => {
|
||||
const ids = keys.map(({ args: [id] }) => id);
|
||||
|
||||
return combineLatest([
|
||||
bountyBase.bounties.multi<Option<Bounty>>(ids),
|
||||
bountyBase.bountyDescriptions.multi<Option<Bytes>>(ids)
|
||||
]);
|
||||
}),
|
||||
map(parseResult)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './bounties';
|
||||
@@ -7,6 +7,7 @@ import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import * as accounts from './accounts';
|
||||
import * as balances from './balances';
|
||||
import * as bounties from './bounties';
|
||||
import * as chain from './chain';
|
||||
import * as contracts from './contracts';
|
||||
import * as council from './council';
|
||||
@@ -23,7 +24,7 @@ import * as tx from './tx';
|
||||
|
||||
export * from './type';
|
||||
|
||||
export const derive = { accounts, balances, chain, contracts, council, democracy, elections, imOnline, parachains, session, society, staking, technicalCommittee, treasury, tx };
|
||||
export const derive = { accounts, balances, bounties, chain, contracts, council, democracy, elections, imOnline, parachains, session, society, staking, technicalCommittee, treasury, tx };
|
||||
|
||||
type DeriveSection<Section> = {
|
||||
[Method in keyof Section]: Section[Method] extends AnyFunction
|
||||
|
||||
@@ -7,16 +7,11 @@ import type { ActiveEraInfo, EraIndex, Moment, SessionIndex } from '@polkadot/ty
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveSessionIndexes } from '../types';
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function isEraOpt (era: Option<EraIndex> | EraIndex): era is Option<EraIndex> {
|
||||
return isFunction((era as Option<EraIndex>).unwrapOrDefault);
|
||||
}
|
||||
|
||||
// parse into Indexes
|
||||
function parse ([activeEra, activeEraStart, currentEra, currentIndex, validatorCount]: [EraIndex, Option<Moment>, EraIndex, SessionIndex, u32]): DeriveSessionIndexes {
|
||||
return {
|
||||
@@ -28,29 +23,6 @@ function parse ([activeEra, activeEraStart, currentEra, currentIndex, validatorC
|
||||
};
|
||||
}
|
||||
|
||||
// query for previous V2
|
||||
function queryNoActive (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
return api.queryMulti<[Option<EraIndex> | EraIndex, SessionIndex, u32]>([
|
||||
api.query.staking.currentEra,
|
||||
api.query.session.currentIndex,
|
||||
api.query.staking.validatorCount
|
||||
]).pipe(
|
||||
map(([currentEraOpt, currentIndex, validatorCount]): DeriveSessionIndexes => {
|
||||
const currentEra = isEraOpt(currentEraOpt)
|
||||
? currentEraOpt.unwrapOrDefault()
|
||||
: currentEraOpt;
|
||||
|
||||
return parse([
|
||||
currentEra,
|
||||
api.registry.createType('Option<Moment>'),
|
||||
currentEra,
|
||||
currentIndex,
|
||||
validatorCount
|
||||
]);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// query based on latest
|
||||
function query (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
return api.queryMulti<[Option<ActiveEraInfo>, Option<EraIndex>, SessionIndex, u32]>([
|
||||
@@ -87,9 +59,7 @@ function empty (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionIndexes> =>
|
||||
api.query.session && api.query.staking
|
||||
? isFunction(api.query.staking.activeEra)
|
||||
? query(api)
|
||||
: queryNoActive(api)
|
||||
? query(api)
|
||||
: empty(api)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import type { SessionIndex } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveSessionInfo, DeriveSessionProgress } from '../types';
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
@@ -57,29 +56,13 @@ function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultS
|
||||
);
|
||||
}
|
||||
|
||||
function queryBabeNoHistory (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultSlotsFlat]> {
|
||||
return combineLatest([
|
||||
api.derive.session.info(),
|
||||
api.queryMulti<ResultSlotsFlat>([
|
||||
api.query.babe.currentSlot,
|
||||
api.query.babe.epochIndex,
|
||||
api.query.babe.genesisSlot,
|
||||
api.query.staking.currentEraStartSessionIndex
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
|
||||
*/
|
||||
export function progress (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionProgress> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionProgress> =>
|
||||
api.consts.babe
|
||||
? (
|
||||
isFunction(api.query.staking.erasStartSessionIndex)
|
||||
? queryBabe(api) // 2.x with Babe
|
||||
: queryBabeNoHistory(api)
|
||||
).pipe(
|
||||
? queryBabe(api).pipe(
|
||||
map(([info, slots]: [DeriveSessionInfo, ResultSlotsFlat]): DeriveSessionProgress =>
|
||||
createDerive(api, info, slots)
|
||||
)
|
||||
|
||||
@@ -2,41 +2,21 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId, EraPoints, EraRewardPoints, RewardPoint } from '@polkadot/types/interfaces';
|
||||
import type { EraRewardPoints } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
import { switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function retrievePointsPrev (api: ApiInterfaceRx, currentElected: AccountId[]): Observable<EraRewardPoints> {
|
||||
return api.query.staking.currentEraPointsEarned<EraPoints>().pipe(
|
||||
map(({ individual, total }): EraRewardPoints =>
|
||||
api.registry.createType('EraRewardPoints', {
|
||||
individual: new Map<AccountId, RewardPoint>(
|
||||
individual
|
||||
.map((points) => api.registry.createType('RewardPoint', points))
|
||||
.map((points, index): [AccountId, RewardPoint] => [currentElected[index], points])
|
||||
),
|
||||
total
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve the staking overview, including elected and points earned
|
||||
*/
|
||||
export function currentPoints (instanceId: string, api: ApiInterfaceRx): () => Observable<EraRewardPoints> {
|
||||
return memo(instanceId, (): Observable<EraRewardPoints> =>
|
||||
api.derive.staking.overview().pipe(
|
||||
switchMap(({ activeEra, nextElected }) =>
|
||||
api.query.staking.erasRewardPoints
|
||||
? api.query.staking.erasRewardPoints<EraRewardPoints>(activeEra)
|
||||
: api.query.staking.currentEraPointsEarned
|
||||
? retrievePointsPrev(api, nextElected)
|
||||
: of(api.registry.createType('EraRewardPoints'))
|
||||
api.derive.session.indexes().pipe(
|
||||
switchMap(({ activeEra }) =>
|
||||
api.query.staking.erasRewardPoints<EraRewardPoints>(activeEra)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -4,21 +4,24 @@
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveStakingElected } from '../types';
|
||||
import type { DeriveStakingElected, StakingQueryFlags } from '../types';
|
||||
|
||||
import { arrayFlatten } from '@polkadot/util';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
const DEFAULT_FLAGS = { withController: true, withExposure: true, withPrefs: true };
|
||||
|
||||
function combineAccounts (nextElected: AccountId[], validators: AccountId[]): AccountId[] {
|
||||
return [...nextElected].concat(...validators.filter((v) => !nextElected.find((n) => n.eq(v))));
|
||||
return arrayFlatten([nextElected, validators.filter((v) => !nextElected.find((n) => n.eq(v)))]);
|
||||
}
|
||||
|
||||
export function electedInfo (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveStakingElected> {
|
||||
return memo(instanceId, (): Observable<DeriveStakingElected> =>
|
||||
export function electedInfo (instanceId: string, api: ApiInterfaceRx): (flags?: StakingQueryFlags) => Observable<DeriveStakingElected> {
|
||||
return memo(instanceId, (flags: StakingQueryFlags = DEFAULT_FLAGS): Observable<DeriveStakingElected> =>
|
||||
api.derive.staking.validators().pipe(
|
||||
switchMap(({ nextElected, validators }): Observable<DeriveStakingElected> =>
|
||||
api.derive.staking.queryMulti(combineAccounts(nextElected, validators), { withExposure: true, withLedger: true, withPrefs: true }).pipe(
|
||||
api.derive.staking.queryMulti(combineAccounts(nextElected, validators), flags).pipe(
|
||||
map((info): DeriveStakingElected => ({
|
||||
info,
|
||||
nextElected,
|
||||
|
||||
@@ -8,36 +8,33 @@ import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { of } from '@polkadot/x-rxjs';
|
||||
import { map } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function erasHistoric (instanceId: string, api: ApiInterfaceRx): (withActive: boolean) => Observable<EraIndex[]> {
|
||||
return memo(instanceId, (withActive: boolean): Observable<EraIndex[]> =>
|
||||
api.query.staking?.activeEra
|
||||
? api.queryMulti<[Option<ActiveEraInfo>, u32]>([
|
||||
api.query.staking.activeEra,
|
||||
api.query.staking.historyDepth
|
||||
]).pipe(
|
||||
map(([activeEraOpt, historyDepth]): EraIndex[] => {
|
||||
const result: EraIndex[] = [];
|
||||
const max = historyDepth.toNumber();
|
||||
const activeEra: BN = activeEraOpt.unwrapOrDefault().index;
|
||||
let lastEra = activeEra;
|
||||
api.queryMulti<[Option<ActiveEraInfo>, u32]>([
|
||||
api.query.staking.activeEra,
|
||||
api.query.staking.historyDepth
|
||||
]).pipe(
|
||||
map(([activeEraOpt, historyDepth]): EraIndex[] => {
|
||||
const result: EraIndex[] = [];
|
||||
const max = historyDepth.toNumber();
|
||||
const activeEra: BN = activeEraOpt.unwrapOrDefault().index;
|
||||
let lastEra = activeEra;
|
||||
|
||||
while (lastEra.gten(0) && (result.length < max)) {
|
||||
if ((lastEra !== activeEra) || (withActive === true)) {
|
||||
result.push(api.registry.createType('EraIndex', lastEra));
|
||||
}
|
||||
|
||||
lastEra = lastEra.subn(1);
|
||||
while (lastEra.gten(0) && (result.length < max)) {
|
||||
if ((lastEra !== activeEra) || (withActive === true)) {
|
||||
result.push(api.registry.createType('EraIndex', lastEra));
|
||||
}
|
||||
|
||||
// go from oldest to newest
|
||||
return result.reverse();
|
||||
})
|
||||
)
|
||||
: of([])
|
||||
lastEra = lastEra.subn(1);
|
||||
}
|
||||
|
||||
// go from oldest to newest
|
||||
return result.reverse();
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,71 +4,63 @@
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId, EraIndex, Exposure, Nominations, RewardDestination, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveStakingQuery } from '../types';
|
||||
import type { DeriveStakingQuery, StakingQueryFlags } from '../types';
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
import { combineLatest, of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
interface QueryFlags {
|
||||
withDestination?: boolean;
|
||||
withExposure?: boolean;
|
||||
withLedger?: boolean;
|
||||
withNominations?: boolean;
|
||||
withPrefs?: boolean;
|
||||
}
|
||||
|
||||
type MultiResult = [Option<AccountId>, Option<ITuple<[Nominations]> | Nominations>, RewardDestination, ITuple<[ValidatorPrefs]> | ValidatorPrefs, Exposure];
|
||||
|
||||
type MultiResultCombo = [Option<AccountId>, Option<Nominations>, RewardDestination, ValidatorPrefs, Exposure];
|
||||
|
||||
function parseDetails (stashId: AccountId, [controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, exposure]: MultiResult, stakingLedgerOpt: Option<StakingLedger>): DeriveStakingQuery {
|
||||
const nominators = nominatorsOpt && nominatorsOpt.unwrapOr(null);
|
||||
|
||||
function parseDetails (stashId: AccountId, controllerIdOpt: Option<AccountId> | null, nominatorsOpt: Option<Nominations>, rewardDestination: RewardDestination, validatorPrefs: ValidatorPrefs, exposure: Exposure, stakingLedgerOpt: Option<StakingLedger>): DeriveStakingQuery {
|
||||
return {
|
||||
accountId: stashId,
|
||||
controllerId: controllerIdOpt && controllerIdOpt.unwrapOr(null),
|
||||
exposure,
|
||||
nominators: nominators
|
||||
? Array.isArray(nominators)
|
||||
? nominators[0].targets
|
||||
: nominators.targets
|
||||
nominators: nominatorsOpt.isSome
|
||||
? nominatorsOpt.unwrap().targets
|
||||
: [],
|
||||
rewardDestination,
|
||||
stakingLedger: stakingLedgerOpt.unwrapOrDefault(),
|
||||
stashId,
|
||||
validatorPrefs: Array.isArray(validatorPrefs)
|
||||
? validatorPrefs[0]
|
||||
: validatorPrefs
|
||||
validatorPrefs
|
||||
};
|
||||
}
|
||||
|
||||
function retrievePrev (api: ApiInterfaceRx, stashId: AccountId): Observable<MultiResult> {
|
||||
return api.queryMulti<MultiResult>([
|
||||
[api.query.staking.bonded, stashId],
|
||||
[api.query.staking.nominators, stashId],
|
||||
[api.query.staking.payee, stashId],
|
||||
[api.query.staking.validators, stashId],
|
||||
[api.query.staking.stakers, stashId]
|
||||
]);
|
||||
function getLedgers (api: ApiInterfaceRx, optIds: (Option<AccountId> | null)[], { withLedger = false }: StakingQueryFlags): Observable<Option<StakingLedger>[]> {
|
||||
const ids = optIds
|
||||
.filter((opt): opt is Option<AccountId> => withLedger && !!opt && opt.isSome)
|
||||
.map((opt) => opt.unwrap());
|
||||
const emptyLed = api.registry.createType('Option<StakingLedger>');
|
||||
|
||||
return (
|
||||
ids.length
|
||||
? api.query.staking.ledger.multi<Option<StakingLedger>>(ids)
|
||||
: of([])
|
||||
).pipe(
|
||||
map((optLedgers): Option<StakingLedger>[] => {
|
||||
let offset = -1;
|
||||
|
||||
return optIds.map((opt): Option<StakingLedger> =>
|
||||
opt && opt.isSome
|
||||
? optLedgers[++offset] || emptyLed
|
||||
: emptyLed
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function retrieveCurr (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: EraIndex, { withDestination, withExposure, withLedger, withNominations, withPrefs }: QueryFlags): Observable<MultiResultCombo[]> {
|
||||
const emptyCont = api.registry.createType('Option<AccountId>');
|
||||
function getStashInfo (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: EraIndex, { withController, withDestination, withExposure, withLedger, withNominations, withPrefs }: StakingQueryFlags): Observable<[(Option<AccountId> | null)[], Option<Nominations>[], RewardDestination[], ValidatorPrefs[], Exposure[]]> {
|
||||
const emptyNoms = api.registry.createType('Option<Nominations>');
|
||||
const emptyRewa = api.registry.createType('RewardDestination');
|
||||
const emptyExpo = api.registry.createType('Exposure');
|
||||
const emptyPrefs = api.registry.createType('ValidatorPrefs');
|
||||
|
||||
return combineLatest([
|
||||
withLedger
|
||||
withController || withLedger
|
||||
? api.query.staking.bonded.multi<Option<AccountId>>(stashIds)
|
||||
: of(stashIds.map(() => emptyCont)),
|
||||
withNominations && api.query.staking.nominators
|
||||
: of(stashIds.map(() => null)),
|
||||
withNominations
|
||||
? api.query.staking.nominators.multi<Option<Nominations>>(stashIds)
|
||||
: of(stashIds.map(() => emptyNoms)),
|
||||
withDestination
|
||||
@@ -80,67 +72,43 @@ function retrieveCurr (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: Er
|
||||
withExposure
|
||||
? api.query.staking.erasStakers.multi<Exposure>(stashIds.map((stashId) => [activeEra, stashId]))
|
||||
: of(stashIds.map(() => emptyExpo))
|
||||
]).pipe(
|
||||
map(([controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, exposure]): MultiResultCombo[] =>
|
||||
controllerIdOpt.map((controllerIdOpt, index): MultiResultCombo =>
|
||||
[controllerIdOpt, nominatorsOpt[index], rewardDestination[index], validatorPrefs[index], exposure[index]]
|
||||
]);
|
||||
}
|
||||
|
||||
function getBatch (api: ApiInterfaceRx, activeEra: EraIndex, stashIds: AccountId[], flags: StakingQueryFlags): Observable<DeriveStakingQuery[]> {
|
||||
return getStashInfo(api, stashIds, activeEra, flags).pipe(
|
||||
switchMap(([controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, exposure]): Observable<DeriveStakingQuery[]> =>
|
||||
getLedgers(api, controllerIdOpt, flags).pipe(
|
||||
map((stakingLedgerOpts) =>
|
||||
stashIds.map((stashId, index) =>
|
||||
parseDetails(stashId, controllerIdOpt[index], nominatorsOpt[index], rewardDestination[index], validatorPrefs[index], exposure[index], stakingLedgerOpts[index])
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function retrieveControllers (api: ApiInterfaceRx, optControllerIds: Option<AccountId>[]): Observable<Option<StakingLedger>[]> {
|
||||
const ids = optControllerIds.filter((opt) => opt.isSome).map((opt) => opt.unwrap());
|
||||
const emptyLed = api.registry.createType('Option<StakingLedger>');
|
||||
|
||||
if (!ids.length) {
|
||||
return of(optControllerIds.map(() => emptyLed));
|
||||
}
|
||||
|
||||
return api.query.staking.ledger.multi<Option<StakingLedger>>(ids).pipe(
|
||||
map((optLedgers): Option<StakingLedger>[] => {
|
||||
let offset = -1;
|
||||
|
||||
return optControllerIds.map((opt): Option<StakingLedger> =>
|
||||
opt.isSome
|
||||
? optLedgers[++offset]
|
||||
: emptyLed
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
/**
|
||||
* @description From a stash, retrieve the controllerId and all relevant details
|
||||
*/
|
||||
export function query (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, flags: QueryFlags) => Observable<DeriveStakingQuery> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, flags: QueryFlags): Observable<DeriveStakingQuery> =>
|
||||
export function query (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, flags: StakingQueryFlags) => Observable<DeriveStakingQuery> {
|
||||
return memo(instanceId, (accountId: Uint8Array | string, flags: StakingQueryFlags): Observable<DeriveStakingQuery> =>
|
||||
api.derive.staking.queryMulti([accountId], flags).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function queryMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], flags: QueryFlags) => Observable<DeriveStakingQuery[]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], flags: QueryFlags): Observable<DeriveStakingQuery[]> =>
|
||||
export function queryMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags) => Observable<DeriveStakingQuery[]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags): Observable<DeriveStakingQuery[]> =>
|
||||
accountIds.length
|
||||
? api.derive.session.indexes().pipe(
|
||||
switchMap(({ activeEra }): Observable<DeriveStakingQuery[]> => {
|
||||
const stashIds = accountIds.map((accountId) => api.registry.createType('AccountId', accountId));
|
||||
|
||||
return (
|
||||
isFunction(api.query.staking.erasStakers)
|
||||
? retrieveCurr(api, stashIds, activeEra, flags)
|
||||
: combineLatest(stashIds.map((stashId) => retrievePrev(api, stashId)))
|
||||
).pipe(
|
||||
switchMap((results): Observable<DeriveStakingQuery[]> =>
|
||||
retrieveControllers(api, results.map(([optController]) => optController)).pipe(
|
||||
map((stakingLedgerOpts) =>
|
||||
stashIds.map((stashId, index) => parseDetails(stashId, results[index], stakingLedgerOpts[index]))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
return getBatch(api, activeEra, stashIds, flags);
|
||||
})
|
||||
)
|
||||
: of([])
|
||||
|
||||
@@ -21,7 +21,6 @@ type ErasResult = [{ unwrapOr: (value: BN) => BN }, DeriveEraPoints[], DeriveEra
|
||||
const ZERO = new BN(0);
|
||||
const MIN_ONE = new BN(-1);
|
||||
const COMM_DIV = new BN(1_000_000_000);
|
||||
const MAX_ERAS = new BN(1_000_000_000);
|
||||
|
||||
function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [, erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
|
||||
return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
|
||||
@@ -126,11 +125,7 @@ function filterRewards (api: ApiInterfaceRx, eras: EraIndex[], { migrateEra, rew
|
||||
const validators = uniqValidators(rewards);
|
||||
const filter = filterEras(eras, stakingLedger);
|
||||
|
||||
return (
|
||||
isFunction(api.tx.staking.payoutStakers)
|
||||
? api.derive.staking.queryMulti(validators, { withLedger: true })
|
||||
: of([])
|
||||
).pipe(
|
||||
return api.derive.staking.queryMulti(validators, { withLedger: true }).pipe(
|
||||
map((queryValidators): DeriveStakerReward[] =>
|
||||
rewards
|
||||
.filter(({ isEmpty }) => !isEmpty)
|
||||
@@ -162,7 +157,7 @@ export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (e
|
||||
combineLatest([
|
||||
isFunction(api.query.staking.migrateEra)
|
||||
? api.query.staking.migrateEra<Option<EraIndex>>()
|
||||
: of({ unwrapOr: () => isFunction(api.tx.staking.payoutStakers) ? ZERO : MAX_ERAS }),
|
||||
: of(api.registry.createType('Option<EraIndex>')),
|
||||
api.derive.staking._erasPoints(eras, withActive),
|
||||
api.derive.staking._erasPrefs(eras, withActive),
|
||||
api.derive.staking._erasRewards(eras, withActive)
|
||||
|
||||
@@ -144,3 +144,12 @@ export interface DeriveStakingOverview extends DeriveSessionIndexes {
|
||||
nextElected: AccountId[];
|
||||
validators: AccountId[];
|
||||
}
|
||||
|
||||
export interface StakingQueryFlags {
|
||||
withController?: boolean;
|
||||
withDestination?: boolean;
|
||||
withExposure?: boolean;
|
||||
withLedger?: boolean;
|
||||
withNominations?: boolean;
|
||||
withPrefs?: boolean;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,17 @@
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { DeriveStakingWaiting } from '../types';
|
||||
import type { DeriveStakingWaiting, StakingQueryFlags } from '../types';
|
||||
|
||||
import { combineLatest } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function waitingInfo (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveStakingWaiting> {
|
||||
return memo(instanceId, (): Observable<DeriveStakingWaiting> =>
|
||||
const DEFAULT_FLAGS = { withController: true, withPrefs: true };
|
||||
|
||||
export function waitingInfo (instanceId: string, api: ApiInterfaceRx): (flags?: StakingQueryFlags) => Observable<DeriveStakingWaiting> {
|
||||
return memo(instanceId, (flags: StakingQueryFlags = DEFAULT_FLAGS): Observable<DeriveStakingWaiting> =>
|
||||
combineLatest([
|
||||
api.derive.staking.validators(),
|
||||
api.derive.staking.stashes()
|
||||
@@ -20,7 +22,7 @@ export function waitingInfo (instanceId: string, api: ApiInterfaceRx): () => Obs
|
||||
const elected = nextElected.map((a) => a.toString());
|
||||
const waiting = stashes.filter((v) => !elected.includes(v.toString()));
|
||||
|
||||
return api.derive.staking.queryMulti(waiting, { withLedger: true, withPrefs: true }).pipe(
|
||||
return api.derive.staking.queryMulti(waiting, flags).pipe(
|
||||
map((info): DeriveStakingWaiting => ({
|
||||
info,
|
||||
waiting
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { DeriveBounties } from '@polkadot/api-derive/types';
|
||||
import type { Bytes, Option, StorageKey } from '@polkadot/types';
|
||||
import type { Bounty } from '@polkadot/types/interfaces';
|
||||
import type { Codec } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
|
||||
import { memo } from '@polkadot/api-derive/util';
|
||||
import { combineLatest } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
function parseResult ([maybeBounties, maybeDescriptions]: [Option<Bounty>[], Option<Bytes>[]]): DeriveBounties {
|
||||
const bounties: DeriveBounties = [];
|
||||
|
||||
maybeBounties.forEach((bounty, index) => {
|
||||
if (bounty.isSome) {
|
||||
bounties.push({ bounty: bounty.unwrap(), description: maybeDescriptions[index].unwrapOrDefault().toUtf8() });
|
||||
}
|
||||
});
|
||||
|
||||
return bounties;
|
||||
}
|
||||
|
||||
function extractIds (keys: StorageKey[]): Codec[] {
|
||||
return keys.map(({ args: [id] }: StorageKey) => id);
|
||||
}
|
||||
|
||||
export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveBounties> {
|
||||
return memo(instanceId, (): Observable<DeriveBounties> => api.query.treasury.bountyCount().pipe(
|
||||
switchMap(() => api.query.treasury.bounties.keys()),
|
||||
switchMap((keys: StorageKey[]) => {
|
||||
return combineLatest([
|
||||
api.query.treasury.bounties.multi<Option<Bounty>>(extractIds(keys)),
|
||||
api.query.treasury.bountyDescriptions.multi<Option<Bytes>>(extractIds(keys))
|
||||
]
|
||||
).pipe(map(parseResult));
|
||||
})));
|
||||
}
|
||||
@@ -2,4 +2,3 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './proposals';
|
||||
export * from './bounties';
|
||||
|
||||
@@ -15,11 +15,14 @@ export class BountyFactory {
|
||||
this.#registry = this.#api.registry;
|
||||
}
|
||||
|
||||
public storageKey = (index: number): StorageKey => new StorageKey(this.#registry, this.#api.query.treasury.bounties.key(this.bountyIndex(index)));
|
||||
public storageKey = (index: number): StorageKey =>
|
||||
new StorageKey(this.#registry, this.#api.query.bounties.bounties.key(this.bountyIndex(index)));
|
||||
|
||||
public bountyIndex = (index: number): BountyIndex => this.#registry.createType('BountyIndex', index);
|
||||
public bountyIndex = (index: number): BountyIndex =>
|
||||
this.#registry.createType('BountyIndex', index);
|
||||
|
||||
public defaultBounty = (): Bounty => this.#registry.createType('Bounty');
|
||||
public defaultBounty = (): Bounty =>
|
||||
this.#registry.createType('Bounty');
|
||||
|
||||
public optionOf = <T extends Codec>(value: T): Option<T> => {
|
||||
const typeName = this.#registry.getClassName(value.constructor as Constructor<T>);
|
||||
@@ -27,5 +30,6 @@ export class BountyFactory {
|
||||
return new Option<T>(this.#registry, typeName as keyof InterfaceTypes, value);
|
||||
};
|
||||
|
||||
public emptyOption = <T extends Codec>(typeName: keyof InterfaceTypes): Option<T> => new Option<T>(this.#registry, typeName);
|
||||
public emptyOption = <T extends Codec>(typeName: keyof InterfaceTypes): Option<T> =>
|
||||
new Option<T>(this.#registry, typeName);
|
||||
}
|
||||
|
||||
+16
-12
@@ -1,9 +1,13 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"module": "index.mjs",
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.mjs"
|
||||
],
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
@@ -13,16 +17,16 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/api-derive": "3.0.1",
|
||||
"@polkadot/keyring": "^5.0.1",
|
||||
"@polkadot/metadata": "3.0.1",
|
||||
"@polkadot/rpc-core": "3.0.1",
|
||||
"@polkadot/rpc-provider": "3.0.1",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/types-known": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/util-crypto": "^5.0.1",
|
||||
"@polkadot/x-rxjs": "3.0.1",
|
||||
"@polkadot/api-derive": "3.2.1",
|
||||
"@polkadot/keyring": "^5.2.2",
|
||||
"@polkadot/metadata": "3.2.1",
|
||||
"@polkadot/rpc-core": "3.2.1",
|
||||
"@polkadot/rpc-provider": "3.2.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/types-known": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"@polkadot/util-crypto": "^5.2.2",
|
||||
"@polkadot/x-rxjs": "3.2.1",
|
||||
"bn.js": "^4.11.9",
|
||||
"eventemitter3": "^4.0.7"
|
||||
}
|
||||
|
||||
@@ -35,6 +35,33 @@ declare module '@polkadot/api/types/consts' {
|
||||
**/
|
||||
existentialDeposit: Balance & AugmentedConst<ApiType>;
|
||||
};
|
||||
bounties: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* Percentage of the curator fee that will be reserved upfront as deposit for bounty curator.
|
||||
**/
|
||||
bountyCuratorDeposit: Permill & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount held on deposit for placing a bounty proposal.
|
||||
**/
|
||||
bountyDepositBase: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The delay period for which a bounty beneficiary need to wait before claim the payout.
|
||||
**/
|
||||
bountyDepositPayoutDelay: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Minimum value for a bounty.
|
||||
**/
|
||||
bountyValueMinimum: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount held on deposit per byte within bounty description.
|
||||
**/
|
||||
dataDepositPerByte: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Maximum acceptable reason length.
|
||||
**/
|
||||
maximumReasonLength: u32 & AugmentedConst<ApiType>;
|
||||
};
|
||||
contracts: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
@@ -338,6 +365,29 @@ declare module '@polkadot/api/types/consts' {
|
||||
**/
|
||||
minimumPeriod: Moment & AugmentedConst<ApiType>;
|
||||
};
|
||||
tips: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* The amount held on deposit per byte within the tip report reason.
|
||||
**/
|
||||
dataDepositPerByte: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Maximum acceptable reason length.
|
||||
**/
|
||||
maximumReasonLength: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The period for which a tip remains open after is has achieved threshold tippers.
|
||||
**/
|
||||
tipCountdown: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount of the final tip which goes to the original reporter of the tip.
|
||||
**/
|
||||
tipFindersFee: Percent & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount held on deposit for placing a tip report.
|
||||
**/
|
||||
tipReportDepositBase: BalanceOf & AugmentedConst<ApiType>;
|
||||
};
|
||||
transactionPayment: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
@@ -351,31 +401,10 @@ declare module '@polkadot/api/types/consts' {
|
||||
};
|
||||
treasury: {
|
||||
[key: string]: Codec;
|
||||
/**
|
||||
* Percentage of the curator fee that will be reserved upfront as deposit for bounty curator.
|
||||
**/
|
||||
bountyCuratorDeposit: Permill & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount held on deposit for placing a bounty proposal.
|
||||
**/
|
||||
bountyDepositBase: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The delay period for which a bounty beneficiary need to wait before claim the payout.
|
||||
**/
|
||||
bountyDepositPayoutDelay: BlockNumber & AugmentedConst<ApiType>;
|
||||
bountyValueMinimum: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Percentage of spare funds (if any) that are burnt per spend period.
|
||||
**/
|
||||
burn: Permill & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount held on deposit per byte within the tip report reason or bounty description.
|
||||
**/
|
||||
dataDepositPerByte: BalanceOf & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* Maximum acceptable reason length.
|
||||
**/
|
||||
maximumReasonLength: u32 & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The treasury's module id, used for deriving its sovereign account ID.
|
||||
**/
|
||||
@@ -393,18 +422,6 @@ declare module '@polkadot/api/types/consts' {
|
||||
* Period between successive spends.
|
||||
**/
|
||||
spendPeriod: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The period for which a tip remains open after is has achieved threshold tippers.
|
||||
**/
|
||||
tipCountdown: BlockNumber & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount of the final tip which goes to the original reporter of the tip.
|
||||
**/
|
||||
tipFindersFee: Percent & AugmentedConst<ApiType>;
|
||||
/**
|
||||
* The amount held on deposit for placing a tip report.
|
||||
**/
|
||||
tipReportDepositBase: BalanceOf & AugmentedConst<ApiType>;
|
||||
};
|
||||
vesting: {
|
||||
[key: string]: Codec;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,842 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
import type { Bytes, Option, Vec, bool, u16, u32 } from '@polkadot/types';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { BalanceStatus } from '@polkadot/types/interfaces/balances';
|
||||
import type { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collective';
|
||||
import type { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import type { PropIndex, ReferendumIndex } from '@polkadot/types/interfaces/democracy';
|
||||
import type { VoteThreshold } from '@polkadot/types/interfaces/elections';
|
||||
import type { AuthorityList } from '@polkadot/types/interfaces/grandpa';
|
||||
import type { RegistrarIndex } from '@polkadot/types/interfaces/identity';
|
||||
import type { Kind, OpaqueTimeSlot } from '@polkadot/types/interfaces/offences';
|
||||
import type { ProxyType } from '@polkadot/types/interfaces/proxy';
|
||||
import type { AccountId, AccountIndex, AssetId, Balance, BlockNumber, CallHash, Hash, PhantomData } from '@polkadot/types/interfaces/runtime';
|
||||
import type { TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import type { IdentificationTuple, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import type { ElectionCompute, EraIndex } from '@polkadot/types/interfaces/staking';
|
||||
import type { DispatchError, DispatchInfo, DispatchResult } from '@polkadot/types/interfaces/system';
|
||||
import type { BountyIndex } from '@polkadot/types/interfaces/treasury';
|
||||
import type { Timepoint } from '@polkadot/types/interfaces/utility';
|
||||
import type { ApiTypes } from '@polkadot/api/types';
|
||||
|
||||
declare module '@polkadot/api/types/events' {
|
||||
export interface AugmentedEvents<ApiType> {
|
||||
assets: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* Some assets were destroyed. \[asset_id, owner, balance\]
|
||||
**/
|
||||
Burned: AugmentedEvent<ApiType, [AssetId, AccountId, Balance]>;
|
||||
/**
|
||||
* Some asset class was created. \[asset_id, creator, owner\]
|
||||
**/
|
||||
Created: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId]>;
|
||||
/**
|
||||
* An asset class was destroyed.
|
||||
**/
|
||||
Destroyed: AugmentedEvent<ApiType, [AssetId]>;
|
||||
/**
|
||||
* Some asset class was force-created. \[asset_id, owner\]
|
||||
**/
|
||||
ForceCreated: AugmentedEvent<ApiType, [AssetId, AccountId]>;
|
||||
/**
|
||||
* Some assets was transferred by an admin. \[asset_id, from, to, amount\]
|
||||
**/
|
||||
ForceTransferred: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId, Balance]>;
|
||||
/**
|
||||
* Some account `who` was frozen. \[asset_id, who\]
|
||||
**/
|
||||
Frozen: AugmentedEvent<ApiType, [AssetId, AccountId]>;
|
||||
/**
|
||||
* Some assets were issued. \[asset_id, owner, total_supply\]
|
||||
**/
|
||||
Issued: AugmentedEvent<ApiType, [AssetId, AccountId, Balance]>;
|
||||
/**
|
||||
* The maximum amount of zombies allowed has changed. \[asset_id, max_zombies\]
|
||||
**/
|
||||
MaxZombiesChanged: AugmentedEvent<ApiType, [AssetId, u32]>;
|
||||
/**
|
||||
* The owner changed \[asset_id, owner\]
|
||||
**/
|
||||
OwnerChanged: AugmentedEvent<ApiType, [AssetId, AccountId]>;
|
||||
/**
|
||||
* The management team changed \[asset_id, issuer, admin, freezer\]
|
||||
**/
|
||||
TeamChanged: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId, AccountId]>;
|
||||
/**
|
||||
* Some account `who` was thawed. \[asset_id, who\]
|
||||
**/
|
||||
Thawed: AugmentedEvent<ApiType, [AssetId, AccountId]>;
|
||||
/**
|
||||
* Some assets were transferred. \[asset_id, from, to, amount\]
|
||||
**/
|
||||
Transferred: AugmentedEvent<ApiType, [AssetId, AccountId, AccountId, Balance]>;
|
||||
};
|
||||
balances: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A balance was set by root. \[who, free, reserved\]
|
||||
**/
|
||||
BalanceSet: AugmentedEvent<ApiType, [AccountId, Balance, Balance]>;
|
||||
/**
|
||||
* Some amount was deposited (e.g. for transaction fees). \[who, deposit\]
|
||||
**/
|
||||
Deposit: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* An account was removed whose balance was non-zero but below ExistentialDeposit,
|
||||
* resulting in an outright loss. \[account, balance\]
|
||||
**/
|
||||
DustLost: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* An account was created with some free balance. \[account, free_balance\]
|
||||
**/
|
||||
Endowed: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* Some balance was reserved (moved from free to reserved). \[who, value\]
|
||||
**/
|
||||
Reserved: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* Some balance was moved from the reserve of the first account to the second account.
|
||||
* Final argument indicates the destination balance type.
|
||||
* \[from, to, balance, destination_status\]
|
||||
**/
|
||||
ReserveRepatriated: AugmentedEvent<ApiType, [AccountId, AccountId, Balance, BalanceStatus]>;
|
||||
/**
|
||||
* Transfer succeeded. \[from, to, value\]
|
||||
**/
|
||||
Transfer: AugmentedEvent<ApiType, [AccountId, AccountId, Balance]>;
|
||||
/**
|
||||
* Some balance was unreserved (moved from reserved to free). \[who, value\]
|
||||
**/
|
||||
Unreserved: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
};
|
||||
bounties: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A bounty is awarded to a beneficiary. \[index, beneficiary\]
|
||||
**/
|
||||
BountyAwarded: AugmentedEvent<ApiType, [BountyIndex, AccountId]>;
|
||||
/**
|
||||
* A bounty proposal is funded and became active. \[index\]
|
||||
**/
|
||||
BountyBecameActive: AugmentedEvent<ApiType, [BountyIndex]>;
|
||||
/**
|
||||
* A bounty is cancelled. \[index\]
|
||||
**/
|
||||
BountyCanceled: AugmentedEvent<ApiType, [BountyIndex]>;
|
||||
/**
|
||||
* A bounty is claimed by beneficiary. \[index, payout, beneficiary\]
|
||||
**/
|
||||
BountyClaimed: AugmentedEvent<ApiType, [BountyIndex, Balance, AccountId]>;
|
||||
/**
|
||||
* A bounty expiry is extended. \[index\]
|
||||
**/
|
||||
BountyExtended: AugmentedEvent<ApiType, [BountyIndex]>;
|
||||
/**
|
||||
* New bounty proposal. \[index\]
|
||||
**/
|
||||
BountyProposed: AugmentedEvent<ApiType, [BountyIndex]>;
|
||||
/**
|
||||
* A bounty proposal was rejected; funds were slashed. \[index, bond\]
|
||||
**/
|
||||
BountyRejected: AugmentedEvent<ApiType, [BountyIndex, Balance]>;
|
||||
};
|
||||
contracts: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* Code with the specified hash has been stored.
|
||||
* \[code_hash\]
|
||||
**/
|
||||
CodeStored: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* An event deposited upon execution of a contract from the account.
|
||||
* \[account, data\]
|
||||
**/
|
||||
ContractExecution: AugmentedEvent<ApiType, [AccountId, Bytes]>;
|
||||
/**
|
||||
* Contract has been evicted and is now in tombstone state.
|
||||
* \[contract, tombstone\]
|
||||
*
|
||||
* # Params
|
||||
*
|
||||
* - `contract`: `AccountId`: The account ID of the evicted contract.
|
||||
* - `tombstone`: `bool`: True if the evicted contract left behind a tombstone.
|
||||
**/
|
||||
Evicted: AugmentedEvent<ApiType, [AccountId, bool]>;
|
||||
/**
|
||||
* Contract deployed by address at the specified address. \[owner, contract\]
|
||||
**/
|
||||
Instantiated: AugmentedEvent<ApiType, [AccountId, AccountId]>;
|
||||
/**
|
||||
* Restoration for a contract has been successful.
|
||||
* \[donor, dest, code_hash, rent_allowance\]
|
||||
*
|
||||
* # Params
|
||||
*
|
||||
* - `donor`: `AccountId`: Account ID of the restoring contract
|
||||
* - `dest`: `AccountId`: Account ID of the restored contract
|
||||
* - `code_hash`: `Hash`: Code hash of the restored contract
|
||||
* - `rent_allowance: `Balance`: Rent allowance of the restored contract
|
||||
**/
|
||||
Restored: AugmentedEvent<ApiType, [AccountId, AccountId, Hash, Balance]>;
|
||||
/**
|
||||
* Triggered when the current \[schedule\] is updated.
|
||||
**/
|
||||
ScheduleUpdated: AugmentedEvent<ApiType, [u32]>;
|
||||
};
|
||||
council: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A motion was approved by the required threshold.
|
||||
* \[proposal_hash\]
|
||||
**/
|
||||
Approved: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* A proposal was closed because its threshold was reached or after its duration was up.
|
||||
* \[proposal_hash, yes, no\]
|
||||
**/
|
||||
Closed: AugmentedEvent<ApiType, [Hash, MemberCount, MemberCount]>;
|
||||
/**
|
||||
* A motion was not approved by the required threshold.
|
||||
* \[proposal_hash\]
|
||||
**/
|
||||
Disapproved: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* A motion was executed; result will be `Ok` if it returned without error.
|
||||
* \[proposal_hash, result\]
|
||||
**/
|
||||
Executed: AugmentedEvent<ApiType, [Hash, DispatchResult]>;
|
||||
/**
|
||||
* A single member did some action; result will be `Ok` if it returned without error.
|
||||
* \[proposal_hash, result\]
|
||||
**/
|
||||
MemberExecuted: AugmentedEvent<ApiType, [Hash, DispatchResult]>;
|
||||
/**
|
||||
* A motion (given hash) has been proposed (by given account) with a threshold (given
|
||||
* `MemberCount`).
|
||||
* \[account, proposal_index, proposal_hash, threshold\]
|
||||
**/
|
||||
Proposed: AugmentedEvent<ApiType, [AccountId, ProposalIndex, Hash, MemberCount]>;
|
||||
/**
|
||||
* A motion (given hash) has been voted on by given account, leaving
|
||||
* a tally (yes votes and no votes given respectively as `MemberCount`).
|
||||
* \[account, proposal_hash, voted, yes, no\]
|
||||
**/
|
||||
Voted: AugmentedEvent<ApiType, [AccountId, Hash, bool, MemberCount, MemberCount]>;
|
||||
};
|
||||
democracy: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A proposal \[hash\] has been blacklisted permanently.
|
||||
**/
|
||||
Blacklisted: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* A referendum has been cancelled. \[ref_index\]
|
||||
**/
|
||||
Cancelled: AugmentedEvent<ApiType, [ReferendumIndex]>;
|
||||
/**
|
||||
* An account has delegated their vote to another account. \[who, target\]
|
||||
**/
|
||||
Delegated: AugmentedEvent<ApiType, [AccountId, AccountId]>;
|
||||
/**
|
||||
* A proposal has been enacted. \[ref_index, is_ok\]
|
||||
**/
|
||||
Executed: AugmentedEvent<ApiType, [ReferendumIndex, bool]>;
|
||||
/**
|
||||
* An external proposal has been tabled.
|
||||
**/
|
||||
ExternalTabled: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* A proposal has been rejected by referendum. \[ref_index\]
|
||||
**/
|
||||
NotPassed: AugmentedEvent<ApiType, [ReferendumIndex]>;
|
||||
/**
|
||||
* A proposal has been approved by referendum. \[ref_index\]
|
||||
**/
|
||||
Passed: AugmentedEvent<ApiType, [ReferendumIndex]>;
|
||||
/**
|
||||
* A proposal could not be executed because its preimage was invalid.
|
||||
* \[proposal_hash, ref_index\]
|
||||
**/
|
||||
PreimageInvalid: AugmentedEvent<ApiType, [Hash, ReferendumIndex]>;
|
||||
/**
|
||||
* A proposal could not be executed because its preimage was missing.
|
||||
* \[proposal_hash, ref_index\]
|
||||
**/
|
||||
PreimageMissing: AugmentedEvent<ApiType, [Hash, ReferendumIndex]>;
|
||||
/**
|
||||
* A proposal's preimage was noted, and the deposit taken. \[proposal_hash, who, deposit\]
|
||||
**/
|
||||
PreimageNoted: AugmentedEvent<ApiType, [Hash, AccountId, Balance]>;
|
||||
/**
|
||||
* A registered preimage was removed and the deposit collected by the reaper.
|
||||
* \[proposal_hash, provider, deposit, reaper\]
|
||||
**/
|
||||
PreimageReaped: AugmentedEvent<ApiType, [Hash, AccountId, Balance, AccountId]>;
|
||||
/**
|
||||
* A proposal preimage was removed and used (the deposit was returned).
|
||||
* \[proposal_hash, provider, deposit\]
|
||||
**/
|
||||
PreimageUsed: AugmentedEvent<ApiType, [Hash, AccountId, Balance]>;
|
||||
/**
|
||||
* A motion has been proposed by a public account. \[proposal_index, deposit\]
|
||||
**/
|
||||
Proposed: AugmentedEvent<ApiType, [PropIndex, Balance]>;
|
||||
/**
|
||||
* A referendum has begun. \[ref_index, threshold\]
|
||||
**/
|
||||
Started: AugmentedEvent<ApiType, [ReferendumIndex, VoteThreshold]>;
|
||||
/**
|
||||
* A public proposal has been tabled for referendum vote. \[proposal_index, deposit, depositors\]
|
||||
**/
|
||||
Tabled: AugmentedEvent<ApiType, [PropIndex, Balance, Vec<AccountId>]>;
|
||||
/**
|
||||
* An \[account\] has cancelled a previous delegation operation.
|
||||
**/
|
||||
Undelegated: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* An \[account\] has been unlocked successfully.
|
||||
**/
|
||||
Unlocked: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* An external proposal has been vetoed. \[who, proposal_hash, until\]
|
||||
**/
|
||||
Vetoed: AugmentedEvent<ApiType, [AccountId, Hash, BlockNumber]>;
|
||||
};
|
||||
elections: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A candidate was slashed due to failing to obtain a seat as member or runner-up
|
||||
**/
|
||||
CandidateSlashed: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* Internal error happened while trying to perform election.
|
||||
**/
|
||||
ElectionError: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* No (or not enough) candidates existed for this round. This is different from
|
||||
* `NewTerm(\[\])`. See the description of `NewTerm`.
|
||||
**/
|
||||
EmptyTerm: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* A \[member\] has been removed. This should always be followed by either `NewTerm` or
|
||||
* `EmptyTerm`.
|
||||
**/
|
||||
MemberKicked: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A \[member\] has renounced their candidacy.
|
||||
**/
|
||||
MemberRenounced: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A new term with \[new_members\]. This indicates that enough candidates existed to run the
|
||||
* election, not that enough have has been elected. The inner value must be examined for
|
||||
* this purpose. A `NewTerm(\[\])` indicates that some candidates got their bond slashed and
|
||||
* none were elected, whilst `EmptyTerm` means that no candidates existed to begin with.
|
||||
**/
|
||||
NewTerm: AugmentedEvent<ApiType, [Vec<ITuple<[AccountId, Balance]>>]>;
|
||||
/**
|
||||
* A seat holder (member or runner-up) was slashed due to failing to retaining their position.
|
||||
**/
|
||||
SeatHolderSlashed: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* A voter was reported with the the report being successful or not.
|
||||
* \[voter, reporter, success\]
|
||||
**/
|
||||
VoterReported: AugmentedEvent<ApiType, [AccountId, AccountId, bool]>;
|
||||
};
|
||||
grandpa: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* New authority set has been applied. \[authority_set\]
|
||||
**/
|
||||
NewAuthorities: AugmentedEvent<ApiType, [AuthorityList]>;
|
||||
/**
|
||||
* Current authority set has been paused.
|
||||
**/
|
||||
Paused: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* Current authority set has been resumed.
|
||||
**/
|
||||
Resumed: AugmentedEvent<ApiType, []>;
|
||||
};
|
||||
identity: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A name was cleared, and the given balance returned. \[who, deposit\]
|
||||
**/
|
||||
IdentityCleared: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* A name was removed and the given balance slashed. \[who, deposit\]
|
||||
**/
|
||||
IdentityKilled: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* A name was set or reset (which will remove all judgements). \[who\]
|
||||
**/
|
||||
IdentitySet: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A judgement was given by a registrar. \[target, registrar_index\]
|
||||
**/
|
||||
JudgementGiven: AugmentedEvent<ApiType, [AccountId, RegistrarIndex]>;
|
||||
/**
|
||||
* A judgement was asked from a registrar. \[who, registrar_index\]
|
||||
**/
|
||||
JudgementRequested: AugmentedEvent<ApiType, [AccountId, RegistrarIndex]>;
|
||||
/**
|
||||
* A judgement request was retracted. \[who, registrar_index\]
|
||||
**/
|
||||
JudgementUnrequested: AugmentedEvent<ApiType, [AccountId, RegistrarIndex]>;
|
||||
/**
|
||||
* A registrar was added. \[registrar_index\]
|
||||
**/
|
||||
RegistrarAdded: AugmentedEvent<ApiType, [RegistrarIndex]>;
|
||||
/**
|
||||
* A sub-identity was added to an identity and the deposit paid. \[sub, main, deposit\]
|
||||
**/
|
||||
SubIdentityAdded: AugmentedEvent<ApiType, [AccountId, AccountId, Balance]>;
|
||||
/**
|
||||
* A sub-identity was removed from an identity and the deposit freed.
|
||||
* \[sub, main, deposit\]
|
||||
**/
|
||||
SubIdentityRemoved: AugmentedEvent<ApiType, [AccountId, AccountId, Balance]>;
|
||||
/**
|
||||
* A sub-identity was cleared, and the given deposit repatriated from the
|
||||
* main identity account to the sub-identity account. \[sub, main, deposit\]
|
||||
**/
|
||||
SubIdentityRevoked: AugmentedEvent<ApiType, [AccountId, AccountId, Balance]>;
|
||||
};
|
||||
imOnline: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* At the end of the session, no offence was committed.
|
||||
**/
|
||||
AllGood: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* A new heartbeat was received from `AuthorityId` \[authority_id\]
|
||||
**/
|
||||
HeartbeatReceived: AugmentedEvent<ApiType, [AuthorityId]>;
|
||||
/**
|
||||
* At the end of the session, at least one validator was found to be \[offline\].
|
||||
**/
|
||||
SomeOffline: AugmentedEvent<ApiType, [Vec<IdentificationTuple>]>;
|
||||
};
|
||||
indices: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A account index was assigned. \[index, who\]
|
||||
**/
|
||||
IndexAssigned: AugmentedEvent<ApiType, [AccountId, AccountIndex]>;
|
||||
/**
|
||||
* A account index has been freed up (unassigned). \[index\]
|
||||
**/
|
||||
IndexFreed: AugmentedEvent<ApiType, [AccountIndex]>;
|
||||
/**
|
||||
* A account index has been frozen to its current account ID. \[index, who\]
|
||||
**/
|
||||
IndexFrozen: AugmentedEvent<ApiType, [AccountIndex, AccountId]>;
|
||||
};
|
||||
multisig: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A multisig operation has been approved by someone.
|
||||
* \[approving, timepoint, multisig, call_hash\]
|
||||
**/
|
||||
MultisigApproval: AugmentedEvent<ApiType, [AccountId, Timepoint, AccountId, CallHash]>;
|
||||
/**
|
||||
* A multisig operation has been cancelled. \[cancelling, timepoint, multisig, call_hash\]
|
||||
**/
|
||||
MultisigCancelled: AugmentedEvent<ApiType, [AccountId, Timepoint, AccountId, CallHash]>;
|
||||
/**
|
||||
* A multisig operation has been executed. \[approving, timepoint, multisig, call_hash\]
|
||||
**/
|
||||
MultisigExecuted: AugmentedEvent<ApiType, [AccountId, Timepoint, AccountId, CallHash, DispatchResult]>;
|
||||
/**
|
||||
* A new multisig operation has begun. \[approving, multisig, call_hash\]
|
||||
**/
|
||||
NewMultisig: AugmentedEvent<ApiType, [AccountId, AccountId, CallHash]>;
|
||||
};
|
||||
offences: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* There is an offence reported of the given `kind` happened at the `session_index` and
|
||||
* (kind-specific) time slot. This event is not deposited for duplicate slashes. last
|
||||
* element indicates of the offence was applied (true) or queued (false)
|
||||
* \[kind, timeslot, applied\].
|
||||
**/
|
||||
Offence: AugmentedEvent<ApiType, [Kind, OpaqueTimeSlot, bool]>;
|
||||
};
|
||||
proxy: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* An announcement was placed to make a call in the future. \[real, proxy, call_hash\]
|
||||
**/
|
||||
Announced: AugmentedEvent<ApiType, [AccountId, AccountId, Hash]>;
|
||||
/**
|
||||
* Anonymous account has been created by new proxy with given
|
||||
* disambiguation index and proxy type. \[anonymous, who, proxy_type, disambiguation_index\]
|
||||
**/
|
||||
AnonymousCreated: AugmentedEvent<ApiType, [AccountId, AccountId, ProxyType, u16]>;
|
||||
/**
|
||||
* A proxy was executed correctly, with the given \[result\].
|
||||
**/
|
||||
ProxyExecuted: AugmentedEvent<ApiType, [DispatchResult]>;
|
||||
};
|
||||
recovery: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* Lost account has been successfully recovered by rescuer account.
|
||||
* \[lost, rescuer\]
|
||||
**/
|
||||
AccountRecovered: AugmentedEvent<ApiType, [AccountId, AccountId]>;
|
||||
/**
|
||||
* A recovery process for lost account by rescuer account has been closed.
|
||||
* \[lost, rescuer\]
|
||||
**/
|
||||
RecoveryClosed: AugmentedEvent<ApiType, [AccountId, AccountId]>;
|
||||
/**
|
||||
* A recovery process has been set up for an \[account\].
|
||||
**/
|
||||
RecoveryCreated: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A recovery process has been initiated for lost account by rescuer account.
|
||||
* \[lost, rescuer\]
|
||||
**/
|
||||
RecoveryInitiated: AugmentedEvent<ApiType, [AccountId, AccountId]>;
|
||||
/**
|
||||
* A recovery process has been removed for an \[account\].
|
||||
**/
|
||||
RecoveryRemoved: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A recovery process for lost account by rescuer account has been vouched for by sender.
|
||||
* \[lost, rescuer, sender\]
|
||||
**/
|
||||
RecoveryVouched: AugmentedEvent<ApiType, [AccountId, AccountId, AccountId]>;
|
||||
};
|
||||
scheduler: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* Canceled some task. \[when, index\]
|
||||
**/
|
||||
Canceled: AugmentedEvent<ApiType, [BlockNumber, u32]>;
|
||||
/**
|
||||
* Dispatched some task. \[task, id, result\]
|
||||
**/
|
||||
Dispatched: AugmentedEvent<ApiType, [TaskAddress, Option<Bytes>, DispatchResult]>;
|
||||
/**
|
||||
* Scheduled some task. \[when, index\]
|
||||
**/
|
||||
Scheduled: AugmentedEvent<ApiType, [BlockNumber, u32]>;
|
||||
};
|
||||
session: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* New session has happened. Note that the argument is the \[session_index\], not the block
|
||||
* number as the type might suggest.
|
||||
**/
|
||||
NewSession: AugmentedEvent<ApiType, [SessionIndex]>;
|
||||
};
|
||||
society: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A \[candidate\] was dropped (due to an excess of bids in the system).
|
||||
**/
|
||||
AutoUnbid: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A membership bid just happened. The given account is the candidate's ID and their offer
|
||||
* is the second. \[candidate_id, offer\]
|
||||
**/
|
||||
Bid: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* A \[candidate\] has been suspended
|
||||
**/
|
||||
CandidateSuspended: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A \[member\] has been challenged
|
||||
**/
|
||||
Challenged: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A vote has been placed for a defending member \[voter, vote\]
|
||||
**/
|
||||
DefenderVote: AugmentedEvent<ApiType, [AccountId, bool]>;
|
||||
/**
|
||||
* Some funds were deposited into the society account. \[value\]
|
||||
**/
|
||||
Deposit: AugmentedEvent<ApiType, [Balance]>;
|
||||
/**
|
||||
* The society is founded by the given identity. \[founder\]
|
||||
**/
|
||||
Founded: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A group of candidates have been inducted. The batch's primary is the first value, the
|
||||
* batch in full is the second. \[primary, candidates\]
|
||||
**/
|
||||
Inducted: AugmentedEvent<ApiType, [AccountId, Vec<AccountId>]>;
|
||||
/**
|
||||
* A \[member\] has been suspended
|
||||
**/
|
||||
MemberSuspended: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A new \[max\] member count has been set
|
||||
**/
|
||||
NewMaxMembers: AugmentedEvent<ApiType, [u32]>;
|
||||
/**
|
||||
* A suspended member has been judged. \[who, judged\]
|
||||
**/
|
||||
SuspendedMemberJudgement: AugmentedEvent<ApiType, [AccountId, bool]>;
|
||||
/**
|
||||
* A \[candidate\] was dropped (by their request).
|
||||
**/
|
||||
Unbid: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* Society is unfounded. \[founder\]
|
||||
**/
|
||||
Unfounded: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A \[candidate\] was dropped (by request of who vouched for them).
|
||||
**/
|
||||
Unvouch: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A vote has been placed \[candidate, voter, vote\]
|
||||
**/
|
||||
Vote: AugmentedEvent<ApiType, [AccountId, AccountId, bool]>;
|
||||
/**
|
||||
* A membership bid just happened by vouching. The given account is the candidate's ID and
|
||||
* their offer is the second. The vouching party is the third. \[candidate_id, offer, vouching\]
|
||||
**/
|
||||
Vouch: AugmentedEvent<ApiType, [AccountId, Balance, AccountId]>;
|
||||
};
|
||||
staking: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* An account has bonded this amount. \[stash, amount\]
|
||||
*
|
||||
* NOTE: This event is only emitted when funds are bonded via a dispatchable. Notably,
|
||||
* it will not be emitted for staking rewards when they are added to stake.
|
||||
**/
|
||||
Bonded: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* The era payout has been set; the first balance is the validator-payout; the second is
|
||||
* the remainder from the maximum amount of reward.
|
||||
* \[era_index, validator_payout, remainder\]
|
||||
**/
|
||||
EraPayout: AugmentedEvent<ApiType, [EraIndex, Balance, Balance]>;
|
||||
/**
|
||||
* An old slashing report from a prior era was discarded because it could
|
||||
* not be processed. \[session_index\]
|
||||
**/
|
||||
OldSlashingReportDiscarded: AugmentedEvent<ApiType, [SessionIndex]>;
|
||||
/**
|
||||
* The staker has been rewarded by this amount. \[stash, amount\]
|
||||
**/
|
||||
Reward: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* One validator (and its nominators) has been slashed by the given amount.
|
||||
* \[validator, amount\]
|
||||
**/
|
||||
Slash: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* A new solution for the upcoming election has been stored. \[compute\]
|
||||
**/
|
||||
SolutionStored: AugmentedEvent<ApiType, [ElectionCompute]>;
|
||||
/**
|
||||
* A new set of stakers was elected with the given \[compute\].
|
||||
**/
|
||||
StakingElection: AugmentedEvent<ApiType, [ElectionCompute]>;
|
||||
/**
|
||||
* An account has unbonded this amount. \[stash, amount\]
|
||||
**/
|
||||
Unbonded: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
/**
|
||||
* An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance`
|
||||
* from the unlocking queue. \[stash, amount\]
|
||||
**/
|
||||
Withdrawn: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
};
|
||||
sudo: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* The \[sudoer\] just switched identity; the old key is supplied.
|
||||
**/
|
||||
KeyChanged: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A sudo just took place. \[result\]
|
||||
**/
|
||||
Sudid: AugmentedEvent<ApiType, [DispatchResult]>;
|
||||
/**
|
||||
* A sudo just took place. \[result\]
|
||||
**/
|
||||
SudoAsDone: AugmentedEvent<ApiType, [DispatchResult]>;
|
||||
};
|
||||
system: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* `:code` was updated.
|
||||
**/
|
||||
CodeUpdated: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* An extrinsic failed. \[error, info\]
|
||||
**/
|
||||
ExtrinsicFailed: AugmentedEvent<ApiType, [DispatchError, DispatchInfo]>;
|
||||
/**
|
||||
* An extrinsic completed successfully. \[info\]
|
||||
**/
|
||||
ExtrinsicSuccess: AugmentedEvent<ApiType, [DispatchInfo]>;
|
||||
/**
|
||||
* An \[account\] was reaped.
|
||||
**/
|
||||
KilledAccount: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* A new \[account\] was created.
|
||||
**/
|
||||
NewAccount: AugmentedEvent<ApiType, [AccountId]>;
|
||||
};
|
||||
technicalCommittee: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A motion was approved by the required threshold.
|
||||
* \[proposal_hash\]
|
||||
**/
|
||||
Approved: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* A proposal was closed because its threshold was reached or after its duration was up.
|
||||
* \[proposal_hash, yes, no\]
|
||||
**/
|
||||
Closed: AugmentedEvent<ApiType, [Hash, MemberCount, MemberCount]>;
|
||||
/**
|
||||
* A motion was not approved by the required threshold.
|
||||
* \[proposal_hash\]
|
||||
**/
|
||||
Disapproved: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* A motion was executed; result will be `Ok` if it returned without error.
|
||||
* \[proposal_hash, result\]
|
||||
**/
|
||||
Executed: AugmentedEvent<ApiType, [Hash, DispatchResult]>;
|
||||
/**
|
||||
* A single member did some action; result will be `Ok` if it returned without error.
|
||||
* \[proposal_hash, result\]
|
||||
**/
|
||||
MemberExecuted: AugmentedEvent<ApiType, [Hash, DispatchResult]>;
|
||||
/**
|
||||
* A motion (given hash) has been proposed (by given account) with a threshold (given
|
||||
* `MemberCount`).
|
||||
* \[account, proposal_index, proposal_hash, threshold\]
|
||||
**/
|
||||
Proposed: AugmentedEvent<ApiType, [AccountId, ProposalIndex, Hash, MemberCount]>;
|
||||
/**
|
||||
* A motion (given hash) has been voted on by given account, leaving
|
||||
* a tally (yes votes and no votes given respectively as `MemberCount`).
|
||||
* \[account, proposal_hash, voted, yes, no\]
|
||||
**/
|
||||
Voted: AugmentedEvent<ApiType, [AccountId, Hash, bool, MemberCount, MemberCount]>;
|
||||
};
|
||||
technicalMembership: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* Phantom member, never used.
|
||||
**/
|
||||
Dummy: AugmentedEvent<ApiType, [PhantomData]>;
|
||||
/**
|
||||
* One of the members' keys changed.
|
||||
**/
|
||||
KeyChanged: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* The given member was added; see the transaction for who.
|
||||
**/
|
||||
MemberAdded: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* The given member was removed; see the transaction for who.
|
||||
**/
|
||||
MemberRemoved: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* The membership was reset; see the transaction for who the new set is.
|
||||
**/
|
||||
MembersReset: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* Two members were swapped; see the transaction for who.
|
||||
**/
|
||||
MembersSwapped: AugmentedEvent<ApiType, []>;
|
||||
};
|
||||
tips: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* A new tip suggestion has been opened. \[tip_hash\]
|
||||
**/
|
||||
NewTip: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* A tip suggestion has been closed. \[tip_hash, who, payout\]
|
||||
**/
|
||||
TipClosed: AugmentedEvent<ApiType, [Hash, AccountId, Balance]>;
|
||||
/**
|
||||
* A tip suggestion has reached threshold and is closing. \[tip_hash\]
|
||||
**/
|
||||
TipClosing: AugmentedEvent<ApiType, [Hash]>;
|
||||
/**
|
||||
* A tip suggestion has been retracted. \[tip_hash\]
|
||||
**/
|
||||
TipRetracted: AugmentedEvent<ApiType, [Hash]>;
|
||||
};
|
||||
treasury: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* Some funds have been allocated. \[proposal_index, award, beneficiary\]
|
||||
**/
|
||||
Awarded: AugmentedEvent<ApiType, [ProposalIndex, Balance, AccountId]>;
|
||||
/**
|
||||
* Some of our funds have been burnt. \[burn\]
|
||||
**/
|
||||
Burnt: AugmentedEvent<ApiType, [Balance]>;
|
||||
/**
|
||||
* Some funds have been deposited. \[deposit\]
|
||||
**/
|
||||
Deposit: AugmentedEvent<ApiType, [Balance]>;
|
||||
/**
|
||||
* New proposal. \[proposal_index\]
|
||||
**/
|
||||
Proposed: AugmentedEvent<ApiType, [ProposalIndex]>;
|
||||
/**
|
||||
* A proposal was rejected; funds were slashed. \[proposal_index, slashed\]
|
||||
**/
|
||||
Rejected: AugmentedEvent<ApiType, [ProposalIndex, Balance]>;
|
||||
/**
|
||||
* Spending has finished; this is the amount that rolls over until next spend.
|
||||
* \[budget_remaining\]
|
||||
**/
|
||||
Rollover: AugmentedEvent<ApiType, [Balance]>;
|
||||
/**
|
||||
* We have ended a spend period and will now allocate funds. \[budget_remaining\]
|
||||
**/
|
||||
Spending: AugmentedEvent<ApiType, [Balance]>;
|
||||
};
|
||||
utility: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* Batch of dispatches completed fully with no error.
|
||||
**/
|
||||
BatchCompleted: AugmentedEvent<ApiType, []>;
|
||||
/**
|
||||
* Batch of dispatches did not complete fully. Index of first failing dispatch given, as
|
||||
* well as the error. \[index, error\]
|
||||
**/
|
||||
BatchInterrupted: AugmentedEvent<ApiType, [u32, DispatchError]>;
|
||||
};
|
||||
vesting: {
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
/**
|
||||
* An \[account\] has become fully vested. No further vesting can happen.
|
||||
**/
|
||||
VestingCompleted: AugmentedEvent<ApiType, [AccountId]>;
|
||||
/**
|
||||
* The amount vested has been updated. This could indicate more funds are available. The
|
||||
* balance given is the amount which is left unvested (and thus locked).
|
||||
* \[account, unvested\]
|
||||
**/
|
||||
VestingUpdated: AugmentedEvent<ApiType, [AccountId, Balance]>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface DecoratedEvents<ApiType extends ApiTypes> extends AugmentedEvents<ApiType> {
|
||||
[key: string]: ModuleEvents<ApiType>;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './consts';
|
||||
import './errors';
|
||||
import './events';
|
||||
import './query';
|
||||
import './rpc';
|
||||
import './tx';
|
||||
|
||||
+208
-202
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
/* eslint-disable */
|
||||
|
||||
import type { Metadata } from '@polkadot/metadata';
|
||||
import type { Bytes, HashMap, Json, Null, Option, StorageKey, Text, Vec, bool, u32, u64 } from '@polkadot/types';
|
||||
import type { Bytes, HashMap, Json, Null, Option, StorageKey, Text, U256, U64, Vec, bool, u32, u64 } from '@polkadot/types';
|
||||
import type { AnyNumber, Codec, IExtrinsic, Observable } from '@polkadot/types/types';
|
||||
import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
|
||||
import type { EpochAuthorship } from '@polkadot/types/interfaces/babe';
|
||||
@@ -11,12 +11,13 @@ import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
|
||||
import type { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import type { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
|
||||
import type { CreatedBlock } from '@polkadot/types/interfaces/engine';
|
||||
import type { EthAccount, EthCallRequest, EthFilter, EthLog, EthReceipt, EthRichBlock, EthSubKind, EthSubParams, EthSyncStatus, EthTransaction, EthTransactionRequest, EthWork } from '@polkadot/types/interfaces/eth';
|
||||
import type { Extrinsic } from '@polkadot/types/interfaces/extrinsics';
|
||||
import type { EncodedFinalityProofs, JustificationNotification, ReportedRoundStates } from '@polkadot/types/interfaces/grandpa';
|
||||
import type { StorageKind } from '@polkadot/types/interfaces/offchain';
|
||||
import type { RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
|
||||
import type { RpcMethods } from '@polkadot/types/interfaces/rpc';
|
||||
import type { AccountId, BlockNumber, H256, Hash, Header, Index, Justification, KeyValue, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime';
|
||||
import type { AccountId, BlockNumber, H160, H256, H64, Hash, Header, Index, Justification, KeyValue, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime';
|
||||
import type { ReadProof, RuntimeVersion } from '@polkadot/types/interfaces/state';
|
||||
import type { ApplyExtrinsicResult, ChainProperties, ChainType, Health, NetworkState, NodeRole, PeerInfo, SyncState } from '@polkadot/types/interfaces/system';
|
||||
|
||||
@@ -134,6 +135,160 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
**/
|
||||
finalizeBlock: AugmentedRpc<(hash: BlockHash | string | Uint8Array, justification?: Justification | string | Uint8Array) => Observable<bool>>;
|
||||
};
|
||||
eth: {
|
||||
/**
|
||||
* Returns accounts list.
|
||||
**/
|
||||
accounts: AugmentedRpc<() => Observable<Vec<H160>>>;
|
||||
/**
|
||||
* Returns balance of the given account.
|
||||
**/
|
||||
blockNumber: AugmentedRpc<() => Observable<U256>>;
|
||||
/**
|
||||
* Call contract, returning the output data.
|
||||
**/
|
||||
call: AugmentedRpc<(request: EthCallRequest | { from?: any; to?: any; gasPrice?: any; gas?: any; value?: any; data?: any; nonce?: any } | string | Uint8Array, number?: BlockNumber | AnyNumber | Uint8Array) => Observable<Bytes>>;
|
||||
/**
|
||||
* Returns the chain ID used for transaction signing at the current best block. None is returned if not available.
|
||||
**/
|
||||
chainId: AugmentedRpc<() => Observable<U64>>;
|
||||
/**
|
||||
* Returns block author.
|
||||
**/
|
||||
coinbase: AugmentedRpc<() => Observable<H160>>;
|
||||
/**
|
||||
* Estimate gas needed for execution of given contract.
|
||||
**/
|
||||
estimateGas: AugmentedRpc<(request: EthCallRequest | { from?: any; to?: any; gasPrice?: any; gas?: any; value?: any; data?: any; nonce?: any } | string | Uint8Array, number?: BlockNumber | AnyNumber | Uint8Array) => Observable<U256>>;
|
||||
/**
|
||||
* Returns current gas price.
|
||||
**/
|
||||
gasPrice: AugmentedRpc<() => Observable<U256>>;
|
||||
/**
|
||||
* Returns balance of the given account.
|
||||
**/
|
||||
getBalance: AugmentedRpc<(address: H160 | string | Uint8Array, number?: BlockNumber | AnyNumber | Uint8Array) => Observable<U256>>;
|
||||
/**
|
||||
* Returns block with given hash.
|
||||
**/
|
||||
getBlockByHash: AugmentedRpc<(hash: H256 | string | Uint8Array, full: bool | boolean | Uint8Array) => Observable<Option<EthRichBlock>>>;
|
||||
/**
|
||||
* Returns block with given number.
|
||||
**/
|
||||
getBlockByNumber: AugmentedRpc<(block: BlockNumber | AnyNumber | Uint8Array, full: bool | boolean | Uint8Array) => Observable<Option<EthRichBlock>>>;
|
||||
/**
|
||||
* Returns the number of transactions in a block with given hash.
|
||||
**/
|
||||
getBlockTransactionCountByHash: AugmentedRpc<(hash: H256 | string | Uint8Array) => Observable<U256>>;
|
||||
/**
|
||||
* Returns the number of transactions in a block with given block number.
|
||||
**/
|
||||
getBlockTransactionCountByNumber: AugmentedRpc<(block: BlockNumber | AnyNumber | Uint8Array) => Observable<U256>>;
|
||||
/**
|
||||
* Returns the code at given address at given time (block number).
|
||||
**/
|
||||
getCode: AugmentedRpc<(address: H160 | string | Uint8Array, number?: BlockNumber | AnyNumber | Uint8Array) => Observable<Bytes>>;
|
||||
/**
|
||||
* Returns logs matching given filter object.
|
||||
**/
|
||||
getLogs: AugmentedRpc<(filter: EthFilter | { fromBlock?: any; toBlock?: any; blockHash?: any; address?: any; topics?: any } | string | Uint8Array) => Observable<Vec<EthLog>>>;
|
||||
/**
|
||||
* Returns proof for account and storage.
|
||||
**/
|
||||
getProof: AugmentedRpc<(address: H160 | string | Uint8Array, storageKeys: Vec<H256> | (H256 | string | Uint8Array)[], number: BlockNumber | AnyNumber | Uint8Array) => Observable<EthAccount>>;
|
||||
/**
|
||||
* Returns content of the storage at given address.
|
||||
**/
|
||||
getStorageAt: AugmentedRpc<(address: H160 | string | Uint8Array, index: U256 | AnyNumber | Uint8Array, number?: BlockNumber | AnyNumber | Uint8Array) => Observable<H256>>;
|
||||
/**
|
||||
* Returns transaction at given block hash and index.
|
||||
**/
|
||||
getTransactionByBlockHashAndIndex: AugmentedRpc<(hash: H256 | string | Uint8Array, index: U256 | AnyNumber | Uint8Array) => Observable<EthTransaction>>;
|
||||
/**
|
||||
* Returns transaction by given block number and index.
|
||||
**/
|
||||
getTransactionByBlockNumberAndIndex: AugmentedRpc<(number: BlockNumber | AnyNumber | Uint8Array, index: U256 | AnyNumber | Uint8Array) => Observable<EthTransaction>>;
|
||||
/**
|
||||
* Get transaction by its hash.
|
||||
**/
|
||||
getTransactionByHash: AugmentedRpc<(hash: H256 | string | Uint8Array) => Observable<EthTransaction>>;
|
||||
/**
|
||||
* Returns the number of transactions sent from given address at given time (block number).
|
||||
**/
|
||||
getTransactionCount: AugmentedRpc<(hash: H256 | string | Uint8Array, number?: BlockNumber | AnyNumber | Uint8Array) => Observable<U256>>;
|
||||
/**
|
||||
* Returns transaction receipt by transaction hash.
|
||||
**/
|
||||
getTransactionReceipt: AugmentedRpc<(hash: H256 | string | Uint8Array) => Observable<EthReceipt>>;
|
||||
/**
|
||||
* Returns an uncles at given block and index.
|
||||
**/
|
||||
getUncleByBlockHashAndIndex: AugmentedRpc<(hash: H256 | string | Uint8Array, index: U256 | AnyNumber | Uint8Array) => Observable<EthRichBlock>>;
|
||||
/**
|
||||
* Returns an uncles at given block and index.
|
||||
**/
|
||||
getUncleByBlockNumberAndIndex: AugmentedRpc<(number: BlockNumber | AnyNumber | Uint8Array, index: U256 | AnyNumber | Uint8Array) => Observable<EthRichBlock>>;
|
||||
/**
|
||||
* Returns the number of uncles in a block with given hash.
|
||||
**/
|
||||
getUncleCountByBlockHash: AugmentedRpc<(hash: H256 | string | Uint8Array) => Observable<U256>>;
|
||||
/**
|
||||
* Returns the number of uncles in a block with given block number.
|
||||
**/
|
||||
getUncleCountByBlockNumber: AugmentedRpc<(number: BlockNumber | AnyNumber | Uint8Array) => Observable<U256>>;
|
||||
/**
|
||||
* Returns the hash of the current block, the seedHash, and the boundary condition to be met.
|
||||
**/
|
||||
getWork: AugmentedRpc<() => Observable<EthWork>>;
|
||||
/**
|
||||
* Returns the number of hashes per second that the node is mining with.
|
||||
**/
|
||||
hashrate: AugmentedRpc<() => Observable<U256>>;
|
||||
/**
|
||||
* Returns true if client is actively listening for network connections. Otherwise false.
|
||||
**/
|
||||
listening: AugmentedRpc<() => Observable<bool>>;
|
||||
/**
|
||||
* Returns true if client is actively mining new blocks.
|
||||
**/
|
||||
mining: AugmentedRpc<() => Observable<bool>>;
|
||||
/**
|
||||
* Returns number of peers connected to node.
|
||||
**/
|
||||
peerCount: AugmentedRpc<() => Observable<Text>>;
|
||||
/**
|
||||
* Returns protocol version encoded as a string (quotes are necessary).
|
||||
**/
|
||||
protocolVersion: AugmentedRpc<() => Observable<u64>>;
|
||||
/**
|
||||
* Sends signed transaction, returning its hash.
|
||||
**/
|
||||
sendRawTransaction: AugmentedRpc<(bytes: Bytes | string | Uint8Array) => Observable<H256>>;
|
||||
/**
|
||||
* Sends transaction; will block waiting for signer to return the transaction hash
|
||||
**/
|
||||
sendTransaction: AugmentedRpc<(tx: EthTransactionRequest | { from?: any; to?: any; gasPrice?: any; gas?: any; value?: any; data?: any; nonce?: any } | string | Uint8Array) => Observable<H256>>;
|
||||
/**
|
||||
* Used for submitting mining hashrate.
|
||||
**/
|
||||
submitHashrate: AugmentedRpc<(index: U256 | AnyNumber | Uint8Array, hash: H256 | string | Uint8Array) => Observable<bool>>;
|
||||
/**
|
||||
* Used for submitting a proof-of-work solution.
|
||||
**/
|
||||
submitWork: AugmentedRpc<(nonce: H64 | string | Uint8Array, headerHash: H256 | string | Uint8Array, mixDigest: H256 | string | Uint8Array) => Observable<bool>>;
|
||||
/**
|
||||
* Subscribe to Eth subscription.
|
||||
**/
|
||||
subscribe: AugmentedRpc<(kind: EthSubKind | 'newHeads' | 'logs' | 'newPendingTransactions' | 'syncing' | number | Uint8Array, params?: EthSubParams | { None: any } | { Logs: any } | string | Uint8Array) => Observable<Null>>;
|
||||
/**
|
||||
* Returns an object with data about the sync status or false.
|
||||
**/
|
||||
syncing: AugmentedRpc<() => Observable<EthSyncStatus>>;
|
||||
/**
|
||||
* Returns protocol version.
|
||||
**/
|
||||
version: AugmentedRpc<() => Observable<Text>>;
|
||||
};
|
||||
grandpa: {
|
||||
/**
|
||||
* Prove finality for the range (begin; end] hash.
|
||||
|
||||
+360
-336
File diff suppressed because it is too large
Load Diff
@@ -1,18 +1,18 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constants, DecoratedMeta } from '@polkadot/metadata/decorate/types';
|
||||
import type { DecoratedMeta } from '@polkadot/metadata/decorate/types';
|
||||
import type { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import type { Option, Raw, StorageKey, Text, u64 } from '@polkadot/types';
|
||||
import type { Call, Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import type { StorageEntry } from '@polkadot/types/primitive/types';
|
||||
import type { AnyFunction, CallFunction, Codec, CodecArg as Arg, DefinitionRpc, DefinitionRpcSub, InterfaceTypes, Registry, RegistryTypes } from '@polkadot/types/types';
|
||||
import type { AnyFunction, AnyTuple, CallFunction, Codec, CodecArg as Arg, DefinitionRpc, DefinitionRpcSub, IMethod, InterfaceTypes, IStorageKey, Registry, RegistryTypes } from '@polkadot/types/types';
|
||||
import type { SubmittableExtrinsic } from '../submittable/types';
|
||||
import type { ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedRpc, DecoratedRpcSection, DecorateMethod, PaginationOptions, QueryableConsts, QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types';
|
||||
import type { ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecoratedRpcSection, DecorateMethod, PaginationOptions, QueryableConsts, QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { decorateDerive, DeriveCustom, ExactDerive } from '@polkadot/api-derive';
|
||||
import { decorateDerive, ExactDerive } from '@polkadot/api-derive';
|
||||
import { memo } from '@polkadot/api-derive/util';
|
||||
import { expandMetadata, Metadata } from '@polkadot/metadata';
|
||||
import { RpcCore } from '@polkadot/rpc-core';
|
||||
@@ -20,9 +20,9 @@ import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/extrinsic/constants';
|
||||
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, compactStripLength, logger, u8aToHex } from '@polkadot/util';
|
||||
import { arrayChunk, arrayFlatten, assert, compactStripLength, logger, u8aToHex } from '@polkadot/util';
|
||||
import { BehaviorSubject, combineLatest, Observable, of } from '@polkadot/x-rxjs';
|
||||
import { map, switchMap, take, tap, toArray } from '@polkadot/x-rxjs/operators';
|
||||
import { map, switchMap, tap, toArray } from '@polkadot/x-rxjs/operators';
|
||||
|
||||
import { createSubmittable } from '../submittable';
|
||||
import { augmentObject } from '../util/augmentObject';
|
||||
@@ -38,8 +38,8 @@ interface MetaDecoration {
|
||||
toJSON: () => any;
|
||||
}
|
||||
|
||||
const PAGE_SIZE_KEYS = 384;
|
||||
const PAGE_SIZE_VALS = PAGE_SIZE_KEYS;
|
||||
// the max amount of keys/values that we will retrieve at once
|
||||
const PAGE_SIZE = 384;
|
||||
|
||||
const l = logger('api/init');
|
||||
|
||||
@@ -57,6 +57,10 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
|
||||
protected _derive?: ReturnType<Decorate<ApiType>['_decorateDerive']>;
|
||||
|
||||
protected _errors: DecoratedErrors<ApiType> = {} as DecoratedErrors<ApiType>;
|
||||
|
||||
protected _events: DecoratedEvents<ApiType> = {} as DecoratedEvents<ApiType>;
|
||||
|
||||
protected _extrinsics?: SubmittableExtrinsics<ApiType>;
|
||||
|
||||
protected _extrinsicType: number = EXTRINSIC_DEFAULT_VERSION;
|
||||
@@ -84,7 +88,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
protected _runtimeVersion?: RuntimeVersion;
|
||||
|
||||
protected _rx: ApiInterfaceRx = {
|
||||
consts: {} as Constants,
|
||||
consts: {} as QueryableConsts<'rxjs'>,
|
||||
query: {} as QueryableStorage<'rxjs'>,
|
||||
tx: {} as SubmittableExtrinsics<'rxjs'>
|
||||
} as ApiInterfaceRx;
|
||||
@@ -174,6 +178,13 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
return this._rpcCore.provider.hasSubscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns `true` if the API decorate multi-key queries
|
||||
*/
|
||||
get supportMulti (): boolean {
|
||||
return this._rpcCore.provider.hasSubscriptions || !!this._rpcCore.state.queryStorageAt;
|
||||
}
|
||||
|
||||
public injectMetadata (metadata: Metadata, fromEmpty?: boolean, registry?: Registry): void {
|
||||
const decoratedMeta = expandMetadata(registry || this.#registry, metadata);
|
||||
|
||||
@@ -188,6 +199,8 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
// this API
|
||||
augmentObject('query', this._decorateStorage(decoratedMeta, this._decorateMethod), this._query, fromEmpty);
|
||||
augmentObject('consts', decoratedMeta.consts, this._consts, fromEmpty);
|
||||
augmentObject('errors', decoratedMeta.errors, this._errors, fromEmpty);
|
||||
augmentObject('events', decoratedMeta.events, this._events, fromEmpty);
|
||||
|
||||
// rx
|
||||
augmentObject(null, this._decorateStorage(decoratedMeta, this._rxDecorateMethod), this._rx.query, fromEmpty);
|
||||
@@ -300,10 +313,13 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
}, input as DecoratedRpc<ApiType, RpcInterface>);
|
||||
}
|
||||
|
||||
// only be called if supportMulti is true
|
||||
protected _decorateMulti<ApiType extends ApiTypes> (decorateMethod: DecorateMethod<ApiType>): QueryableStorageMulti<ApiType> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return decorateMethod((calls: QueryableStorageMultiArg<ApiType>[]): Observable<Codec[]> =>
|
||||
this._rpcCore.state.subscribeStorage(
|
||||
(this.hasSubscriptions
|
||||
? this._rpcCore.state.subscribeStorage
|
||||
: this._rpcCore.state.queryStorageAt)(
|
||||
calls.map((arg: QueryableStorageMultiArg<ApiType>) =>
|
||||
Array.isArray(arg)
|
||||
? [arg[0].creator, ...arg.slice(1)]
|
||||
@@ -328,6 +344,10 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
const decorated = (...params: Arg[]): SubmittableExtrinsic<ApiType> =>
|
||||
creator(method(...params));
|
||||
|
||||
// pass through the `.is`
|
||||
decorated.is = (other: IMethod<AnyTuple>) =>
|
||||
method.is(other);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return this._decorateFunctionMeta(method as any, decorated as any) as unknown as SubmittableExtrinsicFunction<ApiType>;
|
||||
}
|
||||
@@ -361,6 +381,9 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
decorated.hash = decorateMethod((arg1?: Arg, arg2?: Arg): Observable<Hash> =>
|
||||
this._rpcCore.state.getStorageHash(getArgs(arg1, arg2)));
|
||||
|
||||
decorated.is = <A extends AnyTuple> (key: IStorageKey<AnyTuple>): key is IStorageKey<A> =>
|
||||
key.section === creator.section && key.method === creator.method;
|
||||
|
||||
decorated.key = (arg1?: Arg, arg2?: Arg): string =>
|
||||
u8aToHex(compactStripLength(creator(creator.meta.type.isDoubleMap ? [arg1, arg2] : arg1))[1]);
|
||||
|
||||
@@ -403,8 +426,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
this._retrieveMapKeysPaged(creator, opts)));
|
||||
}
|
||||
|
||||
// only support multi where subs are available
|
||||
if (this.hasSubscriptions) {
|
||||
if (this.supportMulti) {
|
||||
// When using double map storage function, user need to pass double map key as an array
|
||||
decorated.multi = decorateMethod((args: (Arg | Arg[])[]): Observable<Codec[]> =>
|
||||
this._retrieveMulti(args.map((arg) => [creator, arg])));
|
||||
@@ -444,22 +466,21 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
));
|
||||
}
|
||||
|
||||
// retrieve a set of values for a specific set of keys - here we chunk the keys into PAGE_SIZE_VALS sizes
|
||||
// retrieve a set of values for a specific set of keys - here we chunk the keys into PAGE_SIZE sizes
|
||||
private _retrieveMulti (keys: [StorageEntry, Arg | Arg[]][]): Observable<Codec[]> {
|
||||
if (!keys.length) {
|
||||
return of([]);
|
||||
}
|
||||
|
||||
return combineLatest(
|
||||
...Array(Math.ceil(keys.length / PAGE_SIZE_VALS))
|
||||
.fill(0)
|
||||
.map((_, index): Observable<Codec[]> =>
|
||||
this._rpcCore.state.subscribeStorage(keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS))
|
||||
)
|
||||
).pipe(
|
||||
map((valsArr): Codec[] =>
|
||||
valsArr.reduce((result: Codec[], vals) => result.concat(vals), [])
|
||||
arrayChunk(keys, PAGE_SIZE).map((keys) =>
|
||||
(this.hasSubscriptions
|
||||
? this._rpcCore.state.subscribeStorage
|
||||
: this._rpcCore.state.queryStorageAt
|
||||
)(keys)
|
||||
)
|
||||
).pipe(
|
||||
map((valsArr): Codec[] => arrayFlatten(valsArr))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -469,8 +490,8 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
const headKey = iterKey(arg).toHex();
|
||||
const startSubject = new BehaviorSubject<string>(headKey);
|
||||
const query = at
|
||||
? (startKey: string) => this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_KEYS, startKey, at)
|
||||
: (startKey: string) => this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_KEYS, startKey);
|
||||
? (startKey: string) => this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE, startKey, at)
|
||||
: (startKey: string) => this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE, startKey);
|
||||
|
||||
return startSubject.pipe(
|
||||
switchMap((startKey) =>
|
||||
@@ -479,12 +500,12 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
)
|
||||
),
|
||||
tap((keys): void => {
|
||||
keys.length === PAGE_SIZE_KEYS
|
||||
? startSubject.next(keys[PAGE_SIZE_KEYS - 1].toHex())
|
||||
keys.length === PAGE_SIZE
|
||||
? startSubject.next(keys[PAGE_SIZE - 1].toHex())
|
||||
: startSubject.complete();
|
||||
}),
|
||||
toArray(), // toArray since we want to startSubject to be completed
|
||||
map((keysArr: StorageKey[][]) => keysArr.reduce((result: StorageKey[], keys) => result.concat(keys), []))
|
||||
map((keysArr: StorageKey[][]) => arrayFlatten(keysArr))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -499,28 +520,19 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
}
|
||||
|
||||
private _retrieveMapEntries (entry: StorageEntry, at: Hash | Uint8Array | string | null, arg?: Arg): Observable<[StorageKey, Codec][]> {
|
||||
const query = this._rpcCore.state.queryStorageAt
|
||||
? at
|
||||
? (keyset: StorageKey[]) => this._rpcCore.state.queryStorageAt(keyset, at)
|
||||
: (keyset: StorageKey[]) => this._rpcCore.state.queryStorageAt(keyset)
|
||||
// this is horrible, but need older support (which now doesn't work with at)
|
||||
: (keyset: StorageKey[]) => this._rpcCore.state.subscribeStorage(keyset).pipe(take(1));
|
||||
const query = at
|
||||
? (keyset: StorageKey[]) => this._rpcCore.state.queryStorageAt(keyset, at)
|
||||
: (keyset: StorageKey[]) => this._rpcCore.state.queryStorageAt(keyset);
|
||||
|
||||
return this._retrieveMapKeys(entry, at, arg).pipe(
|
||||
switchMap((keys) =>
|
||||
combineLatest<[StorageKey[], ...Codec[][]]>([
|
||||
of(keys),
|
||||
...Array(Math.ceil(keys.length / PAGE_SIZE_VALS))
|
||||
.fill(0)
|
||||
.map((_, index): Observable<Codec[]> =>
|
||||
query(keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS))
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([keys, ...valsArr]): [StorageKey, Codec][] =>
|
||||
valsArr
|
||||
.reduce((result: Codec[], vals) => result.concat(vals), [])
|
||||
.map((value, index) => [keys[index], value])
|
||||
combineLatest(
|
||||
arrayChunk(keys, PAGE_SIZE).map((keys) => query(keys))
|
||||
).pipe(
|
||||
map((valsArr) =>
|
||||
arrayFlatten(valsArr).map((value, index): [StorageKey, Codec] => [keys[index], value])
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -528,24 +540,21 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
private _retrieveMapEntriesPaged (entry: StorageEntry, opts: PaginationOptions): Observable<[StorageKey, Codec][]> {
|
||||
return this._retrieveMapKeysPaged(entry, opts).pipe(
|
||||
switchMap((keys) =>
|
||||
combineLatest<[StorageKey[], ...Codec[][]]>([
|
||||
of(keys),
|
||||
this._rpcCore.state.queryStorageAt<Codec[]>(keys)
|
||||
])
|
||||
),
|
||||
map(([keys, ...valsArr]): [StorageKey, Codec][] =>
|
||||
valsArr
|
||||
.reduce((result: Codec[], vals) => result.concat(vals), [])
|
||||
.map((value, index) => [keys[index], value])
|
||||
this._rpcCore.state.queryStorageAt(keys).pipe(
|
||||
map((valsArr) =>
|
||||
valsArr.map((value, index): [StorageKey, Codec] => [keys[index], value])
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected _decorateDeriveRx (decorateMethod: DecorateMethod<ApiType>): DeriveAllSections<'rxjs', ExactDerive> {
|
||||
const specName = this._runtimeVersion?.specName.toString();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
const derives = { ...this._options.derives, ...(this._options.typesBundle?.spec?.[specName ?? '']?.derives as DeriveCustom) }; // use typesBundle
|
||||
const derives = {
|
||||
...this._options.derives,
|
||||
...(this._options.typesBundle?.spec?.[specName ?? '']?.derives || {})
|
||||
};
|
||||
|
||||
// Pull in derive from api-derive
|
||||
const derive = decorateDerive(this.#instanceId, this._rx, derives);
|
||||
|
||||
@@ -5,10 +5,11 @@ import type { Metadata } from '@polkadot/metadata';
|
||||
import type { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import type { Text } from '@polkadot/types';
|
||||
import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx, ApiTypes, DecoratedRpc, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types';
|
||||
import type { ApiInterfaceRx, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types';
|
||||
|
||||
import { assertReturn } from '@polkadot/util';
|
||||
|
||||
import { packageInfo } from '../detectPackage';
|
||||
import { Init } from './Init';
|
||||
|
||||
interface PkgJson {
|
||||
@@ -16,16 +17,6 @@ interface PkgJson {
|
||||
version: string;
|
||||
}
|
||||
|
||||
let pkgJson: PkgJson = { name: '@polkadot/api', version: '-' };
|
||||
|
||||
import('../package.json')
|
||||
.then((_pkgJson: unknown): void => {
|
||||
pkgJson = _pkgJson as PkgJson;
|
||||
})
|
||||
.catch((): void => {
|
||||
// ignore
|
||||
});
|
||||
|
||||
function assertResult<T> (value: T | undefined): T {
|
||||
return assertReturn(value, 'Api needs to be initialized before using, listen on \'ready\'');
|
||||
}
|
||||
@@ -63,6 +54,20 @@ export abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> {
|
||||
return assertResult(this._derive);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Errors from metadata
|
||||
*/
|
||||
public get errors (): DecoratedErrors<ApiType> {
|
||||
return assertResult(this._errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Events from metadata
|
||||
*/
|
||||
public get events (): DecoratedEvents<ApiType> {
|
||||
return assertResult(this._events);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the version of extrinsics in-use on this chain
|
||||
*/
|
||||
@@ -95,7 +100,7 @@ export abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> {
|
||||
* @description The library information name & version (from package.json)
|
||||
*/
|
||||
public get libraryInfo (): string {
|
||||
return `${pkgJson.name} v${pkgJson.version}`;
|
||||
return `${(packageInfo as PkgJson).name} v${(packageInfo as PkgJson).version}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,8 +54,12 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
|
||||
this._rpc = this._decorateRpc(this._rpcCore, this._decorateMethod);
|
||||
this._rx.rpc = this._decorateRpc(this._rpcCore, this._rxDecorateMethod);
|
||||
this._queryMulti = this._decorateMulti(this._decorateMethod);
|
||||
this._rx.queryMulti = this._decorateMulti(this._rxDecorateMethod);
|
||||
|
||||
if (this.supportMulti) {
|
||||
this._queryMulti = this._decorateMulti(this._decorateMethod);
|
||||
this._rx.queryMulti = this._decorateMulti(this._rxDecorateMethod);
|
||||
}
|
||||
|
||||
this._rx.signer = options.signer;
|
||||
|
||||
this._rpcCore.setRegistrySwap((hash: string | Uint8Array) => this.getBlockRegistry(hash));
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import type { AccountId, Balance, Header, Index } from '@polkadot/types/interfaces';
|
||||
import type { IExtrinsic, IMethod } from '@polkadot/types/types';
|
||||
import type { StorageKey } from '@polkadot/types';
|
||||
import type { AccountId, Balance, DispatchError, EventRecord, Header, Index } from '@polkadot/types/interfaces';
|
||||
import type { AnyTuple, IExtrinsic, IMethod } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
@@ -34,6 +35,39 @@ async function derive (api: ApiPromise): Promise<void> {
|
||||
console.log('fees', fees);
|
||||
}
|
||||
|
||||
function errors (api: ApiPromise): void {
|
||||
const someError = {} as DispatchError;
|
||||
|
||||
// existing
|
||||
console.log(api.errors.vesting.AmountLow.is(someError));
|
||||
|
||||
// non-existing error, existing module
|
||||
console.log(api.errors.vesting.Something.is(someError));
|
||||
|
||||
// something random
|
||||
console.log(api.errors.something.Random.is(someError));
|
||||
}
|
||||
|
||||
function events (api: ApiPromise): void {
|
||||
const eventRecord = {} as EventRecord;
|
||||
|
||||
// existing
|
||||
if (api.events.balances.Transfer.is(eventRecord)) {
|
||||
// the types are correctly expanded
|
||||
const [from, to, amount] = eventRecord.event.data;
|
||||
|
||||
console.log(from.toHuman(), to.toHuman(), amount.toBn());
|
||||
}
|
||||
|
||||
// something random
|
||||
if (api.events.something.Random.is(eventRecord)) {
|
||||
// the types are just codec
|
||||
const [a, b] = eventRecord.event.data;
|
||||
|
||||
console.log(a.toHuman(), b.toHuman());
|
||||
}
|
||||
}
|
||||
|
||||
async function query (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
|
||||
const intentions = await api.query.staking.bonded();
|
||||
|
||||
@@ -102,6 +136,16 @@ async function queryExtra (api: ApiPromise, pairs: TestKeyringMap): Promise<void
|
||||
const entries = await api.query.system.events.range(['0x12345', '0x7890']);
|
||||
|
||||
console.log(`Received ${entries.length} entries, ${entries.map(([hash, events]) => `${hash.toHex()}: ${events.length} events`).join(', ')}`);
|
||||
|
||||
// is
|
||||
const key = {} as StorageKey;
|
||||
|
||||
if (api.query.balances.account.is(key)) {
|
||||
const [accountId] = key.args;
|
||||
|
||||
// should be AccountId type
|
||||
console.log(accountId.toHuman());
|
||||
}
|
||||
}
|
||||
|
||||
async function rpc (api: ApiPromise): Promise<void> {
|
||||
@@ -143,7 +187,7 @@ async function tx (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
|
||||
// transfer, also allows for BigInt inputs here
|
||||
const transfer = api.tx.balances.transfer(pairs.bob.address, 123456789n);
|
||||
|
||||
console.log('transfer casted', transfer as IMethod, transfer as IExtrinsic);
|
||||
console.log('transfer casted', transfer as IMethod<AnyTuple>, transfer as IExtrinsic<AnyTuple>);
|
||||
|
||||
// simple "return the hash" variant
|
||||
console.log('hash:', (await transfer.signAndSend(pairs.alice)).toHex());
|
||||
@@ -179,6 +223,14 @@ async function tx (api: ApiPromise, pairs: TestKeyringMap): Promise<void> {
|
||||
|
||||
// it handles enum inputs correctly
|
||||
await api.tx.democracy.proxyVote(123, { Split: { nay: 456, yay: 123 } }).signAndSend(pairs.alice);
|
||||
|
||||
// is
|
||||
if (api.tx.balances.transfer.is(second)) {
|
||||
const [recipientId, balance] = second.args;
|
||||
|
||||
// should be LookupSource & Balance types
|
||||
console.log(recipientId.toHuman(), balance.toNumber());
|
||||
}
|
||||
}
|
||||
|
||||
async function main (): Promise<void> {
|
||||
@@ -189,6 +241,8 @@ async function main (): Promise<void> {
|
||||
Promise.all([
|
||||
consts(api),
|
||||
derive(api),
|
||||
errors(api),
|
||||
events(api),
|
||||
query(api, pairs),
|
||||
queryExtra(api, pairs),
|
||||
rpc(api),
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
|
||||
//
|
||||
// new URL(import.meta.url).pathname)
|
||||
//
|
||||
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
|
||||
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
|
||||
// there is a complete dead end with usage thereof
|
||||
//
|
||||
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
|
||||
//
|
||||
// cjs: util.detectPackage(packageInfo, () => __dirname);
|
||||
// esm: detectPackage(packageInfo, () => import.meta.url);
|
||||
//
|
||||
// With the above we additionally need a .d.ts to just export the packageInfo
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import packageJson from './package.json';
|
||||
import packageInfo from './package-info.json';
|
||||
|
||||
detectPackage(packageJson, typeof __dirname !== 'undefined' && __dirname);
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { packageInfo };
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { IsError } from '@polkadot/metadata/decorate/types';
|
||||
import type { ApiTypes } from './base';
|
||||
|
||||
// In errors we don't need the ApiType, however add it for consistency
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars
|
||||
export interface AugmentedErrors<ApiType extends ApiTypes> { }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export type AugmentedError<ApiType extends ApiTypes> = IsError;
|
||||
|
||||
export interface ModuleErrors<ApiType extends ApiTypes> {
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { IsEvent } from '@polkadot/metadata/decorate/types';
|
||||
import type { AnyTuple } from '@polkadot/types/types';
|
||||
import type { ApiTypes } from './base';
|
||||
|
||||
// In events we don't need the ApiType, however add it for consistency
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars
|
||||
export interface AugmentedEvents<ApiType extends ApiTypes> { }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export type AugmentedEvent<ApiType extends ApiTypes, T extends AnyTuple = AnyTuple> = IsEvent<T>;
|
||||
|
||||
export interface ModuleEvents<ApiType extends ApiTypes> {
|
||||
[key: string]: AugmentedEvent<ApiType, AnyTuple>;
|
||||
}
|
||||
@@ -23,6 +23,8 @@ export { ApiBase } from '../base';
|
||||
export * from '../submittable/types';
|
||||
export * from './base';
|
||||
export * from './consts';
|
||||
export * from './errors';
|
||||
export * from './events';
|
||||
export * from './rpc';
|
||||
export * from './storage';
|
||||
export * from './submittable';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { StorageKey, u64 } from '@polkadot/types';
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { StorageEntry } from '@polkadot/types/primitive/types';
|
||||
import type { AnyFunction, Callback, Codec, CodecArg } from '@polkadot/types/types';
|
||||
import type { AnyFunction, AnyTuple, Callback, Codec, CodecArg, IStorageKey } from '@polkadot/types/types';
|
||||
import type { Observable } from '@polkadot/x-rxjs';
|
||||
import type { ApiTypes, MethodResult, ObsInnerType, PaginationOptions, PromiseOrObs, UnsubscribePromise } from './base';
|
||||
|
||||
@@ -28,20 +28,21 @@ export interface StorageEntryPromiseOverloads {
|
||||
// This is the most generic typings we can have for a storage entry function
|
||||
type GenericStorageEntryFunction = (arg1?: CodecArg, arg2?: CodecArg) => Observable<Codec>
|
||||
|
||||
export type QueryableStorageEntry<ApiType extends ApiTypes> =
|
||||
export type QueryableStorageEntry<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> =
|
||||
ApiType extends 'rxjs'
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
? AugmentedQuery<'rxjs', GenericStorageEntryFunction>
|
||||
? AugmentedQuery<'rxjs', GenericStorageEntryFunction, A>
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
: AugmentedQuery<'promise', GenericStorageEntryFunction> & StorageEntryPromiseOverloads;
|
||||
: AugmentedQuery<'promise', GenericStorageEntryFunction, A> & StorageEntryPromiseOverloads;
|
||||
|
||||
export interface StorageEntryBase<ApiType extends ApiTypes, F extends AnyFunction> {
|
||||
export interface StorageEntryBase<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple> {
|
||||
at: <T extends Codec | any = ObsInnerType<ReturnType<F>>>(hash: Hash | Uint8Array | string, ...args: Parameters<F>) => PromiseOrObs<ApiType, T>;
|
||||
creator: StorageEntry;
|
||||
entries: <T extends Codec | any = ObsInnerType<ReturnType<F>>>(arg?: Parameters<F>[0]) => PromiseOrObs<ApiType, [StorageKey, T][]>;
|
||||
entriesAt: <T extends Codec | any = ObsInnerType<ReturnType<F>>>(hash: Hash | Uint8Array | string, arg?: Parameters<F>[0]) => PromiseOrObs<ApiType, [StorageKey, T][]>;
|
||||
entriesPaged: <T extends Codec | any = ObsInnerType<ReturnType<F>>>(opts: PaginationOptions<Parameters<F>[0]>) => PromiseOrObs<ApiType, [StorageKey, T][]>;
|
||||
hash: (...args: Parameters<F>) => PromiseOrObs<ApiType, Hash>;
|
||||
is: (key: IStorageKey<AnyTuple>) => key is IStorageKey<A>;
|
||||
key: (...args: Parameters<F>) => string;
|
||||
keyPrefix: () => string;
|
||||
keys: (arg?: any) => PromiseOrObs<ApiType, StorageKey[]>;
|
||||
@@ -55,7 +56,7 @@ export interface StorageEntryBase<ApiType extends ApiTypes, F extends AnyFunctio
|
||||
}
|
||||
|
||||
export interface QueryableModuleStorage<ApiType extends ApiTypes> {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
[index: string]: QueryableStorageEntry<ApiType, AnyTuple>;
|
||||
}
|
||||
|
||||
export type QueryableStorageMultiArg<ApiType extends ApiTypes> =
|
||||
@@ -79,10 +80,10 @@ export type QueryableStorageMulti<ApiType extends ApiTypes> =
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars
|
||||
export interface AugmentedQueries<ApiType extends ApiTypes> { }
|
||||
|
||||
export interface StorageEntryDoubleMap<ApiType extends ApiTypes, F extends AnyFunction> extends StorageEntryBase<ApiType, F> {
|
||||
export interface StorageEntryDoubleMap<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple> extends StorageEntryBase<ApiType, F, A> {
|
||||
keyPrefix: (key1?: Parameters<F>[0]) => string;
|
||||
}
|
||||
|
||||
export type AugmentedQuery<ApiType extends ApiTypes, F extends AnyFunction> = MethodResult<ApiType, F> & StorageEntryBase<ApiType, F>
|
||||
export type AugmentedQuery<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = MethodResult<ApiType, F> & StorageEntryBase<ApiType, F, A>;
|
||||
|
||||
export type AugmentedQueryDoubleMap<ApiType extends ApiTypes, F extends AnyFunction> = MethodResult<ApiType, F> & StorageEntryDoubleMap<ApiType, F>
|
||||
export type AugmentedQueryDoubleMap<ApiType extends ApiTypes, F extends AnyFunction, A extends AnyTuple = AnyTuple> = MethodResult<ApiType, F> & StorageEntryDoubleMap<ApiType, F, A>;
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyFunction, CallBase } from '@polkadot/types/types';
|
||||
import type { AnyFunction, AnyTuple, CallBase } from '@polkadot/types/types';
|
||||
import type { SubmittableExtrinsic } from '../submittable/types';
|
||||
import type { ApiTypes } from './base';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars
|
||||
export interface AugmentedSubmittables<ApiType extends ApiTypes> { }
|
||||
|
||||
export type AugmentedSubmittable<T extends AnyFunction> = T & CallBase;
|
||||
export type AugmentedSubmittable<T extends AnyFunction, A extends AnyTuple = AnyTuple> = T & CallBase<A>;
|
||||
|
||||
export interface SubmittableExtrinsicFunction<ApiType extends ApiTypes> extends CallBase {
|
||||
export interface SubmittableExtrinsicFunction<ApiType extends ApiTypes, A extends AnyTuple = AnyTuple> extends CallBase<A> {
|
||||
(...params: any[]): SubmittableExtrinsic<ApiType>;
|
||||
}
|
||||
|
||||
export interface SubmittableModuleExtrinsics<ApiType extends ApiTypes> {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
// only with is<Type> augmentation
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>; // | AugmentedIsSubmittable<ApiType, AnyTuple>;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { Metadata, storageFromMeta } from '@polkadot/metadata';
|
||||
import { decorateStorage, Metadata } from '@polkadot/metadata';
|
||||
import { Storage } from '@polkadot/metadata/decorate/types';
|
||||
import metaStatic from '@polkadot/metadata/static';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
@@ -15,7 +15,7 @@ describe('extractStorageArgs', (): void => {
|
||||
beforeEach((): void => {
|
||||
const metadata = new Metadata(registry, metaStatic);
|
||||
|
||||
storage = storageFromMeta(registry, metadata);
|
||||
storage = decorateStorage(registry, metadata.asLatest, metadata.version);
|
||||
});
|
||||
|
||||
it('validates no-arg plain', (): void => {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
{
|
||||
"name": "@polkadot/metadata",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "Helpers to extract information from runtime metadata",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"module": "index.mjs",
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.mjs"
|
||||
],
|
||||
"repository": "github:polkadot-js/api",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
@@ -13,13 +17,13 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/types-known": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/util-crypto": "^5.0.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/types-known": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"@polkadot/util-crypto": "^5.2.2",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^5.0.1"
|
||||
"@polkadot/keyring": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ export class MetadataVersioned extends Struct {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped metadata as a V1 object
|
||||
* @description Returns the wrapped metadata as a V9 object
|
||||
*/
|
||||
public get asV9 (): MetadataV9 {
|
||||
this._assertVersion(9);
|
||||
@@ -81,16 +81,16 @@ export class MetadataVersioned extends Struct {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V10 object
|
||||
* @description Returns the wrapped values as a V11 object
|
||||
*/
|
||||
public get asV11 (): MetadataV11 {
|
||||
return this._getVersion(11, toV11);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V10 object
|
||||
* @description Returns the wrapped values as a V12 object
|
||||
*/
|
||||
public get asV12 (): MetadataV11 {
|
||||
public get asV12 (): MetadataV12 {
|
||||
return this._getVersion(12, toV12);
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -1,6 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { Constants } from '../types';
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
@@ -8,7 +9,7 @@ import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { Metadata } from '../../Metadata';
|
||||
import rpcMetadata from '../../static';
|
||||
import rpcMetadataV10 from '../../v10/static';
|
||||
import { constantsFromMeta } from './fromMetadata';
|
||||
import { decorateConstants } from '..';
|
||||
|
||||
function init (meta: string): [Constants, TypeRegistry] {
|
||||
const registry = new TypeRegistry();
|
||||
@@ -16,16 +17,16 @@ function init (meta: string): [Constants, TypeRegistry] {
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
return [constantsFromMeta(registry, metadata), registry];
|
||||
return [decorateConstants(registry, metadata.asLatest), registry];
|
||||
}
|
||||
|
||||
describe('fromMetadata', (): void => {
|
||||
describe('decorateConstants', (): void => {
|
||||
it('should return constants with the correct type and value', (): void => {
|
||||
const [consts, registry] = init(rpcMetadata);
|
||||
|
||||
expect(consts.democracy.cooloffPeriod).toBeInstanceOf(registry.createClass('BlockNumber'));
|
||||
// 3 second blocks, 28 days
|
||||
expect(consts.democracy.cooloffPeriod.toNumber()).toEqual(28 * 24 * 60 * (60 / 3));
|
||||
expect((consts.democracy.cooloffPeriod as unknown as BlockNumber).toNumber()).toEqual(28 * 24 * 60 * (60 / 3));
|
||||
});
|
||||
|
||||
// removed from session
|
||||
+8
-11
@@ -1,30 +1,27 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { MetadataLatest } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { ConstantCodec, Constants, ModuleConstants } from '../types';
|
||||
|
||||
import { hexToU8a, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { Metadata } from '../../Metadata';
|
||||
|
||||
/** @internal */
|
||||
export function constantsFromMeta (registry: Registry, metadata: Metadata): Constants {
|
||||
return metadata.asLatest.modules.reduce((result: Constants, moduleMetadata): Constants => {
|
||||
if (moduleMetadata.constants.isEmpty) {
|
||||
export function decorateConstants (registry: Registry, { modules }: MetadataLatest): Constants {
|
||||
return modules.reduce((result: Constants, { constants, name }): Constants => {
|
||||
if (constants.isEmpty) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const { name } = moduleMetadata;
|
||||
|
||||
// For access, we change the index names, i.e. Democracy.EnactmentPeriod -> democracy.enactmentPeriod
|
||||
result[stringCamelCase(name)] = moduleMetadata.constants.reduce((newModule: ModuleConstants, meta): ModuleConstants => {
|
||||
result[stringCamelCase(name)] = constants.reduce((newModule: ModuleConstants, meta): ModuleConstants => {
|
||||
// convert to the natural type as received
|
||||
const type = meta.type.toString();
|
||||
const codec = registry.createType(type as 'Raw', hexToU8a(meta.value.toHex())) as unknown as ConstantCodec;
|
||||
const codec = registry.createType(type as 'Raw', hexToU8a(meta.value.toHex())) as unknown;
|
||||
|
||||
codec.meta = meta;
|
||||
newModule[stringCamelCase(meta.name)] = codec;
|
||||
(codec as Record<string, unknown>).meta = meta;
|
||||
newModule[stringCamelCase(meta.name)] = codec as ConstantCodec;
|
||||
|
||||
return newModule;
|
||||
}, {} as ModuleConstants);
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { DispatchError, MetadataLatest } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { Errors, ModuleErrors } from '../types';
|
||||
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
function isError (dispatchError: DispatchError, sectionIndex: number, errorIndex: number): boolean {
|
||||
if (!dispatchError.isModule) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { error, index } = dispatchError.asModule;
|
||||
|
||||
return index.eq(sectionIndex) && error.eq(errorIndex);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function decorateErrors (_: Registry, { modules }: MetadataLatest, metaVersion: number): Errors {
|
||||
return modules.reduce((result: Errors, { errors, index, name }, _sectionIndex): Errors => {
|
||||
if (!errors.length) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const sectionIndex = metaVersion === 12 ? index.toNumber() : _sectionIndex;
|
||||
|
||||
result[stringCamelCase(name)] = errors.reduce((newModule: ModuleErrors, meta, errorIndex): ModuleErrors => {
|
||||
// we don't camelCase the error name
|
||||
newModule[meta.name.toString()] = {
|
||||
is: (dispatchError: DispatchError): boolean =>
|
||||
isError(dispatchError, sectionIndex, errorIndex),
|
||||
meta
|
||||
};
|
||||
|
||||
return newModule;
|
||||
}, {} as ModuleErrors);
|
||||
|
||||
return result;
|
||||
}, {} as Errors);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { MetadataLatest } from '@polkadot/types/interfaces';
|
||||
import type { AnyTuple, IEventRecord, Registry } from '@polkadot/types/types';
|
||||
import type { Events, ModuleEvents } from '../types';
|
||||
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
function isEvent <T extends AnyTuple> (eventRecord: IEventRecord<AnyTuple>, sectionIndex: number, eventIndex: number): eventRecord is IEventRecord<T> {
|
||||
return eventRecord.event.index[0] === sectionIndex && eventRecord.event.index[0] === eventIndex;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function decorateEvents (_: Registry, { modules }: MetadataLatest, metaVersion: number): Events {
|
||||
return modules.reduce((result: Events, { events, index, name }, _sectionIndex): Events => {
|
||||
if (!events.isSome) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const sectionIndex = metaVersion === 12 ? index.toNumber() : _sectionIndex;
|
||||
|
||||
result[stringCamelCase(name)] = events.unwrap().reduce((newModule: ModuleEvents, meta, eventIndex): ModuleEvents => {
|
||||
// we don't camelCase the event name
|
||||
newModule[meta.name.toString()] = {
|
||||
is: <T extends AnyTuple> (eventRecord: IEventRecord<AnyTuple>): eventRecord is IEventRecord<T> =>
|
||||
isEvent(eventRecord, sectionIndex, eventIndex),
|
||||
meta
|
||||
};
|
||||
|
||||
return newModule;
|
||||
}, {} as ModuleEvents);
|
||||
|
||||
return result;
|
||||
}, {} as Events);
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Call } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, CallFunction, Registry, RegistryMetadataCall } from '@polkadot/types/types';
|
||||
import type { Call, FunctionMetadataLatest } from '@polkadot/types/interfaces';
|
||||
import type { AnyJson, AnyTuple, CallFunction, IMethod, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { assert, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
function isTx <A extends AnyTuple> (tx: IMethod<AnyTuple>, callIndex: Uint8Array): tx is IMethod<A> {
|
||||
return tx.callIndex[0] === callIndex[0] && tx.callIndex[1] === callIndex[1];
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function createUnchecked (registry: Registry, section: string, callIndex: Uint8Array, callMetadata: RegistryMetadataCall): CallFunction {
|
||||
export function createUnchecked (registry: Registry, section: string, callIndex: Uint8Array, callMetadata: FunctionMetadataLatest): CallFunction {
|
||||
const expectedArgs = callMetadata.args;
|
||||
const funcName = stringCamelCase(callMetadata.name);
|
||||
|
||||
@@ -20,6 +24,9 @@ export function createUnchecked (registry: Registry, section: string, callIndex:
|
||||
}, callMetadata);
|
||||
};
|
||||
|
||||
extrinsicFn.is = <A extends AnyTuple> (tx: IMethod<AnyTuple>): tx is IMethod<A> =>
|
||||
isTx(tx, callIndex);
|
||||
|
||||
extrinsicFn.callIndex = callIndex;
|
||||
extrinsicFn.meta = callMetadata;
|
||||
extrinsicFn.method = funcName;
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
|
||||
import { Metadata } from '../../Metadata';
|
||||
import json from '../../static';
|
||||
import { extrinsicsFromMeta } from './fromMetadata';
|
||||
|
||||
// Use the pre-generated metadata
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, json);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const newExtrinsics = extrinsicsFromMeta(registry, metadata);
|
||||
|
||||
describe('fromMetadata', (): void => {
|
||||
it('should throw if an incorrect number of args is supplied', (): void => {
|
||||
expect((): any => newExtrinsics.balances.setBalance()).toThrowError(/expects 3 arguments/);
|
||||
});
|
||||
|
||||
it('should return a value if the storage function does not expect an argument', (): void => {
|
||||
expect((): any => newExtrinsics.balances.setBalance('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', 2, 3)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should return properly-encoded transactions', (): void => {
|
||||
expect(
|
||||
registry.createType('Extrinsic', newExtrinsics.timestamp.set([10101])).toU8a()
|
||||
).toEqual(
|
||||
new Uint8Array([
|
||||
// length (encoded)
|
||||
4 << 2,
|
||||
// version, no signature
|
||||
4,
|
||||
// index
|
||||
3, 0,
|
||||
// values, Compact<Moment>
|
||||
116
|
||||
])
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Calls, ModulesWithCalls, Registry, RegistryMetadata, RegistryMetadataModule } from '@polkadot/types/types';
|
||||
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { createUnchecked } from './createUnchecked';
|
||||
import extrinsics from '.';
|
||||
|
||||
/** @internal */
|
||||
export function extrinsicsFromMeta (registry: Registry, metadata: RegistryMetadata): ModulesWithCalls {
|
||||
const modules = metadata.asLatest.modules;
|
||||
const isIndexed = modules.some(({ index }) => !index.eqn(255));
|
||||
|
||||
return modules
|
||||
.filter(({ calls }) => calls.isSome)
|
||||
.reduce((result, { calls, index, name }: RegistryMetadataModule, _sectionIndex): ModulesWithCalls => {
|
||||
const sectionIndex = isIndexed
|
||||
? index.toNumber()
|
||||
: _sectionIndex;
|
||||
const section = stringCamelCase(name);
|
||||
|
||||
result[section] = calls.unwrap().reduce((newModule: Calls, callMetadata, methodIndex): Calls => {
|
||||
const method = stringCamelCase(callMetadata.name);
|
||||
|
||||
newModule[method] = createUnchecked(registry, section, new Uint8Array([sectionIndex, methodIndex]), callMetadata);
|
||||
|
||||
return newModule;
|
||||
}, {});
|
||||
|
||||
return result;
|
||||
}, { ...extrinsics });
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { TypeRegistry } from '@polkadot/types/create';
|
||||
|
||||
import { Metadata } from '../../Metadata';
|
||||
import metadataStatic from '../../static';
|
||||
import { extrinsicsFromMeta } from './fromMetadata';
|
||||
import { decorateExtrinsics } from '..';
|
||||
|
||||
const keyring = createTestPairs({ type: 'ed25519' }, false);
|
||||
const registry = new TypeRegistry();
|
||||
@@ -16,7 +16,7 @@ const metadata = new Metadata(registry, metadataStatic);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const extrinsics = extrinsicsFromMeta(registry, metadata);
|
||||
const extrinsics = decorateExtrinsics(registry, metadata.asLatest, metadata.version);
|
||||
|
||||
describe('extrinsics', (): void => {
|
||||
it('encodes an actual transfer (actual data)', (): void => {
|
||||
@@ -52,3 +52,37 @@ describe('extrinsics', (): void => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decorateExtrinsics', (): void => {
|
||||
it('should throw if an incorrect number of args is supplied', (): void => {
|
||||
expect(() => extrinsics.balances.setBalance()).toThrowError(/expects 3 arguments/);
|
||||
});
|
||||
|
||||
it('should return a value if the storage function does not expect an argument', (): void => {
|
||||
expect(() => extrinsics.balances.setBalance('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', 2, 3)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should return properly-encoded transactions', (): void => {
|
||||
expect(
|
||||
registry.createType('Extrinsic', extrinsics.timestamp.set([10101])).toU8a()
|
||||
).toEqual(
|
||||
new Uint8Array([
|
||||
// length (encoded)
|
||||
4 << 2,
|
||||
// version, no signature
|
||||
4,
|
||||
// index
|
||||
3, 0,
|
||||
// values, Compact<Moment>
|
||||
116
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it('has working .is', (): void => {
|
||||
const tx = extrinsics.balances.setBalance('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', 2, 3);
|
||||
|
||||
expect(extrinsics.balances.setBalance.is(tx)).toBe(true);
|
||||
expect(extrinsics.balances.transfer.is(tx)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ModulesWithCalls } from '@polkadot/types/types';
|
||||
import type { MetadataLatest } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { Extrinsics, ModuleExtrinsics } from '../types';
|
||||
|
||||
const extrinsics: ModulesWithCalls = {};
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
export default extrinsics;
|
||||
import { createUnchecked } from './createUnchecked';
|
||||
|
||||
/** @internal */
|
||||
export function decorateExtrinsics (registry: Registry, { modules }: MetadataLatest, metaVersion: number): Extrinsics {
|
||||
return modules
|
||||
.filter(({ calls }) => calls.isSome)
|
||||
.reduce((result: Extrinsics, { calls, index, name }, _sectionIndex): Extrinsics => {
|
||||
const sectionIndex = metaVersion === 12
|
||||
? index.toNumber()
|
||||
: _sectionIndex;
|
||||
const section = stringCamelCase(name);
|
||||
|
||||
result[section] = calls.unwrap().reduce((newModule: ModuleExtrinsics, callMetadata, methodIndex): ModuleExtrinsics => {
|
||||
newModule[stringCamelCase(callMetadata.name)] = createUnchecked(registry, section, new Uint8Array([sectionIndex, methodIndex]), callMetadata);
|
||||
|
||||
return newModule;
|
||||
}, {});
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { Metadata } from '../Metadata';
|
||||
import json from '../static';
|
||||
import { constantsFromMeta, extrinsicsFromMeta, storageFromMeta } from './';
|
||||
import { decorateConstants, decorateExtrinsics, decorateStorage } from './';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, json);
|
||||
@@ -15,7 +15,7 @@ registry.setMetadata(metadata);
|
||||
|
||||
describe('Decorated', () => {
|
||||
it('should correctly get Alice\'s nonce storage key (u8a)', (): void => {
|
||||
const query = storageFromMeta(registry, metadata);
|
||||
const query = decorateStorage(registry, metadata.asLatest, metadata.version);
|
||||
|
||||
expect(
|
||||
u8aToHex(
|
||||
@@ -27,7 +27,7 @@ describe('Decorated', () => {
|
||||
});
|
||||
|
||||
it('should return properly-encoded transactions', (): void => {
|
||||
const tx = extrinsicsFromMeta(registry, metadata);
|
||||
const tx = decorateExtrinsics(registry, metadata.asLatest, metadata.version);
|
||||
|
||||
expect(
|
||||
registry.createType('Extrinsic', tx.timestamp.set([10101])).toU8a()
|
||||
@@ -46,7 +46,7 @@ describe('Decorated', () => {
|
||||
});
|
||||
|
||||
it('should return constants with the correct type and value', (): void => {
|
||||
const consts = constantsFromMeta(registry, metadata);
|
||||
const consts = decorateConstants(registry, metadata.asLatest);
|
||||
|
||||
expect(consts.democracy.cooloffPeriod).toBeInstanceOf(registry.createClass('BlockNumber'));
|
||||
expect(consts.democracy.cooloffPeriod.toHex()).toEqual('0x000c4e00');
|
||||
|
||||
@@ -7,21 +7,27 @@ import type { DecoratedMeta } from './types';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { Metadata } from '../Metadata';
|
||||
import { constantsFromMeta } from './consts/fromMetadata';
|
||||
import { extrinsicsFromMeta } from './extrinsics/fromMetadata';
|
||||
import { storageFromMeta } from './storage/fromMetadata';
|
||||
import { decorateConstants } from './constants';
|
||||
import { decorateErrors } from './errors';
|
||||
import { decorateEvents } from './events';
|
||||
import { decorateExtrinsics } from './extrinsics';
|
||||
import { decorateStorage } from './storage';
|
||||
|
||||
/**
|
||||
* Expands the metadata by decoration int consts, query and tx sections
|
||||
* Expands the metadata by decoration into consts, query and tx sections
|
||||
*/
|
||||
export function expandMetadata (registry: Registry, value: Metadata): DecoratedMeta {
|
||||
assert(value instanceof Metadata, 'You need to pass a valid Metadata instance to Decorated');
|
||||
export function expandMetadata (registry: Registry, metadata: Metadata): DecoratedMeta {
|
||||
assert(metadata instanceof Metadata, 'You need to pass a valid Metadata instance to Decorated');
|
||||
|
||||
const latest = metadata.asLatest;
|
||||
|
||||
return {
|
||||
consts: constantsFromMeta(registry, value),
|
||||
query: storageFromMeta(registry, value),
|
||||
tx: extrinsicsFromMeta(registry, value)
|
||||
consts: decorateConstants(registry, latest),
|
||||
errors: decorateErrors(registry, latest, metadata.version),
|
||||
events: decorateEvents(registry, latest, metadata.version),
|
||||
query: decorateStorage(registry, latest, metadata.version),
|
||||
tx: decorateExtrinsics(registry, latest, metadata.version)
|
||||
};
|
||||
}
|
||||
|
||||
export { constantsFromMeta, extrinsicsFromMeta, storageFromMeta };
|
||||
export { decorateConstants, decorateExtrinsics, decorateStorage };
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { ModuleStorage, Storage } from '../types';
|
||||
|
||||
import { stringCamelCase, stringLowerFirst } from '@polkadot/util';
|
||||
|
||||
import { Metadata } from '../../Metadata';
|
||||
import { createFunction } from './createFunction';
|
||||
import { getStorage } from './storage';
|
||||
|
||||
/** @internal */
|
||||
export function storageFromMeta (registry: Registry, metadata: Metadata): Storage {
|
||||
return metadata.asLatest.modules.reduce((result: Storage, moduleMetadata): Storage => {
|
||||
if (moduleMetadata.storage.isNone) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const { name } = moduleMetadata;
|
||||
const section = stringCamelCase(name);
|
||||
const unwrapped = moduleMetadata.storage.unwrap();
|
||||
const prefix = unwrapped.prefix.toString();
|
||||
|
||||
// For access, we change the index names, i.e. System.Account -> system.account
|
||||
result[section] = unwrapped.items.reduce((newModule, meta): ModuleStorage => {
|
||||
const method = meta.name.toString();
|
||||
|
||||
newModule[stringLowerFirst(method)] = createFunction(registry, {
|
||||
meta,
|
||||
method,
|
||||
prefix,
|
||||
section
|
||||
}, { metaVersion: metadata.version });
|
||||
|
||||
return newModule;
|
||||
}, {} as ModuleStorage);
|
||||
|
||||
return result;
|
||||
}, { ...getStorage(registry, metadata.version) });
|
||||
}
|
||||
+2
-2
@@ -3,9 +3,9 @@
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
|
||||
import { getStorage } from './storage';
|
||||
import { getStorage } from './getStorage';
|
||||
|
||||
describe('storage', (): void => {
|
||||
describe('getSorage', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const storage = getStorage(registry, 8);
|
||||
|
||||
+5
-5
@@ -7,25 +7,25 @@ import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { Metadata } from '../../';
|
||||
import rpcMetadata from '../../static';
|
||||
import { storageFromMeta } from '../';
|
||||
import { decorateStorage } from '..';
|
||||
|
||||
const keyring = createTestPairs({ type: 'ed25519' });
|
||||
|
||||
describe('fromMetadata', (): void => {
|
||||
describe('decorateStorage', (): void => {
|
||||
describe('latest', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, rpcMetadata);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
const query = storageFromMeta(registry, metadata);
|
||||
const query = decorateStorage(registry, metadata.asLatest, metadata.version);
|
||||
|
||||
it('should throw if the storage function expects an argument', (): void => {
|
||||
expect((): any => query.balances.account()).toThrowError(/requires one argument/);
|
||||
expect(() => query.balances.account()).toThrowError(/requires one argument/);
|
||||
});
|
||||
|
||||
it('should return a value if the storage function does not expect an argument', (): void => {
|
||||
expect((): any => query.timestamp.now()).not.toThrow();
|
||||
expect(() => query.timestamp.now()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should return the correct length-prefixed storage key', (): void => {
|
||||
@@ -1,6 +1,41 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { getStorage } from './storage';
|
||||
import type { MetadataLatest } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { ModuleStorage, Storage } from '../types';
|
||||
|
||||
export default getStorage;
|
||||
import { stringCamelCase, stringLowerFirst } from '@polkadot/util';
|
||||
|
||||
import { createFunction } from './createFunction';
|
||||
import { getStorage } from './getStorage';
|
||||
|
||||
/** @internal */
|
||||
export function decorateStorage (registry: Registry, { modules }: MetadataLatest, metaVersion: number): Storage {
|
||||
return modules.reduce((result: Storage, moduleMetadata): Storage => {
|
||||
if (moduleMetadata.storage.isNone) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const { name } = moduleMetadata;
|
||||
const section = stringCamelCase(name);
|
||||
const unwrapped = moduleMetadata.storage.unwrap();
|
||||
const prefix = unwrapped.prefix.toString();
|
||||
|
||||
// For access, we change the index names, i.e. System.Account -> system.account
|
||||
result[section] = unwrapped.items.reduce((newModule, meta): ModuleStorage => {
|
||||
const method = meta.name.toString();
|
||||
|
||||
newModule[stringLowerFirst(method)] = createFunction(registry, {
|
||||
meta,
|
||||
method,
|
||||
prefix,
|
||||
section
|
||||
}, { metaVersion });
|
||||
|
||||
return newModule;
|
||||
}, {} as ModuleStorage);
|
||||
|
||||
return result;
|
||||
}, { ...getStorage(registry, metaVersion) });
|
||||
}
|
||||
|
||||
@@ -1,27 +1,50 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AugmentedConst, QueryableConsts, QueryableModuleConsts } from '@polkadot/api/types/consts';
|
||||
import type { DispatchError, ErrorMetadataLatest, EventMetadataLatest, ModuleConstantMetadataLatest } from '@polkadot/types/interfaces';
|
||||
import type { StorageEntry } from '@polkadot/types/primitive/types';
|
||||
import type { Codec, ModulesWithCalls } from '@polkadot/types/types';
|
||||
import type { AnyTuple, CallFunction, Codec, IEventRecord } from '@polkadot/types/types';
|
||||
|
||||
export interface ModuleStorage {
|
||||
[key: string]: StorageEntry;
|
||||
export interface ConstantCodec extends Codec {
|
||||
readonly meta: ModuleConstantMetadataLatest;
|
||||
}
|
||||
|
||||
export type Constants = QueryableConsts<'rxjs'>;
|
||||
export interface IsError {
|
||||
readonly meta: ErrorMetadataLatest;
|
||||
|
||||
export type ConstantCodec = Codec & AugmentedConst<'rxjs'>;
|
||||
|
||||
export type ModuleConstants = QueryableModuleConsts;
|
||||
|
||||
export interface Storage {
|
||||
[key: string]: ModuleStorage;
|
||||
substrate: ModuleStorage;
|
||||
is: (dispatchError: DispatchError) => boolean;
|
||||
}
|
||||
|
||||
export interface IsEvent <T extends AnyTuple> {
|
||||
readonly meta: EventMetadataLatest;
|
||||
|
||||
is: (record: IEventRecord<AnyTuple>) => record is IEventRecord<T>;
|
||||
}
|
||||
|
||||
export type ModuleConstants = Record<string, ConstantCodec>;
|
||||
|
||||
export type ModuleErrors = Record<string, IsError>;
|
||||
|
||||
export type ModuleEvents = Record<string, IsEvent<AnyTuple>>;
|
||||
|
||||
export type ModuleExtrinsics = Record<string, CallFunction>;
|
||||
|
||||
export type ModuleStorage = Record<string, StorageEntry>
|
||||
|
||||
export type Constants = Record<string, ModuleConstants>;
|
||||
|
||||
export type Errors = Record<string, ModuleErrors>;
|
||||
|
||||
export type Events = Record<string, ModuleEvents>;
|
||||
|
||||
export type Extrinsics = Record<string, ModuleExtrinsics>
|
||||
|
||||
export type Storage = Record<string, ModuleStorage>;
|
||||
|
||||
export interface DecoratedMeta {
|
||||
consts: Constants;
|
||||
query: Storage;
|
||||
tx: ModulesWithCalls
|
||||
readonly consts: Constants;
|
||||
readonly errors: Errors;
|
||||
readonly events: Events;
|
||||
readonly query: Storage;
|
||||
readonly tx: Extrinsics
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// For esm, this should be import.meta.url or to get the same behavior as __dirname, we can use
|
||||
//
|
||||
// new URL(import.meta.url).pathname)
|
||||
//
|
||||
// The issue is the WP4 has "some" issues with import.meta.url. So because of bundlers, we can't have
|
||||
// nice things... In this case it is even worse since import.meta.url won't even make it compile, so
|
||||
// there is a complete dead end with usage thereof
|
||||
//
|
||||
// When that is fixed, a solution is to have both .js & .mjs files, with the following content -
|
||||
//
|
||||
// cjs: util.detectPackage(packageInfo, () => __dirname);
|
||||
// esm: detectPackage(packageInfo, () => import.meta.url);
|
||||
//
|
||||
// With the above we additionally need a .d.ts to just export the packageInfo
|
||||
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import packageInfo from './package-info.json';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { packageInfo };
|
||||
@@ -1,5 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/metadata authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
export { Metadata } from './Metadata';
|
||||
export { constantsFromMeta, expandMetadata, extrinsicsFromMeta, storageFromMeta } from './decorate';
|
||||
export { decorateConstants, decorateExtrinsics, decorateStorage, expandMetadata } from './decorate';
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-core",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"sideEffects": false,
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
@@ -13,13 +14,13 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/metadata": "3.0.1",
|
||||
"@polkadot/rpc-provider": "3.0.1",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/x-rxjs": "3.0.1"
|
||||
"@polkadot/metadata": "3.2.1",
|
||||
"@polkadot/rpc-provider": "3.2.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"@polkadot/x-rxjs": "3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^5.0.1"
|
||||
"@polkadot/keyring": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ function logErrorMessage (method: string, { params, type }: DefinitionRpc, error
|
||||
l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
|
||||
}
|
||||
|
||||
function isTreatAsHex (key: StorageKey): boolean {
|
||||
// :code is problematic - it does not have the length attached, which is
|
||||
// unlike all other storage entries where it is indeed properly encoded
|
||||
return ['0x3a636f6465'].includes(key.toHex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Rpc
|
||||
* @summary The API may use a HTTP or WebSockets provider.
|
||||
@@ -100,6 +106,8 @@ export class RpcCore implements RpcInterface {
|
||||
|
||||
public readonly engine!: RpcInterface['engine'];
|
||||
|
||||
public readonly eth!: RpcInterface['eth'];
|
||||
|
||||
public readonly grandpa!: RpcInterface['grandpa'];
|
||||
|
||||
public readonly offchain!: RpcInterface['offchain'];
|
||||
@@ -369,12 +377,6 @@ export class RpcCore implements RpcInterface {
|
||||
);
|
||||
}
|
||||
|
||||
private _treatAsHex (key: StorageKey): boolean {
|
||||
// :code is problematic - it does not have the length attached, which is
|
||||
// unlike all other storage entries where it is indeed properly encoded
|
||||
return ['0x3a636f6465'].includes(key.toHex());
|
||||
}
|
||||
|
||||
private _formatOutput (registry: Registry, method: string, rpc: DefinitionRpc, params: Codec[], result?: any): Codec | Codec[] {
|
||||
if (rpc.type === 'StorageData') {
|
||||
const key = params[0] as StorageKey;
|
||||
@@ -402,47 +404,17 @@ export class RpcCore implements RpcInterface {
|
||||
}
|
||||
|
||||
private _formatStorageData (registry: Registry, key: StorageKey, value: string | null): Codec {
|
||||
// single return value (via state.getStorage), decode the value based on the
|
||||
// outputType that we have specified. Fallback to Raw on nothing
|
||||
const type = key.outputType || 'Raw';
|
||||
const meta = key.meta || EMPTY_META;
|
||||
const isEmpty = isNull(value);
|
||||
|
||||
// we convert to Uint8Array since it maps to the raw encoding, all
|
||||
// data will be correctly encoded (incl. numbers, excl. :code)
|
||||
const input = isEmpty
|
||||
? null
|
||||
: this._treatAsHex(key)
|
||||
: isTreatAsHex(key)
|
||||
? value
|
||||
: u8aToU8a(value);
|
||||
|
||||
if (meta.modifier.isOptional) {
|
||||
let inner = null;
|
||||
|
||||
if (!isEmpty) {
|
||||
try {
|
||||
inner = createTypeUnsafe(registry, type, [input], true);
|
||||
} catch (error) {
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:`, (error as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
return new Option(registry, createClass(registry, type), inner);
|
||||
}
|
||||
|
||||
try {
|
||||
return createTypeUnsafe(registry, type, [
|
||||
isEmpty
|
||||
? meta.fallback
|
||||
? hexToU8a(meta.fallback.toHex())
|
||||
: undefined
|
||||
: input
|
||||
], true);
|
||||
} catch (error) {
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:`, (error as Error).message);
|
||||
|
||||
return registry.createType('Raw', input);
|
||||
}
|
||||
return this._newType(registry, key, input, isEmpty);
|
||||
}
|
||||
|
||||
private _formatStorageSet (registry: Registry, keys: Vec<StorageKey>, changes: [string, string | null][]): Codec[] {
|
||||
@@ -453,7 +425,7 @@ export class RpcCore implements RpcInterface {
|
||||
// one at a time, all based on the query types. Three values can be returned -
|
||||
// - Codec - There is a valid value, non-empty
|
||||
// - null - The storage key is empty
|
||||
return keys.reduce((results: Codec[], key: StorageKey, index: number): Codec[] => {
|
||||
return keys.reduce((results: Codec[], key: StorageKey, index): Codec[] => {
|
||||
results.push(this._formatStorageSetEntry(registry, key, changes, withCache, index));
|
||||
|
||||
return results;
|
||||
@@ -461,10 +433,7 @@ export class RpcCore implements RpcInterface {
|
||||
}
|
||||
|
||||
private _formatStorageSetEntry (registry: Registry, key: StorageKey, changes: [string, string | null][], witCache: boolean, entryIndex: number): Codec {
|
||||
// Fallback to Raw (i.e. just the encoding) if we don't have a specific type
|
||||
const type = key.outputType || 'Raw';
|
||||
const hexKey = key.toHex();
|
||||
const meta = key.meta || EMPTY_META;
|
||||
const found = changes.find(([key]) => key === hexKey);
|
||||
|
||||
// if we don't find the value, this is our fallback
|
||||
@@ -475,7 +444,7 @@ export class RpcCore implements RpcInterface {
|
||||
? (witCache && this.#storageCache.get(hexKey)) || null
|
||||
: found[1];
|
||||
const isEmpty = isNull(value);
|
||||
const input = isEmpty || this._treatAsHex(key)
|
||||
const input = isEmpty || isTreatAsHex(key)
|
||||
? value
|
||||
: u8aToU8a(value);
|
||||
|
||||
@@ -484,14 +453,26 @@ export class RpcCore implements RpcInterface {
|
||||
// will increase memory beyond what is allowed.
|
||||
this.#storageCache.set(hexKey, value);
|
||||
|
||||
return this._newType(registry, key, input, isEmpty, entryIndex);
|
||||
}
|
||||
|
||||
private _newType (registry: Registry, key: StorageKey, input: string | Uint8Array | null, isEmpty: boolean, entryIndex = -1): Codec {
|
||||
// single return value (via state.getStorage), decode the value based on the
|
||||
// outputType that we have specified. Fallback to Raw on nothing
|
||||
const type = key.outputType || 'Raw';
|
||||
const meta = key.meta || EMPTY_META;
|
||||
const entryNum = entryIndex === -1
|
||||
? ''
|
||||
: ` entry ${entryIndex}:`;
|
||||
|
||||
if (meta.modifier.isOptional) {
|
||||
let inner = null;
|
||||
|
||||
if (!isEmpty) {
|
||||
try {
|
||||
inner = createTypeUnsafe(registry, type, [input], true);
|
||||
inner = createTypeUnsafe(registry, type, [input], { isPedantic: true });
|
||||
} catch (error) {
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}: entry ${entryIndex}:`, (error as Error).message);
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}`, (error as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,9 +486,9 @@ export class RpcCore implements RpcInterface {
|
||||
? hexToU8a(meta.fallback.toHex())
|
||||
: undefined
|
||||
: input
|
||||
], true);
|
||||
], { isPedantic: true });
|
||||
} catch (error) {
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}: entry ${entryIndex}:`, (error as Error).message);
|
||||
l.error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}`, (error as Error).message);
|
||||
|
||||
return registry.createType('Raw', input);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { asapScheduler, ConnectableObservable, MonoTypeOperatorFunction, Observable, Subscription, TeardownLogic } from '@polkadot/x-rxjs';
|
||||
import type { ConnectableObservable, MonoTypeOperatorFunction, TeardownLogic } from '@polkadot/x-rxjs';
|
||||
|
||||
import { asapScheduler, Observable, Subscription } from '@polkadot/x-rxjs';
|
||||
|
||||
/** @internal */
|
||||
export function refCountDelay <T> (delay = 1750): MonoTypeOperatorFunction<T> {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-provider",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "Transport providers for the API",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"sideEffects": false,
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
@@ -13,17 +14,17 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/util-crypto": "^5.0.1",
|
||||
"@polkadot/x-fetch": "^5.0.1",
|
||||
"@polkadot/x-ws": "^5.0.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"@polkadot/util-crypto": "^5.2.2",
|
||||
"@polkadot/x-fetch": "^5.2.2",
|
||||
"@polkadot/x-ws": "^5.2.2",
|
||||
"bn.js": "^4.11.9",
|
||||
"eventemitter3": "^4.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^5.0.1",
|
||||
"@polkadot/metadata": "3.0.1",
|
||||
"@polkadot/keyring": "^5.2.2",
|
||||
"@polkadot/metadata": "3.2.1",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.0.5"
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import BN from 'bn.js';
|
||||
import EventEmitter from 'eventemitter3';
|
||||
|
||||
import { createTestKeyring } from '@polkadot/keyring/testing';
|
||||
import { Metadata, storageFromMeta } from '@polkadot/metadata';
|
||||
import { decorateStorage, Metadata } from '@polkadot/metadata';
|
||||
import rpcMetadata from '@polkadot/metadata/static';
|
||||
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
|
||||
import rpcHeader from '@polkadot/types/json/Header.004.json';
|
||||
@@ -168,7 +168,7 @@ export class MockProvider implements ProviderInterface {
|
||||
|
||||
this.registry.setMetadata(metadata);
|
||||
|
||||
const query = storageFromMeta(this.registry, metadata);
|
||||
const query = decorateStorage(this.registry, metadata.asLatest, metadata.version);
|
||||
|
||||
// Do something every 1 seconds
|
||||
setInterval((): void => {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@polkadot/typegen",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "Type generation scripts",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"sideEffects": false,
|
||||
"bin": {
|
||||
"polkadot-types-chain-info": "./scripts/polkadot-types-chain-info.js",
|
||||
@@ -22,17 +23,17 @@
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/register": "^7.12.10",
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/api": "3.0.1",
|
||||
"@polkadot/metadata": "3.0.1",
|
||||
"@polkadot/rpc-provider": "3.0.1",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/api": "3.2.1",
|
||||
"@polkadot/metadata": "3.2.1",
|
||||
"@polkadot/rpc-provider": "3.2.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"handlebars": "^4.7.6",
|
||||
"websocket": "^1.0.33",
|
||||
"yargs": "^16.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/websocket": "^1.0.1",
|
||||
"@types/yargs": "^15.0.11"
|
||||
"@types/yargs": "^15.0.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,11 @@ try {
|
||||
['module-resolver', {
|
||||
alias: {
|
||||
'^@polkadot/api-derive(.*)': './packages/api-derive/src\\1',
|
||||
'^@polkadot/api/package.json': './packages/api/package.json',
|
||||
'^@polkadot/api(.*)': './packages/api/src/\\1',
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1',
|
||||
'^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1',
|
||||
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
|
||||
'^@polkadot/types/package.json': './packages/types/package.json',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
|
||||
@@ -16,7 +16,6 @@ try {
|
||||
alias: {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
|
||||
'^@polkadot/types/package.json': './packages/types/package.json',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
|
||||
@@ -17,7 +17,6 @@ try {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/typegen(.*)': './packages/typegen/src\\1',
|
||||
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
|
||||
'^@polkadot/types/package.json': './packages/types/package.json',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
|
||||
@@ -16,7 +16,6 @@ try {
|
||||
alias: {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
|
||||
'^@polkadot/types/package.json': './packages/types/package.json',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
|
||||
@@ -16,7 +16,6 @@ try {
|
||||
alias: {
|
||||
'^@polkadot/metadata(.*)': './packages/metadata/src\\1',
|
||||
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
|
||||
'^@polkadot/types/package.json': './packages/types/package.json',
|
||||
'^@polkadot/types(.*)': './packages/types/src\\1'
|
||||
}
|
||||
}]
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import process from 'process';
|
||||
import yargs from 'yargs';
|
||||
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api/index';
|
||||
import { ApiPromise, WsProvider } from '@polkadot/api';
|
||||
|
||||
/** @internal */
|
||||
async function run (ws: string): Promise<void> {
|
||||
|
||||
@@ -7,7 +7,7 @@ import yargs from 'yargs';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
import { WebSocket } from '@polkadot/x-ws';
|
||||
|
||||
import { generateDefaultConsts, generateDefaultQuery, generateDefaultRpc, generateDefaultTx } from './generate';
|
||||
import { generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultQuery, generateDefaultRpc, generateDefaultTx } from './generate';
|
||||
import { HEADER, writeFile } from './util';
|
||||
|
||||
function generate (metaHex: string, pkg: string | undefined, output: string, isStrict?: boolean): void {
|
||||
@@ -19,6 +19,8 @@ function generate (metaHex: string, pkg: string | undefined, output: string, isS
|
||||
: {};
|
||||
|
||||
generateDefaultConsts(path.join(process.cwd(), output, 'augment-api-consts.ts'), metaHex, extraTypes, isStrict);
|
||||
generateDefaultErrors(path.join(process.cwd(), output, 'augment-api-errors.ts'), metaHex, isStrict);
|
||||
generateDefaultEvents(path.join(process.cwd(), output, 'augment-api-events.ts'), metaHex, extraTypes, isStrict);
|
||||
generateDefaultQuery(path.join(process.cwd(), output, 'augment-api-query.ts'), metaHex, extraTypes, isStrict);
|
||||
generateDefaultRpc(path.join(process.cwd(), output, 'augment-api-rpc.ts'), extraTypes);
|
||||
generateDefaultTx(path.join(process.cwd(), output, 'augment-api-tx.ts'), metaHex, extraTypes, isStrict);
|
||||
@@ -28,7 +30,7 @@ function generate (metaHex: string, pkg: string | undefined, output: string, isS
|
||||
HEADER('chain'),
|
||||
...[
|
||||
'@polkadot/api/augment/rpc',
|
||||
...['consts', 'query', 'tx', 'rpc'].filter((key) => !!key).map((key) => `./augment-api-${key}`)
|
||||
...['consts', 'errors', 'events', 'query', 'tx', 'rpc'].filter((key) => !!key).map((key) => `./augment-api-${key}`)
|
||||
].map((path) => `import '${path}';\n`)
|
||||
].join('')
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import { Metadata } from '@polkadot/metadata';
|
||||
import { Metadata } from '@polkadot/metadata/Metadata';
|
||||
import staticData from '@polkadot/metadata/static';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import { Metadata } from '@polkadot/metadata/Metadata';
|
||||
import staticData from '@polkadot/metadata/static';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { compareName, createImports, readTemplate, writeFile } from '../util';
|
||||
|
||||
const template = readTemplate('errors');
|
||||
const generateForMetaTemplate = Handlebars.compile(template);
|
||||
|
||||
/** @internal */
|
||||
function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void {
|
||||
writeFile(dest, (): string => {
|
||||
const imports = createImports({});
|
||||
|
||||
const modules = meta.asLatest.modules
|
||||
.sort(compareName)
|
||||
.filter((mod) => mod.errors.length > 0)
|
||||
.map(({ errors, name }) => ({
|
||||
items: errors
|
||||
.sort(compareName)
|
||||
.map(({ documentation, name }) => ({
|
||||
docs: documentation,
|
||||
name: name.toString()
|
||||
})),
|
||||
name: stringCamelCase(name)
|
||||
}));
|
||||
|
||||
const types = [
|
||||
{
|
||||
file: '@polkadot/api/types',
|
||||
types: ['ApiTypes']
|
||||
}
|
||||
];
|
||||
|
||||
return generateForMetaTemplate({
|
||||
headerType: 'chain',
|
||||
imports,
|
||||
isStrict,
|
||||
modules,
|
||||
types
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Call `generateForMeta()` with current static metadata
|
||||
/** @internal */
|
||||
export function generateDefaultErrors (dest = 'packages/api/src/augment/errors.ts', data = staticData, isStrict = false): void {
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, data);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
return generateForMeta(metadata, dest, isStrict);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import { Metadata } from '@polkadot/metadata/Metadata';
|
||||
import staticData from '@polkadot/metadata/static';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { compareName, createImports, formatType, readTemplate, registerDefinitions, setImports, writeFile } from '../util';
|
||||
|
||||
const template = readTemplate('events');
|
||||
const generateForMetaTemplate = Handlebars.compile(template);
|
||||
|
||||
/** @internal */
|
||||
function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<string, Record<string, { types: Record<string, any> }>>, isStrict: boolean): void {
|
||||
writeFile(dest, (): string => {
|
||||
const allTypes: Record<string, Record<string, { types: Record<string, unknown> }>> = { '@polkadot/types/interfaces': defaultDefs, ...extraTypes };
|
||||
const imports = createImports(allTypes);
|
||||
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
||||
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
||||
}, {});
|
||||
|
||||
const modules = meta.asLatest.modules
|
||||
.sort(compareName)
|
||||
.filter((mod) => mod.events.isSome)
|
||||
.map(({ events, name }) => ({
|
||||
items: events
|
||||
.unwrap()
|
||||
.sort(compareName)
|
||||
.map(({ args, documentation, name }) => {
|
||||
const types = args.map((type) => formatType(allDefs, type.toString(), imports));
|
||||
|
||||
setImports(allDefs, imports, types);
|
||||
|
||||
return {
|
||||
docs: documentation,
|
||||
name: name.toString(),
|
||||
type: types.join(', ')
|
||||
};
|
||||
}),
|
||||
name: stringCamelCase(name)
|
||||
}));
|
||||
|
||||
const types = [
|
||||
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
||||
file: packagePath,
|
||||
types: Object.keys(imports.localTypes[packagePath])
|
||||
})),
|
||||
{
|
||||
file: '@polkadot/api/types',
|
||||
types: ['ApiTypes']
|
||||
}
|
||||
];
|
||||
|
||||
return generateForMetaTemplate({
|
||||
headerType: 'chain',
|
||||
imports,
|
||||
isStrict,
|
||||
modules,
|
||||
types
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Call `generateForMeta()` with current static metadata
|
||||
/** @internal */
|
||||
export function generateDefaultEvents (dest = 'packages/api/src/augment/events.ts', data = staticData, extraTypes: Record<string, Record<string, { types: Record<string, any> }>> = {}, isStrict = false): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
registerDefinitions(registry, extraTypes);
|
||||
|
||||
const metadata = new Metadata(registry, data);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
return generateForMeta(metadata, dest, extraTypes, isStrict);
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { generateDefaultConsts } from './consts';
|
||||
export { generateDefaultErrors } from './errors';
|
||||
export { generateDefaultEvents } from './events';
|
||||
export { generateDefaultInterface } from './interfaceRegistry';
|
||||
export { generateDefaultQuery } from './query';
|
||||
export { generateDefaultRpc } from './rpc';
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import { Metadata } from '@polkadot/metadata';
|
||||
import { Metadata } from '@polkadot/metadata/Metadata';
|
||||
import staticData from '@polkadot/metadata/static';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
@@ -18,13 +18,13 @@ import { ModuleTypes } from '../util/imports';
|
||||
|
||||
// From a storage entry metadata, we return [args, returnType]
|
||||
/** @internal */
|
||||
function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [string, string] {
|
||||
function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [string, string, string] {
|
||||
const outputType = unwrapStorageType(storageEntry.type, storageEntry.modifier.isOptional);
|
||||
|
||||
if (storageEntry.type.isPlain) {
|
||||
setImports(allDefs, imports, [storageEntry.type.asPlain.toString()]);
|
||||
|
||||
return ['', formatType(allDefs, outputType, imports)];
|
||||
return ['', '', formatType(allDefs, outputType, imports)];
|
||||
} else if (storageEntry.type.isMap) {
|
||||
// Find similar types of the `key` type
|
||||
const similarTypes = getSimilarTypes(registry, allDefs, storageEntry.type.asMap.key.toString(), imports);
|
||||
@@ -35,6 +35,7 @@ function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registr
|
||||
]);
|
||||
|
||||
return [
|
||||
formatType(allDefs, storageEntry.type.asMap.key.toString(), imports),
|
||||
`arg: ${similarTypes.join(' | ')}`,
|
||||
formatType(allDefs, outputType, imports)
|
||||
];
|
||||
@@ -53,6 +54,7 @@ function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registr
|
||||
const key2Types = similarTypes2.join(' | ');
|
||||
|
||||
return [
|
||||
[formatType(allDefs, storageEntry.type.asDoubleMap.key1.toString(), imports), formatType(allDefs, storageEntry.type.asDoubleMap.key2.toString(), imports)].join(', '),
|
||||
`key1: ${key1Types}, key2: ${key2Types}`,
|
||||
formatType(allDefs, outputType, imports)
|
||||
];
|
||||
@@ -80,7 +82,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
const items = storage.unwrap().items
|
||||
.sort(compareName)
|
||||
.map((storageEntry) => {
|
||||
const [args, returnType] = entrySignature(allDefs, registry, storageEntry, imports);
|
||||
const [args, params, returnType] = entrySignature(allDefs, registry, storageEntry, imports);
|
||||
let entryType = 'AugmentedQuery';
|
||||
|
||||
if (storageEntry.type.isDoubleMap) {
|
||||
@@ -92,6 +94,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
docs: storageEntry.documentation,
|
||||
entryType,
|
||||
name: stringCamelCase(storageEntry.name),
|
||||
params,
|
||||
returnType
|
||||
};
|
||||
});
|
||||
|
||||
@@ -5,14 +5,14 @@ import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import { Metadata } from '@polkadot/metadata';
|
||||
import { Metadata } from '@polkadot/metadata/Metadata';
|
||||
import staticData from '@polkadot/metadata/static';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
import { Text } from '@polkadot/types/primitive';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { compareName, createImports, getSimilarTypes, readTemplate, registerDefinitions, setImports, writeFile } from '../util';
|
||||
import { compareName, createImports, formatType, getSimilarTypes, readTemplate, registerDefinitions, setImports, writeFile } from '../util';
|
||||
|
||||
const MAPPED_NAMES: Record<string, string> = {
|
||||
new: 'updated'
|
||||
@@ -57,6 +57,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
.join(', ');
|
||||
|
||||
return {
|
||||
args: args.map(({ type }) => formatType(allDefs, type.toString(), imports)).join(', '),
|
||||
docs: documentation,
|
||||
name: stringCamelCase(name),
|
||||
params
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
// Copyright 2017-2020 @polkadot/typegen authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { generateDefaultConsts, generateDefaultInterface, generateDefaultQuery, generateDefaultRpc, generateDefaultTsDef, generateDefaultTx } from './generate';
|
||||
import { generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultInterface, generateDefaultQuery, generateDefaultRpc, generateDefaultTsDef, generateDefaultTx } from './generate';
|
||||
|
||||
export function main (): void {
|
||||
generateDefaultInterface();
|
||||
|
||||
generateDefaultConsts();
|
||||
generateDefaultErrors();
|
||||
generateDefaultEvents();
|
||||
generateDefaultQuery();
|
||||
generateDefaultTx();
|
||||
generateDefaultRpc();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{{> header }}
|
||||
|
||||
{{{ imports }}}
|
||||
|
||||
declare module '@polkadot/api/types/errors' {
|
||||
export interface AugmentedErrors<ApiType> {
|
||||
{{#each modules}}
|
||||
{{{name}}}: {
|
||||
{{#unless @root.isStrict}}
|
||||
[key: string]: AugmentedError<ApiType>;
|
||||
{{/unless}}
|
||||
{{~#each items}}
|
||||
{{> docs}}
|
||||
{{{name}}}: AugmentedError<ApiType>;
|
||||
{{/each}}
|
||||
};
|
||||
{{/each}}
|
||||
}
|
||||
|
||||
export interface DecoratedErrors<ApiType extends ApiTypes> extends AugmentedErrors<ApiType> {
|
||||
{{#unless isStrict}}
|
||||
[key: string]: ModuleErrors<ApiType>;
|
||||
{{/unless}}
|
||||
}
|
||||
}
|
||||
{{> footer }}
|
||||
@@ -0,0 +1,26 @@
|
||||
{{> header }}
|
||||
|
||||
{{{ imports }}}
|
||||
|
||||
declare module '@polkadot/api/types/events' {
|
||||
export interface AugmentedEvents<ApiType> {
|
||||
{{#each modules}}
|
||||
{{{name}}}: {
|
||||
{{#unless @root.isStrict}}
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
{{/unless}}
|
||||
{{~#each items}}
|
||||
{{> docs}}
|
||||
{{{name}}}: AugmentedEvent<ApiType, [{{{type}}}]>;
|
||||
{{/each}}
|
||||
};
|
||||
{{/each}}
|
||||
}
|
||||
|
||||
export interface DecoratedEvents<ApiType extends ApiTypes> extends AugmentedEvents<ApiType> {
|
||||
{{#unless isStrict}}
|
||||
[key: string]: ModuleEvents<ApiType>;
|
||||
{{/unless}}
|
||||
}
|
||||
}
|
||||
{{> footer }}
|
||||
@@ -11,7 +11,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
{{/unless}}
|
||||
{{~#each items}}
|
||||
{{> docs}}
|
||||
{{{name}}}: {{{entryType}}}<ApiType, ({{{args}}}) => Observable<{{{returnType}}}>>{{#unless @root.isStrict}} & QueryableStorageEntry<ApiType>{{/unless}};
|
||||
{{{name}}}: {{{entryType}}}<ApiType, ({{{params}}}) => Observable<{{{returnType}}}>, [{{{args}}}]>{{#unless @root.isStrict}} & QueryableStorageEntry<ApiType, [{{{args}}}]>{{/unless}};
|
||||
{{/each}}
|
||||
};
|
||||
{{/each}}
|
||||
|
||||
@@ -11,7 +11,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
{{/unless}}
|
||||
{{~#each items}}
|
||||
{{> docs}}
|
||||
{{{name}}}: AugmentedSubmittable<({{{params}}}) => SubmittableExtrinsic<ApiType>>;
|
||||
{{{name}}}: AugmentedSubmittable<({{{params}}}) => SubmittableExtrinsic<ApiType>, [{{{args}}}]>;
|
||||
{{/each}}
|
||||
};
|
||||
{{/each}}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@polkadot/types-known",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"sideEffects": false,
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
@@ -13,8 +14,8 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/types": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/types": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -14,6 +14,13 @@ const typesModules: Record<string, OverrideModuleType> = {
|
||||
contracts: {
|
||||
StorageKey: 'ContractStorageKey'
|
||||
},
|
||||
ethereum: {
|
||||
Block: 'EthBlock',
|
||||
Header: 'EthHeader',
|
||||
Receipt: 'EthReceipt',
|
||||
Transaction: 'EthTransaction',
|
||||
TransactionStatus: 'EthTransactionStatus'
|
||||
},
|
||||
grandpa: {
|
||||
Equivocation: 'GrandpaEquivocation',
|
||||
EquivocationProof: 'GrandpaEquivocationProof'
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
// substrate
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'LookupSource',
|
||||
LookupSource: 'IndicesLookupSource',
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import type { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
@@ -14,18 +15,23 @@ const sharedTypes = {
|
||||
}
|
||||
};
|
||||
|
||||
const indicesTypes = {
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'LookupSource',
|
||||
LookupSource: 'IndicesLookupSource'
|
||||
};
|
||||
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
// 1020 is first CC3
|
||||
minmax: [1019, 1031],
|
||||
types: {
|
||||
Address: 'LookupSource',
|
||||
...indicesTypes,
|
||||
BalanceLock: 'BalanceLockTo212',
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchError: 'DispatchErrorTo198',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'IndicesLookupSource',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RefCount: 'RefCountTo259',
|
||||
@@ -40,12 +46,11 @@ const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [1032, 1042],
|
||||
types: {
|
||||
Address: 'LookupSource',
|
||||
...indicesTypes,
|
||||
BalanceLock: 'BalanceLockTo212',
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'IndicesLookupSource',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RefCount: 'RefCountTo259',
|
||||
@@ -61,12 +66,11 @@ const versioned: OverrideVersionedType[] = [
|
||||
// actual at 1045 (1043-1044 is dev)
|
||||
minmax: [1043, 1045],
|
||||
types: {
|
||||
Address: 'LookupSource',
|
||||
...indicesTypes,
|
||||
BalanceLock: 'BalanceLockTo212',
|
||||
CompactAssignments: 'CompactAssignmentsTo257',
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'IndicesLookupSource',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
RefCount: 'RefCountTo259',
|
||||
|
||||
@@ -10,6 +10,7 @@ const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [0, 259],
|
||||
types: {
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'LookupSource',
|
||||
LookupSource: 'IndicesLookupSource'
|
||||
}
|
||||
@@ -17,6 +18,7 @@ const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [260, undefined],
|
||||
types: {
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'MultiAddress',
|
||||
LookupSource: 'MultiAddress'
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import type { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { OverrideVersionedType } from '@polkadot/types/types';
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
const sharedTypes = {
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId'
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import type { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
AccountInfo: 'AccountInfoWithRefCount',
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
{
|
||||
"name": "@polkadot/types",
|
||||
"version": "3.0.1",
|
||||
"version": "3.2.1",
|
||||
"description": "Implementation of the Parity codec",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
"module": "index.mjs",
|
||||
"sideEffects": [
|
||||
"./detectPackage.js",
|
||||
"./detectPackage.mjs"
|
||||
],
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"maintainers": [],
|
||||
"contributors": [],
|
||||
@@ -13,14 +17,14 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.12.5",
|
||||
"@polkadot/metadata": "3.0.1",
|
||||
"@polkadot/util": "^5.0.1",
|
||||
"@polkadot/util-crypto": "^5.0.1",
|
||||
"@polkadot/x-rxjs": "3.0.1",
|
||||
"@polkadot/metadata": "3.2.1",
|
||||
"@polkadot/util": "^5.2.2",
|
||||
"@polkadot/util-crypto": "^5.2.2",
|
||||
"@polkadot/x-rxjs": "3.2.1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.11.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^5.0.1"
|
||||
"@polkadot/keyring": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user