Skip to content

Commit

Permalink
[api] Export generated types from api (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Sep 18, 2023
1 parent 4d8268b commit 15e0fb5
Show file tree
Hide file tree
Showing 22 changed files with 1,131 additions and 1,147 deletions.
6 changes: 3 additions & 3 deletions api/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typescript from 'rollup-plugin-typescript2';
import { cpSync, writeFileSync } from 'fs';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { writeFileSync, cpSync } from 'fs';
import typescript from 'rollup-plugin-typescript2';

function writePackageJson() {
return {
Expand Down
2 changes: 1 addition & 1 deletion api/src/Code.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Bytes, Option } from '@polkadot/types';
import { GearCommonCodeMetadata, GearCoreCodeInstrumentedCode } from '@polkadot/types/lookup';
import { GearCommonCodeMetadata, GearCoreCodeInstrumentedCode } from './types';
import { HexString } from '@polkadot/util/types';
import { ISubmittableResult } from '@polkadot/types/types';
import { SubmittableExtrinsic } from '@polkadot/api/types';
Expand Down
4 changes: 2 additions & 2 deletions api/src/Gas.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HexString } from '@polkadot/util/types';

import { PayloadType, Value } from './types';
import { GasInfo } from './types';
import { GasInfo, PayloadType } from './types';
import { GearApi } from './GearApi';
import { ProgramMetadata } from './metadata';
import { Value } from './types/common';
import { encodePayload } from './utils/create-payload';

export class GearGas {
Expand Down
3 changes: 1 addition & 2 deletions api/src/GearApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { DispatchError, Event } from '@polkadot/types/interfaces';
import { u128, u64 } from '@polkadot/types';
import { GearCommonGasMultiplier } from '@polkadot/types/lookup';
import { RegistryError } from '@polkadot/types-codec/types';

import { GearApiOptions, GearCommonGasMultiplier } from './types';
import { gearRpc, gearTypes } from './default';
import { GearApiOptions } from './types';
import { GearBalance } from './Balance';
import { GearBlock } from './Blocks';
import { GearClaimValue } from './Claim';
Expand Down
9 changes: 7 additions & 2 deletions api/src/Program.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Bytes, Option, u128, u32 } from '@polkadot/types';
import { GearCommonProgram } from '@polkadot/types/lookup';
import { H256 } from '@polkadot/types/interfaces';
import { HexString } from '@polkadot/util/types';
import { ISubmittableResult } from '@polkadot/types/types';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { randomAsHex } from '@polkadot/util-crypto';

import { IProgramCreateOptions, IProgramCreateResult, IProgramUploadOptions, IProgramUploadResult } from './types';
import {
GearCommonProgram,
IProgramCreateOptions,
IProgramCreateResult,
IProgramUploadOptions,
IProgramUploadResult,
} from './types';
import { ProgramDoesNotExistError, ProgramHasNoMetahash, SubmitProgramError } from './errors';
import {
encodePayload,
Expand Down
3 changes: 1 addition & 2 deletions api/src/Storage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { GearCommonActiveProgram, GearCommonProgram } from '@polkadot/types/lookup';
import { Option, u32 } from '@polkadot/types';
import { H256 } from '@polkadot/types/interfaces';
import { HexString } from '@polkadot/util/types';
import { ITuple } from '@polkadot/types-codec/types';
import { u8aToU8a } from '@polkadot/util';

import { IGearPages, PausedProgramBlockAndHash } from './types';
import { GearCommonActiveProgram, GearCommonProgram, IGearPages, PausedProgramBlockAndHash } from './types';
import {
PausedProgramDoesNotExistError,
ProgramDoesNotExistError,
Expand Down
36 changes: 13 additions & 23 deletions api/src/Waitlist.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { GearCommonStoragePrimitivesInterval, GearCoreMessageStoredStoredDispatch } from '@polkadot/types/lookup';
import { HexString } from '@polkadot/util/types';
import { Option } from '@polkadot/types';

import { GearApi } from './GearApi';
import { ITuple } from '@polkadot/types-codec/types';
import { WaitlistItem } from 'types';

export class GearWaitlist {
constructor(private _api: GearApi) {}
Expand All @@ -19,10 +18,7 @@ export class GearWaitlist {
* console.log(waitlist.map(item => item.toHuman()));
* ```
*/
async read(
programId: HexString,
numberOfMessages?: number,
): Promise<ITuple<[GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval]>[]>;
async read(programId: HexString, numberOfMessages?: number): Promise<WaitlistItem[]>;

/**
* ## _Get particular message from program's waitlist_
Expand All @@ -37,42 +33,36 @@ export class GearWaitlist {
* console.log(waitlist.toHuman());
* ```
*/
async read(
programId: HexString,
messageId: HexString,
): Promise<ITuple<[GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval]>>;
async read(programId: HexString, messageId: HexString): Promise<WaitlistItem>;

async read(
programId: HexString,
messageIdOrNumberOfMessages?: HexString | number,
): Promise<
| ITuple<[GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval]>[]
| ITuple<[GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval]>
> {
): Promise<WaitlistItem[] | WaitlistItem> {
const [messageId, numberOfMessages] =
typeof messageIdOrNumberOfMessages === 'string'
? [messageIdOrNumberOfMessages, undefined]
: [undefined, messageIdOrNumberOfMessages || 1000];

if (messageId) {
const waitlist = await this._api.query.gearMessenger.waitlist(programId, messageId);
const typedWaitlist = this._api.createType<
Option<ITuple<[GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval]>>
>('Option<(GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval)>', waitlist);
const typedWaitlist = this._api.createType<Option<WaitlistItem>>(
'Option<(GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval)>',
waitlist,
);
return typedWaitlist.unwrapOr(null);
} else {
const keyPrefix = this._api.query.gearMessenger.waitlist.keyPrefix(programId);
const keysPaged = await this._api.rpc.state.getKeysPaged(keyPrefix, numberOfMessages, keyPrefix);
if (keysPaged.length === 0) {
return [];
}
const waitlist = (await this._api.rpc.state.queryStorageAt(keysPaged)) as Option<
ITuple<[GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval]>
>[];
const waitlist = (await this._api.rpc.state.queryStorageAt(keysPaged)) as Option<WaitlistItem>[];
return waitlist.map((item) => {
const typedItem = this._api.createType<
Option<ITuple<[GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval]>>
>('Option<(GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval)>', item);
const typedItem = this._api.createType<Option<WaitlistItem>>(
'Option<(GearCoreMessageStoredStoredDispatch, GearCommonStoragePrimitivesInterval)>',
item,
);
return typedItem.unwrapOr(null);
});
}
Expand Down
12 changes: 8 additions & 4 deletions api/src/events/GearEventData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AccountId32, BlockNumber } from '@polkadot/types/interfaces';
import { BTreeMap, BTreeSet, GenericEventData, Option, u128, u32 } from '@polkadot/types';
import { GasNodeId, ReservationId } from 'types/interfaces/ids/gas';

import {
CodeId,
GasNodeId,
GearCommonEventCodeChangeKind,
GearCommonEventDispatchStatus,
GearCommonEventMessageEntry,
Expand All @@ -10,9 +12,11 @@ import {
GearCommonEventReasonMessageWokenRuntimeReason,
GearCommonEventReasonUserMessageReadRuntimeReason,
GearCoreMessageUserUserMessage,
} from '@polkadot/types/lookup';

import { CodeId, MessageId, ProgramId, ResumeProgramSessionId } from '../types';
MessageId,
ProgramId,
ReservationId,
ResumeProgramSessionId,
} from '../types';

export class GearEventData extends GenericEventData {
constructor(data: GenericEventData) {
Expand Down
7 changes: 3 additions & 4 deletions api/src/types/augment/augment-api-consts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import '@polkadot/api-base/types/consts';

import type { ApiTypes, AugmentedConst } from '@polkadot/api-base/types';
import { FrameSupportPalletId, GearCommonGasMultiplier, PalletGearSchedule } from '@polkadot/types/lookup';
import { GearCommonGasMultiplier, PalletGearSchedule } from '../lookup';
import type { bool, u128, u32, u64 } from '@polkadot/types-codec';
import type { AccountId32 } from '@polkadot/types/interfaces/runtime';
import type { ApiTypes } from '@polkadot/api-base/types';
import type { Codec } from '@polkadot/types-codec/types';

export type __AugmentedConst<ApiType extends ApiTypes> = AugmentedConst<ApiType>;
import { FrameSupportPalletId } from '@polkadot/types/lookup';

declare module '@polkadot/api-base/types/consts' {
interface AugmentedConsts<ApiType extends ApiTypes> {
Expand Down
2 changes: 0 additions & 2 deletions api/src/types/augment/augment-api-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import '@polkadot/api-base/types/errors';

import type { ApiTypes, AugmentedError } from '@polkadot/api-base/types';

export type __AugmentedError<ApiType extends ApiTypes> = AugmentedError<ApiType>;

declare module '@polkadot/api-base/types/errors' {
interface AugmentedErrors<ApiType extends ApiTypes> {
gear: {
Expand Down
4 changes: 1 addition & 3 deletions api/src/types/augment/augment-api-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import {
GearCoreIdsMessageId,
GearCoreIdsProgramId,
GearCoreMessageUserUserMessage,
} from '@polkadot/types/lookup';
} from '../lookup';
import type { AccountId32 } from '@polkadot/types/interfaces/runtime';

export type __AugmentedEvent<ApiType extends ApiTypes> = AugmentedEvent<ApiType>;

declare module '@polkadot/api-base/types/events' {
interface AugmentedEvents<ApiType extends ApiTypes> {
gear: {
Expand Down
5 changes: 1 addition & 4 deletions api/src/types/augment/augment-api-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ import {
GearCoreMessageStoredStoredDispatch,
GearCoreMessageUserUserStoredMessage,
PalletGearBankBankAccount,
} from '@polkadot/types/lookup';
} from '../lookup';
import type { Observable } from '@polkadot/types/types';

export type __AugmentedQuery<ApiType extends ApiTypes> = AugmentedQuery<ApiType, () => unknown>;
export type __QueryableStorageEntry<ApiType extends ApiTypes> = QueryableStorageEntry<ApiType>;

declare module '@polkadot/api-base/types/storage' {
interface AugmentedQueries<ApiType extends ApiTypes> {
gear: {
Expand Down
4 changes: 1 addition & 3 deletions api/src/types/augment/augment-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import type { Bytes } from '@polkadot/types-codec';
import type { H256 } from '@polkadot/types/interfaces/runtime';
import type { Observable } from '@polkadot/types/types';

import { GasInfo } from '..';

export type __AugmentedRpc = AugmentedRpc<() => unknown>;
import { GasInfo } from '../interfaces';

declare module '@polkadot/rpc-core/types/jsonrpc' {
interface RpcInterface {
Expand Down
13 changes: 2 additions & 11 deletions api/src/types/augment/augment-api-tx.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import '@polkadot/api-base/types/submittable';

import type { AnyNumber, ITuple } from '@polkadot/types-codec/types';
import type {
ApiTypes,
AugmentedSubmittable,
SubmittableExtrinsic,
SubmittableExtrinsicFunction,
} from '@polkadot/api-base/types';
import type { ApiTypes, AugmentedSubmittable } from '@polkadot/api-base/types';
import type { BTreeSet, Bytes, Option, Vec, bool, u128, u32, u64 } from '@polkadot/types-codec';
import { GearCoreIdsCodeId, GearCoreIdsMessageId, GearCoreIdsProgramId } from '@polkadot/types/lookup';
import { GearCoreIdsCodeId, GearCoreIdsMessageId, GearCoreIdsProgramId } from '../lookup';
import type { MultiAddress } from '@polkadot/types/interfaces/runtime';

export type __AugmentedSubmittable = AugmentedSubmittable<() => unknown>;
export type __SubmittableExtrinsic<ApiType extends ApiTypes> = SubmittableExtrinsic<ApiType>;
export type __SubmittableExtrinsicFunction<ApiType extends ApiTypes> = SubmittableExtrinsicFunction<ApiType>;

declare module '@polkadot/api-base/types/submittable' {
interface AugmentedSubmittables<ApiType extends ApiTypes> {
gear: {
Expand Down
2 changes: 0 additions & 2 deletions api/src/types/augment/index.ts

This file was deleted.

Loading

0 comments on commit 15e0fb5

Please sign in to comment.