indra icon indicating copy to clipboard operation
indra copied to clipboard

[channel-provider] remote event listeners

Open pedrouid opened this issue 5 years ago • 2 comments

Currently event listeners are implemented as no-ops for dumb clients like WalletConnect and Torus but as demonstrated by the test-runner channelProvider test these are necessary in dumb clients.

This can be handled by integrating a nats client to listen for events targeted at the client's nodePublicIdentifier.

See channelProvider.test.ts as example

pedrouid avatar Jan 14 '20 19:01 pedrouid

This should also refactor the logic handled by setupMultisigAddress() method in connect.ts to be handled by the remote event listener to await CREATE_CHANNEL_EVENT to get multisigAddress instead of being assigned externally

pedrouid avatar Jan 23 '20 11:01 pedrouid

Using a natsConnection similar to channelProvider.test.ts implementation doesn't cover all events emitted by CFCore. Instead we should implement remove event listeners through RPC. similar to ETH subscriptions.

Registering subscriptions

Send JSON-RPC request with method chan_subscribe and params with field event which should be responded with a subscription id

// request
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "chan_subscribe",
    "params": {
        "event": "RECEIVE_TRANSFER_FAILED_EVENT"
    }
}

// response
}
    "id": 1,
    "result": "0x16ff2c63013"
}

Emitting subscribed events will have a JSON-RPC request using method chan_subscription with a field matching the subscription id called subscription and field called data with event callback response. This method should not expect a response from its peer.

// subscription
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "chan_subscription",
    "params": {
        "subscription": "0x16ff2c63013",
        "data": {
            "paymentId": "0xa9059cbb2ab09eb219583f4a59a5d0623ade34"
         }
    }
}

pedrouid avatar Jan 29 '20 16:01 pedrouid