Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b269d25b8 | ||
|
|
86f3f4748a | ||
|
|
3773ae8ed5 | ||
|
|
b8dd03f25c | ||
|
|
a0a787d8b9 | ||
|
|
1b72a1cb11 | ||
|
|
c334c161f0 | ||
|
|
311cbe5fee | ||
|
|
cf7e2f01ac | ||
|
|
4863709083 | ||
|
|
a1d7cad9d8 | ||
|
|
7f7acd6421 | ||
|
|
a5c5f76aee | ||
|
|
d0905268a4 | ||
|
|
852cbeb123 | ||
|
|
8f94c8852e | ||
|
|
95d4d7ee71 | ||
|
|
e6d40eb8d0 | ||
|
|
3f73f4dbf5 | ||
|
|
bbd52e5150 | ||
|
|
dc5c66e8af | ||
|
|
9db7d8d290 | ||
|
|
a1c43fed9e | ||
|
|
ed62d164ea | ||
|
|
3d45da3195 | ||
|
|
fff3bb912c |
+34
-1
@@ -1,10 +1,43 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 15.9.2 Apr 15, 2025
|
||||
|
||||
Changes:
|
||||
|
||||
- Enhance property access validation in Struct decoding ([#6126](https://github.com/polkadot-js/api/pull/6126))
|
||||
- Improve type registry known defaults implementation to a Map ([#6127](https://github.com/polkadot-js/api/pull/6127))
|
||||
- bump polkadot/common to 13.4.4 ([#6128](https://github.com/polkadot-js/api/pull/6128))
|
||||
|
||||
|
||||
## 15.9.1 Mar 27, 2025
|
||||
|
||||
Changes:
|
||||
|
||||
- Fix signAsync() docs ([#6121](https://github.com/polkadot-js/api/pull/6121))
|
||||
- Make TTL configurable on WsProvider & HttpProvider ([#6123](https://github.com/polkadot-js/api/pull/6123))
|
||||
|
||||
|
||||
## 15.8.1 Mar 10, 2025
|
||||
|
||||
Changes:
|
||||
|
||||
- Add derives to obtain Extrinsic Information ([#6113](https://github.com/polkadot-js/api/pull/6113))
|
||||
|
||||
|
||||
## 15.7.2 Mar 3, 2025
|
||||
|
||||
Changes:
|
||||
|
||||
- Update asset-hub type-support metadata files for v1.4.0 ([#6105](https://github.com/polkadot-js/api/pull/6105))
|
||||
- Document available Api Derives ([#6106](https://github.com/polkadot-js/api/pull/6106))
|
||||
- Fix derives base path in typegen ([#6107](https://github.com/polkadot-js/api/pull/6107))
|
||||
|
||||
|
||||
## 15.7.1 Feb 25, 2025
|
||||
|
||||
Changes:
|
||||
|
||||
- Upgrade Kusama types to 1.4.0 ([#6098](https://github.com/polkadot-js/api/pull/6098))
|
||||
- Upgrade Kusama types to 1.4.0 ([#6098](https://github.com/polkadot-js/api/pull/6098))
|
||||
- Api-Derives documentation generator ([#6099](https://github.com/polkadot-js/api/pull/6099))
|
||||
- Upgrade Polkadot types to v1.4.0 ([#6100](https://github.com/polkadot-js/api/pull/6100))
|
||||
- Add WeightReclaim transaction extension to known extensions ([#6102](https://github.com/polkadot-js/api/pull/6102))
|
||||
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
3512 Jaco Bump deps (#5785)
|
||||
161 Tarik Gul Add WeightReclaim transaction extension to known extensions (#6102)
|
||||
163 Tarik Gul Improve type registry known defaults implementation to a Map (#6127)
|
||||
83 Amaury Martiny StatementKind: Regular and Saft (#2303)
|
||||
37 Keith Ingram Update contract types and rpc (#4541)
|
||||
35 Stefanie Doll Updated child storage parameters (#1709)
|
||||
23 Valentin Fernandez 15.9.2 (#6129)
|
||||
20 Luke Schoen fix: Fixes TypeError: Cannot read property 'vesting' of undefined (#1970)
|
||||
19 Xiliang Chen no warm for unknown signed extensions (#5601)
|
||||
15 Jeremías Díaz feat(types): add correct tuple type to storage key (#3054)
|
||||
14 Nikos Kontakis Bump substrate connect to 0.7.16 (#5307)
|
||||
12 Valentin Fernandez 15.7.1
|
||||
11 Ian He HttpProvider support clone() (#3949)
|
||||
10 Axel Chalon Make Enum/Tuple constructor use value directly if instance (#1954)
|
||||
6 Andreea Eftene Update check for contract instantiation (#5699)
|
||||
|
||||
+3
-3
@@ -14,10 +14,10 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "15.7.1",
|
||||
"version": "15.9.2",
|
||||
"versions": {
|
||||
"git": "15.7.1",
|
||||
"npm": "15.7.1"
|
||||
"git": "15.9.2",
|
||||
"npm": "15.9.2"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
|
||||
@@ -18,15 +18,15 @@
|
||||
"./packageDetect.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "15.7.1",
|
||||
"version": "15.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/api-base": "15.7.1",
|
||||
"@polkadot/rpc-augment": "15.7.1",
|
||||
"@polkadot/types": "15.7.1",
|
||||
"@polkadot/types-augment": "15.7.1",
|
||||
"@polkadot/types-codec": "15.7.1",
|
||||
"@polkadot/util": "^13.4.3",
|
||||
"@polkadot/api-base": "15.9.2",
|
||||
"@polkadot/rpc-augment": "15.9.2",
|
||||
"@polkadot/types": "15.9.2",
|
||||
"@polkadot/types-augment": "15.9.2",
|
||||
"@polkadot/types-codec": "15.9.2",
|
||||
"@polkadot/util": "^13.4.4",
|
||||
"tslib": "^2.8.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-augment', path: 'auto', type: 'auto', version: '15.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-augment', path: 'auto', type: 'auto', version: '15.9.2' };
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
"./packageDetect.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "15.7.1",
|
||||
"version": "15.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/rpc-core": "15.7.1",
|
||||
"@polkadot/types": "15.7.1",
|
||||
"@polkadot/util": "^13.4.3",
|
||||
"@polkadot/rpc-core": "15.9.2",
|
||||
"@polkadot/types": "15.9.2",
|
||||
"@polkadot/util": "^13.4.4",
|
||||
"rxjs": "^7.8.1",
|
||||
"tslib": "^2.8.1"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-base', path: 'auto', type: 'auto', version: '15.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-base', path: 'auto', type: 'auto', version: '15.9.2' };
|
||||
|
||||
@@ -68,13 +68,10 @@ export interface SubmittableExtrinsic<ApiType extends ApiTypes, R extends ISubmi
|
||||
send (statusCb: Callback<R>): SubmittableResultSubscription<ApiType, R>;
|
||||
|
||||
/**
|
||||
* @description Sign and broadcast the constructued transaction.
|
||||
* @description Sign the constructed transaction asynchronously.
|
||||
*
|
||||
* Note for injected signers:
|
||||
* As of v12.0.2 and up the `SignerResult` return type for `signPayload` allows for the `signedTransaction` field.
|
||||
* This allows the signer to input a signed transaction that will modify the payload. This
|
||||
* The api will ensure that the Call Data is not changed. This allows for the signer to modify the payload to add
|
||||
* things like `mode`, and `metadataHash` for signedExtensions such as `CheckMetadataHash`.
|
||||
* The result is a signed extrinsic that is ready to be broadcast to the network via `.send()`, `rpc.author.submitExtrinsic()`, or
|
||||
* any custom submission logic.
|
||||
*/
|
||||
signAsync (account: AddressOrPair, _options?: Partial<SignerOptions>): PromiseOrObs<ApiType, this>;
|
||||
|
||||
|
||||
@@ -18,22 +18,22 @@
|
||||
"./packageDetect.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "15.7.1",
|
||||
"version": "15.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/api": "15.7.1",
|
||||
"@polkadot/api-augment": "15.7.1",
|
||||
"@polkadot/types": "15.7.1",
|
||||
"@polkadot/types-codec": "15.7.1",
|
||||
"@polkadot/types-create": "15.7.1",
|
||||
"@polkadot/util": "^13.4.3",
|
||||
"@polkadot/util-crypto": "^13.4.3",
|
||||
"@polkadot/api": "15.9.2",
|
||||
"@polkadot/api-augment": "15.9.2",
|
||||
"@polkadot/types": "15.9.2",
|
||||
"@polkadot/types-codec": "15.9.2",
|
||||
"@polkadot/types-create": "15.9.2",
|
||||
"@polkadot/util": "^13.4.4",
|
||||
"@polkadot/util-crypto": "^13.4.4",
|
||||
"rxjs": "^7.8.1",
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api-augment": "15.7.1",
|
||||
"@polkadot/keyring": "^13.4.3",
|
||||
"@polkadot/types-support": "15.7.1"
|
||||
"@polkadot/api-augment": "15.9.2",
|
||||
"@polkadot/keyring": "^13.4.4",
|
||||
"@polkadot/types-support": "15.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-contract', path: 'auto', type: 'auto', version: '15.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-contract', path: 'auto', type: 'auto', version: '15.9.2' };
|
||||
|
||||
@@ -3,3 +3,28 @@
|
||||
Collection of high-level utility functions built on top of the @polkadot/api library. Designed to simplify the process of querying complex on-chain data by combining multiple RPC calls, storage queries, and runtime logic into a single, callable function.
|
||||
|
||||
Instead of manually fetching and processing blockchain data, developers can use `api.derive` methods to retrieve information.
|
||||
|
||||
## Available Derive Namespaces
|
||||
|
||||
The derive functions are categorized into namespaces based on different common Substrate modules. Accesible by calling `api.derive.NAMESPACE` (e.g. `api.derive.balances`). The available modules are as follows:
|
||||
|
||||
- [accounts](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/accounts)
|
||||
- [alliance](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/alliance)
|
||||
- [bagsList](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/bagsList)
|
||||
- [balances](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/balances)
|
||||
- [bounties](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/bounties)
|
||||
- [chain](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/chain)
|
||||
- [contracts](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/contracts)
|
||||
- [council](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/council)
|
||||
- [crowdloan](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/crowdloan)
|
||||
- [democracy](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/democracy)
|
||||
- [elections](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/elections)
|
||||
- [imOnline](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/imOnline)
|
||||
- [membership](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/membership)
|
||||
- [parachains](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/parachains)
|
||||
- [session](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/session)
|
||||
- [society](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/society)
|
||||
- [staking](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/staking)
|
||||
- [technicalCommittee](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/technicalCommittee)
|
||||
- [treasury](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/treasury)
|
||||
- [tx](https://github.com/polkadot-js/api/tree/master/packages/api-derive/src/tx)
|
||||
|
||||
@@ -18,25 +18,25 @@
|
||||
"./packageDetect.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "15.7.1",
|
||||
"version": "15.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/api": "15.7.1",
|
||||
"@polkadot/api-augment": "15.7.1",
|
||||
"@polkadot/api-base": "15.7.1",
|
||||
"@polkadot/rpc-core": "15.7.1",
|
||||
"@polkadot/types": "15.7.1",
|
||||
"@polkadot/types-codec": "15.7.1",
|
||||
"@polkadot/util": "^13.4.3",
|
||||
"@polkadot/util-crypto": "^13.4.3",
|
||||
"@polkadot/api": "15.9.2",
|
||||
"@polkadot/api-augment": "15.9.2",
|
||||
"@polkadot/api-base": "15.9.2",
|
||||
"@polkadot/rpc-core": "15.9.2",
|
||||
"@polkadot/types": "15.9.2",
|
||||
"@polkadot/types-codec": "15.9.2",
|
||||
"@polkadot/util": "^13.4.4",
|
||||
"@polkadot/util-crypto": "^13.4.4",
|
||||
"rxjs": "^7.8.1",
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api": "15.7.1",
|
||||
"@polkadot/api-augment": "15.7.1",
|
||||
"@polkadot/rpc-augment": "15.7.1",
|
||||
"@polkadot/rpc-provider": "15.7.1",
|
||||
"@polkadot/types-support": "15.7.1"
|
||||
"@polkadot/api": "15.9.2",
|
||||
"@polkadot/api-augment": "15.9.2",
|
||||
"@polkadot/rpc-augment": "15.9.2",
|
||||
"@polkadot/rpc-provider": "15.9.2",
|
||||
"@polkadot/types-support": "15.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,15 @@ import { memo } from '../util/index.js';
|
||||
/**
|
||||
* @name accountId
|
||||
* @param {(Address | AccountId | AccountIndex | string | null)} address An accounts address in various formats.
|
||||
* @description An [[AccountId]]
|
||||
* @description Resolves an address (in different formats) to its corresponding `AccountId`.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const ALICE = "F7Hs";
|
||||
*
|
||||
* api.derive.accounts.accountId(ALICE, (accountId) => {
|
||||
* console.log(`Resolved AccountId: ${accountId}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function accountId (instanceId: string, api: DeriveApi): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> {
|
||||
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> => {
|
||||
|
||||
@@ -68,8 +68,18 @@ export function _flags (instanceId: string, api: DeriveApi): () => Observable<Fl
|
||||
}
|
||||
|
||||
/**
|
||||
* @name info
|
||||
* @description Returns account membership flags
|
||||
* @name flags
|
||||
* @param {(AccountId | Address | string | null)} address The account identifier.
|
||||
* @description Retrieves the membership flags for a given account.
|
||||
* @example
|
||||
* const ALICE = "F7Hs";
|
||||
*
|
||||
* api.derive.accounts.flags(ALICE, (flags) => {
|
||||
* console.log(
|
||||
* `Account Flags:`,
|
||||
* Object.keys(flags).map((flag) => `${flag}: ${flags[flag]}`)
|
||||
* );
|
||||
* });
|
||||
*/
|
||||
export function flags (instanceId: string, api: DeriveApi): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
||||
return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> =>
|
||||
|
||||
@@ -14,11 +14,9 @@ import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name idAndIndex
|
||||
* @param {(Address | AccountId | AccountIndex | Uint8Array | string | null)} address - An accounts address in various formats.
|
||||
* @description An array containing the [[AccountId]] and [[AccountIndex]] as optional values.
|
||||
* @param {(Address | AccountId | AccountIndex | Uint8Array | string | null)} address An accounts address in various formats.
|
||||
* @description An array containing the [[AccountId]] and [[AccountIndex]] as optional values.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.accounts.idAndIndex('F7Hs', ([id, ix]) => {
|
||||
* console.log(`AccountId #${id} with corresponding AccountIndex ${ix}`);
|
||||
|
||||
@@ -11,11 +11,9 @@ import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name idToIndex
|
||||
* @param {( AccountId | string )} accountId - An accounts Id in different formats.
|
||||
* @returns Returns the corresponding AccountIndex.
|
||||
* @description Retrieves the corresponding AccountIndex.
|
||||
* @param {( AccountId | string )} accountId An accounts Id in different formats.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
|
||||
* api.derive.accounts.idToIndex(ALICE, (accountIndex) => {
|
||||
|
||||
@@ -125,7 +125,19 @@ export function _identity (instanceId: string, api: DeriveApi): (accountId?: Acc
|
||||
|
||||
/**
|
||||
* @name identity
|
||||
* @description Returns identity info for an account
|
||||
* @description Retrieves the on chain identity information for a given account.
|
||||
* @param {(AccountId | Uint8Array | string)} accoutId The account identifier to query the identity for.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const ALICE = "13xAUH";
|
||||
*
|
||||
* api.derive.accounts.identity(ALICE, (identity) => {
|
||||
* console.log(
|
||||
* "Account Identity:",
|
||||
* Object.keys(identity).map((key) => `${key}: ${identity[key]}`)
|
||||
* );
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function identity (instanceId: string, api: DeriveApi): (accountId?: AccountId | Uint8Array | string) => Observable<DeriveAccountRegistration> {
|
||||
return memo(instanceId, (accountId?: AccountId | Uint8Array | string): Observable<DeriveAccountRegistration> =>
|
||||
@@ -165,11 +177,32 @@ function getSubIdentities (identity: DeriveAccountRegistration, api: DeriveApi,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name hasIdentity
|
||||
* @description Checks if a specific account has an identity registered on chain.
|
||||
* @param {(AccountId | Uint8Array | string)} accoutId The account identifier to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const ALICE = "13AU";
|
||||
* console.log(await api.derive.accounts.hasIdentity(ALICE));
|
||||
* ```
|
||||
*/
|
||||
export const hasIdentity = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: AccountId | Uint8Array | string) =>
|
||||
api.derive.accounts.hasIdentityMulti([accountId])
|
||||
);
|
||||
|
||||
/**
|
||||
* @name hasIdentityMulti
|
||||
* @description Checks whether multiple accounts have on chain identities registered.
|
||||
* @param {(AccountId | Uint8Array | string)[]} accountIds Array of account identifiers to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const ALICE = "13AU";
|
||||
* const BOB = "16WW";
|
||||
* console.log(await api.derive.accounts.hasIdentityMulti([ALICE, BOB]));
|
||||
* ```
|
||||
*/
|
||||
export function hasIdentityMulti (instanceId: string, api: DeriveApi): (accountIds: (AccountId | Uint8Array | string)[]) => Observable<DeriveHasIdentity[]> {
|
||||
return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable<DeriveHasIdentity[]> =>
|
||||
api.query.identity?.identityOf
|
||||
|
||||
@@ -11,15 +11,13 @@ import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name indexToId
|
||||
* @param {( AccountIndex | string )} accountIndex - An accounts index in different formats.
|
||||
* @returns Returns the corresponding AccountId.
|
||||
* @description Resolves an AccountIndex (short address) to the full AccountId.
|
||||
* @param {( AccountIndex | string )} accountIndex An accounts index in different formats.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.accounts.indexToId('F7Hs', (accountId) => {
|
||||
* console.log(`The AccountId of F7Hs is ${accountId}`);
|
||||
* });
|
||||
* const ALICE = "13AU";
|
||||
* const id = await api.derive.accounts.indexToId(ALICE);
|
||||
* console.log(id);
|
||||
* ```
|
||||
*/
|
||||
export function indexToId (instanceId: string, api: DeriveApi): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
||||
|
||||
@@ -29,10 +29,8 @@ function queryAccounts (api: DeriveApi): Observable<AccountIndexes> {
|
||||
* @returns Returns all the indexes on the system.
|
||||
* @description This is an unwieldly query since it loops through
|
||||
* all of the enumsets and returns all of the values found. This could be up to 32k depending
|
||||
* on the number of active accounts in the system
|
||||
* on the number of active accounts in the system.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.accounts.indexes((indexes) => {
|
||||
* console.log('All existing AccountIndexes', indexes);
|
||||
|
||||
@@ -30,6 +30,16 @@ function retrieveNick (api: DeriveApi, accountId?: AccountId): Observable<string
|
||||
/**
|
||||
* @name info
|
||||
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex, identity and nickname
|
||||
* @param {(AccountIndex | AccountId | Address | Uint8Array | string | null)} address An accounts in different formats.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const ALICE = "13AU";
|
||||
* const info = await api.derive.accounts.info(ALICE);
|
||||
* console.log(
|
||||
* "Account Info: ",
|
||||
* Object.keys(info).map((key) => `${key}: ${info[key]}`)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function info (instanceId: string, api: DeriveApi): (address?: AccountIndex | AccountId | Address | Uint8Array | string | null) => Observable<DeriveAccountInfo> {
|
||||
return memo(instanceId, (address?: AccountIndex | AccountId | Address | Uint8Array | string | null): Observable<DeriveAccountInfo> =>
|
||||
|
||||
@@ -3,12 +3,74 @@
|
||||
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
|
||||
|
||||
/**
|
||||
* @name members
|
||||
* @description Retrieves the list of members in the "allianceMotion" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const members = await api.derive.alliance.members();
|
||||
* console.log(`Members: ${JSON.stringify(members)});
|
||||
* ```
|
||||
*/
|
||||
export const members = /*#__PURE__*/ collectiveMembers('allianceMotion');
|
||||
|
||||
/**
|
||||
* @name hasProposals
|
||||
* @description Checks if there are any active proposals in the "allianceMotion" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exists = await api.derive.alliance.hasProposals();
|
||||
* console.log(exists);
|
||||
* ```
|
||||
*/
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('allianceMotion');
|
||||
/**
|
||||
* @name proposal
|
||||
* @description Retrieves details of a specific proposal in the "allianceMotion" collective by its hash.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposalDetails = await api.derive.alliance.proposal(PROPOSAL_HASH);
|
||||
* console.log(proposalDetails);
|
||||
* ```
|
||||
*/
|
||||
export const proposal = /*#__PURE__*/ collectiveProposal('allianceMotion');
|
||||
/**
|
||||
* @name proposalCount
|
||||
* @description Retrieves the total number of proposals in the "allianceMotion" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const count = await api.derive.alliance.proposalCount();
|
||||
* console.log(`Amount of proposals: ${count}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalCount = /*#__PURE__*/ collectiveProposalCount('allianceMotion');
|
||||
/**
|
||||
* @name proposalHashes
|
||||
* @description Retrieves an array of hashes for all active proposals in the "allianceMotion" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hashes = await api.derive.alliance.proposalHashes();
|
||||
* console.log(`Proposals ${JSON.stringify(hashes)}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalHashes = /*#__PURE__*/ collectiveProposalHashes('allianceMotion');
|
||||
/**
|
||||
* @name proposals
|
||||
* @description Retrieves a list of all active proposals in the "allianceMotion" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposals = await api.derive.alliance.proposals();
|
||||
* console.log(proposals);
|
||||
* ```
|
||||
*/
|
||||
export const proposals = /*#__PURE__*/ collectiveProposals('allianceMotion');
|
||||
|
||||
/**
|
||||
* @name prime
|
||||
* @description Retrieves the prime member of the "allianceMotion" collective, if one exists.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const primeMember = await api.derive.alliance.prime();
|
||||
* console.log(primeMember);
|
||||
* ```
|
||||
*/
|
||||
export const prime = /*#__PURE__*/ collectivePrime('allianceMotion');
|
||||
|
||||
@@ -65,6 +65,11 @@ export function all (instanceId: string, api: DeriveApi): () => Observable<Bag[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name get
|
||||
* @param {(BN | number)} id The id of the bag to retrieve.
|
||||
* @description Retrieves a specific bag from the BagsList pallet by its id.
|
||||
*/
|
||||
export function get (instanceId: string, api: DeriveApi): (id: BN | number) => Observable<Bag> {
|
||||
return memo(instanceId, (id: BN | number): Observable<Bag> =>
|
||||
api.derive.bagsList._getIds([bnToBn(id)]).pipe(
|
||||
|
||||
@@ -12,6 +12,11 @@ import { objectSpread } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name expand
|
||||
* @description Expands a given bag by retrieving all its nodes (accounts contained within the bag).
|
||||
* @param {Bag} bag The bag to be expanded.
|
||||
*/
|
||||
export function expand (instanceId: string, api: DeriveApi): (bag: Bag) => Observable<BagExpanded> {
|
||||
return memo(instanceId, (bag: Bag): Observable<BagExpanded> =>
|
||||
api.derive.bagsList.listNodes(bag.bag).pipe(
|
||||
@@ -20,6 +25,11 @@ export function expand (instanceId: string, api: DeriveApi): (bag: Bag) => Obser
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name getExpanded
|
||||
* @description Retrieves and expands a specific bag from the BagsList pallet.
|
||||
* @param {BN | number} id The id of the bag to expand.
|
||||
*/
|
||||
export function getExpanded (instanceId: string, api: DeriveApi): (id: BN | number) => Observable<BagExpanded> {
|
||||
return memo(instanceId, (id: BN | number): Observable<BagExpanded> =>
|
||||
api.derive.bagsList.get(id).pipe(
|
||||
|
||||
@@ -36,6 +36,11 @@ function traverseLinks (api: DeriveApi, head: AccountId32 | string): Observable<
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name listNodes
|
||||
* @param {(PalletBagsListListBag | null)} bag A reference to a specific bag in the BagsList pallet.
|
||||
* @description Retrieves the list of nodes (accounts) contained in a specific bag within the BagsList pallet.
|
||||
*/
|
||||
export function listNodes (instanceId: string, api: DeriveApi): (bag: PalletBagsListListBag | null) => Observable<PalletBagsListListNode[]> {
|
||||
return memo(instanceId, (bag: PalletBagsListListBag | null): Observable<PalletBagsListListNode[]> =>
|
||||
bag && bag.head.isSome
|
||||
|
||||
@@ -167,11 +167,9 @@ function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<R
|
||||
|
||||
/**
|
||||
* @name account
|
||||
* @param {( AccountIndex | AccountId | Address | string )} address - An accounts Id in different formats.
|
||||
* @returns An object containing the results of various balance queries
|
||||
* @description Retrieves the essential balance details for an account, such as free balance and account nonce.
|
||||
* @param {( AccountIndex | AccountId | Address | string )} address An accountsId in different formats.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const ALICE = 'F7Hs';
|
||||
*
|
||||
|
||||
@@ -210,16 +210,17 @@ function queryCurrent (api: DeriveApi, accountId: AccountId | string, balanceIns
|
||||
|
||||
/**
|
||||
* @name all
|
||||
* @param {( AccountIndex | AccountId | Address | string )} address - An accounts Id in different formats.
|
||||
* @returns An object containing the results of various balance queries
|
||||
* @description Retrieves the complete balance information for an account, including free balance, locked balance, reserved balance, and more.
|
||||
* @param {( AccountId | string )} address An accountsId in different formats.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const ALICE = 'F7Hs';
|
||||
*
|
||||
* api.derive.balances.all(ALICE, ({ accountId, lockedBalance }) => {
|
||||
* console.log(`The account ${accountId} has a locked balance ${lockedBalance} units.`);
|
||||
* api.derive.balances.account(ALICE, (accountInfo) => {
|
||||
* console.log(
|
||||
* `${accountInfo.accountId} info:`,
|
||||
* Object.keys(accountInfo).map((key) => `${key}: ${accountInfo[key]}`)
|
||||
* );
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,21 @@ import { all } from './all.js';
|
||||
export * from './account.js';
|
||||
export * from './votingBalances.js';
|
||||
|
||||
/**
|
||||
* @name votingBalance
|
||||
* @param {( AccountId | string )} address An accounts Id in different formats.
|
||||
* @returns An object containing the results of various balance queries
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const ALICE = 'F7Hs';
|
||||
*
|
||||
* api.derive.balances.votingBalance(ALICE, ({ accountId, lockedBalance }) => {
|
||||
* console.log(`The account ${accountId} has a locked balance ${lockedBalance} units.`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
const votingBalance = all;
|
||||
|
||||
export { all, votingBalance };
|
||||
|
||||
@@ -9,6 +9,17 @@ import { combineLatest, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name votingBalances
|
||||
* @description Retrieves the balance information for multiple accounts, typically used in governance-related contexts to check voting power.
|
||||
* @param {(AccountId | AccountIndex | Address | string)[]} addresses An array of account identifiers.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const addresses = ["5D4b...Zf1", "5HGj...yrV"];
|
||||
* const balances = await api.derive.balances.votingBalances(addresses);
|
||||
* console.log("Voting Balances:", balances);
|
||||
* ```
|
||||
*/
|
||||
export function votingBalances (instanceId: string, api: DeriveApi): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DeriveBalancesAccount[]> {
|
||||
return memo(instanceId, (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DeriveBalancesAccount[]> =>
|
||||
!addresses?.length
|
||||
|
||||
@@ -33,6 +33,15 @@ function parseResult ([maybeBounties, maybeDescriptions, ids, bountyProposals]:
|
||||
return bounties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name bounties
|
||||
* @descrive Retrieves all active bounties, their descriptions, and associated proposals.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const bounties = await api.derive.bounties();
|
||||
* console.log("Active bounties:", bounties);
|
||||
* ```
|
||||
*/
|
||||
export function bounties (instanceId: string, api: DeriveApi): () => Observable<DeriveBounties> {
|
||||
const bountyBase = api.query.bounties || api.query.treasury;
|
||||
|
||||
|
||||
@@ -7,10 +7,8 @@ import { createBlockNumberDerive } from './util.js';
|
||||
|
||||
/**
|
||||
* @name bestNumber
|
||||
* @returns The latest block number.
|
||||
* @descrive Retrieves the latest block number.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.chain.bestNumber((blockNumber) => {
|
||||
* console.log(`the current best block is #${blockNumber}`);
|
||||
|
||||
@@ -10,8 +10,6 @@ import { createBlockNumberDerive } from './util.js';
|
||||
* @returns A BlockNumber
|
||||
* @description Get the latest finalized block number.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.chain.bestNumberFinalized((blockNumber) => {
|
||||
* console.log(`the current finalized block is #${blockNumber}`);
|
||||
|
||||
@@ -13,9 +13,7 @@ import { memo } from '../util/index.js';
|
||||
* @name bestNumberLag
|
||||
* @returns A number of blocks
|
||||
* @description Calculates the lag between finalized head and best head
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* @examplew
|
||||
* ```javascript
|
||||
* api.derive.chain.bestNumberLag((lag) => {
|
||||
* console.log(`finalized is ${lag} blocks behind head`);
|
||||
|
||||
@@ -13,11 +13,9 @@ import { getAuthorDetails } from './util.js';
|
||||
|
||||
/**
|
||||
* @name getBlock
|
||||
* @param {( Uint8Array | string )} hash - A block hash as U8 array or string.
|
||||
* @param {( Uint8Array | string )} hash A block hash as U8 array or string.
|
||||
* @description Get a specific block (e.g. rpc.chain.getBlock) and extend it with the author
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { author, block } = await api.derive.chain.getBlock('0x123...456');
|
||||
*
|
||||
|
||||
@@ -10,6 +10,17 @@ import { switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name getBlockByNumber
|
||||
* @param {( BN | bigint | Uint8Array | number | string )} blockNumber
|
||||
* @description Get a specific block (e.g. rpc.chain.getBlock) and extend it with the author by block number
|
||||
* @example
|
||||
* ```javascript
|
||||
* const { author, block } = await api.derive.chain.getBlockByNumber(123);
|
||||
*
|
||||
* console.log(`block #${block.header.number} was authored by ${author}`);
|
||||
* ```
|
||||
*/
|
||||
export function getBlockByNumber (instanceId: string, api: DeriveApi): (blockNumber: AnyNumber) => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (blockNumber: AnyNumber): Observable<SignedBlockExtended> =>
|
||||
api.rpc.chain.getBlockHash(blockNumber).pipe(
|
||||
|
||||
@@ -17,8 +17,6 @@ import { getAuthorDetails } from './util.js';
|
||||
* @returns An array containing the block header and the block author
|
||||
* @description Get a specific block header and extend it with the author
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { author, number } = await api.derive.chain.getHeader('0x123...456');
|
||||
*
|
||||
|
||||
@@ -11,7 +11,13 @@ import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name subscribeFinalizedBlocks
|
||||
* @returns The finalized block & events for that block
|
||||
* @description Retrieves the finalized block & events for that block
|
||||
* @example
|
||||
* ```javascript
|
||||
* const unsub = await api.derive.chain.subscribeFinalizedBlocks((finalizedBlock) => {
|
||||
* console.log(`# Finalized block ${finalizedBlock.block.hash}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeFinalizedBlocks (instanceId: string, api: DeriveApi): () => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||
|
||||
@@ -29,8 +29,14 @@ export function _getHeaderRange (instanceId: string, api: DeriveApi): (startHash
|
||||
* @description An observable of the finalized block headers. Unlike the base
|
||||
* chain.subscribeFinalizedHeads this does not skip any headers. Since finalization
|
||||
* may skip specific blocks (finalization happens in terms of chains), this version
|
||||
* of the derive tracks missing headers (since last retrieved) and provides them
|
||||
* to the caller
|
||||
* of the derive tracks missing headers (since last retrieved) and provides them
|
||||
* to the caller.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const unsub = await api.derive.chain.subscribeFinalizedHeads((finalizedHead) => {
|
||||
* console.log(`${finalizedHead.hash}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeFinalizedHeads (instanceId: string, api: DeriveApi): () => Observable<Header> {
|
||||
return memo(instanceId, (): Observable<Header> => {
|
||||
|
||||
@@ -12,6 +12,12 @@ import { memo } from '../util/index.js';
|
||||
/**
|
||||
* @name subscribeNewBlocks
|
||||
* @returns The latest block & events for that block
|
||||
* @example
|
||||
* ```javascript
|
||||
* const unsub = await api.derive.chain.subscribeNewBlocks((newBlock) => {
|
||||
* console.log(`Block Hash: ${newBlock.hash}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeNewBlocks (instanceId: string, api: DeriveApi): () => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||
|
||||
@@ -13,11 +13,9 @@ import { getAuthorDetails } from './util.js';
|
||||
|
||||
/**
|
||||
* @name subscribeNewHeads
|
||||
* @returns A header with the current header (including extracted author)
|
||||
* @description An observable of the current block header and it's author
|
||||
* @returns A header with the current header (including extracted author).
|
||||
* @description An observable of the current block header and it's author.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.chain.subscribeNewHeads((header) => {
|
||||
* console.log(`block #${header.number} was authored by ${header.author}`);
|
||||
|
||||
@@ -35,8 +35,6 @@ function queryConstants (api: DeriveApi): Observable<ResultV2> {
|
||||
* @returns An object containing the combined results of the queries for
|
||||
* all relevant contract fees as declared in the substrate chain spec.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.contracts.fees(([creationFee, transferFee]) => {
|
||||
* console.log(`The fee for creating a new contract on this chain is ${creationFee} units. The fee required to call this contract is ${transferFee} units.`);
|
||||
|
||||
@@ -6,12 +6,74 @@ import { hasProposals as collectiveHasProposals, members as collectiveMembers, p
|
||||
export * from './votes.js';
|
||||
export * from './votesOf.js';
|
||||
|
||||
/**
|
||||
* @name members
|
||||
* @description Retrieves the list of members in the "council" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const members = await api.derive.council.members();
|
||||
* console.log(`Members: ${JSON.stringify(members)});
|
||||
* ```
|
||||
*/
|
||||
export const members = /*#__PURE__*/ collectiveMembers('council');
|
||||
|
||||
/**
|
||||
* @name hasProposals
|
||||
* @description Checks if there are any active proposals in the "council" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exists = await api.derive.council.hasProposals();
|
||||
* console.log(exists);
|
||||
* ```
|
||||
*/
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('council');
|
||||
/**
|
||||
* @name proposal
|
||||
* @description Retrieves details of a specific proposal in the "councilMotion" collective by its hash.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposalDetails = await api.derive.council.proposal(PROPOSAL_HASH);
|
||||
* console.log(proposalDetails);
|
||||
* ```
|
||||
*/
|
||||
export const proposal = /*#__PURE__*/ collectiveProposal('council');
|
||||
/**
|
||||
* @name proposalCount
|
||||
* @description Retrieves the total number of proposals in the "council" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const count = await api.derive.council.proposalCount();
|
||||
* console.log(`Amount of proposals: ${count}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalCount = /*#__PURE__*/ collectiveProposalCount('council');
|
||||
/**
|
||||
* @name proposalHashes
|
||||
* @description Retrieves an array of hashes for all active proposals in the "council" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hashes = await api.derive.council.proposalHashes();
|
||||
* console.log(`Proposals ${JSON.stringify(hashes)}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalHashes = /*#__PURE__*/ collectiveProposalHashes('council');
|
||||
/**
|
||||
* @name proposals
|
||||
* @description Retrieves a list of all active proposals in the "council" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposals = await api.derive.council.proposals();
|
||||
* console.log(proposals);
|
||||
* ```
|
||||
*/
|
||||
export const proposals = /*#__PURE__*/ collectiveProposals('council');
|
||||
|
||||
/**
|
||||
* @name prime
|
||||
* @description Retrieves the prime member of the "council" collective, if one exists.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const primeMember = await api.derive.council.prime();
|
||||
* console.log(primeMember);
|
||||
* ```
|
||||
*/
|
||||
export const prime = /*#__PURE__*/ collectivePrime('council');
|
||||
|
||||
@@ -76,6 +76,14 @@ function retrieveCurrent (elections: DeriveApi['query']['elections']): Observabl
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name votes
|
||||
* @description Retrieves the council election votes for all participants.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const votes = await api.derive.council.votes();
|
||||
* ```
|
||||
*/
|
||||
export function votes (instanceId: string, api: DeriveApi): () => Observable<DeriveCouncilVotes> {
|
||||
const elections = api.query.elections || api.query['phragmenElection'] || api.query['electionsPhragmen'];
|
||||
|
||||
|
||||
@@ -9,6 +9,18 @@ import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name votesOf
|
||||
* @description Retrieves the council votes associated with a given account.
|
||||
* @returns The stake and the list of candidates the account has voted for.
|
||||
* @param {string | Uint8Array | AccountId} accountId The accountId to retrieve votes for.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const accountId = "5Gw3s7qQ9Z..."; // Replace with a valid account ID
|
||||
* const votes = await api.derive.council.votesOf(accountId);
|
||||
* console.log("Account votes:", votes);
|
||||
* ```
|
||||
*/
|
||||
export function votesOf (instanceId: string, api: DeriveApi): (accountId: string | Uint8Array | AccountId) => Observable<DeriveCouncilVote> {
|
||||
return memo(instanceId, (accountId: string | Uint8Array | AccountId): Observable<DeriveCouncilVote> =>
|
||||
api.derive.council.votes().pipe(
|
||||
|
||||
@@ -33,6 +33,17 @@ function createChildKey (info: AllInfo): string {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name childKey
|
||||
* @description Retrieves the child storage key for a given parachain’s crowdloan contributions.
|
||||
* This key is used to access contribution data stored in a separate child trie of the blockchain’s state.
|
||||
* @param {string | number | BN} paraId The parachain ID for which contributions are being queried.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const childKey = await api.derive.crowdloan.childKey(3369);
|
||||
* console.log("Child Key:", childKey);
|
||||
* ```
|
||||
*/
|
||||
export function childKey (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable<string | null> {
|
||||
return memo(instanceId, (paraId: string | number | BN): Observable<string | null> =>
|
||||
api.query['crowdloan']['funds']<Option<PolkadotRuntimeCommonCrowdloanFundInfo>>(paraId).pipe(
|
||||
|
||||
@@ -119,6 +119,16 @@ function _contributions (api: DeriveApi, paraId: string | number | BN, childKey:
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name contributions
|
||||
* @description Retrieves all contributions for a given parachain crowdloan.
|
||||
* @param {string | number | BN} paraId The parachain ID for which contributions are being queried.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const contributions = await api.derive.crowdloan.contributions(3369);
|
||||
* console.log("Contributions:", contributions);
|
||||
* ```
|
||||
*/
|
||||
export function contributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable<DeriveContributions> {
|
||||
return memo(instanceId, (paraId: string | number | BN): Observable<DeriveContributions> =>
|
||||
api.derive.crowdloan.childKey(paraId).pipe(
|
||||
|
||||
@@ -57,6 +57,17 @@ function _contributions (api: DeriveApi, paraId: string | number | BN, childKey:
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name ownContributions
|
||||
* @description Retrieves the contribution amounts made by specific accounts (`keys`) to a given parachain crowdloan (`paraId`).
|
||||
* @param {string | number | BN} paraId The parachain ID for which contributions are being queried.
|
||||
* @param {string[]} keys An array of account addresses whose contributions are to be fetched.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const contributions = await api.derive.crowdloan.ownContributions(2000, ['5Ff...PqV', '5Gg...XyZ']);
|
||||
* console.log("Own Contributions:", contributions);
|
||||
* ```
|
||||
*/
|
||||
export function ownContributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN, keys: string[]) => Observable<DeriveOwnContributions> {
|
||||
return memo(instanceId, (paraId: string | number | BN, keys: string[]): Observable<DeriveOwnContributions> =>
|
||||
api.derive.crowdloan.childKey(paraId).pipe(
|
||||
|
||||
@@ -138,6 +138,15 @@ function queryScheduler (api: DeriveApi): Observable<DeriveDispatch[]> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name dispatchQueue
|
||||
* @description Retrieves the list of scheduled or pending dispatches in the governance system.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const queue = await api.derive.democracy.dispatchQueue();
|
||||
* console.log("Dispatch Queue:", queue);
|
||||
* ```
|
||||
*/
|
||||
export function dispatchQueue (instanceId: string, api: DeriveApi): () => Observable<DeriveDispatch[]> {
|
||||
return memo(instanceId, (): Observable<DeriveDispatch[]> =>
|
||||
isFunction(api.query.scheduler?.agenda)
|
||||
|
||||
@@ -87,6 +87,16 @@ function directLocks (api: DeriveApi, { votes }: VotingDirect): Observable<Deriv
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name locks
|
||||
* @description Retrieves the democracy voting locks for a given account.
|
||||
* @param { string | AccountId } accountId The accountId for which to retrieve democracy voting locks.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const locks = await api.derive.democracy.locks('5FfFjX...'); // Replace with an actual accountId
|
||||
* console.log("Democracy Locks:", locks);
|
||||
* ```
|
||||
*/
|
||||
export function locks (instanceId: string, api: DeriveApi): (accountId: string | AccountId) => Observable<DeriveDemocracyLock[]> {
|
||||
return memo(instanceId, (accountId: string | AccountId): Observable<DeriveDemocracyLock[]> =>
|
||||
api.query.democracy.votingOf
|
||||
|
||||
@@ -29,6 +29,15 @@ function withImage (api: DeriveApi, nextOpt: Option<ITuple<[H256 | FrameSupportP
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name nextExternal
|
||||
* @description Retrieves the next external proposal that is scheduled for a referendum.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const nextExternal = await api.derive.democracy.nextExternal();
|
||||
* console.log("Next external proposal:", nextExternal);
|
||||
* ```
|
||||
*/
|
||||
export function nextExternal (instanceId: string, api: DeriveApi): () => Observable<DeriveProposalExternal | null> {
|
||||
return memo(instanceId, (): Observable<DeriveProposalExternal | null> =>
|
||||
api.query.democracy?.nextExternal
|
||||
|
||||
@@ -135,6 +135,15 @@ function getImages (api: DeriveApi, bounded: (FrameSupportPreimagesBounded | Uin
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name preimages
|
||||
* @description Retrieves the full details (preimages) of governance proposals using their on-chain hashes.
|
||||
* @param { (Hash | Uint8Array | string | FrameSupportPreimagesBounded)[] } hashes An array of hashes representing governance proposals.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const preimages = await api.derive.democracy.preimages([HASH1, HASH2]);
|
||||
* ```
|
||||
*/
|
||||
export function preimages (instanceId: string, api: DeriveApi): (hashes: (Hash | Uint8Array | string | FrameSupportPreimagesBounded)[]) => Observable<(DeriveProposalImage | undefined)[]> {
|
||||
return memo(instanceId, (hashes: (Hash | Uint8Array | string | FrameSupportPreimagesBounded)[]): Observable<(DeriveProposalImage | undefined)[]> =>
|
||||
hashes.length
|
||||
@@ -147,6 +156,15 @@ export function preimages (instanceId: string, api: DeriveApi): (hashes: (Hash |
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name preimage
|
||||
* @description Retrieves the full details (preimage) of a governance proposal using its on-chain hash.
|
||||
* @param { Hash | Uint8Array | string | FrameSupportPreimagesBounded } hash Hash that represents governance proposals.
|
||||
* * @example
|
||||
* ```javascript
|
||||
* const preimage = await api.derive.democracy.preimage(HASH);
|
||||
* ```
|
||||
*/
|
||||
export const preimage = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, hash: Hash | Uint8Array | string | FrameSupportPreimagesBounded) =>
|
||||
api.derive.democracy.preimages([hash])
|
||||
|
||||
@@ -48,6 +48,15 @@ function parse ([proposals, images, optDepositors]: Result): DeriveProposal[] {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name proposals
|
||||
* @description Retrieves the list of active public proposals in the democracy module, along with their associated preimage data and deposit information.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposals = await api.derive.democracy.proposals();
|
||||
* console.log("proposals:", proposals);
|
||||
* ```
|
||||
*/
|
||||
export function proposals (instanceId: string, api: DeriveApi): () => Observable<DeriveProposal[]> {
|
||||
return memo(instanceId, (): Observable<DeriveProposal[]> =>
|
||||
isFunction(api.query.democracy?.publicProps)
|
||||
|
||||
@@ -10,6 +10,14 @@ import { map, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name referendumIds
|
||||
* @description Retrieves an array of active referendum IDs.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const referendums = await api.derive.democracy.referendumIds();
|
||||
* ```
|
||||
*/
|
||||
export function referendumIds (instanceId: string, api: DeriveApi): () => Observable<BN[]> {
|
||||
return memo(instanceId, (): Observable<BN[]> =>
|
||||
api.query.democracy?.lowestUnbaked
|
||||
|
||||
@@ -10,6 +10,14 @@ import { objectSpread } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name referendums
|
||||
* @description Retrieves information about all active referendums, including their details and associated votes.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const referendums = await api.derive.democracy.referendums();
|
||||
* ```
|
||||
*/
|
||||
export function referendums (instanceId: string, api: DeriveApi): () => Observable<DeriveReferendumExt[]> {
|
||||
return memo(instanceId, (): Observable<DeriveReferendumExt[]> =>
|
||||
api.derive.democracy.referendumsActive().pipe(
|
||||
|
||||
@@ -8,6 +8,15 @@ import { of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name referendumsActive
|
||||
* @description Retrieves information about active referendums.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const referendums = await api.derive.democracy.referendumsActive();
|
||||
* console.log("Active Referendums:", referendums);
|
||||
* ```
|
||||
*/
|
||||
export function referendumsActive (instanceId: string, api: DeriveApi): () => Observable<DeriveReferendum[]> {
|
||||
return memo(instanceId, (): Observable<DeriveReferendum[]> =>
|
||||
api.derive.democracy.referendumIds().pipe(
|
||||
|
||||
@@ -11,6 +11,15 @@ import { memo } from '../util/index.js';
|
||||
|
||||
type ReferendumInfoFinished = PalletDemocracyReferendumInfo['asFinished'];
|
||||
|
||||
/**
|
||||
* @name referendumsFinished
|
||||
* @description Retrieves information about finished referendums.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const referendums = await api.derive.democracy.referendumsFinished();
|
||||
* console.log("Finished Referendums:", referendums);
|
||||
* ```
|
||||
*/
|
||||
export function referendumsFinished (instanceId: string, api: DeriveApi): () => Observable<ReferendumInfoFinished[]> {
|
||||
return memo(instanceId, (): Observable<ReferendumInfoFinished[]> =>
|
||||
api.derive.democracy.referendumIds().pipe(
|
||||
|
||||
@@ -148,6 +148,19 @@ export function _referendumInfo (instanceId: string, api: DeriveApi): (index: BN
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name referendumsInfo
|
||||
* @description Retrieves information about multiple referendums by their IDs.
|
||||
* @param {BN[]} ids An array of referendum IDs to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
* import { BN } from "@polkadot/util";
|
||||
*
|
||||
* const referendumIds = [new BN(1)];
|
||||
* const referendums = await api.derive.democracy.referendumsInfo(referendumIds);
|
||||
* console.log("Referendums Info:", referendums);
|
||||
* ```
|
||||
*/
|
||||
export function referendumsInfo (instanceId: string, api: DeriveApi): (ids: BN[]) => Observable<DeriveReferendum[]> {
|
||||
return memo(instanceId, (ids: BN[]): Observable<DeriveReferendum[]> =>
|
||||
ids.length
|
||||
|
||||
@@ -11,6 +11,15 @@ import { bnSqrt } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name sqrtElectorate
|
||||
* @description Computes the square root of the total token issuance in the network.
|
||||
* @example
|
||||
* ```javascript
|
||||
* let sqrtElectorate = await api.derive.democracy.sqrtElectorate();
|
||||
* console.log("Square root of token issuance:", sqrtElectorate);
|
||||
* ```
|
||||
*/
|
||||
export function sqrtElectorate (instanceId: string, api: DeriveApi): () => Observable<BN> {
|
||||
return memo(instanceId, (): Observable<BN> =>
|
||||
api.query.balances.totalIssuance().pipe(
|
||||
|
||||
@@ -94,11 +94,8 @@ function queryCouncil (api: DeriveApi, council: string): Observable<[AccountId32
|
||||
|
||||
/**
|
||||
* @name info
|
||||
* @returns An object containing the combined results of the storage queries for
|
||||
* all relevant election module properties.
|
||||
* @description An object containing the combined results of the storage queries for all relevant election module properties.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.derive.elections.info(({ members, candidates }) => {
|
||||
* console.log(`There are currently ${members.length} council members and ${candidates.length} prospective council candidates.`);
|
||||
|
||||
@@ -35,7 +35,14 @@ function mapResult ([result, validators, heartbeats, numBlocks]: Result): Derive
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session
|
||||
* @name receivedHeartbeats
|
||||
* @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session.
|
||||
* @example
|
||||
* ```javascript
|
||||
* let unsub = await api.derive.imOnline.receivedHeartbeats((heartbeat) => {
|
||||
* console.log(heartbeat);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function receivedHeartbeats (instanceId: string, api: DeriveApi): () => Observable<DeriveHeartbeats> {
|
||||
return memo(instanceId, (): Observable<DeriveHeartbeats> =>
|
||||
|
||||
@@ -3,12 +3,74 @@
|
||||
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
|
||||
|
||||
/**
|
||||
* @name members
|
||||
* @description Retrieves the list of members in the "membership" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const members = await api.derive.membership.members();
|
||||
* console.log(`Members: ${JSON.stringify(members)});
|
||||
* ```
|
||||
*/
|
||||
export const members = /*#__PURE__*/ collectiveMembers('membership');
|
||||
|
||||
/**
|
||||
* @name hasProposals
|
||||
* @description Checks if there are any active proposals in the "membership" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exists = await api.derive.membership.hasProposals();
|
||||
* console.log(exists);
|
||||
* ```
|
||||
*/
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('membership');
|
||||
/**
|
||||
* @name proposal
|
||||
* @description Retrieves details of a specific proposal in the "membership" collective by its hash.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposalDetails = await api.derive.membership.proposal(PROPOSAL_HASH);
|
||||
* console.log(proposalDetails);
|
||||
* ```
|
||||
*/
|
||||
export const proposal = /*#__PURE__*/ collectiveProposal('membership');
|
||||
/**
|
||||
* @name proposalCount
|
||||
* @description Retrieves the total number of proposals in the "membership" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const count = await api.derive.membership.proposalCount();
|
||||
* console.log(`Amount of proposals: ${count}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalCount = /*#__PURE__*/ collectiveProposalCount('membership');
|
||||
/**
|
||||
* @name proposalHashes
|
||||
* @description Retrieves an array of hashes for all active proposals in the "membership" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hashes = await api.derive.membership.proposalHashes();
|
||||
* console.log(`Proposals ${JSON.stringify(hashes)}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalHashes = /*#__PURE__*/ collectiveProposalHashes('membership');
|
||||
/**
|
||||
* @name proposals
|
||||
* @description Retrieves a list of all active proposals in the "membership" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposals = await api.derive.membership.proposals();
|
||||
* console.log(proposals);
|
||||
* ```
|
||||
*/
|
||||
export const proposals = /*#__PURE__*/ collectiveProposals('membership');
|
||||
|
||||
/**
|
||||
* @name prime
|
||||
* @description Retrieves the prime member of the "membership" collective, if one exists.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const primeMember = await api.derive.membership.prime();
|
||||
* console.log(primeMember);
|
||||
* ```
|
||||
*/
|
||||
export const prime = /*#__PURE__*/ collectivePrime('membership');
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-derive', path: 'auto', type: 'auto', version: '15.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-derive', path: 'auto', type: 'auto', version: '15.9.2' };
|
||||
|
||||
@@ -73,6 +73,21 @@ function parse (id: ParaId, [active, retryQueue, selectedThreads, didUpdate, inf
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @name info
|
||||
* @param {ParaId | number} id A unique numeric (non-negative integer) identifier for a parachain.
|
||||
* @description Retrieves detailed information about a specific parachain.
|
||||
* @example
|
||||
* ```javascript
|
||||
* await api.derive.parachains.info(1000, (info) => {
|
||||
* if (info) {
|
||||
* console.log(`Parachain ${info.id.toString()} is active: ${info.active}`);
|
||||
* } else {
|
||||
* console.log("Parachain information not available.");
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function info (instanceId: string, api: DeriveApi): (id: ParaId | number) => Observable<DeriveParachainFull | null> {
|
||||
return memo(instanceId, (id: ParaId | number): Observable<DeriveParachainFull | null> =>
|
||||
api.query['registrar'] && api.query['parachains']
|
||||
|
||||
@@ -31,6 +31,18 @@ function parse ([ids, didUpdate, relayDispatchQueueSizes, infos, pendingSwaps]:
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name overview
|
||||
* @description Retrieves an overview of all registered parachains.
|
||||
* @example
|
||||
* ```javascript
|
||||
* await api.derive.parachains.overview((overview) => {
|
||||
* parachains.forEach(parachain => {
|
||||
* console.log(`Parachain ${parachain.id.toString()} is registered.`);
|
||||
* });
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function overview (instanceId: string, api: DeriveApi): () => Observable<DeriveParachain[]> {
|
||||
return memo(instanceId, (): Observable<DeriveParachain[]> =>
|
||||
api.query['registrar']?.['parachains'] && api.query['parachains']
|
||||
|
||||
@@ -67,6 +67,18 @@ function empty (api: DeriveApi): Observable<DeriveSessionIndexes> {
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name indexes
|
||||
* @description Retrieves session-related index data, adapting to whether
|
||||
* the chain has staking enabled.
|
||||
* @example
|
||||
* ```javascript
|
||||
* api.derive.session.indexes((indexes) => {
|
||||
* console.log(`Current session index: ${indexes.currentIndex}`);
|
||||
* console.log(`Validator count: ${indexes.validatorCount}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function indexes (instanceId: string, api: DeriveApi): () => Observable<DeriveSessionIndexes> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionIndexes> =>
|
||||
api.query.session
|
||||
|
||||
@@ -11,7 +11,14 @@ import { objectSpread } from '@polkadot/util';
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
|
||||
* @name info
|
||||
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras.
|
||||
* @example
|
||||
* ```javascript
|
||||
* api.derive.session.info((info) => {
|
||||
* console.log(`Session info ${JSON.stringify(info)}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function info (instanceId: string, api: DeriveApi): () => Observable<DeriveSessionInfo> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionInfo> =>
|
||||
|
||||
@@ -74,7 +74,14 @@ function queryBabe (api: DeriveApi): Observable<[DeriveSessionInfo, ResultSlotsF
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
|
||||
* @name progress
|
||||
* @description Retrieves session information and progress.
|
||||
* @example
|
||||
* ```javascript
|
||||
* api.derive.session.progress((progress) => {
|
||||
* console.log(`Session progress ${JSON.stringify(progress)}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function progress (instanceId: string, api: DeriveApi): () => Observable<DeriveSessionProgress> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionProgress> =>
|
||||
@@ -88,6 +95,36 @@ export function progress (instanceId: string, api: DeriveApi): () => Observable<
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name eraLenght
|
||||
* @description Retrieves the total length of the current era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* api.derive.session.eraLength((length) => {
|
||||
* console.log(`Current era length: ${length} sessions`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const eraLength = /*#__PURE__*/ withProgressField('eraLength');
|
||||
/**
|
||||
* @name eraProgress
|
||||
* @description Retrieves the progress of the current era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* api.derive.session.eraProgress((progress) => {
|
||||
* console.log(`Current era progress: ${progress} sessions`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const eraProgress = /*#__PURE__*/ withProgressField('eraProgress');
|
||||
/**
|
||||
* @name sessionProgress
|
||||
* @description Retrieves the progress of the current session.
|
||||
* @example
|
||||
* ```javascript
|
||||
* api.derive.session.sessionProgress((progress) => {
|
||||
* console.log(`Current session progress: ${progress} slots`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export const sessionProgress = /*#__PURE__*/ withProgressField('sessionProgress');
|
||||
|
||||
@@ -54,7 +54,13 @@ function getCurr (api: DeriveApi) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the candidate info for a society
|
||||
* @name candidate
|
||||
* @description Retrieves the list of candidates for the society module.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const societyCandidates = await api.derive.society.candidates();
|
||||
* console.log(societyCandidates);
|
||||
* ```
|
||||
*/
|
||||
export function candidates (instanceId: string, api: DeriveApi): () => Observable<DeriveSocietyCandidate[]> {
|
||||
return memo(instanceId, (): Observable<DeriveSocietyCandidate[]> =>
|
||||
|
||||
@@ -14,7 +14,13 @@ import { memo } from '../util/index.js';
|
||||
type Result = [Vec<PalletSocietyBid>, Option<AccountId> | undefined, Option<AccountId>, Option<AccountId>, u32 | undefined, BalanceOf]
|
||||
|
||||
/**
|
||||
* @description Get the overall info for a society
|
||||
* @name info
|
||||
* @description Get the overall info for a society.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const societyInfo = await api.derive.society.candidates();
|
||||
* console.log(societyInfo);
|
||||
* ```
|
||||
*/
|
||||
export function info (instanceId: string, api: DeriveApi): () => Observable<DeriveSociety> {
|
||||
return memo(instanceId, (): Observable<DeriveSociety> =>
|
||||
|
||||
@@ -10,7 +10,14 @@ import { map } from 'rxjs';
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @description Get the member info for a society
|
||||
* @name member
|
||||
* @description Get the member info for a society.
|
||||
* @param { AccountId } accountId
|
||||
* @example
|
||||
* ```javascript
|
||||
* const member = await api.derive.society.member(ALICE);
|
||||
* console.log(member);
|
||||
* ```
|
||||
*/
|
||||
export function member (instanceId: string, api: DeriveApi): (accountId: AccountId) => Observable<DeriveSocietyMember> {
|
||||
return memo(instanceId, (accountId: AccountId): Observable<DeriveSocietyMember> =>
|
||||
|
||||
@@ -82,7 +82,13 @@ export function _members (instanceId: string, api: DeriveApi): (accountIds: Acco
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the member info for a society
|
||||
* @name members
|
||||
* @description Get the society members.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const members = await api.derive.society.members();
|
||||
* console.log(members);
|
||||
* ```
|
||||
*/
|
||||
export function members (instanceId: string, api: DeriveApi): () => Observable<DeriveSocietyMember[]> {
|
||||
return memo(instanceId, (): Observable<DeriveSocietyMember[]> =>
|
||||
|
||||
@@ -68,6 +68,13 @@ function parseResult (api: DeriveApi, sessionInfo: DeriveSessionInfo, keys: Deri
|
||||
* @param {(Uint8Array | string)[]} accountIds List of account stashes
|
||||
* @param {StakingQueryFlags} opts optional filtering flag
|
||||
* @description From a list of stashes, fill in all the relevant staking details
|
||||
* @example
|
||||
* ```javascript
|
||||
* const accounts = await api.derive.staking.accounts([
|
||||
* "149B17nn7zVL4SkLSNmANupEkGexUBAxVrdk4bbWFZYibkFc",
|
||||
* ]);
|
||||
* console.log("First account staking info:", accounts[0]);
|
||||
* ```
|
||||
*/
|
||||
export function accounts (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], opts?: StakingQueryFlags) => Observable<DeriveStakingAccount[]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], opts: StakingQueryFlags = QUERY_OPTS): Observable<DeriveStakingAccount[]> =>
|
||||
@@ -88,9 +95,16 @@ export function accounts (instanceId: string, api: DeriveApi): (accountIds: (Uin
|
||||
|
||||
/**
|
||||
* @name account
|
||||
* @param {(Uint8Array | string)} accountId AccountId of the stash
|
||||
* @param {StakingQueryFlags} opts optional filtering flag
|
||||
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
||||
* @param {(Uint8Array | string)} accountId AccountId of the stash.
|
||||
* @param {StakingQueryFlags} opts (Optional) filtering flag.
|
||||
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const accountStakingData = await api.derive.staking.account(
|
||||
* "149B17nn7zVL4SkLSNmANupEkGexUBAxVrdk4bbWFZYibkFc"
|
||||
* );
|
||||
* console.log(accountStakingData);
|
||||
* ```
|
||||
*/
|
||||
export const account = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: Uint8Array | string, opts?: StakingQueryFlags) =>
|
||||
|
||||
@@ -10,7 +10,13 @@ import { switchMap } from 'rxjs';
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @description Retrieve the staking overview, including elected and points earned
|
||||
* @name currentPoints
|
||||
* @description Retrieve the staking overview, including elected and points earned.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const currentPoints = await api.derive.staking.currentPoints();
|
||||
* console.log(currentPoints.toHuman());
|
||||
* ```
|
||||
*/
|
||||
export function currentPoints (instanceId: string, api: DeriveApi): () => Observable<PalletStakingEraRewardPoints> {
|
||||
return memo(instanceId, (): Observable<PalletStakingEraRewardPoints> =>
|
||||
|
||||
@@ -17,6 +17,26 @@ function combineAccounts (nextElected: AccountId[], validators: AccountId[]): Ac
|
||||
return arrayFlatten([nextElected, validators.filter((v) => !nextElected.find((n) => n.eq(v)))]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name electedInfo
|
||||
* @param {StakingQueryFlags} flags? (Optional) Query flags to filter the staking data.
|
||||
* @param {number} page? (Optional) The page index for paginated results.
|
||||
* @description Retrieves detailed staking information about the next elected validators and their associated staking data.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const { nextElected, validators, info } =
|
||||
* await api.derive.staking.electedInfo();
|
||||
* console.log(
|
||||
* "Next Elected Validators:",
|
||||
* nextElected.map((acc) => acc.toString())
|
||||
* );
|
||||
* console.log(
|
||||
* "Current Validators:",
|
||||
* validators.map((acc) => acc.toString())
|
||||
* );
|
||||
* console.log("Validator Staking Info:", info);
|
||||
* ```
|
||||
*/
|
||||
export function electedInfo (instanceId: string, api: DeriveApi): (flags?: StakingQueryFlags, page?: number) => Observable<DeriveStakingElected> {
|
||||
return memo(instanceId, (flags: StakingQueryFlags = DEFAULT_FLAGS, page = 0): Observable<DeriveStakingElected> =>
|
||||
api.derive.staking.validators().pipe(
|
||||
|
||||
@@ -81,6 +81,25 @@ export function _eraExposure (instanceId: string, api: DeriveApi): (era: EraInde
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name eraExposure
|
||||
* @description Retrieves the staking exposure (nominators and total stake) for a specific era.
|
||||
* @param {EraIndex} eras The staking era to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const era = api.createType("EraIndex", 1000);
|
||||
* const exposure = await api.derive.staking.eraExposure(era);
|
||||
* ```
|
||||
*/
|
||||
export const eraExposure = /*#__PURE__*/ singleEra('_eraExposure');
|
||||
export const _erasExposure = /*#__PURE__*/ combineEras('_eraExposure');
|
||||
/**
|
||||
* @name erasExposure
|
||||
* @description Retrieves staking exposure details for multiple past eras.
|
||||
* @param {boolean} withActive? (Optional) Whether to include the active era in the result.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exposure = await api.derive.staking.erasExposure(true);
|
||||
* ```
|
||||
*/
|
||||
export const erasExposure = /*#__PURE__*/ erasHistoricApply('_erasExposure');
|
||||
|
||||
@@ -13,6 +13,10 @@ import { BN_ONE, BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name erasHistoric
|
||||
* @param {boolean} withActive? (Optional) Whether to include the active era in the result.
|
||||
*/
|
||||
export function erasHistoric (instanceId: string, api: DeriveApi): (withActive?: boolean) => Observable<EraIndex[]> {
|
||||
return memo(instanceId, (withActive?: boolean): Observable<EraIndex[]> =>
|
||||
combineLatest([
|
||||
|
||||
@@ -51,4 +51,17 @@ export function _erasPoints (instanceId: string, api: DeriveApi): (eras: EraInde
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name erasPoints
|
||||
* @description Retrieves historical era points with its validators.
|
||||
* @param {boolean} withActive? (Optional) Whether to include the active era in the result.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const points = await api.derive.staking.erasPoints(true);
|
||||
* console.log(
|
||||
* "Validator points:",
|
||||
* points.map(({ era, eraPoints }) => `Era: ${era}, points ${eraPoints}`)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const erasPoints = /*#__PURE__*/ erasHistoricApply('_erasPoints');
|
||||
|
||||
@@ -37,6 +37,27 @@ export function _eraPrefs (instanceId: string, api: DeriveApi): (era: EraIndex,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name eraPrefs
|
||||
* @description Retrieves the validators commission preferences for a given staking era.
|
||||
* @param {EraIndex} era The staking era to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const era = api.createType("EraIndex", 1000);
|
||||
* const prefs = await api.derive.staking.eraPrefs(era);
|
||||
* console.log(JSON.stringify(prefs));
|
||||
* ```
|
||||
*/
|
||||
export const eraPrefs = /*#__PURE__*/ singleEra('_eraPrefs');
|
||||
export const _erasPrefs = /*#__PURE__*/ combineEras('_eraPrefs');
|
||||
|
||||
/**
|
||||
* @name erasPrefs
|
||||
* @description Retrieves validators commission preferences for multiple past staking eras
|
||||
* @param {boolean} withActive? (Optional) Whether to include the active era in the result.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const prefs = await api.derive.staking.erasPrefs(true);
|
||||
* ```
|
||||
*/
|
||||
export const erasPrefs = /*#__PURE__*/ erasHistoricApply('_erasPrefs');
|
||||
|
||||
@@ -40,4 +40,13 @@ export function _erasRewards (instanceId: string, api: DeriveApi): (eras: EraInd
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name erasRewards
|
||||
* @description Retrieves rewards for historical eras.
|
||||
* @param {boolean} withActive? (Optional) Whether to include the active era in the result.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const rewards = await api.derive.staking.erasRewards(true);
|
||||
* ```
|
||||
*/
|
||||
export const erasRewards = /*#__PURE__*/ erasHistoricApply('_erasRewards');
|
||||
|
||||
@@ -45,6 +45,25 @@ export function _eraSlashes (instanceId: string, api: DeriveApi): (era: EraIndex
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name eraSlashes
|
||||
* @description Retrieves the slashes for a specific staking era.
|
||||
* @param {EraIndex} eras The staking era to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const era = api.createType("EraIndex", 1000);
|
||||
* const slashes = await api.derive.staking.eraSlashes(era);
|
||||
* ```
|
||||
*/
|
||||
export const eraSlashes = /*#__PURE__*/ singleEra('_eraSlashes');
|
||||
export const _erasSlashes = /*#__PURE__*/ combineEras('_eraSlashes');
|
||||
/**
|
||||
* @name erasSlashes
|
||||
* @description Retrieves slashes for historical eras.
|
||||
* @param {boolean} withActive? (Optional) Whether to include the active era in the result.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const slashes = await api.derive.staking.erasSlashes(true);
|
||||
* ```
|
||||
*/
|
||||
export const erasSlashes = /*#__PURE__*/ erasHistoricApply('_erasSlashes');
|
||||
|
||||
@@ -26,11 +26,41 @@ function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, Kitc
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @name keys
|
||||
* @param { Uint8Array | string } stashId The stash account ID whose session keys are to be retrieved.
|
||||
* @description Retrieves the session keys associated with a given stash account.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const keys = await api.derive.staking.keys(
|
||||
* ALICE
|
||||
* );
|
||||
* console.log(
|
||||
* "Session keys:",
|
||||
* keys.sessionIds.map((key) => `Key: ${key}`)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const keys = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, stashId: Uint8Array | string) =>
|
||||
api.derive.staking.keysMulti([stashId])
|
||||
);
|
||||
|
||||
/**
|
||||
* @name keysMulti
|
||||
* @description Retrieves session keys for multiple stash accounts.
|
||||
* @param { (Uint8Array | string)[] } stashIds Array of stash account IDs.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const keysMulti = await api.derive.staking.keysMulti([ ALICE, BOB ]);
|
||||
* keysMulti.forEach((keys) => {
|
||||
* console.log(
|
||||
* "Session keys:",
|
||||
* keys.sessionIds.map((key) => `Key: ${key}`)
|
||||
* );
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function keysMulti (instanceId: string, api: DeriveApi): (stashIds: (Uint8Array | string)[]) => Observable<DeriveStakingKeys[]> {
|
||||
return memo(instanceId, (stashIds: (Uint8Array | string)[]): Observable<DeriveStakingKeys[]> =>
|
||||
stashIds.length
|
||||
|
||||
@@ -11,7 +11,20 @@ import { objectSpread } from '@polkadot/util';
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @description Retrieve the staking overview, including elected and points earned
|
||||
* @name overview
|
||||
* @description Retrieve the staking overview, including elected validators and points earned.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const {
|
||||
* activeEra,
|
||||
* activeEraStart,
|
||||
* currentEra,
|
||||
* currentIndex,
|
||||
* nextElected,
|
||||
* validatorCount,
|
||||
* validators,
|
||||
* } = await api.derive.staking.overview();
|
||||
* ```
|
||||
*/
|
||||
export function overview (instanceId: string, api: DeriveApi): () => Observable<DeriveStakingOverview> {
|
||||
return memo(instanceId, (): Observable<DeriveStakingOverview> =>
|
||||
|
||||
@@ -46,9 +46,38 @@ export function _ownExposures (instanceId: string, api: DeriveApi): (accountId:
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name ownExposure
|
||||
* @description Retrieves the staking exposure of a validator for a specific era, including their own stake.
|
||||
* @param { Uint8Array | string } accountId The validator stash account.
|
||||
* @param {EraIndex} era The staking era to query.
|
||||
* @param { u32 | AnyNumber } page? (Optional) The pagination index.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const era = api.createType("EraIndex", 1000);
|
||||
* const exposure = await api.derive.staking.ownExposure(
|
||||
* "11VR4pF6c7kfBhfmuwwjWY3FodeYBKWx7ix2rsRCU2q6hqJ",
|
||||
* era
|
||||
* );
|
||||
* console.log(JSON.stringify(exposure));
|
||||
* ```
|
||||
*/
|
||||
export const ownExposure = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: Uint8Array | string, era: EraIndex, page?: u32 | AnyNumber) =>
|
||||
api.derive.staking._ownExposures(accountId, [era], true, page || 0)
|
||||
);
|
||||
|
||||
/**
|
||||
* @name ownExposures
|
||||
* @description Retrieves staking exposures for a validator across multiple historical eras.
|
||||
* @param { Uint8Array | string } accountId The validator stash account.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exposures = await api.derive.staking.ownExposures(
|
||||
* ALICE,
|
||||
* true
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const ownExposures = /*#__PURE__*/ erasHistoricApplyAccount('_ownExposures');
|
||||
|
||||
@@ -31,9 +31,38 @@ export function _ownSlashes (instanceId: string, api: DeriveApi): (accountId: Ui
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name ownSlash
|
||||
* @description Retrieves the slashes applied to a specific account in a given era.
|
||||
* @param { Uint8Array | string } accountId The validator stash account.
|
||||
* @param {EraIndex} era The staking era to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const era = api.createType("EraIndex", 1000);
|
||||
* const slashedAmount = await api.derive.staking.ownSlash(
|
||||
* ALICE,
|
||||
* era
|
||||
* );
|
||||
* console.log(`Era: ${slashedAmount.era}, total ${slashedAmount.total}`);
|
||||
* ```
|
||||
*/
|
||||
export const ownSlash = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: Uint8Array | string, era: EraIndex) =>
|
||||
api.derive.staking._ownSlashes(accountId, [era], true)
|
||||
);
|
||||
|
||||
/**
|
||||
* @name ownSlashes
|
||||
* @description Retrieves the slashes for a specific account across all historic eras.
|
||||
* @param { Uint8Array | string } accountId The validator stash account.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const slashes = await api.derive.staking.ownSlashes(
|
||||
* ALICE,
|
||||
* true
|
||||
* );
|
||||
* console.log(slashes);
|
||||
* ```
|
||||
*/
|
||||
export const ownSlashes = /*#__PURE__*/ erasHistoricApplyAccount('_ownSlashes');
|
||||
|
||||
@@ -184,15 +184,36 @@ function getBatch (api: DeriveApi, activeEra: EraIndex, stashIds: AccountId[], f
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
/**
|
||||
* @description From a stash, retrieve the controllerId and all relevant details
|
||||
* @name query
|
||||
* @param { Uint8Array | string } accountId The stash account to query.
|
||||
* @param { StakingQueryFlags } flags Flags to customize the query.
|
||||
* @param { u32 } page (Optional) pagination parameter.
|
||||
* @description Retrieves staking details for a given stash account.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const stakingInfo = await api.derive.staking.query(
|
||||
* ALICE,
|
||||
* {}
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const query = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: Uint8Array | string, flags: StakingQueryFlags, page?: u32) =>
|
||||
api.derive.staking.queryMulti([accountId], flags, page)
|
||||
);
|
||||
|
||||
/**
|
||||
* @name queryMulti
|
||||
* @param { (Uint8Array | string)[] } accountIds List of stash accounts to query.
|
||||
* @param { StakingQueryFlags } flags Flags to customize the query.
|
||||
* @param { u32 } page (Optional) pagination parameter.
|
||||
* @description Retrieves staking details for multiple stash accounts.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const stakingInfos = await api.derive.staking.queryMulti([stashId1, stashId2], {});
|
||||
* ```
|
||||
*/
|
||||
export function queryMulti (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags, page?: u32 | AnyNumber) => Observable<DeriveStakingQuery[]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags, page?: u32 | AnyNumber): Observable<DeriveStakingQuery[]> =>
|
||||
api.derive.session.indexes().pipe(
|
||||
|
||||
@@ -38,6 +38,19 @@ export function _stakerExposures (instanceId: string, api: DeriveApi): (accountI
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name stakerExposures
|
||||
* @param { (Uint8Array | string)[] } accountIds List of validator stash accounts.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @description Retrieves staking exposure for multiple accounts across historical eras.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exposure = await api.derive.staking.stakerExposures(
|
||||
* [ALICE, BOB],
|
||||
* true
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function stakerExposures (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable<DeriveStakerExposure[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], withActive = false): Observable<DeriveStakerExposure[][]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
@@ -46,6 +59,19 @@ export function stakerExposures (instanceId: string, api: DeriveApi): (accountId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name stakerExposure
|
||||
* @param { Uint8Array | string } accountId The validator stash account.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @description Retrieves staking exposure for a single account across historical eras. Exposure refers to the total stake associated with a validator.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exposure = await api.derive.staking.stakerExposure(
|
||||
* ALICE,
|
||||
* true
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const stakerExposure = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: Uint8Array | string, withActive?: boolean) =>
|
||||
api.derive.staking.stakerExposures([accountId], withActive)
|
||||
|
||||
@@ -26,4 +26,21 @@ export function _stakerPoints (instanceId: string, api: DeriveApi): (accountId:
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name stakerPoints
|
||||
* @param { Uint8Array | string } accountId The stakers AccountId.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @description Retrieves the era reward points earned by a given staker across all eras.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const points = await api.derive.staking.stakerPoints(
|
||||
* ALICE, //Alice accountId
|
||||
* false
|
||||
* );
|
||||
* console.log(
|
||||
* 'Validator Era Points:',
|
||||
* points.map(({ era, points }) => `Era ${era}: ${points.toString()} points`)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const stakerPoints = /*#__PURE__*/ erasHistoricApplyAccount('_stakerPoints');
|
||||
|
||||
@@ -23,4 +23,23 @@ export function _stakerPrefs (instanceId: string, api: DeriveApi): (accountId: U
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name stakerPrefs
|
||||
* @param { Uint8Array | string } accountId The stakers AccountId.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @description Retrieves the validator preferences for a given staker across historical eras.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const prefs = await api.derive.staking.stakerPrefs(
|
||||
* ALICE, //Alice accountId
|
||||
* false
|
||||
* );
|
||||
* console.log(
|
||||
* 'Validator Preferences:',
|
||||
* prefs.map(
|
||||
* ({ era, validatorPrefs }) => `Era ${era}: Commission ${validatorPrefs.commission.toString()}`
|
||||
* )
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const stakerPrefs = /*#__PURE__*/ erasHistoricApplyAccount('_stakerPrefs');
|
||||
|
||||
@@ -235,6 +235,19 @@ export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name stakerRewards
|
||||
* @description Staking rewards history for a given staker.
|
||||
* @param { Uint8Array | string } accountId The stakers AccountId.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const rewards = await api.derive.staking.stakerRewards(
|
||||
* ALICE, //Alice accountId
|
||||
* false
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const stakerRewards = /*#__PURE__*/ firstMemo(
|
||||
(api: DeriveApi, accountId: Uint8Array | string, withActive?: boolean) =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
@@ -242,6 +255,19 @@ export const stakerRewards = /*#__PURE__*/ firstMemo(
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* @name stakerRewardsMultiEras
|
||||
* @description Staking rewards for multiple stakers over specific eras.
|
||||
* @param { Uint8Array | string } accountIds List of stakers identified by their AccountId.
|
||||
* @param { EraIndex[] } eras Eras for which to retrieve the data.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const rewards = await api.derive.staking.stakerRewardsMultiEras(
|
||||
* [ALICE, BOB, CHARLIER], //accountIds
|
||||
* [100,101] //eras
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function stakerRewardsMultiEras (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable<DeriveStakerReward[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[]): Observable<DeriveStakerReward[][]> =>
|
||||
accountIds.length && eras.length
|
||||
@@ -250,6 +276,19 @@ export function stakerRewardsMultiEras (instanceId: string, api: DeriveApi): (ac
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name stakerRewardsMulti
|
||||
* @description Staking rewards for multiple stakers.
|
||||
* @param { Uint8Array | string } accountIds List of stakers identified by their AccountId.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const rewards = await api.derive.staking.stakerRewardsMulti(
|
||||
* [ALICE, BOB, CHARLIER], //accountIds
|
||||
* true
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function stakerRewardsMulti (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
|
||||
return memo(instanceId, (accountIds: (Uint8Array | string)[], withActive = false): Observable<DeriveStakerReward[][]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
|
||||
@@ -25,4 +25,21 @@ export function _stakerSlashes (instanceId: string, api: DeriveApi): (accountId:
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name stakerSlashes
|
||||
* @param { Uint8Array | string } accountId The stakers AccountId.
|
||||
* @param { boolean } withActive Whether to include the active era.
|
||||
* @description Retrieve the historical slashes (penalties) for a given staker.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const stakerSlashes = await api.derive.staking.stakerSlashes(
|
||||
* ALICE, //Alice accountId
|
||||
* true
|
||||
* );
|
||||
* console.log(
|
||||
* 'Staker Slashes:',
|
||||
* stakerSlashes.map(({ era, total }) => `Era ${era}: Slashed ${total.toString()}`)
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export const stakerSlashes = /*#__PURE__*/ erasHistoricApplyAccount('_stakerSlashes');
|
||||
|
||||
@@ -34,7 +34,16 @@ function onBondedEvent (api: DeriveApi): Observable<number> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve the list of all validator stashes
|
||||
* @name stashes
|
||||
* @description Retrieve the list of all validator stashes.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const stashes = await api.derive.staking.stashes();
|
||||
* console.log(
|
||||
* "Validator Stashes:",
|
||||
* stashes.map((s) => s.toString())
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function stashes (instanceId: string, api: DeriveApi): () => Observable<AccountId[]> {
|
||||
return memo(instanceId, (): Observable<AccountId[]> =>
|
||||
|
||||
@@ -9,6 +9,18 @@ import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name nextElected
|
||||
* @description Retrieves the list of accounts that are set to be the next elected validators in the staking system. It provides a preview of who will be validators in the next staking era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const nextElected = await api.derive.staking.nextElected();
|
||||
* console.log(
|
||||
* "Next Elected Validators:",
|
||||
* nextElected.map((acc) => acc.toString())
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function nextElected (instanceId: string, api: DeriveApi): () => Observable<AccountId[]> {
|
||||
return memo(instanceId, (): Observable<AccountId[]> =>
|
||||
// Compatibility for future generation changes in staking.
|
||||
@@ -33,7 +45,20 @@ export function nextElected (instanceId: string, api: DeriveApi): () => Observab
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve latest list of validators
|
||||
* @name validators
|
||||
* @description Retrieve latest list of validators.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const { validators, nextElected } = await api.derive.staking.validators();
|
||||
* console.log(
|
||||
* "Current Validators:",
|
||||
* validators.map((v) => v.toString())
|
||||
* );
|
||||
* console.log(
|
||||
* "Next Elected Validators:",
|
||||
* nextElected.map((v) => v.toString())
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function validators (instanceId: string, api: DeriveApi): () => Observable<DeriveStakingValidators> {
|
||||
return memo(instanceId, (): Observable<DeriveStakingValidators> =>
|
||||
|
||||
@@ -10,6 +10,19 @@ import { memo } from '../util/index.js';
|
||||
|
||||
const DEFAULT_FLAGS = { withController: true, withPrefs: true };
|
||||
|
||||
/**
|
||||
* @name waitingInfo
|
||||
* @param {StakingQueryFlags} flags? (Optional) Query flags to filter the staking data.
|
||||
* @description Staking candidates who are waiting to become validators.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const { waiting, info } = await api.derive.staking.waitingInfo();
|
||||
* console.log(
|
||||
* "Waiting Candidates:",
|
||||
* waiting.map((acc) => acc.toString())
|
||||
* );
|
||||
* ```
|
||||
*/
|
||||
export function waitingInfo (instanceId: string, api: DeriveApi): (flags?: StakingQueryFlags) => Observable<DeriveStakingWaiting> {
|
||||
return memo(instanceId, (flags: StakingQueryFlags = DEFAULT_FLAGS): Observable<DeriveStakingWaiting> =>
|
||||
combineLatest([
|
||||
|
||||
@@ -3,12 +3,74 @@
|
||||
|
||||
import { hasProposals as collectiveHasProposals, members as collectiveMembers, prime as collectivePrime, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective/index.js';
|
||||
|
||||
/**
|
||||
* @name members
|
||||
* @description Retrieves the list of members in the "technicalCommittee" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const members = await api.derive.technicalCommittee.members();
|
||||
* console.log(`Members: ${JSON.stringify(members)});
|
||||
* ```
|
||||
*/
|
||||
export const members = /*#__PURE__*/ collectiveMembers('technicalCommittee');
|
||||
|
||||
/**
|
||||
* @name hasProposals
|
||||
* @description Checks if there are any active proposals in the "technicalCommittee" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const exists = await api.derive.technicalCommittee.hasProposals();
|
||||
* console.log(exists);
|
||||
* ```
|
||||
*/
|
||||
export const hasProposals = /*#__PURE__*/ collectiveHasProposals('technicalCommittee');
|
||||
/**
|
||||
* @name proposal
|
||||
* @description Retrieves details of a specific proposal in the "technicalCommitteeMotion" collective by its hash.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposalDetails = await api.derive.technicalCommittee.proposal(PROPOSAL_HASH);
|
||||
* console.log(proposalDetails);
|
||||
* ```
|
||||
*/
|
||||
export const proposal = /*#__PURE__*/ collectiveProposal('technicalCommittee');
|
||||
/**
|
||||
* @name proposalCount
|
||||
* @description Retrieves the total number of proposals in the "technicalCommittee" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const count = await api.derive.technicalCommittee.proposalCount();
|
||||
* console.log(`Amount of proposals: ${count}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalCount = /*#__PURE__*/ collectiveProposalCount('technicalCommittee');
|
||||
/**
|
||||
* @name proposalHashes
|
||||
* @description Retrieves an array of hashes for all active proposals in the "technicalCommittee" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const hashes = await api.derive.technicalCommittee.proposalHashes();
|
||||
* console.log(`Proposals ${JSON.stringify(hashes)}`);
|
||||
* ```
|
||||
*/
|
||||
export const proposalHashes = /*#__PURE__*/ collectiveProposalHashes('technicalCommittee');
|
||||
/**
|
||||
* @name proposals
|
||||
* @description Retrieves a list of all active proposals in the "technicalCommittee" collective.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const proposals = await api.derive.technicalCommittee.proposals();
|
||||
* console.log(proposals);
|
||||
* ```
|
||||
*/
|
||||
export const proposals = /*#__PURE__*/ collectiveProposals('technicalCommittee');
|
||||
|
||||
/**
|
||||
* @name prime
|
||||
* @description Retrieves the prime member of the "technicalCommittee" collective, if one exists.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const primeMember = await api.derive.technicalCommittee.prime();
|
||||
* console.log(primeMember);
|
||||
* ```
|
||||
*/
|
||||
export const prime = /*#__PURE__*/ collectivePrime('technicalCommittee');
|
||||
|
||||
@@ -81,7 +81,13 @@ function retrieveProposals (api: DeriveApi, proposalCount: ProposalIndex, approv
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve all active and approved treasury proposals, along with their info
|
||||
* @name proposals
|
||||
* @description Retrieve all active and approved treasury proposals, along with their info.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const treasuryProposals = await api.derive.treasury.proposals();
|
||||
* console.log(treasuryProposals);
|
||||
* ```
|
||||
*/
|
||||
export function proposals (instanceId: string, api: DeriveApi): () => Observable<DeriveTreasuryProposals> {
|
||||
return memo(instanceId, (): Observable<DeriveTreasuryProposals> =>
|
||||
|
||||
@@ -14,6 +14,19 @@ interface Result {
|
||||
events: EventRecord[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @name events
|
||||
* @param {Hash} at Block hash to query at.
|
||||
* @description Retrieves the block information alongside its events at a given block hash
|
||||
* @example
|
||||
* ```javascript
|
||||
* const blockHash = api.registry.createType(
|
||||
* "Hash",
|
||||
* "0xf1dc2efe8265be67deea5e91b05a98a7f9f81f66854e92825cf36f541beb7af6"
|
||||
* );
|
||||
* const { events, block } = await api.derive.tx.events(blockHash);
|
||||
* ```
|
||||
*/
|
||||
export function events (instanceId: string, api: DeriveApi): (at: Hash) => Observable<Result> {
|
||||
return memo(instanceId, (blockHash: Hash) =>
|
||||
combineLatest([
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
// Copyright 2017-2025 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { GenericExtrinsic } from '@polkadot/types';
|
||||
import type { EventRecord, Hash } from '@polkadot/types/interfaces';
|
||||
import type { DeriveApi } from '../types.js';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
interface ExtrinsicInfo {
|
||||
blockHash: Hash | string,
|
||||
blockNumber: number,
|
||||
extrinsic: GenericExtrinsic,
|
||||
events: EventRecord[]
|
||||
success: boolean
|
||||
}
|
||||
|
||||
interface ExtrinsicsInfo {
|
||||
blockHash: Hash | string,
|
||||
blockNumber: number,
|
||||
extrinsics: {
|
||||
events: EventRecord[]
|
||||
extrinsic: GenericExtrinsic,
|
||||
success: boolean
|
||||
}[],
|
||||
}
|
||||
|
||||
/**
|
||||
* @name extrinsicInfo
|
||||
* @param { Hash } at The block hash to query at.
|
||||
* @param { Uint8Array | string } transactionHash A transaction hash as U8 array or string.
|
||||
* @description Retrieves the extrinsic information and its events.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const blockHash = api.registry.createType(
|
||||
* 'Hash',
|
||||
* '0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
|
||||
* );
|
||||
* const extrinsicInfo = await api.derive.tx.extrinsicInfo(
|
||||
* blockHash,
|
||||
* '0xcd96520b05e0c4648ea365f3f063f27c5cdd8be10d41a1c44566428c91f37dcb'
|
||||
* );
|
||||
*
|
||||
* console.log(extrinsicInfo.extrinsic.toHuman());
|
||||
* ```
|
||||
*/
|
||||
export function extrinsicInfo (instanceId: string, api: DeriveApi): (at: Hash, transactionHash: Uint8Array | string) => Observable<ExtrinsicInfo | null> {
|
||||
return memo(instanceId, (at: Hash, transactionHash: Uint8Array | string): Observable<ExtrinsicInfo | null> => {
|
||||
return api.derive.tx.events(at).pipe(map(({ block, events }) => {
|
||||
const index = block.block.extrinsics.findIndex((ext) => ext.hash.toString() === transactionHash);
|
||||
|
||||
if (index === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const extEvents = events.filter(
|
||||
({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index)
|
||||
);
|
||||
|
||||
return {
|
||||
blockHash: block.hash.toHex(),
|
||||
blockNumber: block.block.header.number.toNumber(),
|
||||
events: extEvents,
|
||||
extrinsic: block.block.extrinsics[index],
|
||||
success: (extEvents.findIndex((ev) => ev.event.method === 'ExtrinsicSuccess') !== -1)
|
||||
};
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @name accountExtrinsics
|
||||
* @description Retrieves information about every extrinsic submitted by an account at a given block.
|
||||
* @param { Hash } at The block hash to query at.
|
||||
* @param { Uint8Array | strings } accountId The account identifier to query.
|
||||
* @example
|
||||
* ```javascript
|
||||
const blockHash = api.registry.createType(
|
||||
'Hash',
|
||||
'0xb772e4949d2f3eb5ba356aa43f885cc4f9097ee9812c5436543f3846a0491729'
|
||||
);
|
||||
const extrinsicsInfo = await api.derive.tx.accountExtrinsics(
|
||||
blockHash,
|
||||
'0x21895DdfD4640b4e0aDCa2865b907f2CE6e6B777'
|
||||
);
|
||||
|
||||
console.log(extrinsicsInfo.extrinsics[0]).extrinsic.toHuman();
|
||||
* ```
|
||||
*/
|
||||
export function accountExtrinsics (instanceId: string, api: DeriveApi): (at: Hash, accountId: Uint8Array | string) => Observable<ExtrinsicsInfo> {
|
||||
return memo(instanceId, (at: Hash, accountId: Uint8Array | string): Observable<ExtrinsicsInfo> => {
|
||||
return api.derive.tx.events(at).pipe(map(({ block, events }) => {
|
||||
const indexes: number[] = [];
|
||||
|
||||
return {
|
||||
blockHash: block.hash.toHex(),
|
||||
blockNumber: block.block.header.number.toNumber(),
|
||||
extrinsics: block.block.extrinsics.filter((ext, index) => {
|
||||
if (ext.signer.toString() === accountId) {
|
||||
indexes.push(index);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}).map((ext, i) => {
|
||||
const extEvents = events.filter(
|
||||
({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(indexes[i])
|
||||
);
|
||||
|
||||
return {
|
||||
events: extEvents,
|
||||
extrinsic: ext,
|
||||
success: (extEvents.findIndex((ev) => ev.event.method === 'ExtrinsicSuccess') !== -1)
|
||||
};
|
||||
})
|
||||
};
|
||||
}));
|
||||
});
|
||||
}
|
||||
@@ -2,4 +2,5 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './events.js';
|
||||
export * from './extrinsicInfo.js';
|
||||
export * from './signingInfo.js';
|
||||
|
||||
@@ -83,6 +83,20 @@ function babeOrAuraPeriod (api: DeriveApi): BN | undefined {
|
||||
return period && period.isZero && !period.isZero() ? period : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name signingInfo
|
||||
* @description Retrieves signing-related information for an account, including the nonce, block header, and mortal length.
|
||||
* @param {string} address The account address for which signing information is needed.
|
||||
* @param { BN | bigint | Uint8Array | number | string } nonce? (Optional) The nonce to use. If `undefined`, the latest nonce is retrieved.
|
||||
* @param { IExtrinsicEra | number } era? (Optional) The transaction era.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const info = await api.derive.tx.signingInfo(
|
||||
* "14mM9FRDDtwSYicjNxSvMfQkap8o4m9zHq7hNW4JpbSL4PPU"
|
||||
* );
|
||||
* console.log(info);
|
||||
* ```
|
||||
*/
|
||||
export function signingInfo (_instanceId: string, api: DeriveApi): (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number) => Observable<Result> {
|
||||
// no memo, we want to do this fresh on each run
|
||||
return (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number): Observable<Result> =>
|
||||
|
||||
+17
-17
@@ -18,29 +18,29 @@
|
||||
"./packageDetect.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "15.7.1",
|
||||
"version": "15.9.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@polkadot/api-augment": "15.7.1",
|
||||
"@polkadot/api-base": "15.7.1",
|
||||
"@polkadot/api-derive": "15.7.1",
|
||||
"@polkadot/keyring": "^13.4.3",
|
||||
"@polkadot/rpc-augment": "15.7.1",
|
||||
"@polkadot/rpc-core": "15.7.1",
|
||||
"@polkadot/rpc-provider": "15.7.1",
|
||||
"@polkadot/types": "15.7.1",
|
||||
"@polkadot/types-augment": "15.7.1",
|
||||
"@polkadot/types-codec": "15.7.1",
|
||||
"@polkadot/types-create": "15.7.1",
|
||||
"@polkadot/types-known": "15.7.1",
|
||||
"@polkadot/util": "^13.4.3",
|
||||
"@polkadot/util-crypto": "^13.4.3",
|
||||
"@polkadot/api-augment": "15.9.2",
|
||||
"@polkadot/api-base": "15.9.2",
|
||||
"@polkadot/api-derive": "15.9.2",
|
||||
"@polkadot/keyring": "^13.4.4",
|
||||
"@polkadot/rpc-augment": "15.9.2",
|
||||
"@polkadot/rpc-core": "15.9.2",
|
||||
"@polkadot/rpc-provider": "15.9.2",
|
||||
"@polkadot/types": "15.9.2",
|
||||
"@polkadot/types-augment": "15.9.2",
|
||||
"@polkadot/types-codec": "15.9.2",
|
||||
"@polkadot/types-create": "15.9.2",
|
||||
"@polkadot/types-known": "15.9.2",
|
||||
"@polkadot/util": "^13.4.4",
|
||||
"@polkadot/util-crypto": "^13.4.4",
|
||||
"eventemitter3": "^5.0.1",
|
||||
"rxjs": "^7.8.1",
|
||||
"tslib": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api-augment": "15.7.1",
|
||||
"@polkadot/types-support": "15.7.1"
|
||||
"@polkadot/api-augment": "15.9.2",
|
||||
"@polkadot/types-support": "15.9.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api', path: 'auto', type: 'auto', version: '15.7.1' };
|
||||
export const packageInfo = { name: '@polkadot/api', path: 'auto', type: 'auto', version: '15.9.2' };
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user