Skip to content

Commit 178b662

Browse files
Merge pull request #823 from aeternity/fix/channel-5.2.0-compatibility
hotfix(Channel): 5.2.0 compatibility
2 parents d0a29ff + 6296133 commit 178b662

File tree

10 files changed

+138
-63
lines changed

10 files changed

+138
-63
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
TAG=v5.1.0-rc.1
2-
COMPILER_TAG=v4.0.0
1+
TAG=v5.2.0
2+
COMPILER_TAG=v4.1.0

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [6.1.3](https://github.com/aeternity/aepp-sdk-js/compare/6.1.2...6.1.3) (2019-12-11)
2+
3+
4+
### Bug Fixes
5+
6+
* **Channel:** 5.2.0 compatibility ([4be8eb8](https://github.com/aeternity/aepp-sdk-js/commit/4be8eb8))
7+
8+
9+
110
## [6.1.2](https://github.com/aeternity/aepp-sdk-js/compare/6.1.1...6.1.2) (2019-11-12)
211

312

docs/api/channel/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Channel from '@aeternity/aepp-sdk/es/channel/index'
1717
* [~state()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..state)`Promise.<Object>`
1818
* [~round()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..round)`Number`
1919
* [~id()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..id)`String`
20+
* [~fsmId()](#module_@aeternity/aepp-sdk/es/channel/index--Channel..fsmId)`String`
2021
* [~update(from, to, amount, sign, metadata)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..update)`Promise.<Object>`
2122
* [~poi(addresses)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..poi)`Promise.<String>`
2223
* [~balances(accounts)](#module_@aeternity/aepp-sdk/es/channel/index--Channel..balances)`Promise.<Object>`
@@ -151,6 +152,12 @@ it will return `null`.
151152
#### Channel~id() ⇒ `String`
152153
Get channel id
153154

155+
**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel)
156+
<a id="module_@aeternity/aepp-sdk/es/channel/index--Channel..fsmId"></a>
157+
158+
#### Channel~fsmId() ⇒ `String`
159+
Get channel's fsm id
160+
154161
**Kind**: inner method of [`Channel`](#exp_module_@aeternity/aepp-sdk/es/channel/index--Channel)
155162
<a id="module_@aeternity/aepp-sdk/es/channel/index--Channel..update"></a>
156163

docs/examples/node/aecontract.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ implementation directly in the SDK.
107107
108108
109109
```js
110-
Ae({ url: program.host, debug: program.debug, compilerUrl: program.compilerUrl, process }).then(ae => {
110+
Ae({ url: program.host, debug: program.debug, process }).then(ae => {
111111
return ae.contractCompile(code)
112112

113113
```

es/channel/handlers.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import {
2020
options,
2121
changeStatus,
2222
changeState,
23+
call,
2324
send,
2425
emit,
2526
channelId,
26-
disconnect
27+
disconnect,
28+
fsmId
2729
} from './internal'
2830
import { unpackTx, buildTx } from '../tx/builder'
2931

@@ -66,6 +68,10 @@ export function awaitingConnection (channel, message, state) {
6668
if (message.params.data.event === 'channel_reestablished') {
6769
return { handler: awaitingOpenConfirmation }
6870
}
71+
if (message.params.data.event === 'fsm_up') {
72+
fsmId.set(channel, message.params.data.fsm_id)
73+
return { handler: awaitingConnection }
74+
}
6975
return { handler: awaitingConnection }
7076
}
7177
if (message.method === 'channels.error') {
@@ -74,6 +80,17 @@ export function awaitingConnection (channel, message, state) {
7480
}
7581
}
7682

83+
export async function awaitingReconnection (channel, message, state) {
84+
if (message.method === 'channels.info') {
85+
if (message.params.data.event === 'fsm_up') {
86+
fsmId.set(channel, message.params.data.fsm_id)
87+
changeState(channel, (await call(channel, 'channels.get.offchain_state', {})).signed_tx)
88+
return { handler: channelOpen }
89+
}
90+
}
91+
return handleUnexpectedMessage(channel, message, state)
92+
}
93+
7794
export async function awaitingChannelCreateTx (channel, message, state) {
7895
const tag = {
7996
initiator: 'initiator_sign',
@@ -171,6 +188,9 @@ export async function channelOpen (channel, message, state) {
171188
// are blocked until channel is reestablished.
172189
emit(channel, message.params.data.event)
173190
return { handler: channelOpen }
191+
case 'fsm_up':
192+
fsmId.set(channel, message.params.data.fsm_id)
193+
return { handler: channelOpen }
174194
case 'close_mutual':
175195
return { handler: channelOpen }
176196
case 'closing':

es/channel/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import {
3636
send,
3737
channelId,
3838
call,
39-
disconnect as channelDisconnect
39+
disconnect as channelDisconnect,
40+
fsmId as channelFsmId
4041
} from './internal'
4142
import * as R from 'ramda'
4243

@@ -136,6 +137,15 @@ function id () {
136137
return channelId.get(this)
137138
}
138139

140+
/**
141+
* Get channel's fsm id
142+
*
143+
* @return {String}
144+
*/
145+
function fsmId () {
146+
return channelFsmId.get(this)
147+
}
148+
139149
/**
140150
* Trigger a transfer update
141151
*
@@ -783,6 +793,7 @@ const Channel = AsyncInit.compose({
783793
state,
784794
round,
785795
id,
796+
fsmId,
786797
update,
787798
poi,
788799
balances,

es/channel/internal.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { EventEmitter } from 'events'
2020
import * as R from 'ramda'
2121
import JSONBig from '../utils/json-big'
2222
import { pascalToSnake } from '../utils/string'
23-
import { awaitingConnection, channelClosed, channelOpen } from './handlers'
23+
import { awaitingConnection, awaitingReconnection, channelOpen } from './handlers'
2424

2525
// Send ping message every 10 seconds
2626
const PING_TIMEOUT_MS = 10000
@@ -42,6 +42,7 @@ const channelId = new WeakMap()
4242
const rpcCallbacks = new WeakMap()
4343
const pingTimeoutId = new WeakMap()
4444
const pongTimeoutId = new WeakMap()
45+
const fsmId = new WeakMap()
4546

4647
function channelURL (url, params) {
4748
const paramString = R.join('&', R.values(R.mapObjIndexed((value, key) =>
@@ -221,7 +222,11 @@ async function initialize (channel, channelOptions) {
221222
const wsUrl = channelURL(url, { ...params, protocol: 'json-rpc' })
222223

223224
options.set(channel, channelOptions)
224-
fsm.set(channel, { handler: params.reconnectTx ? channelClosed : awaitingConnection })
225+
if (params.existingFsmId) {
226+
fsm.set(channel, { handler: awaitingReconnection })
227+
} else {
228+
fsm.set(channel, { handler: awaitingConnection })
229+
}
225230
eventEmitters.set(channel, new EventEmitter())
226231
sequence.set(channel, 0)
227232
rpcCallbacks.set(channel, new Map())
@@ -260,5 +265,6 @@ export {
260265
enqueueAction,
261266
channelId,
262267
call,
263-
disconnect
268+
disconnect,
269+
fsmId
264270
}

package-lock.json

Lines changed: 14 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aeternity/aepp-sdk",
3-
"version": "6.1.2",
3+
"version": "6.1.3",
44
"description": "SDK for the æternity blockchain",
55
"main": "dist/aepp-sdk.js",
66
"browser": "dist/aepp-sdk.browser.js",
@@ -42,7 +42,7 @@
4242
"libsodium-wrappers-sumo": "0.7.6",
4343
"ramda": "^0.26.1",
4444
"rlp": "2.2.4",
45-
"serialize-javascript": "^2.0.0",
45+
"serialize-javascript": "^2.1.2",
4646
"sha.js": "^2.4.11",
4747
"tweetnacl": "^1.0.0",
4848
"tweetnacl-auth": "^1.0.1",

0 commit comments

Comments
 (0)