diff --git a/docs/classes/FluencePeer.html b/docs/classes/FluencePeer.html index b9e01a1c..b38c4462 100644 --- a/docs/classes/FluencePeer.html +++ b/docs/classes/FluencePeer.html @@ -121,7 +121,7 @@
  • @@ -140,13 +140,13 @@

    internals

    -

    Returns { callServiceHandler: CallServiceHandler; initiateFlow: (request: RequestFlow) => void; initiateParticle: (particle: Particle) => void; regHandler: { common: (serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void; forParticle: (particleId: string, serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void; timeout: (particleId: string, handler: () => void) => void } }

    +

    Returns { callServiceHandler: CallServiceHandler; initiateFlow: (request: RequestFlow) => void; initiateParticle: (particle: Particle, onStageChange: (stage: ParticleExecutionStage) => void) => void; regHandler: { common: (serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void; forParticle: (particleId: string, serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void } }

  • -
    initiateParticle: (particle: Particle) => void
    +
    initiateParticle: (particle: Particle, onStageChange: (stage: ParticleExecutionStage) => void) => void
  • -
    regHandler: { common: (serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void; forParticle: (particleId: string, serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void; timeout: (particleId: string, handler: () => void) => void }
    +
    regHandler: { common: (serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void; forParticle: (particleId: string, serviceId: string, fnName: string, handler: GenericCallServiceHandler) => void }
  • -
  • -
    timeout: (particleId: string, handler: () => void) => void
    - -
  • @@ -345,7 +325,7 @@
  • @@ -367,7 +347,7 @@
  • @@ -399,7 +379,7 @@
  • @@ -422,7 +402,7 @@
  • diff --git a/docs/classes/KeyPair.html b/docs/classes/KeyPair.html index 4ec667b5..77009dbb 100644 --- a/docs/classes/KeyPair.html +++ b/docs/classes/KeyPair.html @@ -112,7 +112,7 @@
  • Parameters

    @@ -134,7 +134,7 @@
    Libp2pPeerId: PeerId
    @@ -156,7 +156,7 @@
  • Returns Uint8Array

    @@ -174,7 +174,7 @@
  • @@ -205,7 +205,7 @@
  • diff --git a/docs/interfaces/CallParams.html b/docs/interfaces/CallParams.html index 9cf99701..e193c41d 100644 --- a/docs/interfaces/CallParams.html +++ b/docs/interfaces/CallParams.html @@ -118,7 +118,7 @@
    initPeerId: string
    @@ -133,7 +133,7 @@
    particleId: string
    @@ -148,7 +148,7 @@
    signature: string
    @@ -163,7 +163,7 @@
    tetraplets: {[ key in string]: SecurityTetraplet[] }
    @@ -178,7 +178,7 @@
    timestamp: number
    @@ -193,7 +193,7 @@
    ttl: number
    diff --git a/docs/interfaces/PeerConfig.html b/docs/interfaces/PeerConfig.html index 90cc3800..6ed5621f 100644 --- a/docs/interfaces/PeerConfig.html +++ b/docs/interfaces/PeerConfig.html @@ -107,7 +107,7 @@
    KeyPair: KeyPair
    @@ -123,7 +123,7 @@
    avmLogLevel: LogLevel
    @@ -138,7 +138,7 @@
    checkConnectionTimeoutMs: number
    @@ -155,7 +155,7 @@
    connectTo: string | Multiaddr | Node
    @@ -177,7 +177,7 @@
    defaultTtlMs: number
    @@ -194,7 +194,7 @@
    dialTimeoutMs: number
    @@ -209,7 +209,7 @@
    skipCheckConnection: boolean
    diff --git a/docs/interfaces/PeerStatus.html b/docs/interfaces/PeerStatus.html index 029aee15..3b6b6cd9 100644 --- a/docs/interfaces/PeerStatus.html +++ b/docs/interfaces/PeerStatus.html @@ -104,7 +104,7 @@
    isConnected: Boolean
    @@ -119,12 +119,12 @@
    isInitialized: Boolean
    -

    Is the peer connected to network or not

    +

    Is the peer initialized or not

    @@ -134,7 +134,7 @@
    peerId: string
    @@ -149,7 +149,7 @@
    relayPeerId: string
    diff --git a/docs/modules.html b/docs/modules.html index 26259d7b..a1a62baf 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -106,7 +106,7 @@
    AvmLoglevel: LogLevel
    @@ -122,7 +122,7 @@
    PeerIdB58: string
    @@ -140,7 +140,7 @@
    Fluence: { getPeer: () => FluencePeer; getStatus: () => PeerStatus; start: (config?: PeerConfig) => Promise<void>; stop: () => Promise<void> } = ...
    @@ -234,7 +234,7 @@
  • -

    Uninitializes the default peer: stops all the underltying workflows, stops the Aqua VM +

    Un-initializes the default peer: stops all the underlying workflows, stops the Aqua VM and disconnects from the Fluence network

    @@ -260,7 +260,7 @@
  • Parameters

    diff --git a/src/internal/FluencePeer.ts b/src/internal/FluencePeer.ts index d795072a..401ec7d7 100644 --- a/src/internal/FluencePeer.ts +++ b/src/internal/FluencePeer.ts @@ -109,7 +109,7 @@ export interface PeerConfig { */ export interface PeerStatus { /** - * Is the peer connected to network or not + * Is the peer initialized or not */ isInitialized: Boolean; diff --git a/src/internal/compilerSupport/v2.ts b/src/internal/compilerSupport/v2.ts index c2fa351f..6ce760d0 100644 --- a/src/internal/compilerSupport/v2.ts +++ b/src/internal/compilerSupport/v2.ts @@ -355,6 +355,12 @@ export function callFunction(rawFnArgs: Array, def: FunctionCallDef, script export function registerService(args: any[], def: ServiceDef) { const { peer, service, serviceId } = extractRegisterServiceArgs(args, def.defaultServiceId); + if (!peer.getStatus().isInitialized) { + throw new Error( + 'Could not register the service because the peer is not initialized. Are you passing the wrong peer to the register function?', + ); + } + // Checking for missing keys const requiredKeys = def.functions.map((x) => x.functionName); const incorrectServiceDefinitions = requiredKeys.filter((f) => !(f in service)); @@ -367,7 +373,8 @@ export function registerService(args: any[], def: ServiceDef) { for (let singleFunction of def.functions) { // The function has type of (arg1, arg2, arg3, ... , callParams) => CallServiceResultType | void - const userDefinedHandler = service[singleFunction.functionName]; + // Account for the fact that user service might be defined as a class - .bind(...) + const userDefinedHandler = service[singleFunction.functionName].bind(service); peer.internals.regHandler.common(serviceId, singleFunction.functionName, async (req) => { const args = convertArgsFromReqToUserCall(req, singleFunction.argDefs);