resolveNames method

Future<void> resolveNames({
  1. required Future<String> resolvePackage(
    1. String package
    ),
  2. required Future<String> resolveType(
    1. String package
    ),
})

Resolve Move Registry (@org/app) names in this transaction's moveCall commands — both the package name and any type arguments — using the given resolver callbacks. Rewrites the commands in place. No-op if no MVR names are present. Mirrors the TypeScript SDK's NamedPackagesPlugin.

Implementation

Future<void> resolveNames({
  required Future<String> Function(String package) resolvePackage,
  required Future<String> Function(String type) resolveType,
}) async {
  final commands = _blockData.commands;
  final packages = <String>{};
  final types = <String>{};
  for (final cmd in commands) {
    final mc = cmd['MoveCall'];
    if (mc == null) continue;
    final pkg = mc['package'];
    if (pkg is String && pkg.contains('@')) packages.add(pkg);
    final typeArgs = mc['typeArguments'];
    if (typeArgs is List) {
      for (final t in typeArgs) {
        if (t is String && t.contains('@')) types.add(t);
      }
    }
  }
  if (packages.isEmpty && types.isEmpty) return;

  final pkgMap = <String, String>{};
  for (final p in packages) {
    pkgMap[p] = await resolvePackage(p);
  }
  final typeMap = <String, String>{};
  for (final t in types) {
    typeMap[t] = await resolveType(t);
  }

  for (final cmd in commands) {
    final mc = cmd['MoveCall'];
    if (mc == null) continue;
    final pkg = mc['package'];
    if (pkg is String && pkgMap.containsKey(pkg)) {
      mc['package'] = pkgMap[pkg];
    }
    final typeArgs = mc['typeArguments'];
    if (typeArgs is List) {
      for (var i = 0; i < typeArgs.length; i++) {
        final t = typeArgs[i];
        if (t is String && typeMap.containsKey(t)) {
          typeArgs[i] = typeMap[t];
        }
      }
    }
  }
}