Skip to content

Commit

Permalink
add formatChainID function (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 authored Jun 18, 2024
1 parent 11e81c3 commit 8d4ebe1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ export interface PodStatus {
reason?: string;
}

export const formatChainID = (input: string): string => {
// Replace underscores with hyphens
let formattedName = input.replace(/_/g, '-');

// Truncate the string to a maximum length of 63 characters
if (formattedName.length > 63) {
formattedName = formattedName.substring(0, 63);
}

return formattedName;
};

export class StarshipClient implements StarshipClientI {
ctx: StarshipContext;
version: string;
Expand Down Expand Up @@ -434,27 +446,27 @@ export class StarshipClient implements StarshipClientI {
if (localPort !== undefined && externalPort !== undefined) {
this.exec([
"kubectl", "port-forward",
`pods/${chain.id}-genesis-0`,
`pods/${formatChainID(chain.id)}-genesis-0`,
`${localPort}:${externalPort}`,
...this.getArgs(),
">", "/dev/null",
"2>&1", "&"
]);
this.log(chalk.yellow(`Forwarded ${chain.id}: local ${localPort} -> target (host) ${externalPort}`));
this.log(chalk.yellow(`Forwarded ${formatChainID(chain.id)}: local ${localPort} -> target (host) ${externalPort}`));
}
}

private forwardPortCometmock(chain: Chain, localPort: number, externalPort: number): void {
if (localPort !== undefined && externalPort !== undefined) {
this.exec([
"kubectl", "port-forward",
`pods/${chain.id}-cometmock-0`,
`pods/${formatChainID(chain.id)}-cometmock-0`,
`${localPort}:${externalPort}`,
...this.getArgs(),
">", "/dev/null",
"2>&1", "&"
]);
this.log(chalk.yellow(`Forwarded ${chain.id}: local ${localPort} -> target (host) ${externalPort}`));
this.log(chalk.yellow(`Forwarded ${formatChainID(chain.id)}: local ${localPort} -> target (host) ${externalPort}`));
}
}

Expand Down

0 comments on commit 8d4ebe1

Please sign in to comment.