isValidNamespacesChainId static method

bool isValidNamespacesChainId({
  1. required Map<String, Namespace> namespaces,
  2. required String chainId,
})

Validates the provided chainId, then ensures that the chainId is contained in the namespaces

Implementation

static bool isValidNamespacesChainId({
  required Map<String, Namespace> namespaces,
  required String chainId,
}) {
  // Validate the chainId
  if (!NamespaceUtils.isValidChainId(chainId)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_CHAINS,
      context: 'chain $chainId should conform to "namespace:chainId" format',
    );
  }

  // Validate the namespaces
  isValidNamespaces(
    namespaces: namespaces,
    context: 'isValidNamespacesChainId',
  );

  // Get the chains from the namespaces and
  List<String> chains = NamespaceUtils.getChainIdsFromNamespaces(
    namespaces: namespaces,
  );

  if (!chains.contains(chainId)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_CHAINS,
      context: 'The chain $chainId is not supported',
    );
  }

  return true;
}