getNamespacesFromAccounts static method

Map<String, Namespace> getNamespacesFromAccounts(
  1. List<String> accounts
)

Gets all unique namespaces from the provided list of accounts This function assumes that all accounts are valid

Implementation

static Map<String, Namespace> getNamespacesFromAccounts(
  List<String> accounts,
) {
  Map<String, Namespace> namespaces = {};
  for (var account in accounts) {
    final ns = account.split(':')[0];
    final cid = account.split(':')[1];
    if (namespaces[ns] == null) {
      namespaces[ns] = Namespace(
        accounts: [],
        methods: [],
        events: [],
      );
    }
    namespaces[ns] = namespaces[ns]!.copyWith(
      accounts: [
        ...namespaces[ns]!.accounts,
        account,
      ],
      chains: [
        ...(namespaces[ns]?.chains ?? []),
        '$ns:$cid',
      ],
    );
  }

  return namespaces;
}