init method

Future init()

Implementation

Future init() async {
  if (_initCalled) {
    return;
  }

  _initCalled = true;

  if (provider == null) {
    provider = SimpleNodeProvider(null, profiles);
    (provider as SimpleNodeProvider).setPersistFunction(save);
  }

  if (loadNodes && provider is SerializableNodeProvider) {
    if (!(await dataStore!.has('dsa_nodes'))) {
      (provider as SerializableNodeProvider).init(defaultNodes!);
    } else {
      Map decoded = DsaJson.decode(await dataStore!.get('dsa_nodes'));

      (provider as SerializableNodeProvider).init(decoded);
    }
  } else {
    (provider as SerializableNodeProvider).init(defaultNodes!);
  }

  // move the waiting part of init into a later frame
  // we need to make sure provider is created at the first frame
  // not affected by any async code
  await initLinkWithPrivateKey();
}