Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Update JS SDK api to the new version #61

Merged
merged 49 commits into from
Sep 8, 2021
Merged

Update JS SDK api to the new version #61

merged 49 commits into from
Sep 8, 2021

Conversation

coder11
Copy link
Contributor

@coder11 coder11 commented Aug 23, 2021

This is the first step of the massive JS SDK refacroing. Currently it only migrates to the new api format without major underlying changes.

Brief overview of what was changed:

  • FluenceClient renamed to FluencePeer.
  • Using Aqua compiler is not the recommended way for all interaction with the network, including services registration and sending requests
  • Old API (sendParticle etc) has been removed
  • Opaque seed format replaced with 32 byte ed25519 private key
  • Readme update
  • Please refer to the update Readme for overview of the new SDK API

@coder11 coder11 requested review from folex, DieMyst and alari September 7, 2021 12:20
* * Multiaddr - multiaddr object, @see https://github.com/multiformats/js-multiaddr
* * Node - node structure, @see Node
*/
export type ConnectionSpec = string | MA | Node;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does Spec mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specification. Feel free to suggest a better name

Copy link
Contributor

@folex folex Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remote / ConnectionTarget / Node / Relay / Peer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just got rid of the explicit type definition

@@ -0,0 +1,350 @@
import { AirInterpreter, CallServiceResult, LogLevel, ParticleHandler, SecurityTetraplet } from '@fluencelabs/avm';
import log from 'loglevel';
import { Multiaddr as MA } from 'multiaddr';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep Multiaddress, MA is cryptic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

peerId = peerIdOrSeed;
} else {
// peerId is string, therefore seed
peerId = await peerIdFromEd25519SK(peerIdOrSeed);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if peerIdOrSeed is malformed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to replace this logic with the help of KeyPair class

const request = this._requests.get(this._currentRequestId);
const particle = request.getParticle();
if (particle === null) {
throw new Error("particle can't be null here");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some debug info to the error? At least this._currentRequestId

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


if (res.result === undefined) {
log.error(
`Call to serviceId=${serviceId} fnName=${fnName} unexpectedly returned undefined result, falling back to null`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's log particle id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

this._requests.delete(key);
}
}
}, 5000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add todo to make 5000 configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -149,6 +150,7 @@ relay peer id: ${this.relayPeerId}
// TODO:: keep the history of particle data mb?
this.prevData = this.state.data;
this.state.data = particle.data;
log.debug('Received update');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

next();
} catch (e) {
resp.retCode = ResultCodes.exceptionInHandler;
resp.result = e.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add more debug info to the error? Particle id maybe? service id and fnName at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@coder11 coder11 linked an issue Sep 8, 2021 that may be closed by this pull request
@coder11 coder11 merged commit 6436cd5 into master Sep 8, 2021
@coder11 coder11 deleted the new-js-sdk-api branch September 8, 2021 09:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

withTTL: specify unit of measurement for ttl parameter
2 participants