diff --git a/.env b/.env
index 09dfed75c1..7afb468695 100644
--- a/.env
+++ b/.env
@@ -1,2 +1,2 @@
-NODE_TAG=v5.1.0
+NODE_TAG=v5.2.0
COMPILER_TAG=v4.1.0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f5ec6d9ecd..589f17b80c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,12 @@
+## [6.1.3](https://github.com/aeternity/aepp-sdk-js/compare/6.1.2...6.1.3) (2019-12-11)
+
+
+### Bug Fixes
+
+* **Channel:** 5.2.0 compatibility ([4be8eb8](https://github.com/aeternity/aepp-sdk-js/commit/4be8eb8))
+
+
+
## [6.1.2](https://github.com/aeternity/aepp-sdk-js/compare/6.1.1...6.1.2) (2019-11-12)
@@ -66,13 +75,6 @@
-
-
-
-
-
-
-
# [6.0.0](https://github.com/aeternity/aepp-sdk-js/compare/4.7.0...6.0.0) (2019-10-16)
diff --git a/docs/api/channel/index.md b/docs/api/channel/index.md
index 85b3180f3a..1650871fff 100644
--- a/docs/api/channel/index.md
+++ b/docs/api/channel/index.md
@@ -17,6 +17,7 @@ import Channel from '@aeternity/aepp-sdk/es/channel/index'
* [~state()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..state) ⇒ `Promise.<Object>`
* [~round()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..round) ⇒ `Number`
* [~id()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..id) ⇒ `String`
+ * [~fsmId()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..fsmId) ⇒ `String`
* [~update(from, to, amount, sign, metadata)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..update) ⇒ `Promise.<Object>`
* [~poi(addresses)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..poi) ⇒ `Promise.<String>`
* [~balances(accounts)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..balances) ⇒ `Promise.<Object>`
@@ -151,6 +152,12 @@ it will return `null`.
#### Channel~id() ⇒ `String`
Get channel id
+**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel)
+
+
+#### Channel~fsmId() ⇒ `String`
+Get channel's fsm id
+
**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel)
diff --git a/es/channel/handlers.js b/es/channel/handlers.js
index 361f78724f..38e3aaf542 100644
--- a/es/channel/handlers.js
+++ b/es/channel/handlers.js
@@ -24,7 +24,8 @@ import {
send,
emit,
channelId,
- disconnect
+ disconnect,
+ fsmId
} from './internal'
import { unpackTx, buildTx } from '../tx/builder'
@@ -67,6 +68,10 @@ export function awaitingConnection (channel, message, state) {
if (message.params.data.event === 'channel_reestablished') {
return { handler: awaitingOpenConfirmation }
}
+ if (message.params.data.event === 'fsm_up') {
+ fsmId.set(channel, message.params.data.fsm_id)
+ return { handler: awaitingConnection }
+ }
return { handler: awaitingConnection }
}
if (message.method === 'channels.error') {
@@ -78,6 +83,7 @@ export function awaitingConnection (channel, message, state) {
export async function awaitingReconnection (channel, message, state) {
if (message.method === 'channels.info') {
if (message.params.data.event === 'fsm_up') {
+ fsmId.set(channel, message.params.data.fsm_id)
changeState(channel, (await call(channel, 'channels.get.offchain_state', {})).signed_tx)
return { handler: channelOpen }
}
@@ -175,7 +181,6 @@ export async function channelOpen (channel, message, state) {
case 'deposit_locked':
case 'peer_disconnected':
case 'channel_reestablished':
- case 'fsm_up':
case 'open':
// TODO: Better handling of peer_disconnected event.
//
@@ -183,6 +188,9 @@ export async function channelOpen (channel, message, state) {
// are blocked until channel is reestablished.
emit(channel, message.params.data.event)
return { handler: channelOpen }
+ case 'fsm_up':
+ fsmId.set(channel, message.params.data.fsm_id)
+ return { handler: channelOpen }
case 'close_mutual':
return { handler: channelOpen }
case 'closing':
diff --git a/es/channel/index.js b/es/channel/index.js
index bc4b1de97b..cf6ca805d5 100644
--- a/es/channel/index.js
+++ b/es/channel/index.js
@@ -36,7 +36,8 @@ import {
send,
channelId,
call,
- disconnect as channelDisconnect
+ disconnect as channelDisconnect,
+ fsmId as channelFsmId
} from './internal'
import * as R from 'ramda'
@@ -136,6 +137,15 @@ function id () {
return channelId.get(this)
}
+/**
+ * Get channel's fsm id
+ *
+ * @return {String}
+ */
+function fsmId () {
+ return channelFsmId.get(this)
+}
+
/**
* Trigger a transfer update
*
@@ -783,6 +793,7 @@ const Channel = AsyncInit.compose({
state,
round,
id,
+ fsmId,
update,
poi,
balances,
diff --git a/es/channel/internal.js b/es/channel/internal.js
index 74a1ec1834..4d7062dadb 100644
--- a/es/channel/internal.js
+++ b/es/channel/internal.js
@@ -20,11 +20,7 @@ import { EventEmitter } from 'events'
import * as R from 'ramda'
import JSONBig from '../utils/json-big'
import { pascalToSnake } from '../utils/string'
-import {
- awaitingConnection,
- awaitingReconnection,
- channelOpen
-} from './handlers'
+import { awaitingConnection, awaitingReconnection, channelOpen } from './handlers'
// Send ping message every 10 seconds
const PING_TIMEOUT_MS = 10000
@@ -46,6 +42,7 @@ const channelId = new WeakMap()
const rpcCallbacks = new WeakMap()
const pingTimeoutId = new WeakMap()
const pongTimeoutId = new WeakMap()
+const fsmId = new WeakMap()
function channelURL (url, params) {
const paramString = R.join('&', R.values(R.mapObjIndexed((value, key) =>
@@ -268,5 +265,6 @@ export {
enqueueAction,
channelId,
call,
- disconnect
+ disconnect,
+ fsmId
}
diff --git a/test/integration/channel.js b/test/integration/channel.js
index 9d710a2f2c..71a5a072be 100644
--- a/test/integration/channel.js
+++ b/test/integration/channel.js
@@ -1065,19 +1065,35 @@ describe('Channel', function () {
result.accepted.should.be.true
const channelId = await initiatorCh.id()
const round = initiatorCh.round()
- initiatorCh.disconnect()
- const ch = await Channel.reconnect({
- ...sharedParams,
- role: 'initiator',
- port: 3006,
- sign: initiatorSign
- }, {
- channelId,
- round,
- role: 'initiator',
- pubkey: await initiator.address()
- })
- await waitForChannel(ch)
+ let ch
+ if (majorVersion > 5 || (majorVersion === 5 && minorVersion >= 2)) {
+ const fsmId = initiatorCh.fsmId()
+ initiatorCh.disconnect()
+ ch = await Channel({
+ url: sharedParams.url,
+ host: sharedParams.host,
+ port: 3006,
+ role: 'initiator',
+ existingChannelId: channelId,
+ existingFsmId: fsmId
+ })
+ await waitForChannel(ch)
+ ch.fsmId().should.equal(fsmId)
+ } else {
+ initiatorCh.disconnect()
+ ch = await Channel.reconnect({
+ ...sharedParams,
+ role: 'initiator',
+ port: 3006,
+ sign: initiatorSign
+ }, {
+ channelId,
+ round,
+ role: 'initiator',
+ pubkey: await initiator.address()
+ })
+ await waitForChannel(ch)
+ }
// TODO: why node doesn't return signed_tx when channel is reestablished?
// await new Promise((resolve) => {
// const checkRound = () => {
@@ -1089,6 +1105,7 @@ describe('Channel', function () {
// ch.on('stateChanged', checkRound)
// })
ch.state().should.eventually.be.fulfilled
+ await new Promise(resolve => setTimeout(resolve, 10 * 1000))
})
it('can post backchannel update', async () => {