From e0c6a926ca937769b16e777abeb04dd56bbfefb9 Mon Sep 17 00:00:00 2001 From: Dmitryii Osipov Date: Tue, 28 Nov 2023 17:44:09 +0400 Subject: [PATCH] [api] Add VaraApiV1000 and VaraApiV1010 classes (#1458) --- api/README.md | 4 +- api/src/Message.ts | 55 +++++++++++-------- api/src/Program.ts | 43 +++++---------- api/src/Storage.ts | 5 +- api/src/apis/index.ts | 4 +- api/src/apis/v1000/api.ts | 8 +++ api/src/apis/{vara => v1000}/message.ts | 16 +++--- api/src/apis/v1000/program.ts | 29 ++++++++++ api/src/apis/v1010/api.ts | 3 + api/src/apis/vara-testnet/api.ts | 3 - api/src/apis/vara/api.ts | 8 --- api/src/apis/vara/program.ts | 29 ---------- api/src/consts.ts | 6 ++ api/src/index.ts | 2 +- api/src/specs/index.ts | 2 - api/src/specs/vara-testnet.ts | 2 - api/src/specs/vara.ts | 2 - api/src/types/interfaces/message/extrinsic.ts | 20 ++++--- api/src/types/interfaces/program/extrinsic.ts | 14 +++-- api/src/utils/generate.ts | 3 +- 20 files changed, 131 insertions(+), 127 deletions(-) create mode 100644 api/src/apis/v1000/api.ts rename api/src/apis/{vara => v1000}/message.ts (73%) create mode 100644 api/src/apis/v1000/program.ts create mode 100644 api/src/apis/v1010/api.ts delete mode 100644 api/src/apis/vara-testnet/api.ts delete mode 100644 api/src/apis/vara/api.ts delete mode 100644 api/src/apis/vara/program.ts create mode 100644 api/src/consts.ts delete mode 100644 api/src/specs/index.ts delete mode 100644 api/src/specs/vara-testnet.ts delete mode 100644 api/src/specs/vara.ts diff --git a/api/README.md b/api/README.md index 2ade645614..1a49b5c803 100644 --- a/api/README.md +++ b/api/README.md @@ -51,7 +51,9 @@ const nodeVersion = await gearApi.nodeVersion(); const genesis = gearApi.genesisHash.toHex(); ``` -Since Vara and VaraTestnet can have different runtime versions, they can have different extrinsics signatures. If your application is running on the Vara Network it is more convinient to use the `VaraApi` class instead of `GearApi` and `VaraTestnetApi` for the Vara Testnet Network +Since different networks can have different runtime versions, they can have different extrinsics / rpc calls signatures. +In general you may use `GearApi` class to interact with the node, but it can be more convivnient to use classes based on a specific runtime version. +For example for interacting with the network that has runtime version more than `1010` you can use the `VaraApiV1010` class. --- ## Payloads and metadata diff --git a/api/src/Message.ts b/api/src/Message.ts index c97c61afea..d48ad9b13e 100644 --- a/api/src/Message.ts +++ b/api/src/Message.ts @@ -3,16 +3,12 @@ import { HexString } from '@polkadot/util/types'; import { ISubmittableResult } from '@polkadot/types/types'; import { ReplaySubject } from 'rxjs'; -import { - IMessageSendOptions, - IMessageSendReplyOptions, - VaraMessageSendOptions, - VaraMessageSendReplyOptions, -} from './types'; +import { MessageSendOptions, MessageSendReplyOptions } from './types'; import { SendMessageError, SendReplyError } from './errors'; import { encodePayload, getExtrinsic, validateGasLimit, validateMailboxItem, validateValue } from './utils'; import { GearTransaction } from './Transaction'; import { ProgramMetadata } from './metadata'; +import { SPEC_VERSION } from './consts'; import { UserMessageSentData } from './events'; export class GearMessage extends GearTransaction { @@ -21,7 +17,9 @@ export class GearMessage extends GearTransaction { * @param args Message parameters. * @param meta Program metadata obtained using `getProgramMetadata` function. * @param typeIndex (optional) Index of type in the registry. If not specified the type index from `meta.handle.input` will be used instead. - * @returns Submittable result + * @returns Submitable result + * + * _Note that parameter `prepaid` is not supported starting from `1010` runtime version._ * @example * ```javascript * const programId = '0x..'; @@ -40,7 +38,7 @@ export class GearMessage extends GearTransaction { * ``` */ send( - args: IMessageSendOptions | VaraMessageSendOptions, + args: MessageSendOptions, meta: ProgramMetadata, typeIndex?: number, ): SubmittableExtrinsic<'promise', ISubmittableResult>; @@ -50,7 +48,9 @@ export class GearMessage extends GearTransaction { * @param args Message parameters * @param hexRegistry Registry in hex format * @param typeIndex Index of type in the registry. - * @returns Submitted result + * @returns Submitable result + * + * _Note that parameter `prepaid` is not supported starting from `1010` runtime version._ * @example * ```javascript * const programId = '0x..'; @@ -68,7 +68,7 @@ export class GearMessage extends GearTransaction { * ``` */ send( - args: IMessageSendOptions | VaraMessageSendOptions, + args: MessageSendOptions, hexRegistry: HexString, typeIndex: number, ): SubmittableExtrinsic<'promise', ISubmittableResult>; @@ -78,7 +78,9 @@ export class GearMessage extends GearTransaction { * @param args Message parameters * @param metaOrHexRegistry (optional) Registry in hex format or ProgramMetadata * @param typeName payload type (one of the default rust types if metadata or registry don't specified) - * @returns Submitted result + * @returns Submitable result + * + * _Note that parameter `prepaid` is not supported starting from `1010` runtime version._ * @example * ```javascript * const programId = '0x..'; @@ -95,7 +97,7 @@ export class GearMessage extends GearTransaction { * ``` */ send( - args: IMessageSendOptions | VaraMessageSendOptions, + args: MessageSendOptions, metaOrHexRegistry?: ProgramMetadata | HexString, typeName?: string, ): SubmittableExtrinsic<'promise', ISubmittableResult>; @@ -105,10 +107,10 @@ export class GearMessage extends GearTransaction { * @param message * @param metaOrHexRegistry Metadata * @param typeIndexOrTypeName type index in registry or type name - * @returns Submitted result + * @returns Submitable result */ send( - { destination, value, gasLimit, payload, ...rest }: IMessageSendOptions | VaraMessageSendOptions, + { destination, value, gasLimit, payload, ...rest }: MessageSendOptions, metaOrHexRegistry?: ProgramMetadata | HexString, typeIndexOrTypeName?: number | string, ): SubmittableExtrinsic<'promise', ISubmittableResult> { @@ -120,7 +122,7 @@ export class GearMessage extends GearTransaction { try { const txArgs: any[] = [destination, _payload, gasLimit, value || 0]; - if (this._api.specVersion >= 1010) { + if (this._api.specVersion >= SPEC_VERSION.V1010) { txArgs.push('keepAlive' in rest ? rest.keepAlive : true); } else { txArgs.push('prepaid' in rest ? rest.prepaid : false); @@ -138,7 +140,9 @@ export class GearMessage extends GearTransaction { * @param args Message parameters * @param meta Program metadata obtained using `ProgramMetadata.from` method. * @param typeIndex (optional) Index of type in the registry. If not specified the type index from `meta.reply.input` will be used instead. - * @returns Submitted result + * @returns Submitable result + * + * _Note that parameter `prepaid` is not supported starting from `1010` runtime version._ * @example * ```javascript * const replyToMessage = '0x..'; @@ -157,7 +161,7 @@ export class GearMessage extends GearTransaction { * ``` */ sendReply( - args: IMessageSendReplyOptions | VaraMessageSendReplyOptions, + args: MessageSendReplyOptions, meta?: ProgramMetadata, typeIndex?: number, ): Promise>; @@ -167,7 +171,9 @@ export class GearMessage extends GearTransaction { * @param args Message parameters * @param hexRegistry Registry in hex format * @param typeIndex Index of type in the registry. - * @returns Submitted result + * @returns Submitable result + * + * _Note that parameter `prepaid` is not supported starting from `1010` runtime version._ * @example * ```javascript * const replyToMessage = '0x..'; @@ -185,7 +191,7 @@ export class GearMessage extends GearTransaction { * ``` */ sendReply( - args: IMessageSendReplyOptions | VaraMessageSendReplyOptions, + args: MessageSendReplyOptions, hexRegistry: HexString, typeIndex: number, ): Promise>; @@ -195,7 +201,10 @@ export class GearMessage extends GearTransaction { * @param args Message parameters * @param metaOrHexRegistry (optional) Registry in hex format or ProgramMetadata * @param typeName payload type (one of the default rust types if metadata or registry don't specified) - * @returns Submitted result + * @returns Submitable result + * + * _Note that parameter `prepaid` is not supported starting from `1010` runtime version._ + * @example * ```javascript * const replyToMessage = '0x..'; * const hexRegistry = '0x...'; @@ -212,7 +221,7 @@ export class GearMessage extends GearTransaction { * ``` */ sendReply( - args: IMessageSendReplyOptions | VaraMessageSendReplyOptions, + args: MessageSendReplyOptions, metaOrHexRegistry?: ProgramMetadata | HexString, typeName?: string, ): Promise>; @@ -226,7 +235,7 @@ export class GearMessage extends GearTransaction { */ async sendReply( - { value, gasLimit, replyToId, payload, account, ...rest }: IMessageSendReplyOptions | VaraMessageSendReplyOptions, + { value, gasLimit, replyToId, payload, account, ...rest }: MessageSendReplyOptions, metaOrHexRegistry?: ProgramMetadata | HexString, typeIndexOrTypeName?: number | string, ): Promise> { @@ -242,7 +251,7 @@ export class GearMessage extends GearTransaction { try { const txArgs: any[] = [replyToId, _payload, gasLimit, value || 0]; - if (this._api.specVersion >= 1010) { + if (this._api.specVersion >= SPEC_VERSION.V1010) { txArgs.push('keepAlive' in rest ? rest.keepAlive : true); } else { txArgs.push('prepaid' in rest ? rest.prepaid : false); diff --git a/api/src/Program.ts b/api/src/Program.ts index 93795b2316..37191018c2 100644 --- a/api/src/Program.ts +++ b/api/src/Program.ts @@ -7,12 +7,10 @@ import { randomAsHex } from '@polkadot/util-crypto'; import { GearCommonProgram, - IProgramCreateOptions, IProgramCreateResult, - IProgramUploadOptions, IProgramUploadResult, - VaraProgramCreateOptions, - VaraProgramUploadOptions, + ProgramCreateOptions, + ProgramUploadOptions, } from './types'; import { ProgramDoesNotExistError, ProgramHasNoMetahash, SubmitProgramError } from './errors'; import { @@ -30,6 +28,7 @@ import { GearGas } from './Gas'; import { GearResumeSession } from './ResumeSession'; import { GearTransaction } from './Transaction'; import { ProgramMetadata } from './metadata'; +import { SPEC_VERSION } from './consts'; export class GearProgram extends GearTransaction { public calculateGas: GearGas; @@ -63,11 +62,7 @@ export class GearProgram extends GearTransaction { * }) * ``` */ - upload( - args: IProgramUploadOptions | VaraProgramUploadOptions, - meta?: ProgramMetadata, - typeIndex?: number, - ): IProgramUploadResult; + upload(args: ProgramUploadOptions, meta?: ProgramMetadata, typeIndex?: number): IProgramUploadResult; /** * ### Upload program with code using registry in hex format to encode payload @@ -76,11 +71,7 @@ export class GearProgram extends GearTransaction { * @param typeIndex Index of type in the registry. * @returns Object containing program id, generated (or specified) salt, code id, prepared extrinsic */ - upload( - args: IProgramUploadOptions | VaraProgramUploadOptions, - hexRegistry: HexString, - typeIndex: number, - ): IProgramUploadResult; + upload(args: ProgramUploadOptions, hexRegistry: HexString, typeIndex: number): IProgramUploadResult; /** ### Upload program with code using type name to encode payload * @param args @@ -88,13 +79,13 @@ export class GearProgram extends GearTransaction { * @param typeName type name (one of the default rust types if metadata or registry don't specified) */ upload( - args: IProgramUploadOptions | VaraProgramUploadOptions, + args: ProgramUploadOptions, metaOrHexRegistry?: ProgramMetadata | HexString, typeName?: string, ): IProgramUploadResult; upload( - args: IProgramUploadOptions | VaraProgramUploadOptions, + args: ProgramUploadOptions, metaOrHexRegistry?: ProgramMetadata | HexString, typeIndexOrTypeName?: number | string, ): IProgramUploadResult { @@ -110,7 +101,7 @@ export class GearProgram extends GearTransaction { try { const txArgs: any[] = [code, salt, payload, args.gasLimit, args.value || 0]; - if (this._api.specVersion >= 1010) { + if (this._api.specVersion >= SPEC_VERSION.V1010) { txArgs.push('keepAlive' in args ? args.keepAlive : true); } @@ -145,11 +136,7 @@ export class GearProgram extends GearTransaction { * }) * ``` */ - create( - args: IProgramCreateOptions | VaraProgramCreateOptions, - meta?: ProgramMetadata, - typeIndex?: number | null, - ): IProgramCreateResult; + create(args: ProgramCreateOptions, meta?: ProgramMetadata, typeIndex?: number | null): IProgramCreateResult; /** * ### Create program from uploaded on chain code using program metadata to encode payload @@ -158,11 +145,7 @@ export class GearProgram extends GearTransaction { * @param typeIndex Index of type in the registry. * @returns Object containing program id, generated (or specified) salt, prepared extrinsic */ - create( - args: IProgramCreateOptions | VaraProgramCreateOptions, - hexRegistry: HexString, - typeIndex: number, - ): IProgramCreateResult; + create(args: ProgramCreateOptions, hexRegistry: HexString, typeIndex: number): IProgramCreateResult; /** ## Create program using existed codeId * @param args @@ -170,13 +153,13 @@ export class GearProgram extends GearTransaction { * @param type name type name (one of the default rust types if metadata or registry don't specified) */ create( - args: IProgramCreateOptions | VaraProgramCreateOptions, + args: ProgramCreateOptions, metaOrHexRegistry?: HexString | ProgramMetadata, typeName?: number | string, ): IProgramCreateResult; create( - { codeId, initPayload, value, gasLimit, ...args }: IProgramCreateOptions | VaraProgramCreateOptions, + { codeId, initPayload, value, gasLimit, ...args }: ProgramCreateOptions, metaOrHexRegistry?: HexString | ProgramMetadata, typeIndexOrTypeName?: number | string | null, ): IProgramCreateResult { @@ -191,7 +174,7 @@ export class GearProgram extends GearTransaction { try { const txArgs: any[] = [codeId, salt, payload, gasLimit, value || 0]; - if (this._api.specVersion >= 1010) { + if (this._api.specVersion >= SPEC_VERSION.V1010) { txArgs.push('keepAlive' in args ? args.keepAlive : true); } diff --git a/api/src/Storage.ts b/api/src/Storage.ts index 54f5369e95..bf8e237b64 100644 --- a/api/src/Storage.ts +++ b/api/src/Storage.ts @@ -12,6 +12,7 @@ import { ProgramTerminatedError, } from './errors'; import { GearApi } from './GearApi'; +import { SPEC_VERSION } from './consts'; export class GearProgramStorage { constructor(protected _api: GearApi) {} @@ -48,11 +49,11 @@ export class GearProgramStorage { async getProgramPages(programId: HexString, program: GearCommonActiveProgram, at?: HexString): Promise { const pages = {}; const query = - this._api.specVersion >= 1020 + this._api.specVersion >= SPEC_VERSION.V1030 ? this._api.query.gearProgram.memoryPages : this._api.query.gearProgram.memoryPageStorage; - const args = this._api.specVersion >= 1020 ? [programId, program.memoryInfix] : [programId]; + const args = this._api.specVersion >= SPEC_VERSION.V1030 ? [programId, program.memoryInfix] : [programId]; for (const page of program.pagesWithData) { pages[page.toNumber()] = u8aToU8a( diff --git a/api/src/apis/index.ts b/api/src/apis/index.ts index a73102d218..eeef18c08b 100644 --- a/api/src/apis/index.ts +++ b/api/src/apis/index.ts @@ -1,2 +1,2 @@ -export { VaraApi } from './vara/api'; -export { VaraTestnetApi } from './vara-testnet/api'; +export { VaraApiV1000 } from './v1000/api'; +export { VaraApiV1010 } from './v1010/api'; diff --git a/api/src/apis/v1000/api.ts b/api/src/apis/v1000/api.ts new file mode 100644 index 0000000000..726d7aa601 --- /dev/null +++ b/api/src/apis/v1000/api.ts @@ -0,0 +1,8 @@ +import { GearApi } from '../../GearApi'; +import { V1000Message } from './message'; +import { V1000Program } from './program'; + +export class VaraApiV1000 extends GearApi { + public declare program: V1000Program; + public declare message: V1000Message; +} diff --git a/api/src/apis/vara/message.ts b/api/src/apis/v1000/message.ts similarity index 73% rename from api/src/apis/vara/message.ts rename to api/src/apis/v1000/message.ts index 8cc3ec83b1..77d22d08d0 100644 --- a/api/src/apis/vara/message.ts +++ b/api/src/apis/v1000/message.ts @@ -1,39 +1,39 @@ import { ISubmittableResult } from '@polkadot/types/types'; import { SubmittableExtrinsic } from '@polkadot/api/types'; -import { VaraMessageSendOptions, VaraMessageSendReplyOptions } from '../../types'; +import { V1000MessageSendOptions, V1000MessageSendReplyOptions } from '../../types'; import { GearMessage } from '../../Message'; import { ProgramMetadata } from '../../metadata'; -export declare class VaraMessage extends GearMessage { +export declare class V1000Message extends GearMessage { send( - args: VaraMessageSendOptions, + args: V1000MessageSendOptions, meta: ProgramMetadata, typeIndex?: number, ): SubmittableExtrinsic<'promise', ISubmittableResult>; send( - args: VaraMessageSendOptions, + args: V1000MessageSendOptions, hexRegistry: `0x${string}`, typeIndex: number, ): SubmittableExtrinsic<'promise', ISubmittableResult>; send( - args: VaraMessageSendOptions, + args: V1000MessageSendOptions, metaOrHexRegistry?: ProgramMetadata | `0x${string}`, typeName?: string, ): SubmittableExtrinsic<'promise', ISubmittableResult>; sendReply( - args: VaraMessageSendReplyOptions, + args: V1000MessageSendReplyOptions, meta?: ProgramMetadata, typeIndex?: number, ): Promise>; sendReply( - args: VaraMessageSendReplyOptions, + args: V1000MessageSendReplyOptions, hexRegistry: `0x${string}`, typeIndex: number, ): Promise>; sendReply( - args: VaraMessageSendReplyOptions, + args: V1000MessageSendReplyOptions, metaOrHexRegistry?: ProgramMetadata | `0x${string}`, typeName?: string, ): Promise>; diff --git a/api/src/apis/v1000/program.ts b/api/src/apis/v1000/program.ts new file mode 100644 index 0000000000..9d385e2c04 --- /dev/null +++ b/api/src/apis/v1000/program.ts @@ -0,0 +1,29 @@ +import { + HexString, + IProgramCreateResult, + IProgramUploadResult, + V1000ProgramCreateOptions, + V1000ProgramUploadOptions, +} from '../../types'; +import { GearProgram } from '../../Program'; +import { ProgramMetadata } from '../../metadata'; + +export declare class V1000Program extends GearProgram { + upload(args: V1000ProgramUploadOptions, meta?: ProgramMetadata, typeIndex?: number): IProgramUploadResult; + + upload(args: V1000ProgramUploadOptions, hexRegistry: HexString, typeIndex: number): IProgramUploadResult; + + upload( + args: V1000ProgramUploadOptions, + metaOrHexRegistry?: ProgramMetadata | HexString, + typeName?: string, + ): IProgramUploadResult; + + create(args: V1000ProgramCreateOptions, meta?: ProgramMetadata, typeIndex?: number): IProgramCreateResult; + create(args: V1000ProgramCreateOptions, hexRegistry: `0x${string}`, typeIndex: number): IProgramCreateResult; + create( + args: V1000ProgramCreateOptions, + metaOrHexRegistry?: ProgramMetadata | `0x${string}`, + typeName?: string | number, + ): IProgramCreateResult; +} diff --git a/api/src/apis/v1010/api.ts b/api/src/apis/v1010/api.ts new file mode 100644 index 0000000000..d142add2f3 --- /dev/null +++ b/api/src/apis/v1010/api.ts @@ -0,0 +1,3 @@ +import { GearApi } from '../../GearApi'; + +export class VaraApiV1010 extends GearApi {} diff --git a/api/src/apis/vara-testnet/api.ts b/api/src/apis/vara-testnet/api.ts deleted file mode 100644 index d4dd2ff9a3..0000000000 --- a/api/src/apis/vara-testnet/api.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { GearApi } from '../../GearApi'; - -export class VaraTestnetApi extends GearApi {} diff --git a/api/src/apis/vara/api.ts b/api/src/apis/vara/api.ts deleted file mode 100644 index f92807cea4..0000000000 --- a/api/src/apis/vara/api.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { GearApi } from '../../GearApi'; -import { VaraMessage } from './message'; -import { VaraProgram } from './program'; - -export class VaraApi extends GearApi { - public declare program: VaraProgram; - public declare message: VaraMessage; -} diff --git a/api/src/apis/vara/program.ts b/api/src/apis/vara/program.ts deleted file mode 100644 index 1602e98089..0000000000 --- a/api/src/apis/vara/program.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { - HexString, - IProgramCreateResult, - IProgramUploadResult, - VaraProgramCreateOptions, - VaraProgramUploadOptions, -} from '../../types'; -import { GearProgram } from '../../Program'; -import { ProgramMetadata } from '../../metadata'; - -export declare class VaraProgram extends GearProgram { - upload(args: VaraProgramUploadOptions, meta?: ProgramMetadata, typeIndex?: number): IProgramUploadResult; - - upload(args: VaraProgramUploadOptions, hexRegistry: HexString, typeIndex: number): IProgramUploadResult; - - upload( - args: VaraProgramUploadOptions, - metaOrHexRegistry?: ProgramMetadata | HexString, - typeName?: string, - ): IProgramUploadResult; - - create(args: VaraProgramCreateOptions, meta?: ProgramMetadata, typeIndex?: number): IProgramCreateResult; - create(args: VaraProgramCreateOptions, hexRegistry: `0x${string}`, typeIndex: number): IProgramCreateResult; - create( - args: VaraProgramCreateOptions, - metaOrHexRegistry?: ProgramMetadata | `0x${string}`, - typeName?: string | number, - ): IProgramCreateResult; -} diff --git a/api/src/consts.ts b/api/src/consts.ts new file mode 100644 index 0000000000..0dc84e0b63 --- /dev/null +++ b/api/src/consts.ts @@ -0,0 +1,6 @@ +export enum SPEC_VERSION { + V1000 = 1000, + V1010 = 1010, + V1020 = 1020, + V1030 = 1030, +} diff --git a/api/src/index.ts b/api/src/index.ts index d6d67bbb7a..156834a5e0 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -11,6 +11,7 @@ export { GearGas } from './Gas'; export { GearProgramStorage } from './Storage'; export { GearClaimValue } from './Claim'; export { GearWaitlist } from './Waitlist'; +export { SPEC_VERSION } from './consts'; export * from './Transaction'; export * from './wasm'; export * from './types/interfaces'; @@ -20,4 +21,3 @@ export * from './events'; export * from './types'; export * from './metadata'; export * from './apis'; -export * from './specs'; diff --git a/api/src/specs/index.ts b/api/src/specs/index.ts deleted file mode 100644 index 69669cf800..0000000000 --- a/api/src/specs/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './vara'; -export * from './vara-testnet'; diff --git a/api/src/specs/vara-testnet.ts b/api/src/specs/vara-testnet.ts deleted file mode 100644 index fe3ab9fc92..0000000000 --- a/api/src/specs/vara-testnet.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const VARA_TESTNET_GENESIS = '0x525639f713f397dcf839bd022cd821f367ebcf179de7b9253531f8adbe5436d6'; -export const VARA_TESTNET_RUNTIME_VERSION = 1010; diff --git a/api/src/specs/vara.ts b/api/src/specs/vara.ts deleted file mode 100644 index 1f41d6e597..0000000000 --- a/api/src/specs/vara.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const VARA_GENESIS = '0xfe1b4c55fd4d668101126434206571a7838a8b6b93a6d1b95d607e78e6c53763'; -export const VARA_RUNTIME_VERSION = 1000; diff --git a/api/src/types/interfaces/message/extrinsic.ts b/api/src/types/interfaces/message/extrinsic.ts index 6ec58a83cf..8da8ca1b36 100644 --- a/api/src/types/interfaces/message/extrinsic.ts +++ b/api/src/types/interfaces/message/extrinsic.ts @@ -3,7 +3,7 @@ import { HexString } from '@polkadot/util/types'; import { GasLimit, Value } from '../../common'; import { PayloadType } from '../../payload'; -export interface IMessageSendOptions { +export interface V1010MessageSendOptions { /** * The message destination */ @@ -30,23 +30,27 @@ export interface IMessageSendOptions { account?: HexString; } -export interface IMessageSendReplyOptions extends Omit { +export interface V1000MessageSendOptions extends Omit { /** - * Message ID to which the reply is sending + * A flag that indicates whether a voucher should be used */ - replyToId: HexString; + prepaid?: boolean; } -export interface VaraMessageSendOptions extends Omit { +export type MessageSendOptions = V1010MessageSendOptions | V1000MessageSendOptions; + +export interface V1010MessageSendReplyOptions extends Omit { /** - * A flag that indicates whether a voucher should be used + * Message ID to which the reply is sending */ - prepaid?: boolean; + replyToId: HexString; } -export interface VaraMessageSendReplyOptions extends Omit { +export interface V1000MessageSendReplyOptions extends Omit { /** * Message ID to which the reply is sending */ replyToId: HexString; } + +export type MessageSendReplyOptions = V1010MessageSendReplyOptions | V1000MessageSendReplyOptions; diff --git a/api/src/types/interfaces/program/extrinsic.ts b/api/src/types/interfaces/program/extrinsic.ts index 129faf19d8..6fb0fa38d3 100644 --- a/api/src/types/interfaces/program/extrinsic.ts +++ b/api/src/types/interfaces/program/extrinsic.ts @@ -6,7 +6,7 @@ import { SubmittableExtrinsic } from '@polkadot/api/types'; import { GasLimit, Value } from '../../common'; -export interface IProgramUploadOptions { +export interface V1010ProgramUploadOptions { code: Buffer | Uint8Array; salt?: `0x${string}`; initPayload?: AnyJson; @@ -15,16 +15,20 @@ export interface IProgramUploadOptions { keepAlive?: boolean; } -export interface IProgramCreateOptions extends Omit { +export type V1000ProgramUploadOptions = Omit; + +export type ProgramUploadOptions = V1010ProgramUploadOptions | V1000ProgramUploadOptions; + +export interface V1010ProgramCreateOptions extends Omit { codeId: HexString | Uint8Array; } -export type VaraProgramUploadOptions = Omit; - -export interface VaraProgramCreateOptions extends Omit { +export interface V1000ProgramCreateOptions extends Omit { codeId: HexString | Uint8Array; } +export type ProgramCreateOptions = V1010ProgramCreateOptions | V1000ProgramCreateOptions; + export interface IProgramUploadResult { programId: HexString; codeId: HexString; diff --git a/api/src/utils/generate.ts b/api/src/utils/generate.ts index 580cf66f8a..90012cd487 100644 --- a/api/src/utils/generate.ts +++ b/api/src/utils/generate.ts @@ -4,6 +4,7 @@ import { HexString } from '@polkadot/util/types'; import { CreateType } from '../metadata'; import { GearApi } from 'GearApi'; +import { SPEC_VERSION } from '../consts'; const VOUCHER_PREFIX = stringToU8a('modlpy/voucher__'); @@ -31,7 +32,7 @@ export function generateProgramId( const [code, codeHash] = typeof codeOrHash === 'string' ? [undefined, codeOrHash] : [codeOrHash, undefined]; const codeHashU8a = codeHash ? u8aToU8a(codeHash) : blake2AsU8a(code, 256); const saltU8a = CreateType.create('Vec', salt).toU8a().slice(1); - const prefix = api.specVersion >= 1010 ? 'program_from_user' : 'program'; + const prefix = api.specVersion >= SPEC_VERSION.V1010 ? 'program_from_user' : 'program'; const programStrU8a = new TextEncoder().encode(prefix); const id = Uint8Array.from([...programStrU8a, ...codeHashU8a, ...saltU8a]); return blake2AsHex(id, 256);