Skip to content

Commit

Permalink
style: Apply the comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud-Emad committed Aug 4, 2024
1 parent 9e462ba commit 841a243
Show file tree
Hide file tree
Showing 30 changed files with 378 additions and 224 deletions.
2 changes: 1 addition & 1 deletion packages/grid_client/scripts/client_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function setConfig() {
* @example
*
* const deploymentName = 'testVM'
* const projectName = 'vm' + deploymentName
* const projectName = 'vm/' + deploymentName
* const gc = await getClient(projectName)
* await gc.machines.deploy({...});
* // When you deploy using this project name, you'll only be able to list your deployments using this same project name.
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/scripts/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"network": "dev",
"mnemonic": "",
"mnemonic": "actual reveal dish guilt inner film scheme between lonely myself material replace",
"storeSecret": "",
"ssh_key": ""
}
29 changes: 29 additions & 0 deletions packages/grid_client/scripts/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { FilterOptions, GridClient, log, NodeInfo } from "../src";
import { getClient } from "./client_loader";

async function pingNodes(client: GridClient, nodes: NodeInfo[]) {
for (const node of nodes) {
try {
const x = await client.zos.getNodePerfTests({ nodeId: node.nodeId });
console.log({ x });
} catch (error) {
log("node " + node.nodeId + " is not responding, trying different node.");
}
}
}

async function main() {
const name = "newVMS";
const grid3 = await getClient(`vm/${name}`);
const nodes = await grid3.capacity.filterNodes({
gateway: true,
farmId: 1,
availableFor: await grid3.twins.get_my_twin_id(),
} as FilterOptions);

await pingNodes(grid3, nodes);

await grid3.disconnect();
}

main();
3 changes: 2 additions & 1 deletion packages/grid_client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class GridClient {
}

/**
* Gets the default URLs for the specified network environment.
* Gets the configured URLs (or the default URLs if not provided) for the specified network environment.
*
* @param {NetworkEnv} network - The network environment.
*
Expand Down
6 changes: 3 additions & 3 deletions packages/grid_client/src/clients/tf-grid/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TFBalances extends Balances {
/**
* Get the balance for a specific address.
*
* This method retrieves the balance for a specific address by dividing the retrieved balances by 10^7.
* This method retrieves the balance for a specific address in TFT.
*
* @param {QueryBalancesGetOptions} options - The options for getting the balance, including the address.
* @returns {Promise<Balance>} A promise that resolves with the balance object containing free, reserved, and frozen amounts.
Expand All @@ -28,10 +28,10 @@ class TFBalances extends Balances {
}

/**
* Transfer a specified amount of TFT (`ThreeFold Tokens`) to a given address.
* Prepare a Transfer extrinsic for a specified amount of TFT (`ThreeFold Tokens`) to a given address.
*
* @param {BalanceTransferOptions} options - The transfer options, including the destination address and the amount to transfer.
* @returns {Promise<ExtrinsicResult<number>>} A promise that resolves once the transfer is successfully completed.
* @returns {Promise<ExtrinsicResult<number>>} A promise that resolves once the transfer extrinsic is created.
*/
async transfer(options: BalanceTransferOptions): Promise<ExtrinsicResult<number>> {
const decimalAmount = new Decimal(options.amount);
Expand Down
4 changes: 2 additions & 2 deletions packages/grid_client/src/clients/tf-grid/kvstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class TFKVStore extends KVStore {
}

/**
* Sets a `key-value` pair in the `key-value` store.
* Prepares a set extrinsic for a `key-value` pair in the `key-value` store.
* 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` pair is set.
* @returns {Promise<ExtrinsicResult<KVStoreSetOptions>>} - A promise that resolves once the `key-value` set extrinsic is created.
*/
async set(options: KVStoreSetOptions & { encrypt?: boolean }): Promise<ExtrinsicResult<KVStoreSetOptions>> {
if (options.encrypt === false) {
Expand Down
8 changes: 4 additions & 4 deletions packages/grid_client/src/clients/tf-grid/twins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ interface TwinOptions {
*/
class TFTwins extends Twins {
/**
* Creates a new `twin` with the specified options.
* Prepare an extrinsic for creating a new `twin` with the specified options.
*
* @param options - The options for creating the `twin`, including the `relay` to connect to.
* @returns {Promise<ExtrinsicResult<Twin>>} A promise that resolves with the created `twin`.
* @returns {Promise<ExtrinsicResult<Twin>>} A promise that resolves with an extrinsic for `twin` creation.
*/
async create(options: TwinOptions): Promise<ExtrinsicResult<Twin>> {
const pk = generatePublicKey(this.client.mnemonicOrSecret!);
return super.create({ pk, relay: options.relay });
}

/**
* Updates an existing `twin` with the specified options.
* Prepare an extrinsic for updating an existing `twin` with the specified options.
*
* @param options - The options for updating the `twin`, including the `relay` to connect to.
* @returns {Promise<ExtrinsicResult<Twin>>} A promise that resolves with the updated `twin`.
* @returns {Promise<ExtrinsicResult<Twin>>} A promise that resolves with an extrinsic for the `twin` update.
*/
async update(options: TwinOptions): Promise<ExtrinsicResult<Twin>> {
const pk = generatePublicKey(this.client.mnemonicOrSecret!);
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Algorand implements blockchainInterface {
/**
* Initializes a new account on the Algorand blockchain.
*
* This method generates a new account using the provided secret key, saves the account under the specified name,
* This method loads an account using the provided secret key, saves the account under the specified name,
* and returns the address of the created account.
*
* @param {AlgorandAccountInitModel} options - The options for initializing the account, including the name and secret key.
Expand Down
11 changes: 5 additions & 6 deletions packages/grid_client/src/modules/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class BaseModule {
*
* This method processes the created and deleted contracts, updates the existing contracts,
* and handles the backend storage operations for storing the contracts data.
* It also applies extrinsics to the TFChain client for updating the contracts on the blockchain.
*
* @param {string} name - The name of the deployment to save contracts for.
* @param {DeploymentResultContracts} contracts - The contracts data containing created and deleted contracts.
Expand Down Expand Up @@ -324,7 +323,7 @@ class BaseModule {
}

/**
* Lists all of the contracts based on the user secret.
* Lists the deployment names for the current user.
*
* @returns {Promise<any>} - A promise that resolves to the list of contract names.
*/
Expand Down Expand Up @@ -920,7 +919,7 @@ class BaseModule {
}

/**
* Add a new machine to the deployment.
* Add a new [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 Expand Up @@ -1014,10 +1013,10 @@ class BaseModule {
* Finally, it saves the updated contracts and returns the result containing created, deleted, and updated contracts.
*
* @param {string} name - The name of the deployment to delete contracts for.
* @returns {Promise<{ created: Contract[]; deleted: Contract[]; updated: Contract[] }>} - A promise that resolves to an object containing the created, deleted, and updated contracts.
* @returns {Promise<DeploymentResultContracts>} - A promise that resolves to an object containing the created, deleted, and updated contracts.
*/
async _delete(name: string): Promise<{ created: Contract[]; deleted: Contract[]; updated: Contract[] }> {
const contracts: { created: Contract[]; deleted: Contract[]; updated: Contract[] } = {
async _delete(name: string): Promise<DeploymentResultContracts> {
const contracts: DeploymentResultContracts = {
created: [],
deleted: [],
updated: [],
Expand Down
59 changes: 38 additions & 21 deletions packages/grid_client/src/modules/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@ import { GridClientError, ValidationError } from "@threefold/types";
import { GridClientConfig } from "../config";
import { expose } from "../helpers/expose";
import { validateInput } from "../helpers/validator";
import * as blockchain from ".";
import { algorand } from "./algorand";
import blockchainInterface, { blockchainType } from "./blockchainInterface";
import {
BlockchainAssetsModel,
BlockchainCreateModel,
BlockchainCreateResultModel,
BlockchainDeleteModel,
BlockchainGetModel,
BlockchainGetResultModel,
BlockchainInitModel,
BlockchainListModel,
BlockchainListResultModel,
BlockchainPayModel,
BlockchainPayNoNameModel,
BlockchainSignModel,
BlockchainSignNoNameModel,
} from "./models";
import { stellar } from "./stellar";
import { tfchain } from "./tfchain";

class Blockchain implements blockchainInterface {
stellar: blockchain.stellar;
algorand: blockchain.algorand;
tfchain: blockchain.tfchain;
stellar: stellar;
algorand: algorand;
tfchain: tfchain;
current_account: string;
blockchain_type: blockchainType;

Expand All @@ -20,9 +37,9 @@ class Blockchain implements blockchainInterface {
*
*/
constructor(public config: GridClientConfig) {
this.stellar = new blockchain.stellar(config);
this.algorand = new blockchain.algorand(config);
this.tfchain = new blockchain.tfchain(config);
this.stellar = new stellar(config);
this.algorand = new algorand(config);
this.tfchain = new tfchain(config);
}

/**
Expand All @@ -31,7 +48,7 @@ class Blockchain implements blockchainInterface {
* @param {BlockchainGetModel} options - The options containing the account name to check.
* @returns {Promise<blockchainType | undefined>} The type of blockchain where the account exists or undefined.
*/
async exist_in(options: blockchain.BlockchainGetModel): Promise<blockchainType | undefined> {
async exist_in(options: BlockchainGetModel): Promise<blockchainType | undefined> {
if (await this.stellar.exist(options)) return blockchainType.stellar;
else if (await this.algorand.exist(options)) return blockchainType.algorand;
else if (await this.tfchain.exist(options)) return blockchainType.tfchain;
Expand All @@ -48,7 +65,7 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async exist(options: blockchain.BlockchainGetModel): Promise<boolean> {
async exist(options: BlockchainGetModel): Promise<boolean> {
return (
(await this.stellar.exist({ name: options.name })) ||
(await this.algorand.exist({ name: options.name })) ||
Expand All @@ -70,7 +87,7 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async select(options: blockchain.BlockchainGetModel): Promise<string> {
async select(options: BlockchainGetModel): Promise<string> {
const account_exists = await this.exist(options);

if (!account_exists) throw new ValidationError(`Account ${options.name} doesn't exist.`);
Expand All @@ -96,7 +113,7 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async create(options: blockchain.BlockchainCreateModel): Promise<blockchain.BlockchainCreateResultModel> {
async create(options: BlockchainCreateModel): Promise<BlockchainCreateResultModel> {
const account_exists = await this.exist(options);

if (account_exists) throw new ValidationError(`Name ${options.name} already exists.`);
Expand All @@ -118,16 +135,16 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async sign(options: blockchain.BlockchainSignNoNameModel): Promise<string> {
async sign(options: BlockchainSignNoNameModel): Promise<string> {
if (!this.current_account) throw new ValidationError(`No account is selected. Please select an account first.`);

const modified_options: blockchain.BlockchainSignModel = { name: this.current_account, content: options.content };
const modified_options: BlockchainSignModel = { name: this.current_account, content: options.content };

return this[this.blockchain_type].sign(modified_options);
}

/**
* Initialize a new account on the specified blockchain type.
* Loads the account based on the specified blockchain type.
*
* This method delegates the initialization to the specific blockchain type based on the provided options.
*
Expand All @@ -139,7 +156,7 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async init(options: blockchain.BlockchainInitModel): Promise<string> {
async init(options: BlockchainInitModel): Promise<string> {
return this[options.blockchain_type].init(options);
}

Expand All @@ -156,7 +173,7 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async get(): Promise<blockchain.BlockchainGetResultModel> {
async get(): Promise<BlockchainGetResultModel> {
if (!this.current_account) throw new ValidationError(`No account is selected. Please select an account first.`);

const options = { name: this.current_account };
Expand All @@ -177,7 +194,7 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async list(options?: blockchain.BlockchainListModel): Promise<blockchain.BlockchainListResultModel[]> {
async list(options?: BlockchainListModel): Promise<BlockchainListResultModel[]> {
if (!options || !options.blockchain_type) {
const stellar_accounts = await this.stellar.list();
const algorand_accounts = await this.algorand.list();
Expand All @@ -201,7 +218,7 @@ class Blockchain implements blockchainInterface {
*/
@expose
@validateInput
async assets(): Promise<blockchain.BlockchainAssetsModel> {
async assets(): Promise<BlockchainAssetsModel> {
if (!this.current_account) throw new ValidationError(`No account is selected. Please select an account first.`);

const options = { name: this.current_account };
Expand All @@ -225,13 +242,13 @@ class Blockchain implements blockchainInterface {
@expose
@validateInput
// TODO : bridge, still
async pay(options: blockchain.BlockchainPayNoNameModel): Promise<any> {
async pay(options: BlockchainPayNoNameModel): Promise<any> {
if (!this.current_account) throw new ValidationError(`No account is selected. Please select an account first.`);

if (this.blockchain_type != options.blockchain_type_dest)
throw new GridClientError(`Transfer between blockchains isn't implemented yet.`);

const modified_options: blockchain.BlockchainPayModel = {
const modified_options: BlockchainPayModel = {
name: this.current_account,
blockchain_type_dest: options.blockchain_type_dest,
description: options.description,
Expand Down Expand Up @@ -259,7 +276,7 @@ class Blockchain implements blockchainInterface {
async delete(): Promise<any> {
if (!this.current_account) throw new ValidationError(`No account is selected. Please select an account first.`);

const options: blockchain.BlockchainDeleteModel = { name: this.current_account };
const options: BlockchainDeleteModel = { name: this.current_account };

return this[this.blockchain_type].delete(options);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/grid_client/src/modules/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Bridge {
client: TFClient;

/**
* Class representing a Bridge for interacting with TFClient's TFTBridge functionality.
* Class representing a Bridge for interacting with TFChain's TFTBridge functionality.
*
* This class provides methods for listening to mint completion, getting withdrawal and deposit fees,
* and swapping assets to Stellar network.
Expand Down
4 changes: 2 additions & 2 deletions packages/grid_client/src/modules/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Calculator {
}

/**
* Asynchronously retrieves the TFT price from the client.
* Asynchronously retrieves the TFT price from the TFChain.
*
* @returns {Promise<number>} A promise that resolves to the TFT price.
* @decorators
Expand All @@ -138,7 +138,7 @@ class Calculator {
}

/**
* Asynchronously calculates the monthly cost in musd (millions of USD) based on the provided options.
* Asynchronously calculates the monthly cost in musd (milli USD) based on the provided options.
*
* @param {CalculatorModel} options - The calculator model options containing, sru, mru, and some other fields.
* @returns {Promise<{ musd_month: number, dedicatedDiscount: number }>} A promise that resolves to an object containing the calculated monthly cost in musd and the discount for dedication nodes.
Expand Down
Loading

0 comments on commit 841a243

Please sign in to comment.