Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] "registerOnNewStorageService" equivalent function that checks if it's already been registered #6

Open
lukehmcc opened this issue Aug 21, 2024 · 0 comments

Comments

@lukehmcc
Copy link
Member

For context, when initializing an s5 node in dart you have to run two main functions:

  1. await s5.recoverIdentityFromSeedPhrase(seed);
  2. await s5.registerOnNewStorageService(nodeURL);

The first uses the seed to "log in" by fetching the reg entry associated with the account info, the second signs up on the node of choice, without the second one there's no way to make sure you're using the node you want to.

So my proposal, there should be a function like ensureRegisteredOnStorageService that does the same thing as registerOnNewStorageService but checks to see if it has already registered first. This is not a difficult thing to work around, but it is a waste of developers time to have to write logic around this for every app they want to build quickly. Below is an example of how I did my checks in s5_deploy and vup_chat.

List<String>? urls;
// then check if already registered
if ((s5!.api as S5NodeAPIWithIdentity).accounts.isNotEmpty) {
  Map<dynamic, dynamic> data =
      (s5!.api as S5NodeAPIWithIdentity).accounts;
  final Map<String, dynamic> accounts = (data['accounts'] as Map).map(
    (key, value) => MapEntry(key as String, value),
  );
  urls =
      accounts.values.map((account) => account['url'] as String).toList();
  // And if the nodeURL isn't on the seed already, authenticate on that server
}
if (urls == null || !urls.contains(nodeURL)) {
  logger.d("Registering @ $nodeURL");
  await s5!.registerOnNewStorageService(
    nodeURL,
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant