mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-10-28 05:39:49 +00:00
Rebrand: polkadot → pezkuwi, substrate → bizinikiwi, kusama → dicle
This commit is contained in:
commit
d5f038faea
1383 files changed
+1088018
No files matched your search
@@ -0,0 +1,5 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './info.js';
|
||||
export * from './overview.js';
|
||||
@@ -0,0 +1,111 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { CollatorId, ParaId } from '@pezkuwi/types/interfaces';
|
||||
import type { DeriveApi, DeriveTeyrchainActive, DeriveTeyrchainFull, DeriveTeyrchainInfo } from '../types.js';
|
||||
import type { Active, DidUpdate, Heads, ParaInfoResult, PendingSwap, RelayDispatchQueue, RetryQueue, SelectedThreads } from './types.js';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { objectSpread } from '@pezkuwi/util';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
import { didUpdateToBool } from './util.js';
|
||||
|
||||
type Result = [
|
||||
Active,
|
||||
RetryQueue,
|
||||
SelectedThreads,
|
||||
DidUpdate,
|
||||
ParaInfoResult,
|
||||
PendingSwap,
|
||||
Heads,
|
||||
RelayDispatchQueue
|
||||
];
|
||||
|
||||
function parseActive (id: ParaId, active: Active): DeriveTeyrchainActive | null {
|
||||
const found = active.find(([paraId]) => paraId === id);
|
||||
|
||||
if (found && found[1].isSome) {
|
||||
const [collatorId, retriable] = found[1].unwrap();
|
||||
|
||||
return objectSpread<DeriveTeyrchainActive>(
|
||||
{ collatorId },
|
||||
retriable.isWithRetries
|
||||
? {
|
||||
isRetriable: true,
|
||||
retries: retriable.asWithRetries.toNumber()
|
||||
}
|
||||
: {
|
||||
isRetriable: false,
|
||||
retries: 0
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseCollators (id: ParaId, collatorQueue: SelectedThreads | RetryQueue): (CollatorId | null)[] {
|
||||
return collatorQueue.map((queue): CollatorId | null => {
|
||||
const found = queue.find(([paraId]) => paraId === id);
|
||||
|
||||
return found ? found[1] : null;
|
||||
});
|
||||
}
|
||||
|
||||
function parse (id: ParaId, [active, retryQueue, selectedThreads, didUpdate, info, pendingSwap, heads, relayDispatchQueue]: Result): DeriveTeyrchainFull | null {
|
||||
if (info.isNone) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
active: parseActive(id, active),
|
||||
didUpdate: didUpdateToBool(didUpdate, id),
|
||||
heads,
|
||||
id,
|
||||
info: objectSpread<DeriveTeyrchainInfo>({ id }, info.unwrap()),
|
||||
pendingSwapId: pendingSwap.unwrapOr(null),
|
||||
relayDispatchQueue,
|
||||
retryCollators: parseCollators(id, retryQueue),
|
||||
selectedCollators: parseCollators(id, selectedThreads)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @name info
|
||||
* @param {ParaId | number} id A unique numeric (non-negative integer) identifier for a teyrchain.
|
||||
* @description Retrieves detailed information about a specific teyrchain.
|
||||
* @example
|
||||
* ```javascript
|
||||
* await api.derive.teyrchains.info(1000, (info) => {
|
||||
* if (info) {
|
||||
* console.log(`Teyrchain ${info.id.toString()} is active: ${info.active}`);
|
||||
* } else {
|
||||
* console.log("Teyrchain information not available.");
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function info (instanceId: string, api: DeriveApi): (id: ParaId | number) => Observable<DeriveTeyrchainFull | null> {
|
||||
return memo(instanceId, (id: ParaId | number): Observable<DeriveTeyrchainFull | null> =>
|
||||
api.query.registrar && api.query['teyrchains']
|
||||
? api.queryMulti<Result>([
|
||||
api.query.registrar['active'],
|
||||
api.query.registrar['retryQueue'],
|
||||
api.query.registrar['selectedThreads'],
|
||||
api.query['teyrchains']['didUpdate'],
|
||||
[api.query.registrar.paras, id],
|
||||
[api.query.registrar.pendingSwap, id],
|
||||
[api.query['teyrchains']['heads'], id],
|
||||
[api.query['teyrchains']['relayDispatchQueue'], id]
|
||||
])
|
||||
.pipe(
|
||||
map((result: Result): DeriveTeyrchainFull | null =>
|
||||
parse(api.registry.createType('ParaId', id), result)
|
||||
)
|
||||
)
|
||||
: of(null)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ParaId } from '@pezkuwi/types/interfaces';
|
||||
import type { DeriveApi, DeriveTeyrchain, DeriveTeyrchainInfo } from '../types.js';
|
||||
import type { DidUpdate, ParaInfoResult, PendingSwap, RelayDispatchQueueSize } from './types.js';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { objectSpread } from '@pezkuwi/util';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
import { didUpdateToBool } from './util.js';
|
||||
|
||||
type Result = [
|
||||
ParaId[],
|
||||
DidUpdate,
|
||||
RelayDispatchQueueSize[],
|
||||
ParaInfoResult[],
|
||||
PendingSwap[]
|
||||
];
|
||||
|
||||
function parse ([ids, didUpdate, relayDispatchQueueSizes, infos, pendingSwaps]: Result): DeriveTeyrchain[] {
|
||||
return ids.map((id, index): DeriveTeyrchain => ({
|
||||
didUpdate: didUpdateToBool(didUpdate, id),
|
||||
id,
|
||||
info: objectSpread<DeriveTeyrchainInfo>({ id }, infos[index].unwrapOr(null)),
|
||||
pendingSwapId: pendingSwaps[index].unwrapOr(null),
|
||||
relayDispatchQueueSize: relayDispatchQueueSizes[index][0].toNumber()
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @name overview
|
||||
* @description Retrieves an overview of all registered teyrchains.
|
||||
* @example
|
||||
* ```javascript
|
||||
* await api.derive.teyrchains.overview((overview) => {
|
||||
* teyrchains.forEach(teyrchain => {
|
||||
* console.log(`Teyrchain ${teyrchain.id.toString()} is registered.`);
|
||||
* });
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function overview (instanceId: string, api: DeriveApi): () => Observable<DeriveTeyrchain[]> {
|
||||
return memo(instanceId, (): Observable<DeriveTeyrchain[]> =>
|
||||
api.query.registrar?.['teyrchains'] && api.query['teyrchains']
|
||||
? api.query.registrar['teyrchains']<ParaId[]>().pipe(
|
||||
switchMap((paraIds) =>
|
||||
combineLatest([
|
||||
of(paraIds),
|
||||
api.query['teyrchains']['didUpdate']<DidUpdate>(),
|
||||
api.query['teyrchains']['relayDispatchQueueSize'].multi<RelayDispatchQueueSize>(paraIds),
|
||||
api.query.registrar.paras.multi<ParaInfoResult>(paraIds),
|
||||
api.query.registrar.pendingSwap.multi<PendingSwap>(paraIds)
|
||||
])
|
||||
),
|
||||
map(parse)
|
||||
)
|
||||
: of([] as DeriveTeyrchain[])
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Bytes, Option, u32, Vec } from '@pezkuwi/types';
|
||||
import type { CollatorId, ParaId, ParaInfo, Retriable, UpwardMessage } from '@pezkuwi/types/interfaces';
|
||||
import type { ITuple } from '@pezkuwi/types/types';
|
||||
|
||||
export type ParaInfoResult = Option<ParaInfo>;
|
||||
export type PendingSwap = Option<ParaId>;
|
||||
export type Active = Vec<ITuple<[ParaId, Option<ITuple<[CollatorId, Retriable]>>]>>;
|
||||
export type RetryQueue = Vec<Vec<ITuple<[ParaId, CollatorId]>>>
|
||||
export type SelectedThreads = Vec<Vec<ITuple<[ParaId, CollatorId]>>>
|
||||
export type Code = Bytes;
|
||||
export type Heads = Bytes;
|
||||
export type RelayDispatchQueue = Vec<UpwardMessage>
|
||||
export type RelayDispatchQueueSize = ITuple<[u32, u32]>;
|
||||
export type DidUpdate = Option<Vec<ParaId>>;
|
||||
|
||||
export interface DeriveTeyrchainActive {
|
||||
collatorId: CollatorId;
|
||||
isRetriable: boolean;
|
||||
retries: number;
|
||||
}
|
||||
|
||||
export interface DeriveTeyrchainInfo extends ParaInfo {
|
||||
id: ParaId;
|
||||
icon?: string;
|
||||
name?: string;
|
||||
owner?: string;
|
||||
}
|
||||
|
||||
export interface DeriveTeyrchain {
|
||||
didUpdate: boolean;
|
||||
pendingSwapId: ParaId | null;
|
||||
id: ParaId;
|
||||
info: DeriveTeyrchainInfo | null;
|
||||
relayDispatchQueueSize?: number;
|
||||
}
|
||||
|
||||
export interface DeriveTeyrchainFull extends DeriveTeyrchain {
|
||||
active: DeriveTeyrchainActive | null;
|
||||
heads: Bytes | null;
|
||||
relayDispatchQueue: UpwardMessage[];
|
||||
retryCollators: (CollatorId | null)[];
|
||||
selectedCollators: (CollatorId | null)[];
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ParaId } from '@pezkuwi/types/interfaces';
|
||||
import type { DidUpdate } from './types.js';
|
||||
|
||||
export function didUpdateToBool (didUpdate: DidUpdate, id: ParaId): boolean {
|
||||
return didUpdate.isSome
|
||||
? didUpdate.unwrap().some((paraId) => paraId.eq(id))
|
||||
: false;
|
||||
}
|
||||
Reference in new issue
Block a user