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

Improve state channel params handling. Fixes #299 #300

Merged
merged 3 commits into from
Apr 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions es/channel/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const actionQueueLocked = new WeakMap()
const sequence = new WeakMap()
const rpcCallbacks = new WeakMap()

function channelURL (url, { endpoint = 'channel', ...params }) {
function channelURL (url, params, endpoint = 'channel') {
const paramString = R.join('&', R.values(R.mapObjIndexed((value, key) =>
`${pascalToSnake(key)}=${encodeURIComponent(value)}`, params)))

Expand Down Expand Up @@ -168,28 +168,17 @@ function WebSocket (url, callbacks) {
}

async function initialize (channel, channelOptions) {
const params = R.pick([
'initiatorId',
'responderId',
'pushAmount',
'initiatorAmount',
'responderAmount',
'channelReserve',
'ttl',
'host',
'port',
'lockPeriod',
'role',
'existingChannelId',
'offchainTx'
], channelOptions)
const optionsKeys = ['sign', 'endpoint', 'url']
const params = R.pickBy(key => !optionsKeys.includes(key), channelOptions)
const { endpoint, url } = channelOptions
const wsUrl = channelURL(url, { ...params, protocol: 'json-rpc' }, endpoint)

options.set(channel, channelOptions)
fsm.set(channel, { handler: awaitingConnection })
eventEmitters.set(channel, new EventEmitter())
sequence.set(channel, 0)
rpcCallbacks.set(channel, new Map())
websockets.set(channel, await WebSocket(channelURL(channelOptions.url, { ...params, protocol: 'json-rpc' }), {
websockets.set(channel, await WebSocket(wsUrl, {
onopen: () => changeStatus(channel, 'connected'),
onclose: () => changeStatus(channel, 'disconnected'),
onmessage: ({ data }) => onMessage(channel, data)
Expand Down