Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for checking the node is already exist on the network #1205

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/grid_client/src/high_level/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class NetworkHL extends HighLevelBase {
}
return twinDeployments;
}

async hasNode(networkName: string, ipRange: string, nodeId: number): Promise<boolean> {
const network = new Network(networkName, ipRange, this.config);
await network.load();
return network.nodeExists(nodeId);
}
}

export { NetworkHL };
7 changes: 7 additions & 0 deletions packages/grid_client/src/modules/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ class NetworkAddNodeModel {
@Expose() @IsString() @IsOptional() description?: string;
}

class NetworkHasNodeModel {
@Expose() @IsString() @IsNotEmpty() @IsAlphanumeric() @MaxLength(NameLength) name: string;
@Expose() @IsString() @IsNotEmpty() ipRange: string;
@Expose() @IsInt() @IsNotEmpty() @Min(1) nodeId: number;
}

class NetworkGetModel {
@Expose() @IsString() @IsNotEmpty() @IsAlphanumeric() @MaxLength(NameLength) name: string;
}
Expand Down Expand Up @@ -778,6 +784,7 @@ export {
SetServiceContractMetadataModel,
GetServiceContractModel,
NetworkAddNodeModel,
NetworkHasNodeModel,
NetworkGetModel,
NodeGetModel,
SetDedicatedNodeExtraFeesModel,
Expand Down
8 changes: 7 additions & 1 deletion packages/grid_client/src/modules/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expose } from "../helpers/expose";
import { validateInput } from "../helpers/validator";
import { NetworkHL } from "../high_level/network";
import { BaseModule } from "./base";
import { NetworkAddNodeModel, NetworkGetModel } from "./models";
import { NetworkAddNodeModel, NetworkGetModel, NetworkHasNodeModel } from "./models";
import { checkBalance } from "./utils";

class NetworkModule extends BaseModule {
Expand Down Expand Up @@ -36,6 +36,12 @@ class NetworkModule extends BaseModule {
return await this._list();
}

@expose
@validateInput
async hasNode(options: NetworkHasNodeModel): Promise<boolean> {
return await this.network.hasNode(options.name, options.ipRange, options.nodeId);
}

@expose
@validateInput
async getWireGuardConfigs(options: NetworkGetModel) {
Expand Down
Loading