Skip to content

Commit

Permalink
remove: deprecated code. Use getConnectionInfo instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansonhkg committed Dec 20, 2024
1 parent 432ac93 commit d97f177
Showing 1 changed file with 3 additions and 120 deletions.
123 changes: 3 additions & 120 deletions packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,128 +1059,12 @@ export class LitContracts {
return addresses;
}

/**
* FIXME: Remove this for Naga
* @deprecated - Use {@link getConnectionInfo } instead, which provides more information.
*/
public static getMinNodeCount = async (
network: LIT_NETWORKS_KEYS,
context?: LitContractContext | LitContractResolverContext,
rpcUrl?: string
) => {
const contract = await LitContracts.getStakingContract(
network,
context,
rpcUrl
);

const minNodeCount = await contract['currentValidatorCountForConsensus']();

if (!minNodeCount) {
throw new InitError(
{
info: {
minNodeCount,
},
},
'❌ Minimum validator count is not set'
);
}
return minNodeCount;
};

/**
* FIXME: remove this for Naga
* @deprecated - Use {@link getConnectionInfo } instead, which provides more information.
*/
public static getValidators = async (
network: LIT_NETWORKS_KEYS,
context?: LitContractContext | LitContractResolverContext,
rpcUrl?: string,
nodeProtocol?: typeof HTTP | typeof HTTPS | null
): Promise<string[]> => {
const contract = await LitContracts.getStakingContract(
network,
context,
rpcUrl
);

// Fetch contract data
const [activeValidators, currentValidatorsCount, kickedValidators] =
await Promise.all([
contract['getValidatorsInCurrentEpoch'](),
contract['currentValidatorCountForConsensus'](),
contract['getKickedValidators'](),
]);

const validators = [];

// Check if active validator set meets the threshold
if (
activeValidators.length - kickedValidators.length >=
currentValidatorsCount
) {
// Process each validator
for (const validator of activeValidators) {
validators.push(validator);
}
} else {
LitContracts.logger.error(
'❌ Active validator set does not meet the threshold'
);
}

// remove kicked validators in active validators
const cleanedActiveValidators = activeValidators.filter(
(av: any) => !kickedValidators.some((kv: any) => kv === av)
);

const activeValidatorStructs: ValidatorStruct[] = (
await contract['getValidatorsStructs'](cleanedActiveValidators)
).map((item: any) => {
return {
ip: item[0],
ipv6: item[1],
port: item[2],
nodeAddress: item[3],
reward: item[4],
seconderPubkey: item[5],
receiverPubkey: item[6],
};
});

const networks = activeValidatorStructs.map((item: ValidatorStruct) => {

// Convert the integer IP to a string format
const ip = intToIP(item.ip);
const port = item.port;

// Determine the protocol to use based on various conditions
const protocol =
// If nodeProtocol is defined, use it
nodeProtocol ||
// If port is 443, use HTTPS, otherwise use network-specific HTTP
(port === 443 ? HTTPS : HTTP_BY_NETWORK[network]) ||
// Fallback to HTTP if no other conditions are met
HTTP;

const url = `${protocol}${ip}:${port}`;

LitContracts.logger.debug("Validator's URL:", url);

return url;
});

return networks;
};


/**
* Generates an array of validator URLs based on the given validator structs and network configurations.
*
* @param {ValidatorStruct[]} activeValidatorStructs - Array of validator structures containing IP and port information.
* @param {string | undefined} nodeProtocol - Optional node protocol to override the default protocol selection logic.
* @param {string} litNetwork - The name of the network used to determine HTTP/HTTPS settings.
* @property {ValidatorStruct[]} activeValidatorStructs - Array of validator structures containing IP and port information.
* @property {string | undefined} nodeProtocol - Optional node protocol to override the default protocol selection logic.
* @property {string} litNetwork - The name of the network used to determine HTTP/HTTPS settings.
* @returns {string[]} Array of constructed validator URLs.
*
* @example
Expand Down Expand Up @@ -1360,7 +1244,6 @@ export class LitContracts {
litNetwork,
networkContext,
rpcUrl,
nodeProtocol,
productIds, // Array of product IDs
}: {
litNetwork: LIT_NETWORKS_KEYS,
Expand Down

0 comments on commit d97f177

Please sign in to comment.