isConformingNamespaces static method
Makes sure that the chains, methods and events of the required namespaces are contained in the namespaces
Implementation
static bool isConformingNamespaces({
required Map<String, RequiredNamespace> requiredNamespaces,
required Map<String, Namespace> namespaces,
required String context,
}) {
List<String> requiredNamespaceKeys = requiredNamespaces.keys.toList();
List<String> namespaceKeys = namespaces.keys.toList();
// If the namespaces doesn't have the correct keys, we can fail automatically
if (!isContainedIn(
container: namespaceKeys, contained: requiredNamespaceKeys)) {
throw Errors.getSdkError(
Errors.UNSUPPORTED_NAMESPACE_KEY,
context: "$context namespaces keys don't satisfy requiredNamespaces",
).toSignError();
} else {
for (var key in requiredNamespaceKeys) {
List<String> requiredNamespaceChains =
NamespaceUtils.getChainsFromRequiredNamespace(
nsOrChainId: key,
requiredNamespace: requiredNamespaces[key]!,
);
List<String> namespaceChains = NamespaceUtils.getChainIdsFromNamespace(
nsOrChainId: key,
namespace: namespaces[key]!,
);
// Check the chains, methods and events for overlaps.
// If any of them don't have it, we fail.
final bool chainsOverlap = isContainedIn(
container: namespaceChains,
contained: requiredNamespaceChains,
);
final bool methodsOverlap = isContainedIn(
container: namespaces[key]!.methods,
contained: requiredNamespaces[key]!.methods,
);
final bool eventsOverlap = isContainedIn(
container: namespaces[key]!.events,
contained: requiredNamespaces[key]!.events,
);
if (!chainsOverlap) {
throw Errors.getSdkError(
Errors.UNSUPPORTED_CHAINS,
context:
"$context namespaces chains don't satisfy requiredNamespaces chains for $key. Requested: $requiredNamespaceChains, Supported: $namespaceChains",
).toSignError();
} else if (!methodsOverlap) {
throw Errors.getSdkError(
Errors.UNSUPPORTED_METHODS,
context:
"$context namespaces methods don't satisfy requiredNamespaces methods for $key. Requested: ${requiredNamespaces[key]!.methods}, Supported: ${namespaces[key]!.methods}",
).toSignError();
} else if (!eventsOverlap) {
throw Errors.getSdkError(
Errors.UNSUPPORTED_EVENTS,
context:
"$context namespaces events don't satisfy requiredNamespaces events for $key. Requested: ${requiredNamespaces[key]!.events}, Supported: ${namespaces[key]!.events}",
).toSignError();
}
}
}
return true;
}