@@ -34,13 +34,14 @@ function encodeRlpTx (rlpBinary) {
34
34
async function appendSignature ( tx , signFn ) {
35
35
const { signatures, encodedTx } = unpackTx ( tx ) . tx
36
36
const result = await signFn ( encodeRlpTx ( encodedTx . rlpEncoded ) )
37
- if ( result ) {
37
+ if ( typeof result === 'string' ) {
38
38
const { tx : signedTx , txType } = unpackTx ( result )
39
39
return encodeRlpTx ( buildTx ( {
40
40
signatures : signatures . concat ( signedTx . signatures ) ,
41
41
encodedTx : signedTx . encodedTx . rlpEncoded
42
42
} , txType ) . rlpEncoded )
43
43
}
44
+ return result
44
45
}
45
46
46
47
function handleUnexpectedMessage ( channel , message , state ) {
@@ -209,8 +210,14 @@ export async function awaitingOffChainTx (channel, message, state) {
209
210
const signedTx = await appendSignature ( message . params . data . signed_tx , tx =>
210
211
sign ( tx , { updates : message . params . data . updates } )
211
212
)
212
- send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { signed_tx : signedTx } } )
213
- return { handler : awaitingOffChainUpdate , state }
213
+ if ( typeof signedTx === 'string' ) {
214
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { signed_tx : signedTx } } )
215
+ return { handler : awaitingOffChainUpdate , state }
216
+ }
217
+ if ( typeof signedTx === 'number' ) {
218
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { error : signedTx } } )
219
+ return { handler : awaitingOffChainTx , state }
220
+ }
214
221
}
215
222
if ( message . method === 'channels.error' ) {
216
223
state . reject ( new Error ( message . data . message ) )
@@ -227,6 +234,14 @@ export async function awaitingOffChainTx (channel, message, state) {
227
234
}
228
235
return { handler : channelOpen }
229
236
}
237
+ if ( message . method === 'channels.conflict' ) {
238
+ state . resolve ( {
239
+ accepted : false ,
240
+ errorCode : message . params . data . error_code ,
241
+ errorMessage : message . params . data . error_msg
242
+ } )
243
+ return { handler : channelOpen }
244
+ }
230
245
return handleUnexpectedMessage ( channel , message , state )
231
246
}
232
247
@@ -237,7 +252,11 @@ export function awaitingOffChainUpdate (channel, message, state) {
237
252
return { handler : channelOpen }
238
253
}
239
254
if ( message . method === 'channels.conflict' ) {
240
- state . resolve ( { accepted : false } )
255
+ state . resolve ( {
256
+ accepted : false ,
257
+ errorCode : message . params . data . error_code ,
258
+ errorMessage : message . params . data . error_msg
259
+ } )
241
260
return { handler : channelOpen }
242
261
}
243
262
if ( message . error ) {
@@ -262,10 +281,14 @@ export async function awaitingTxSignRequest (channel, message, state) {
262
281
const signedTx = await appendSignature ( message . params . data . signed_tx , tx =>
263
282
options . get ( channel ) . sign ( tag , tx , { updates : message . params . data . updates } )
264
283
)
265
- if ( signedTx ) {
284
+ if ( typeof signedTx === 'string' ) {
266
285
send ( channel , { jsonrpc : '2.0' , method : `channels.${ tag } ` , params : { signed_tx : signedTx } } )
267
286
return { handler : channelOpen }
268
287
}
288
+ if ( typeof signedTx === 'number' ) {
289
+ send ( channel , { jsonrpc : '2.0' , method : `channels.${ tag } ` , params : { error : signedTx } } )
290
+ return { handler : awaitingUpdateConflict }
291
+ }
269
292
}
270
293
// soft-reject via competing update
271
294
send ( channel , {
@@ -338,8 +361,14 @@ export async function awaitingWithdrawTx (channel, message, state) {
338
361
const signedTx = await appendSignature ( message . params . data . signed_tx , tx =>
339
362
sign ( tx , { updates : message . params . data . updates } )
340
363
)
341
- send ( channel , { jsonrpc : '2.0' , method : 'channels.withdraw_tx' , params : { signed_tx : signedTx } } )
342
- return { handler : awaitingWithdrawCompletion , state }
364
+ if ( typeof signedTx === 'string' ) {
365
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.withdraw_tx' , params : { signed_tx : signedTx } } )
366
+ return { handler : awaitingWithdrawCompletion , state }
367
+ }
368
+ if ( typeof signedTx === 'number' ) {
369
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.withdraw_tx' , params : { error : signedTx } } )
370
+ return { handler : awaitingWithdrawCompletion , state }
371
+ }
343
372
}
344
373
return handleUnexpectedMessage ( channel , message , state )
345
374
}
@@ -369,7 +398,11 @@ export function awaitingWithdrawCompletion (channel, message, state) {
369
398
return { handler : channelOpen }
370
399
}
371
400
if ( message . method === 'channels.conflict' ) {
372
- state . resolve ( { accepted : false } )
401
+ state . resolve ( {
402
+ accepted : false ,
403
+ errorCode : message . params . data . error_code ,
404
+ errorMessage : message . params . data . error_msg
405
+ } )
373
406
return { handler : channelOpen }
374
407
}
375
408
return handleUnexpectedMessage ( channel , message , state )
@@ -386,8 +419,14 @@ export async function awaitingDepositTx (channel, message, state) {
386
419
const signedTx = await appendSignature ( message . params . data . signed_tx , tx =>
387
420
sign ( tx , { updates : message . params . data . updates } )
388
421
)
389
- send ( channel , { jsonrpc : '2.0' , method : 'channels.deposit_tx' , params : { signed_tx : signedTx } } )
390
- return { handler : awaitingDepositCompletion , state }
422
+ if ( typeof signedTx === 'string' ) {
423
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.deposit_tx' , params : { signed_tx : signedTx } } )
424
+ return { handler : awaitingDepositCompletion , state }
425
+ }
426
+ if ( typeof signedTx === 'number' ) {
427
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.deposit_tx' , params : { error : signedTx } } )
428
+ return { handler : awaitingDepositCompletion , state }
429
+ }
391
430
}
392
431
return handleUnexpectedMessage ( channel , message , state )
393
432
}
@@ -417,7 +456,11 @@ export function awaitingDepositCompletion (channel, message, state) {
417
456
return { handler : channelOpen }
418
457
}
419
458
if ( message . method === 'channels.conflict' ) {
420
- state . resolve ( { accepted : false } )
459
+ state . resolve ( {
460
+ accepted : false ,
461
+ errorCode : message . params . data . error_code ,
462
+ errorMessage : message . params . data . error_msg
463
+ } )
421
464
return { handler : channelOpen }
422
465
}
423
466
return handleUnexpectedMessage ( channel , message , state )
@@ -431,8 +474,14 @@ export async function awaitingNewContractTx (channel, message, state) {
431
474
return { handler : awaitingNewContractCompletion , state }
432
475
}
433
476
const signedTx = await appendSignature ( message . params . data . signed_tx , tx => state . sign ( tx ) )
434
- send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { signed_tx : signedTx } } )
435
- return { handler : awaitingNewContractCompletion , state }
477
+ if ( typeof signedTx === 'string' ) {
478
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { signed_tx : signedTx } } )
479
+ return { handler : awaitingNewContractCompletion , state }
480
+ }
481
+ if ( typeof signedTx === 'number' ) {
482
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { error : signedTx } } )
483
+ return { handler : awaitingNewContractCompletion , state }
484
+ }
436
485
}
437
486
return handleUnexpectedMessage ( channel , message , state )
438
487
}
@@ -453,7 +502,11 @@ export function awaitingNewContractCompletion (channel, message, state) {
453
502
return { handler : channelOpen }
454
503
}
455
504
if ( message . method === 'channels.conflict' ) {
456
- state . resolve ( { accepted : false } )
505
+ state . resolve ( {
506
+ accepted : false ,
507
+ errorCode : message . params . data . error_code ,
508
+ errorMessage : message . params . data . error_msg
509
+ } )
457
510
return { handler : channelOpen }
458
511
}
459
512
return handleUnexpectedMessage ( channel , message , state )
@@ -467,8 +520,14 @@ export async function awaitingCallContractUpdateTx (channel, message, state) {
467
520
return { handler : awaitingCallContractCompletion , state }
468
521
}
469
522
const signedTx = await appendSignature ( message . params . data . signed_tx , tx => state . sign ( tx ) )
470
- send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { signed_tx : signedTx } } )
471
- return { handler : awaitingCallContractCompletion , state }
523
+ if ( typeof signedTx === 'string' ) {
524
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { signed_tx : signedTx } } )
525
+ return { handler : awaitingCallContractCompletion , state }
526
+ }
527
+ if ( typeof signedTx === 'number' ) {
528
+ send ( channel , { jsonrpc : '2.0' , method : 'channels.update' , params : { error : signedTx } } )
529
+ return { handler : awaitingCallContractCompletion , state }
530
+ }
472
531
}
473
532
return handleUnexpectedMessage ( channel , message , state )
474
533
}
@@ -480,7 +539,11 @@ export function awaitingCallContractCompletion (channel, message, state) {
480
539
return { handler : channelOpen }
481
540
}
482
541
if ( message . method === 'channels.conflict' ) {
483
- state . resolve ( { accepted : false } )
542
+ state . resolve ( {
543
+ accepted : false ,
544
+ errorCode : message . params . data . error_code ,
545
+ errorMessage : message . params . data . error_msg
546
+ } )
484
547
return { handler : channelOpen }
485
548
}
486
549
return handleUnexpectedMessage ( channel , message , state )
0 commit comments