Skip to content

Commit

Permalink
feat(state channels): make state channels compatible with node v5.1.0… (
Browse files Browse the repository at this point in the history
#776)

* feat(state channels): make state channels compatible with node v5.1.0-rc.1

* Fix lint error
  • Loading branch information
mpowaga authored and nduchak committed Nov 11, 2019
1 parent 87062ea commit 74952aa
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG=v5.0.2
TAG=v5.1.0-rc.1
COMPILER_TAG=v4.0.0
51 changes: 47 additions & 4 deletions es/channel/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function appendSignature (tx, signFn) {
}

function handleUnexpectedMessage (channel, message, state) {
if (state.reject) {
if (state && state.reject) {
state.reject(Object.assign(
Error(`Unexpected message received:\n\n${JSON.stringify(message)}`),
{ wsMessage: message }
Expand Down Expand Up @@ -162,6 +162,13 @@ export async function channelOpen (channel, message, state) {
case 'withdraw_locked':
case 'own_deposit_locked':
case 'deposit_locked':
case 'peer_disconnected':
case 'channel_reestablished':
case 'open':
// TODO: Better handling of peer_disconnected event.
//
// We should enter intermediate state where offchain transactions
// are blocked until channel is reestablished.
emit(channel, message.params.data.event)
return { handler: channelOpen }
case 'close_mutual':
Expand Down Expand Up @@ -242,6 +249,12 @@ export async function awaitingOffChainTx (channel, message, state) {
})
return { handler: channelOpen }
}
if (message.method === 'channels.info') {
if (message.params.data.event === 'aborted_update') {
state.resolve({ accepted: false })
return { handler: channelOpen }
}
}
return handleUnexpectedMessage(channel, message, state)
}

Expand All @@ -259,6 +272,12 @@ export function awaitingOffChainUpdate (channel, message, state) {
})
return { handler: channelOpen }
}
if (message.method === 'channels.info') {
if (message.params.data.event === 'aborted_update') {
state.resolve({ accepted: false })
return { handler: channelOpen }
}
}
if (message.error) {
state.reject(new Error(message.error.message))
return { handler: channelOpen }
Expand Down Expand Up @@ -287,7 +306,7 @@ export async function awaitingTxSignRequest (channel, message, state) {
}
if (typeof signedTx === 'number') {
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { error: signedTx } })
return { handler: awaitingUpdateConflict }
return { handler: awaitingUpdateConflict, state }
}
}
// soft-reject via competing update
Expand All @@ -300,14 +319,14 @@ export async function awaitingTxSignRequest (channel, message, state) {
amount: 1
}
})
return { handler: awaitingUpdateConflict }
return { handler: awaitingUpdateConflict, state }
}
return handleUnexpectedMessage(channel, message, state)
}

export function awaitingUpdateConflict (channel, message, state) {
if (message.error) {
return { handler: awaitingUpdateConflict }
return { handler: awaitingUpdateConflict, state }
}
if (message.method === 'channels.conflict') {
return { handler: channelOpen }
Expand Down Expand Up @@ -405,6 +424,12 @@ export function awaitingWithdrawCompletion (channel, message, state) {
})
return { handler: channelOpen }
}
if (message.method === 'channels.info') {
if (message.params.data.event === 'aborted_update') {
state.resolve({ accepted: false })
return { handler: channelOpen }
}
}
return handleUnexpectedMessage(channel, message, state)
}

Expand Down Expand Up @@ -463,6 +488,12 @@ export function awaitingDepositCompletion (channel, message, state) {
})
return { handler: channelOpen }
}
if (message.method === 'channels.info') {
if (message.params.data.event === 'aborted_update') {
state.resolve({ accepted: false })
return { handler: channelOpen }
}
}
return handleUnexpectedMessage(channel, message, state)
}

Expand Down Expand Up @@ -509,6 +540,12 @@ export function awaitingNewContractCompletion (channel, message, state) {
})
return { handler: channelOpen }
}
if (message.method === 'channels.info') {
if (message.params.data.event === 'aborted_update') {
state.resolve({ accepted: false })
return { handler: channelOpen }
}
}
return handleUnexpectedMessage(channel, message, state)
}

Expand Down Expand Up @@ -546,6 +583,12 @@ export function awaitingCallContractCompletion (channel, message, state) {
})
return { handler: channelOpen }
}
if (message.method === 'channels.info') {
if (message.params.data.event === 'aborted_update') {
state.resolve({ accepted: false })
return { handler: channelOpen }
}
}
return handleUnexpectedMessage(channel, message, state)
}

Expand Down
66 changes: 19 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 74952aa

Please sign in to comment.