diff --git a/docs/classes/FluencePeer.html b/docs/classes/FluencePeer.html index b9e01a1c7..b38c44626 100644 --- a/docs/classes/FluencePeer.html +++ b/docs/classes/FluencePeer.html @@ -121,7 +121,7 @@

constructor

  • @@ -140,13 +140,13 @@

    Accessors

    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 } }

    @@ -345,7 +325,7 @@

    getStatus

  • @@ -367,7 +347,7 @@

    start

  • @@ -399,7 +379,7 @@

    stop

  • @@ -422,7 +402,7 @@

    Static isInstance

  • diff --git a/docs/classes/KeyPair.html b/docs/classes/KeyPair.html index 4ec667b5a..77009dbba 100644 --- a/docs/classes/KeyPair.html +++ b/docs/classes/KeyPair.html @@ -112,7 +112,7 @@

    constructor

  • Parameters

    @@ -134,7 +134,7 @@

    Libp2pPeerId

    Libp2pPeerId: PeerId
    @@ -156,7 +156,7 @@

    toEd25519PrivateKey

  • Returns Uint8Array

    @@ -174,7 +174,7 @@

    Static fromEd25519SK

  • @@ -205,7 +205,7 @@

    Static randomEd25519

  • diff --git a/docs/interfaces/CallParams.html b/docs/interfaces/CallParams.html index 9cf99701d..e193c41d5 100644 --- a/docs/interfaces/CallParams.html +++ b/docs/interfaces/CallParams.html @@ -118,7 +118,7 @@

    initPeerId

    initPeerId: string
    @@ -133,7 +133,7 @@

    particleId

    particleId: string
    @@ -148,7 +148,7 @@

    signature

    signature: string
    @@ -163,7 +163,7 @@

    tetraplets

    tetraplets: {[ key in string]: SecurityTetraplet[] }
    @@ -178,7 +178,7 @@

    timestamp

    timestamp: number
    @@ -193,7 +193,7 @@

    ttl

    ttl: number
    diff --git a/docs/interfaces/PeerConfig.html b/docs/interfaces/PeerConfig.html index 90cc38006..6ed5621f4 100644 --- a/docs/interfaces/PeerConfig.html +++ b/docs/interfaces/PeerConfig.html @@ -107,7 +107,7 @@

    Optional KeyPair

    KeyPair: KeyPair
    @@ -123,7 +123,7 @@

    Optional avmLogLevel
    avmLogLevel: LogLevel
    @@ -138,7 +138,7 @@

    Optional checkConnection<
    checkConnectionTimeoutMs: number
    @@ -155,7 +155,7 @@

    Optional connectTo

    connectTo: string | Multiaddr | Node
    @@ -177,7 +177,7 @@

    Optional defaultTtlM
    defaultTtlMs: number
    @@ -194,7 +194,7 @@

    Optional dialTimeout
    dialTimeoutMs: number
    @@ -209,7 +209,7 @@

    Optional skipCheckCo
    skipCheckConnection: boolean
    diff --git a/docs/interfaces/PeerStatus.html b/docs/interfaces/PeerStatus.html index 029aee150..3b6b6cd92 100644 --- a/docs/interfaces/PeerStatus.html +++ b/docs/interfaces/PeerStatus.html @@ -104,7 +104,7 @@

    isConnected

    isConnected: Boolean
    @@ -119,12 +119,12 @@

    isInitialized

    isInitialized: Boolean
    -

    Is the peer connected to network or not

    +

    Is the peer initialized or not

    @@ -134,7 +134,7 @@

    peerId

    peerId: string
    @@ -149,7 +149,7 @@

    relayPeerId

    relayPeerId: string
    diff --git a/docs/modules.html b/docs/modules.html index 26259d7b6..a1a62bafa 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -106,7 +106,7 @@

    AvmLoglevel

    AvmLoglevel: LogLevel
    @@ -122,7 +122,7 @@

    PeerIdB58

    PeerIdB58: string
    @@ -140,7 +140,7 @@

    Const Fluence

    Fluence: { getPeer: () => FluencePeer; getStatus: () => PeerStatus; start: (config?: PeerConfig) => Promise<void>; stop: () => Promise<void> } = ...
    @@ -234,7 +234,7 @@
    stop:
    -

    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 @@

    Const setLogLevel

  • Parameters

    diff --git a/src/internal/FluencePeer.ts b/src/internal/FluencePeer.ts index d795072ad..401ec7d72 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 c2fa351f1..6ce760d0f 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);