Skip to content

Commit

Permalink
chore: Apply comments:
Browse files Browse the repository at this point in the history
- 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'
  • Loading branch information
Mahmoud-Emad committed Aug 7, 2024
1 parent 40196ea commit f9383b3
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 34 deletions.
8 changes: 4 additions & 4 deletions packages/grid_client/src/clients/tf-grid/kvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtrinsicResult<KVStoreSetOptions>>} - A promise that resolves once the `key-value` set extrinsic is created.
* @returns {Promise<ExtrinsicResult<string>>} - A promise that resolves to the address of the connected account.
*/
async set(options: KVStoreSetOptions & { encrypt?: boolean }): Promise<ExtrinsicResult<KVStoreSetOptions>> {
async set(options: KVStoreSetOptions & { encrypt?: boolean }): Promise<ExtrinsicResult<string>> {
if (options.encrypt === false) {
return super.set({ key: options.key, value: options.value });
}
Expand Down Expand Up @@ -69,11 +69,11 @@ class TFKVStore extends KVStore {
* @returns {Promise<string[]>} - A promise that resolves with an array of keys that were removed.
*/
async batchRemove(options: KVStoreBatchRemoveOptions): Promise<string[]> {
const extrinsics: ExtrinsicResult<KVStoreSetOptions>[] = [];
const extrinsics: ExtrinsicResult<string>[] = [];
for (const key of options.keys) {
extrinsics.push(await this.delete({ key }));
}
await this.client.applyAllExtrinsics<KVStoreSetOptions>(extrinsics);
await this.client.applyAllExtrinsics<string>(extrinsics);
return options.keys;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/grid_client/src/modules/farms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Farm>} A promise that resolves when the `Stellar` address is successfully added to the farm.
* @returns {Promise<number>} 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.
Expand All @@ -119,7 +119,7 @@ class Farms {
@expose
@validateInput
@checkBalance
async addStellarAddress(options: AddStellarAddressToFarmModel): Promise<Farm> {
async addStellarAddress(options: AddStellarAddressToFarmModel): Promise<number> {
return (await this.client.farms.addStellarAddress(options)).apply();
}

Expand Down
6 changes: 2 additions & 4 deletions packages/grid_client/src/modules/kvstore.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -39,7 +37,7 @@ class KVStore {
@expose
@validateInput
@checkBalance
async set(options: KVStoreSetModel): Promise<KVStoreSetOptions> {
async set(options: KVStoreSetModel): Promise<string> {
return (await this.client.kvStore.set(options)).apply();
}

Expand Down Expand Up @@ -92,7 +90,7 @@ class KVStore {
@expose
@validateInput
@checkBalance
async remove(options: KVStoreRemoveModel): Promise<KVStoreSetOptions> {
async remove(options: KVStoreRemoveModel): Promise<string> {
return (await this.client.kvStore.delete(options)).apply();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/grid_client/src/modules/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>} - A promise that resolves once the extrinsics are saved to the backend.
*/
private async saveIfKVStoreBackend(extrinsics: any[]) {
private async saveIfKVStoreBackend(extrinsics: ExtrinsicResult<string>[]) {
if (this.config.backendStorageType === BackendStorageType.tfkvstore && extrinsics && extrinsics.length > 0) {
extrinsics = extrinsics.filter(e => e !== undefined);
if (extrinsics.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface BackendStorageInterface {
list(key: string);

// This method currently only implemented in tfkvstore
moveValue?(fromKey: string, toKey: string): Promise<ExtrinsicResult<KVStoreSetOptions>[]>;
moveValue?(fromKey: string, toKey: string): Promise<ExtrinsicResult<string>[]>;
}

export default BackendStorageInterface;
4 changes: 2 additions & 2 deletions packages/grid_client/src/storage/tfkvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ class TFKVStoreBackend implements BackendStorageInterface {
return splits;
}

public async moveValue(fromKey: string, toKey: string): Promise<ExtrinsicResult<KVStoreSetOptions>[]> {
public async moveValue(fromKey: string, toKey: string): Promise<ExtrinsicResult<string>[]> {
fromKey = cropKey(fromKey);
toKey = cropKey(toKey);

const exts: ExtrinsicResult<KVStoreSetOptions>[] = [];
const exts: ExtrinsicResult<string>[] = [];

for (let i = 0; ; i++) {
const key = i === 0 ? fromKey : fromKey + "." + i;
Expand Down
14 changes: 7 additions & 7 deletions packages/tfchain_client/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtrinsicResult<any>>} A promise that resolves to the extrinsic for canceling the service contract.
* @returns {Promise<ExtrinsicResult<any>>} A promise that resolves to the extrinsic of the `service ID` for canceling the service contract.
*/
@checkConnection
async cancelService(options: CancelServiceOptions): Promise<ExtrinsicResult<any>> {
async cancelService(options: CancelServiceOptions): Promise<ExtrinsicResult<number>> {
const extrinsic = await this.client.api.tx.smartContractModule.serviceContractCancel(options.serviceId);
return this.client.patchExtrinsic(extrinsic, { map: () => options.serviceId });
}
Expand Down Expand Up @@ -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<any>} A promise that resolves to the extrinsic for setting the extra fee for the dedicated node.
* @returns {Promise<number>} A promise that resolves to the extrinsic `node ID` for setting the extra fee for the dedicated node.
*/
@checkConnection
async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise<any> {
async setDedicatedNodeExtraFee(options: SetDedicatedNodeExtraFeesOptions): Promise<ExtrinsicResult<number>> {
const extrinsic = this.client.api.tx.smartContractModule.setDedicatedNodeExtraFee(options.nodeId, options.extraFee);
return this.client.patchExtrinsic(extrinsic);
return this.client.patchExtrinsic<number>(extrinsic);
}

/**
Expand All @@ -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<ExtrinsicResult<number>>} A promise that resolves to a `ExtrinsicResult<number>`
* @param {number} contractId - Contract ID to be unlocked.
* @returns {Promise<ExtrinsicResult<number>>} A promise that resolves to a `ExtrinsicResult<number>` 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
*
Expand Down
7 changes: 4 additions & 3 deletions packages/tfchain_client/src/farms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Client, QueryClient } from "./client";
import { ExtrinsicResult } from "./types";
import { checkConnection } from "./utils";

enum Certification {
Expand Down Expand Up @@ -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<ExtrinsicResult<number>> {
const extrinsic = this.client.api.tx.tfgridModule.addStellarPayoutV2address(options.farmId, options.stellarAddress);
return this.client.patchExtrinsic<Farm>(extrinsic);
return this.client.patchExtrinsic<number>(extrinsic);
}
}

Expand Down
16 changes: 8 additions & 8 deletions packages/tfchain_client/src/kvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtrinsicResult<KVStoreSetOptions>>} A promise that resolves to the options that were set in the store.
* @returns {Promise<ExtrinsicResult<string>>} A promise that resolves to the address of the connected account.
*/
@checkConnection
async set(options: KVStoreSetOptions): Promise<ExtrinsicResult<KVStoreSetOptions>> {
async set(options: KVStoreSetOptions): Promise<ExtrinsicResult<string>> {
const extrinsic = await this.client.api.tx.tfkvStore.set(options.key, options.value);
return this.client.patchExtrinsic<KVStoreSetOptions>(extrinsic);
return this.client.patchExtrinsic<string>(extrinsic);
}

/**
Expand All @@ -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<ExtrinsicResult<KVStoreSetOptions>>} A promise that resolves once the delete extrinsic is successfully created.
* @returns {Promise<ExtrinsicResult<string>>} A promise that resolves to the address of the connected account.
*/
@checkConnection
async delete(options: KVStoreGetOptions): Promise<ExtrinsicResult<KVStoreSetOptions>> {
async delete(options: KVStoreGetOptions): Promise<ExtrinsicResult<string>> {
const extrinsic = await this.client.api.tx.tfkvStore.delete(options.key);
return this.client.patchExtrinsic<KVStoreSetOptions>(extrinsic);
return this.client.patchExtrinsic<string>(extrinsic);
}

/**
Expand Down Expand Up @@ -91,11 +91,11 @@ class KVStore {
*/
async deleteAll(): Promise<string[]> {
const keys: string[] = await this.list();
const extrinsics: ExtrinsicResult<KVStoreGetOptions>[] = [];
const extrinsics: ExtrinsicResult<string>[] = [];
for (const key of keys) {
extrinsics.push(await this.delete({ key }));
}
await this.client.applyAllExtrinsics<KVStoreGetOptions>(extrinsics);
await this.client.applyAllExtrinsics<string>(extrinsics);
return keys;
}
}
Expand Down

0 comments on commit f9383b3

Please sign in to comment.