From f9383b3931e6e18614a8f7d7a67f3acbf5835bc2 Mon Sep 17 00:00:00 2001 From: Mahmoud Emad Date: Wed, 7 Aug 2024 11:35:24 +0300 Subject: [PATCH] chore: Apply comments: - Update the type of the 'extrinsics' in the 'saveIfKVStoreBackend' method to 'ExtrinsicResult' instead of 'any' type. - Update the description of the 'BaseModule._add' method. - Update the return type of the 'KVStore.set' method to be 'string' instead of 'KVStoreSetOptions' type. - Update the return type of any function in the grid client that return the tf-chain changed methods - Update the return type of the 'addStellarAddress' method to 'number' as the farm ID insteaf of 'Farm' --- .../grid_client/src/clients/tf-grid/kvstore.ts | 8 ++++---- packages/grid_client/src/modules/base.ts | 2 +- packages/grid_client/src/modules/farms.ts | 4 ++-- packages/grid_client/src/modules/kvstore.ts | 6 ++---- packages/grid_client/src/modules/stellar.ts | 4 ++-- .../src/storage/BackendStorageInterface.ts | 2 +- packages/grid_client/src/storage/tfkvstore.ts | 4 ++-- packages/tfchain_client/src/contracts.ts | 14 +++++++------- packages/tfchain_client/src/farms.ts | 7 ++++--- packages/tfchain_client/src/kvstore.ts | 16 ++++++++-------- 10 files changed, 33 insertions(+), 34 deletions(-) diff --git a/packages/grid_client/src/clients/tf-grid/kvstore.ts b/packages/grid_client/src/clients/tf-grid/kvstore.ts index cddfb1b225..6110534f71 100644 --- a/packages/grid_client/src/clients/tf-grid/kvstore.ts +++ b/packages/grid_client/src/clients/tf-grid/kvstore.ts @@ -26,9 +26,9 @@ class TFKVStore extends KVStore { * If encryption is enabled, the value will be encrypted before storing. * * @param {KVStoreSetOptions & { encrypt?: boolean }} options - The options for setting the `key-value` pair. - * @returns {Promise>} - A promise that resolves once the `key-value` set extrinsic is created. + * @returns {Promise>} - A promise that resolves to the address of the connected account. */ - async set(options: KVStoreSetOptions & { encrypt?: boolean }): Promise> { + async set(options: KVStoreSetOptions & { encrypt?: boolean }): Promise> { if (options.encrypt === false) { return super.set({ key: options.key, value: options.value }); } @@ -69,11 +69,11 @@ class TFKVStore extends KVStore { * @returns {Promise} - A promise that resolves with an array of keys that were removed. */ async batchRemove(options: KVStoreBatchRemoveOptions): Promise { - const extrinsics: ExtrinsicResult[] = []; + const extrinsics: ExtrinsicResult[] = []; for (const key of options.keys) { extrinsics.push(await this.delete({ key })); } - await this.client.applyAllExtrinsics(extrinsics); + await this.client.applyAllExtrinsics(extrinsics); return options.keys; } diff --git a/packages/grid_client/src/modules/base.ts b/packages/grid_client/src/modules/base.ts index d5fd52eb03..97115d1291 100644 --- a/packages/grid_client/src/modules/base.ts +++ b/packages/grid_client/src/modules/base.ts @@ -919,7 +919,7 @@ class BaseModule { } /** - * Add a new [ZDB or K8S worker] to the deployment. + * Add a new [machine, ZDB, or K8S worker] to the deployment. * * @param deployment_name The name of the deployment. * @param node_id The ID of the node where the machine will be added. diff --git a/packages/grid_client/src/modules/farms.ts b/packages/grid_client/src/modules/farms.ts index 94a0be6a7a..e569404168 100644 --- a/packages/grid_client/src/modules/farms.ts +++ b/packages/grid_client/src/modules/farms.ts @@ -110,7 +110,7 @@ class Farms { * It then adds the `Stellar` address to the specified farm. * * @param {AddStellarAddressToFarmModel} options - The options for adding the `Stellar` address to the farm, including the `farm ID` and `Stellar address`. - * @returns {Promise} A promise that resolves when the `Stellar` address is successfully added to the farm. + * @returns {Promise} A promise that resolves number as the `Farm ID` after the `Stellar` address is successfully added to the farm. * @decorators * - `@expose`: Exposes the method for external use. * - `@validateInput`: Validates the input options. @@ -119,7 +119,7 @@ class Farms { @expose @validateInput @checkBalance - async addStellarAddress(options: AddStellarAddressToFarmModel): Promise { + async addStellarAddress(options: AddStellarAddressToFarmModel): Promise { return (await this.client.farms.addStellarAddress(options)).apply(); } diff --git a/packages/grid_client/src/modules/kvstore.ts b/packages/grid_client/src/modules/kvstore.ts index 2c97c84ba0..4dfed8dc7b 100644 --- a/packages/grid_client/src/modules/kvstore.ts +++ b/packages/grid_client/src/modules/kvstore.ts @@ -1,5 +1,3 @@ -import { KVStoreSetOptions } from "@threefold/tfchain_client"; - import { TFClient } from "../clients/tf-grid/client"; import { GridClientConfig } from "../config"; import { expose } from "../helpers/expose"; @@ -39,7 +37,7 @@ class KVStore { @expose @validateInput @checkBalance - async set(options: KVStoreSetModel): Promise { + async set(options: KVStoreSetModel): Promise { return (await this.client.kvStore.set(options)).apply(); } @@ -92,7 +90,7 @@ class KVStore { @expose @validateInput @checkBalance - async remove(options: KVStoreRemoveModel): Promise { + async remove(options: KVStoreRemoveModel): Promise { return (await this.client.kvStore.delete(options)).apply(); } diff --git a/packages/grid_client/src/modules/stellar.ts b/packages/grid_client/src/modules/stellar.ts index d204942cee..33145586cb 100644 --- a/packages/grid_client/src/modules/stellar.ts +++ b/packages/grid_client/src/modules/stellar.ts @@ -61,10 +61,10 @@ class Stellar implements blockchainInterface { /** * Saves the extrinsics to the `key-value` store backend if the backend storage type is `tfkvstore` and extrinsics are provided. * - * @param {any[]} extrinsics - The extrinsics to be saved to the `key-value` store backend. + * @param {ExtrinsicResult[]} extrinsics - The extrinsics to be saved to the `key-value` store backend. * @returns {Promise} - A promise that resolves once the extrinsics are saved to the backend. */ - private async saveIfKVStoreBackend(extrinsics: any[]) { + private async saveIfKVStoreBackend(extrinsics: ExtrinsicResult[]) { if (this.config.backendStorageType === BackendStorageType.tfkvstore && extrinsics && extrinsics.length > 0) { extrinsics = extrinsics.filter(e => e !== undefined); if (extrinsics.length > 0) { diff --git a/packages/grid_client/src/storage/BackendStorageInterface.ts b/packages/grid_client/src/storage/BackendStorageInterface.ts index 3fe9385e46..ca20f6ae46 100644 --- a/packages/grid_client/src/storage/BackendStorageInterface.ts +++ b/packages/grid_client/src/storage/BackendStorageInterface.ts @@ -14,7 +14,7 @@ interface BackendStorageInterface { list(key: string); // This method currently only implemented in tfkvstore - moveValue?(fromKey: string, toKey: string): Promise[]>; + moveValue?(fromKey: string, toKey: string): Promise[]>; } export default BackendStorageInterface; diff --git a/packages/grid_client/src/storage/tfkvstore.ts b/packages/grid_client/src/storage/tfkvstore.ts index 84dfa50eca..592031c70d 100644 --- a/packages/grid_client/src/storage/tfkvstore.ts +++ b/packages/grid_client/src/storage/tfkvstore.ts @@ -106,11 +106,11 @@ class TFKVStoreBackend implements BackendStorageInterface { return splits; } - public async moveValue(fromKey: string, toKey: string): Promise[]> { + public async moveValue(fromKey: string, toKey: string): Promise[]> { fromKey = cropKey(fromKey); toKey = cropKey(toKey); - const exts: ExtrinsicResult[] = []; + const exts: ExtrinsicResult[] = []; for (let i = 0; ; i++) { const key = i === 0 ? fromKey : fromKey + "." + i; diff --git a/packages/tfchain_client/src/contracts.ts b/packages/tfchain_client/src/contracts.ts index 061803e3aa..049489bdca 100644 --- a/packages/tfchain_client/src/contracts.ts +++ b/packages/tfchain_client/src/contracts.ts @@ -459,10 +459,10 @@ class Contracts extends QueryContracts { * This method cancels a service contract identified by the provided `serviceId`. * * @param {CancelServiceOptions} options - The options object containing the `serviceId` of the service contract to be canceled. - * @returns {Promise>} A promise that resolves to the extrinsic for canceling the service contract. + * @returns {Promise>} A promise that resolves to the extrinsic of the `service ID` for canceling the service contract. */ @checkConnection - async cancelService(options: CancelServiceOptions): Promise> { + async cancelService(options: CancelServiceOptions): Promise> { const extrinsic = await this.client.api.tx.smartContractModule.serviceContractCancel(options.serviceId); return this.client.patchExtrinsic(extrinsic, { map: () => options.serviceId }); } @@ -491,12 +491,12 @@ class Contracts extends QueryContracts { * This method sets the extra fee for a dedicated node identified by the provided nodeId. * * @param {SetDedicatedNodeExtraFeesOptions} options - The options object containing the nodeId and extraFee to be set. - * @returns {Promise} A promise that resolves to the extrinsic for setting the extra fee for the dedicated node. + * @returns {Promise} A promise that resolves to the extrinsic `node ID` for setting the extra fee for the dedicated node. */ @checkConnection - async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise { + async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise> { const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee); - return this.client.patchExtrinsic(extrinsic); + return this.client.patchExtrinsic(extrinsic); } /** @@ -520,8 +520,8 @@ class Contracts extends QueryContracts { * unlocks a smart contract by triggering the billing of a contract on this block. * * - * @param {number} contractId - Contract id to be unlocked. - * @returns {Promise>} A promise that resolves to a `ExtrinsicResult` + * @param {number} contractId - Contract ID to be unlocked. + * @returns {Promise>} A promise that resolves to a `ExtrinsicResult` as the `contract ID`. * @note This call doesn't guarantee that the contract will be resumed, it just triggers the billing of it, * if the accounts has enough funds the contract will be resumed * diff --git a/packages/tfchain_client/src/farms.ts b/packages/tfchain_client/src/farms.ts index b8fb77dd8d..ea4887dc8f 100644 --- a/packages/tfchain_client/src/farms.ts +++ b/packages/tfchain_client/src/farms.ts @@ -1,4 +1,5 @@ import { Client, QueryClient } from "./client"; +import { ExtrinsicResult } from "./types"; import { checkConnection } from "./utils"; enum Certification { @@ -134,12 +135,12 @@ class Farms extends QueryFarms { * @param options - The options for adding a Stellar address. * @param options.farmId - The ID of the farm to add the Stellar address to. * @param options.stellarAddress - The Stellar address to add for payout. - * @returns A promise that resolves to the updated farm extrinsic after adding the Stellar address. + * @returns A promise that resolves to the farm ID extrinsic after adding the Stellar address. */ @checkConnection - async addStellarAddress(options: AddStellarOptions) { + async addStellarAddress(options: AddStellarOptions): Promise> { const extrinsic = this.client.api.tx.tfgridModule.addStellarPayoutV2address(options.farmId, options.stellarAddress); - return this.client.patchExtrinsic(extrinsic); + return this.client.patchExtrinsic(extrinsic); } } diff --git a/packages/tfchain_client/src/kvstore.ts b/packages/tfchain_client/src/kvstore.ts index a50037221f..f0c5b61254 100644 --- a/packages/tfchain_client/src/kvstore.ts +++ b/packages/tfchain_client/src/kvstore.ts @@ -23,12 +23,12 @@ class KVStore { * It then patches the extrinsic and returns the options that were set. * * @param options - An object containing the key and value to be set in the `key-value` store. - * @returns {Promise>} A promise that resolves to the options that were set in the store. + * @returns {Promise>} A promise that resolves to the address of the connected account. */ @checkConnection - async set(options: KVStoreSetOptions): Promise> { + async set(options: KVStoreSetOptions): Promise> { const extrinsic = await this.client.api.tx.tfkvStore.set(options.key, options.value); - return this.client.patchExtrinsic(extrinsic); + return this.client.patchExtrinsic(extrinsic); } /** @@ -38,12 +38,12 @@ class KVStore { * It then patches the extrinsic and returns the result of the deletion operation. * * @param options - An object containing the key to be deleted from the `key-value` store. - * @returns {Promise>} A promise that resolves once the delete extrinsic is successfully created. + * @returns {Promise>} A promise that resolves to the address of the connected account. */ @checkConnection - async delete(options: KVStoreGetOptions): Promise> { + async delete(options: KVStoreGetOptions): Promise> { const extrinsic = await this.client.api.tx.tfkvStore.delete(options.key); - return this.client.patchExtrinsic(extrinsic); + return this.client.patchExtrinsic(extrinsic); } /** @@ -91,11 +91,11 @@ class KVStore { */ async deleteAll(): Promise { const keys: string[] = await this.list(); - const extrinsics: ExtrinsicResult[] = []; + const extrinsics: ExtrinsicResult[] = []; for (const key of keys) { extrinsics.push(await this.delete({ key })); } - await this.client.applyAllExtrinsics(extrinsics); + await this.client.applyAllExtrinsics(extrinsics); return keys; } }