@aeternity/aepp-sdk 12.0.0 → 12.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
package/src/channel/handlers.ts
CHANGED
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/* eslint-disable consistent-return */
|
|
18
|
+
/* eslint-disable default-case */
|
|
19
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
20
|
+
import { generateKeyPair, encodeContractAddress } from '../utils/crypto';
|
|
19
21
|
import {
|
|
20
22
|
ChannelState,
|
|
21
23
|
options,
|
|
@@ -29,187 +31,198 @@ import {
|
|
|
29
31
|
fsmId,
|
|
30
32
|
ChannelMessage,
|
|
31
33
|
ChannelFsm,
|
|
32
|
-
SignTx
|
|
33
|
-
} from './internal'
|
|
34
|
-
import { unpackTx, buildTx } from '../tx/builder'
|
|
35
|
-
import { encode } from '../
|
|
36
|
-
import { EncodedData } from '../utils/encoder'
|
|
34
|
+
SignTx,
|
|
35
|
+
} from './internal';
|
|
36
|
+
import { unpackTx, buildTx } from '../tx/builder';
|
|
37
|
+
import { encode, Encoded, Encoding } from '../utils/encoder';
|
|
37
38
|
import {
|
|
38
39
|
IllegalArgumentError,
|
|
39
40
|
InsufficientBalanceError,
|
|
40
41
|
ChannelConnectionError,
|
|
41
|
-
UnexpectedChannelMessageError
|
|
42
|
-
} from '../utils/errors'
|
|
43
|
-
import Channel from '.'
|
|
44
|
-
import {
|
|
42
|
+
UnexpectedChannelMessageError,
|
|
43
|
+
} from '../utils/errors';
|
|
44
|
+
import type Channel from '.';
|
|
45
|
+
import { Tag } from '../tx/builder/constants';
|
|
45
46
|
|
|
46
|
-
export async function appendSignature
|
|
47
|
-
tx:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
47
|
+
export async function appendSignature(
|
|
48
|
+
tx: Encoded.Transaction,
|
|
49
|
+
signFn: SignTx,
|
|
50
|
+
): Promise<Encoded.Transaction | number | null> {
|
|
51
|
+
const { signatures, encodedTx } = unpackTx(tx, Tag.SignedTx).tx;
|
|
52
|
+
const result = await signFn(encode(encodedTx.rlpEncoded, Encoding.Transaction));
|
|
51
53
|
if (typeof result === 'string') {
|
|
52
|
-
const { tx: signedTx } = unpackTx(result,
|
|
54
|
+
const { tx: signedTx } = unpackTx(result, Tag.SignedTx);
|
|
53
55
|
return buildTx({
|
|
54
56
|
signatures: signatures.concat(signedTx.signatures),
|
|
55
|
-
encodedTx: signedTx.encodedTx.rlpEncoded
|
|
56
|
-
},
|
|
57
|
+
encodedTx: signedTx.encodedTx.rlpEncoded,
|
|
58
|
+
}, Tag.SignedTx).tx;
|
|
57
59
|
}
|
|
58
|
-
return result
|
|
60
|
+
return result;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
function handleUnexpectedMessage
|
|
62
|
-
_channel: Channel,
|
|
63
|
+
function handleUnexpectedMessage(
|
|
64
|
+
_channel: Channel,
|
|
65
|
+
message: ChannelMessage,
|
|
66
|
+
state: ChannelState,
|
|
63
67
|
): ChannelFsm {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
return { handler: channelOpen }
|
|
68
|
+
state?.reject?.(Object.assign(
|
|
69
|
+
new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`),
|
|
70
|
+
{ wsMessage: message },
|
|
71
|
+
));
|
|
72
|
+
return { handler: channelOpen };
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
export function awaitingConnection
|
|
74
|
-
channel: Channel,
|
|
75
|
+
export function awaitingConnection(
|
|
76
|
+
channel: Channel,
|
|
77
|
+
message: ChannelMessage,
|
|
75
78
|
): ChannelFsm | undefined {
|
|
76
79
|
if (message.method === 'channels.info') {
|
|
77
|
-
const channelInfoStatus: string = message.params.data.event
|
|
80
|
+
const channelInfoStatus: string = message.params.data.event;
|
|
78
81
|
if (['channel_accept', 'funding_created'].includes(channelInfoStatus)) {
|
|
79
82
|
changeStatus(channel, {
|
|
80
83
|
channel_accept: 'accepted',
|
|
81
|
-
funding_created: 'halfSigned'
|
|
82
|
-
}[channelInfoStatus as 'channel_accept' | 'funding_created'])
|
|
83
|
-
return { handler: awaitingChannelCreateTx }
|
|
84
|
+
funding_created: 'halfSigned',
|
|
85
|
+
}[channelInfoStatus as 'channel_accept' | 'funding_created']);
|
|
86
|
+
return { handler: awaitingChannelCreateTx };
|
|
84
87
|
}
|
|
85
88
|
if (message.params.data.event === 'channel_reestablished') {
|
|
86
|
-
return { handler: awaitingOpenConfirmation }
|
|
89
|
+
return { handler: awaitingOpenConfirmation };
|
|
87
90
|
}
|
|
88
91
|
if (message.params.data.event === 'fsm_up') {
|
|
89
|
-
fsmId.set(channel, message.params.data.fsm_id)
|
|
90
|
-
return { handler: awaitingConnection }
|
|
92
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
93
|
+
return { handler: awaitingConnection };
|
|
91
94
|
}
|
|
92
|
-
return { handler: awaitingConnection }
|
|
95
|
+
return { handler: awaitingConnection };
|
|
93
96
|
}
|
|
94
97
|
if (message.method === 'channels.error') {
|
|
95
|
-
emit(channel, 'error', new ChannelConnectionError(message?.payload?.message))
|
|
96
|
-
return { handler: channelClosed }
|
|
98
|
+
emit(channel, 'error', new ChannelConnectionError(message?.payload?.message));
|
|
99
|
+
return { handler: channelClosed };
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
export async function awaitingReconnection
|
|
101
|
-
channel: Channel,
|
|
103
|
+
export async function awaitingReconnection(
|
|
104
|
+
channel: Channel,
|
|
105
|
+
message: ChannelMessage,
|
|
106
|
+
state: ChannelState,
|
|
102
107
|
): Promise<ChannelFsm> {
|
|
103
108
|
if (message.method === 'channels.info') {
|
|
104
109
|
if (message.params.data.event === 'fsm_up') {
|
|
105
|
-
fsmId.set(channel, message.params.data.fsm_id)
|
|
106
|
-
changeState(channel, (await call(channel, 'channels.get.offchain_state', {})).signed_tx)
|
|
107
|
-
return { handler: channelOpen }
|
|
110
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
111
|
+
changeState(channel, (await call(channel, 'channels.get.offchain_state', {})).signed_tx);
|
|
112
|
+
return { handler: channelOpen };
|
|
108
113
|
}
|
|
109
114
|
}
|
|
110
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
115
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
111
116
|
}
|
|
112
117
|
|
|
113
|
-
export async function awaitingChannelCreateTx
|
|
114
|
-
channel: Channel,
|
|
118
|
+
export async function awaitingChannelCreateTx(
|
|
119
|
+
channel: Channel,
|
|
120
|
+
message: ChannelMessage,
|
|
115
121
|
): Promise<ChannelFsm | undefined> {
|
|
116
|
-
const channelOptions = options.get(channel)
|
|
122
|
+
const channelOptions = options.get(channel);
|
|
117
123
|
if (channelOptions != null) {
|
|
118
124
|
const tag = {
|
|
119
125
|
initiator: 'initiator_sign',
|
|
120
|
-
responder: 'responder_sign'
|
|
121
|
-
}[channelOptions.role]
|
|
126
|
+
responder: 'responder_sign',
|
|
127
|
+
}[channelOptions.role];
|
|
122
128
|
if (message.method === `channels.sign.${tag}`) {
|
|
123
129
|
if (message.params.data.tx != null) {
|
|
124
|
-
const signedTx = await channelOptions.sign(tag, message.params.data.tx)
|
|
125
|
-
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } })
|
|
126
|
-
return { handler: awaitingOnChainTx }
|
|
130
|
+
const signedTx = await channelOptions.sign(tag, message.params.data.tx);
|
|
131
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } });
|
|
132
|
+
return { handler: awaitingOnChainTx };
|
|
127
133
|
}
|
|
128
134
|
const signedTx = await appendSignature(
|
|
129
|
-
message.params.data.signed_tx,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
message.params.data.signed_tx,
|
|
136
|
+
async (tx) => channelOptions.sign(tag, tx),
|
|
137
|
+
);
|
|
138
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } });
|
|
139
|
+
return { handler: awaitingOnChainTx };
|
|
133
140
|
}
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
|
|
137
|
-
export function awaitingOnChainTx
|
|
138
|
-
channel: Channel,
|
|
144
|
+
export function awaitingOnChainTx(
|
|
145
|
+
channel: Channel,
|
|
146
|
+
message: ChannelMessage,
|
|
139
147
|
): ChannelFsm | undefined {
|
|
140
|
-
const channelOptions = options.get(channel)
|
|
148
|
+
const channelOptions = options.get(channel);
|
|
141
149
|
if (channelOptions != null) {
|
|
142
150
|
if (message.method === 'channels.on_chain_tx') {
|
|
143
151
|
if (
|
|
144
|
-
message.params.data.info === 'funding_signed'
|
|
145
|
-
channelOptions.role === 'initiator'
|
|
152
|
+
message.params.data.info === 'funding_signed'
|
|
153
|
+
&& channelOptions.role === 'initiator'
|
|
146
154
|
) {
|
|
147
|
-
return { handler: awaitingBlockInclusion }
|
|
155
|
+
return { handler: awaitingBlockInclusion };
|
|
148
156
|
}
|
|
149
157
|
if (
|
|
150
|
-
message.params.data.info === 'funding_created'
|
|
151
|
-
channelOptions.role === 'responder'
|
|
158
|
+
message.params.data.info === 'funding_created'
|
|
159
|
+
&& channelOptions.role === 'responder'
|
|
152
160
|
) {
|
|
153
|
-
return { handler: awaitingBlockInclusion }
|
|
161
|
+
return { handler: awaitingBlockInclusion };
|
|
154
162
|
}
|
|
155
163
|
}
|
|
156
164
|
if (
|
|
157
|
-
message.method === 'channels.info'
|
|
158
|
-
message.params.data.event === 'funding_signed'
|
|
159
|
-
channelOptions.role === 'initiator'
|
|
165
|
+
message.method === 'channels.info'
|
|
166
|
+
&& message.params.data.event === 'funding_signed'
|
|
167
|
+
&& channelOptions.role === 'initiator'
|
|
160
168
|
) {
|
|
161
|
-
channelId.set(channel, message.params.channel_id)
|
|
162
|
-
changeStatus(channel, 'signed')
|
|
163
|
-
return { handler: awaitingOnChainTx }
|
|
169
|
+
channelId.set(channel, message.params.channel_id);
|
|
170
|
+
changeStatus(channel, 'signed');
|
|
171
|
+
return { handler: awaitingOnChainTx };
|
|
164
172
|
}
|
|
165
173
|
}
|
|
166
174
|
}
|
|
167
175
|
|
|
168
|
-
export function awaitingBlockInclusion
|
|
169
|
-
channel: Channel,
|
|
176
|
+
export function awaitingBlockInclusion(
|
|
177
|
+
channel: Channel,
|
|
178
|
+
message: ChannelMessage,
|
|
170
179
|
): ChannelFsm | undefined {
|
|
171
180
|
if (message.method === 'channels.info') {
|
|
172
181
|
const handlers: {
|
|
173
|
-
[key: string]: (channel: Channel, message: ChannelMessage) => ChannelFsm | undefined
|
|
182
|
+
[key: string]: (channel: Channel, message: ChannelMessage) => ChannelFsm | undefined;
|
|
174
183
|
} = {
|
|
175
184
|
funding_created: awaitingBlockInclusion,
|
|
176
185
|
own_funding_locked: awaitingBlockInclusion,
|
|
177
|
-
funding_locked: awaitingOpenConfirmation
|
|
178
|
-
}
|
|
179
|
-
const handler = handlers[message.params.data.event as string]
|
|
186
|
+
funding_locked: awaitingOpenConfirmation,
|
|
187
|
+
};
|
|
188
|
+
const handler = handlers[message.params.data.event as string];
|
|
180
189
|
if (handler != null) {
|
|
181
|
-
return { handler }
|
|
190
|
+
return { handler };
|
|
182
191
|
}
|
|
183
192
|
}
|
|
184
193
|
if (message.method === 'channels.on_chain_tx') {
|
|
185
194
|
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
186
195
|
info: message.params.data.info,
|
|
187
|
-
type: message.params.data.type
|
|
188
|
-
})
|
|
189
|
-
return { handler: awaitingBlockInclusion }
|
|
196
|
+
type: message.params.data.type,
|
|
197
|
+
});
|
|
198
|
+
return { handler: awaitingBlockInclusion };
|
|
190
199
|
}
|
|
191
200
|
}
|
|
192
201
|
|
|
193
|
-
export function awaitingOpenConfirmation
|
|
194
|
-
channel: Channel,
|
|
202
|
+
export function awaitingOpenConfirmation(
|
|
203
|
+
channel: Channel,
|
|
204
|
+
message: ChannelMessage,
|
|
195
205
|
): ChannelFsm | undefined {
|
|
196
206
|
if (message.method === 'channels.info' && message.params.data.event === 'open') {
|
|
197
|
-
channelId.set(channel, message.params.channel_id)
|
|
198
|
-
return { handler: awaitingInitialState }
|
|
207
|
+
channelId.set(channel, message.params.channel_id);
|
|
208
|
+
return { handler: awaitingInitialState };
|
|
199
209
|
}
|
|
200
210
|
}
|
|
201
211
|
|
|
202
|
-
export function awaitingInitialState
|
|
203
|
-
channel: Channel,
|
|
212
|
+
export function awaitingInitialState(
|
|
213
|
+
channel: Channel,
|
|
214
|
+
message: ChannelMessage,
|
|
204
215
|
): ChannelFsm | undefined {
|
|
205
216
|
if (message.method === 'channels.update') {
|
|
206
|
-
changeState(channel, message.params.data.state)
|
|
207
|
-
return { handler: channelOpen }
|
|
217
|
+
changeState(channel, message.params.data.state);
|
|
218
|
+
return { handler: channelOpen };
|
|
208
219
|
}
|
|
209
220
|
}
|
|
210
221
|
|
|
211
|
-
export async function channelOpen
|
|
212
|
-
channel: Channel,
|
|
222
|
+
export async function channelOpen(
|
|
223
|
+
channel: Channel,
|
|
224
|
+
message: ChannelMessage,
|
|
225
|
+
state: ChannelState,
|
|
213
226
|
): Promise<ChannelFsm | undefined> {
|
|
214
227
|
switch (message.method) {
|
|
215
228
|
case 'channels.info':
|
|
@@ -217,7 +230,7 @@ export async function channelOpen (
|
|
|
217
230
|
case 'update':
|
|
218
231
|
case 'withdraw_created':
|
|
219
232
|
case 'deposit_created':
|
|
220
|
-
return { handler: awaitingTxSignRequest }
|
|
233
|
+
return { handler: awaitingTxSignRequest };
|
|
221
234
|
case 'own_withdraw_locked':
|
|
222
235
|
case 'withdraw_locked':
|
|
223
236
|
case 'own_deposit_locked':
|
|
@@ -229,156 +242,163 @@ export async function channelOpen (
|
|
|
229
242
|
//
|
|
230
243
|
// We should enter intermediate state where offchain transactions
|
|
231
244
|
// are blocked until channel is reestablished.
|
|
232
|
-
emit(channel, message.params.data.event)
|
|
233
|
-
return { handler: channelOpen }
|
|
245
|
+
emit(channel, message.params.data.event);
|
|
246
|
+
return { handler: channelOpen };
|
|
234
247
|
case 'fsm_up':
|
|
235
|
-
fsmId.set(channel, message.params.data.fsm_id)
|
|
236
|
-
return { handler: channelOpen }
|
|
248
|
+
fsmId.set(channel, message.params.data.fsm_id);
|
|
249
|
+
return { handler: channelOpen };
|
|
237
250
|
case 'timeout':
|
|
238
251
|
case 'close_mutual':
|
|
239
|
-
return { handler: channelOpen }
|
|
252
|
+
return { handler: channelOpen };
|
|
240
253
|
case 'closing':
|
|
241
|
-
changeStatus(channel, 'closing')
|
|
242
|
-
return { handler: channelOpen }
|
|
254
|
+
changeStatus(channel, 'closing');
|
|
255
|
+
return { handler: channelOpen };
|
|
243
256
|
case 'closed_confirmed':
|
|
244
|
-
changeStatus(channel, 'closed')
|
|
245
|
-
return { handler: channelClosed }
|
|
257
|
+
changeStatus(channel, 'closed');
|
|
258
|
+
return { handler: channelClosed };
|
|
246
259
|
case 'died':
|
|
247
|
-
changeStatus(channel, 'died')
|
|
248
|
-
return { handler: channelClosed }
|
|
260
|
+
changeStatus(channel, 'died');
|
|
261
|
+
return { handler: channelClosed };
|
|
249
262
|
case 'shutdown':
|
|
250
|
-
return { handler: channelOpen }
|
|
263
|
+
return { handler: channelOpen };
|
|
251
264
|
}
|
|
252
|
-
break
|
|
265
|
+
break;
|
|
253
266
|
case 'channels.on_chain_tx':
|
|
254
267
|
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
255
268
|
info: message.params.data.info,
|
|
256
|
-
type: message.params.data.type
|
|
257
|
-
})
|
|
258
|
-
return { handler: channelOpen }
|
|
269
|
+
type: message.params.data.type,
|
|
270
|
+
});
|
|
271
|
+
return { handler: channelOpen };
|
|
259
272
|
case 'channels.leave':
|
|
260
273
|
// TODO: emit event
|
|
261
|
-
return { handler: channelOpen }
|
|
274
|
+
return { handler: channelOpen };
|
|
262
275
|
case 'channels.update':
|
|
263
|
-
changeState(channel, message.params.data.state)
|
|
264
|
-
return { handler: channelOpen }
|
|
276
|
+
changeState(channel, message.params.data.state);
|
|
277
|
+
return { handler: channelOpen };
|
|
265
278
|
case 'channels.sign.shutdown_sign_ack':
|
|
266
|
-
return
|
|
279
|
+
return awaitingTxSignRequest(channel, message, state);
|
|
267
280
|
}
|
|
268
281
|
}
|
|
269
282
|
channelOpen.enter = (channel: Channel) => {
|
|
270
|
-
changeStatus(channel, 'open')
|
|
271
|
-
}
|
|
283
|
+
changeStatus(channel, 'open');
|
|
284
|
+
};
|
|
272
285
|
|
|
273
|
-
export async function awaitingOffChainTx
|
|
274
|
-
channel: Channel,
|
|
286
|
+
export async function awaitingOffChainTx(
|
|
287
|
+
channel: Channel,
|
|
288
|
+
message: ChannelMessage,
|
|
289
|
+
state: ChannelState,
|
|
275
290
|
): Promise<ChannelFsm> {
|
|
276
291
|
if (message.method === 'channels.sign.update') {
|
|
277
|
-
const { sign } = state
|
|
292
|
+
const { sign } = state;
|
|
278
293
|
if (message.params.data.tx != null) {
|
|
279
|
-
const signedTx =
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
)
|
|
294
|
+
const signedTx = await sign(message.params.data.tx, { updates: message.params.data.updates });
|
|
295
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } });
|
|
296
|
+
return { handler: awaitingOffChainUpdate, state };
|
|
297
|
+
}
|
|
298
|
+
const signedTx = await appendSignature(
|
|
299
|
+
message.params.data.signed_tx,
|
|
300
|
+
async (tx) => sign(tx, { updates: message.params.data.updates }),
|
|
301
|
+
);
|
|
287
302
|
if (typeof signedTx === 'string') {
|
|
288
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } })
|
|
289
|
-
return { handler: awaitingOffChainUpdate, state }
|
|
303
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } });
|
|
304
|
+
return { handler: awaitingOffChainUpdate, state };
|
|
290
305
|
}
|
|
291
306
|
if (typeof signedTx === 'number') {
|
|
292
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } })
|
|
293
|
-
return { handler: awaitingOffChainTx, state }
|
|
307
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } });
|
|
308
|
+
return { handler: awaitingOffChainTx, state };
|
|
294
309
|
}
|
|
295
310
|
}
|
|
296
311
|
if (message.method === 'channels.error') {
|
|
297
|
-
state.reject(new ChannelConnectionError(message.data.message))
|
|
298
|
-
return { handler: channelOpen }
|
|
312
|
+
state.reject(new ChannelConnectionError(message.data.message));
|
|
313
|
+
return { handler: channelOpen };
|
|
299
314
|
}
|
|
300
315
|
if (message.error != null) {
|
|
301
|
-
const { data } = message.error ?? { data: [] }
|
|
302
|
-
if (data.find(i => i.code === 1001) != null) {
|
|
303
|
-
state.reject(new InsufficientBalanceError('Insufficient balance'))
|
|
304
|
-
} else if (data.find(i => i.code === 1002) != null) {
|
|
305
|
-
state.reject(new IllegalArgumentError('Amount cannot be negative'))
|
|
316
|
+
const { data } = message.error ?? { data: [] };
|
|
317
|
+
if (data.find((i) => i.code === 1001) != null) {
|
|
318
|
+
state.reject(new InsufficientBalanceError('Insufficient balance'));
|
|
319
|
+
} else if (data.find((i) => i.code === 1002) != null) {
|
|
320
|
+
state.reject(new IllegalArgumentError('Amount cannot be negative'));
|
|
306
321
|
} else {
|
|
307
|
-
state.reject(new ChannelConnectionError(message.error.message))
|
|
322
|
+
state.reject(new ChannelConnectionError(message.error.message));
|
|
308
323
|
}
|
|
309
|
-
return { handler: channelOpen }
|
|
324
|
+
return { handler: channelOpen };
|
|
310
325
|
}
|
|
311
326
|
if (message.method === 'channels.conflict') {
|
|
312
327
|
state.resolve({
|
|
313
328
|
accepted: false,
|
|
314
329
|
errorCode: message.params.data.error_code,
|
|
315
|
-
errorMessage: message.params.data.error_msg
|
|
316
|
-
})
|
|
317
|
-
return { handler: channelOpen }
|
|
330
|
+
errorMessage: message.params.data.error_msg,
|
|
331
|
+
});
|
|
332
|
+
return { handler: channelOpen };
|
|
318
333
|
}
|
|
319
334
|
if (message.method === 'channels.info') {
|
|
320
335
|
if (message.params.data.event === 'aborted_update') {
|
|
321
|
-
state.resolve({ accepted: false })
|
|
322
|
-
return { handler: channelOpen }
|
|
336
|
+
state.resolve({ accepted: false });
|
|
337
|
+
return { handler: channelOpen };
|
|
323
338
|
}
|
|
324
339
|
}
|
|
325
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
340
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
326
341
|
}
|
|
327
342
|
|
|
328
|
-
export function awaitingOffChainUpdate
|
|
329
|
-
channel: Channel,
|
|
343
|
+
export function awaitingOffChainUpdate(
|
|
344
|
+
channel: Channel,
|
|
345
|
+
message: ChannelMessage,
|
|
346
|
+
state: ChannelState,
|
|
330
347
|
): ChannelFsm | undefined {
|
|
331
348
|
if (message.method === 'channels.update') {
|
|
332
|
-
changeState(channel, message.params.data.state)
|
|
333
|
-
state.resolve({ accepted: true, signedTx: message.params.data.state })
|
|
334
|
-
return { handler: channelOpen }
|
|
349
|
+
changeState(channel, message.params.data.state);
|
|
350
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
351
|
+
return { handler: channelOpen };
|
|
335
352
|
}
|
|
336
353
|
if (message.method === 'channels.conflict') {
|
|
337
354
|
state.resolve({
|
|
338
355
|
accepted: false,
|
|
339
356
|
errorCode: message.params.data.error_code,
|
|
340
|
-
errorMessage: message.params.data.error_msg
|
|
341
|
-
})
|
|
342
|
-
return { handler: channelOpen }
|
|
357
|
+
errorMessage: message.params.data.error_msg,
|
|
358
|
+
});
|
|
359
|
+
return { handler: channelOpen };
|
|
343
360
|
}
|
|
344
361
|
if (message.method === 'channels.info') {
|
|
345
362
|
if (message.params.data.event === 'aborted_update') {
|
|
346
|
-
state.resolve({ accepted: false })
|
|
347
|
-
return { handler: channelOpen }
|
|
363
|
+
state.resolve({ accepted: false });
|
|
364
|
+
return { handler: channelOpen };
|
|
348
365
|
}
|
|
349
366
|
}
|
|
350
367
|
if (message.error != null) {
|
|
351
|
-
state.reject(new ChannelConnectionError(message.error.message))
|
|
352
|
-
return { handler: channelOpen }
|
|
368
|
+
state.reject(new ChannelConnectionError(message.error.message));
|
|
369
|
+
return { handler: channelOpen };
|
|
353
370
|
}
|
|
354
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
371
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
355
372
|
}
|
|
356
373
|
|
|
357
|
-
export async function awaitingTxSignRequest
|
|
358
|
-
channel: Channel,
|
|
374
|
+
export async function awaitingTxSignRequest(
|
|
375
|
+
channel: Channel,
|
|
376
|
+
message: ChannelMessage,
|
|
377
|
+
state: ChannelState,
|
|
359
378
|
): Promise<ChannelFsm | undefined> {
|
|
360
|
-
const [, tag] = message.method.match(/^channels\.sign\.([^.]+)$/) ?? []
|
|
361
|
-
const channelOptions = options.get(channel)
|
|
379
|
+
const [, tag] = message.method.match(/^channels\.sign\.([^.]+)$/) ?? [];
|
|
380
|
+
const channelOptions = options.get(channel);
|
|
362
381
|
if (tag != null && (channelOptions != null)) {
|
|
363
382
|
if (message.params.data.tx != null) {
|
|
364
383
|
const signedTx = await channelOptions.sign(tag, message.params.data.tx, {
|
|
365
|
-
updates: message.params.data.updates
|
|
366
|
-
})
|
|
384
|
+
updates: message.params.data.updates,
|
|
385
|
+
});
|
|
367
386
|
if (signedTx != null) {
|
|
368
|
-
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } })
|
|
369
|
-
return { handler: channelOpen }
|
|
387
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } });
|
|
388
|
+
return { handler: channelOpen };
|
|
370
389
|
}
|
|
371
390
|
} else {
|
|
372
|
-
const signedTx = await appendSignature(
|
|
373
|
-
|
|
374
|
-
|
|
391
|
+
const signedTx = await appendSignature(
|
|
392
|
+
message.params.data.signed_tx,
|
|
393
|
+
async (tx) => channelOptions.sign(tag, tx, { updates: message.params.data.updates }),
|
|
394
|
+
);
|
|
375
395
|
if (typeof signedTx === 'string') {
|
|
376
|
-
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } })
|
|
377
|
-
return { handler: channelOpen }
|
|
396
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } });
|
|
397
|
+
return { handler: channelOpen };
|
|
378
398
|
}
|
|
379
399
|
if (typeof signedTx === 'number') {
|
|
380
|
-
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { error: signedTx } })
|
|
381
|
-
return { handler: awaitingUpdateConflict, state }
|
|
400
|
+
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { error: signedTx } });
|
|
401
|
+
return { handler: awaitingUpdateConflict, state };
|
|
382
402
|
}
|
|
383
403
|
}
|
|
384
404
|
// soft-reject via competing update
|
|
@@ -388,254 +408,271 @@ export async function awaitingTxSignRequest (
|
|
|
388
408
|
params: {
|
|
389
409
|
from: generateKeyPair().publicKey,
|
|
390
410
|
to: generateKeyPair().publicKey,
|
|
391
|
-
amount: 1
|
|
392
|
-
}
|
|
393
|
-
})
|
|
394
|
-
return { handler: awaitingUpdateConflict, state }
|
|
411
|
+
amount: 1,
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
return { handler: awaitingUpdateConflict, state };
|
|
395
415
|
}
|
|
396
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
416
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
397
417
|
}
|
|
398
418
|
|
|
399
|
-
export function awaitingUpdateConflict
|
|
400
|
-
channel: Channel,
|
|
419
|
+
export function awaitingUpdateConflict(
|
|
420
|
+
channel: Channel,
|
|
421
|
+
message: ChannelMessage,
|
|
422
|
+
state: ChannelState,
|
|
401
423
|
): ChannelFsm {
|
|
402
424
|
if (message.error != null) {
|
|
403
|
-
return { handler: awaitingUpdateConflict, state }
|
|
425
|
+
return { handler: awaitingUpdateConflict, state };
|
|
404
426
|
}
|
|
405
427
|
if (message.method === 'channels.conflict') {
|
|
406
|
-
return { handler: channelOpen }
|
|
428
|
+
return { handler: channelOpen };
|
|
407
429
|
}
|
|
408
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
430
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
409
431
|
}
|
|
410
432
|
|
|
411
|
-
export async function awaitingShutdownTx
|
|
412
|
-
channel: Channel,
|
|
433
|
+
export async function awaitingShutdownTx(
|
|
434
|
+
channel: Channel,
|
|
435
|
+
message: ChannelMessage,
|
|
436
|
+
state: ChannelState,
|
|
413
437
|
): Promise<ChannelFsm | undefined> {
|
|
414
438
|
if (message.method === 'channels.sign.shutdown_sign') {
|
|
415
439
|
if (message.params.data.tx != null) {
|
|
416
|
-
const signedTx = await state.sign(message.params.data.tx)
|
|
417
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { tx: signedTx } })
|
|
418
|
-
return { handler: awaitingShutdownOnChainTx, state }
|
|
440
|
+
const signedTx = await state.sign(message.params.data.tx);
|
|
441
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { tx: signedTx } });
|
|
442
|
+
return { handler: awaitingShutdownOnChainTx, state };
|
|
419
443
|
}
|
|
420
|
-
const signedTx = await appendSignature(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
444
|
+
const signedTx = await appendSignature(
|
|
445
|
+
message.params.data.signed_tx,
|
|
446
|
+
async (tx) => state.sign(tx),
|
|
447
|
+
);
|
|
448
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.shutdown_sign', params: { signed_tx: signedTx } });
|
|
449
|
+
return { handler: awaitingShutdownOnChainTx, state };
|
|
424
450
|
}
|
|
425
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
451
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
426
452
|
}
|
|
427
453
|
|
|
428
|
-
export function awaitingShutdownOnChainTx
|
|
429
|
-
channel: Channel,
|
|
454
|
+
export function awaitingShutdownOnChainTx(
|
|
455
|
+
channel: Channel,
|
|
456
|
+
message: ChannelMessage,
|
|
457
|
+
state: ChannelState,
|
|
430
458
|
): ChannelFsm {
|
|
431
459
|
if (message.method === 'channels.on_chain_tx') {
|
|
432
460
|
// state.resolve(message.params.data.tx)
|
|
433
|
-
return { handler: channelClosed, state }
|
|
461
|
+
return { handler: channelClosed, state };
|
|
434
462
|
}
|
|
435
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
463
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
436
464
|
}
|
|
437
465
|
|
|
438
|
-
export function awaitingLeave
|
|
439
|
-
channel: Channel,
|
|
466
|
+
export function awaitingLeave(
|
|
467
|
+
channel: Channel,
|
|
468
|
+
message: ChannelMessage,
|
|
469
|
+
state: ChannelState,
|
|
440
470
|
): ChannelFsm {
|
|
441
471
|
if (message.method === 'channels.leave') {
|
|
442
|
-
state.resolve({ channelId: message.params.channel_id, signedTx: message.params.data.state })
|
|
443
|
-
disconnect(channel)
|
|
444
|
-
return { handler: channelClosed }
|
|
472
|
+
state.resolve({ channelId: message.params.channel_id, signedTx: message.params.data.state });
|
|
473
|
+
disconnect(channel);
|
|
474
|
+
return { handler: channelClosed };
|
|
445
475
|
}
|
|
446
476
|
if (message.method === 'channels.error') {
|
|
447
|
-
state.reject(new ChannelConnectionError(message.data.message))
|
|
448
|
-
return { handler: channelOpen }
|
|
477
|
+
state.reject(new ChannelConnectionError(message.data.message));
|
|
478
|
+
return { handler: channelOpen };
|
|
449
479
|
}
|
|
450
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
480
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
451
481
|
}
|
|
452
482
|
|
|
453
|
-
export async function awaitingWithdrawTx
|
|
454
|
-
channel: Channel,
|
|
483
|
+
export async function awaitingWithdrawTx(
|
|
484
|
+
channel: Channel,
|
|
485
|
+
message: ChannelMessage,
|
|
486
|
+
state: ChannelState,
|
|
455
487
|
): Promise<ChannelFsm | undefined> {
|
|
456
488
|
if (message.method === 'channels.sign.withdraw_tx') {
|
|
457
|
-
const { sign } = state
|
|
489
|
+
const { sign } = state;
|
|
458
490
|
if (message.params.data.tx != null) {
|
|
459
|
-
const signedTx =
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
)
|
|
491
|
+
const signedTx = await sign(message.params.data.tx, { updates: message.params.data.updates });
|
|
492
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { tx: signedTx } });
|
|
493
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
494
|
+
}
|
|
495
|
+
const signedTx = await appendSignature(
|
|
496
|
+
message.params.data.signed_tx,
|
|
497
|
+
async (tx) => sign(tx, { updates: message.params.data.updates }),
|
|
498
|
+
);
|
|
467
499
|
if (typeof signedTx === 'string') {
|
|
468
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { signed_tx: signedTx } })
|
|
469
|
-
return { handler: awaitingWithdrawCompletion, state }
|
|
500
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { signed_tx: signedTx } });
|
|
501
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
470
502
|
}
|
|
471
503
|
if (typeof signedTx === 'number') {
|
|
472
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { error: signedTx } })
|
|
473
|
-
return { handler: awaitingWithdrawCompletion, state }
|
|
504
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.withdraw_tx', params: { error: signedTx } });
|
|
505
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
474
506
|
}
|
|
475
507
|
}
|
|
476
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
508
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
477
509
|
}
|
|
478
510
|
|
|
479
|
-
export function awaitingWithdrawCompletion
|
|
480
|
-
channel: Channel,
|
|
511
|
+
export function awaitingWithdrawCompletion(
|
|
512
|
+
channel: Channel,
|
|
513
|
+
message: ChannelMessage,
|
|
514
|
+
state: ChannelState,
|
|
481
515
|
): ChannelFsm {
|
|
482
516
|
if (message.method === 'channels.on_chain_tx') {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
return { handler: awaitingWithdrawCompletion, state }
|
|
517
|
+
state.onOnChainTx?.(message.params.data.tx);
|
|
518
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
487
519
|
}
|
|
488
520
|
if (message.method === 'channels.info') {
|
|
489
521
|
if (['own_withdraw_locked', 'withdraw_locked'].includes(message.params.data.event)) {
|
|
490
522
|
const callbacks: {
|
|
491
|
-
[key: string]: Function | undefined
|
|
523
|
+
[key: string]: Function | undefined;
|
|
492
524
|
} = {
|
|
493
525
|
own_withdraw_locked: state.onOwnWithdrawLocked,
|
|
494
|
-
withdraw_locked: state.onWithdrawLocked
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
callback()
|
|
499
|
-
}
|
|
500
|
-
return { handler: awaitingWithdrawCompletion, state }
|
|
526
|
+
withdraw_locked: state.onWithdrawLocked,
|
|
527
|
+
};
|
|
528
|
+
callbacks[message.params.data.event]?.();
|
|
529
|
+
return { handler: awaitingWithdrawCompletion, state };
|
|
501
530
|
}
|
|
502
531
|
}
|
|
503
532
|
if (message.method === 'channels.update') {
|
|
504
|
-
changeState(channel, message.params.data.state)
|
|
505
|
-
state.resolve({ accepted: true, signedTx: message.params.data.state })
|
|
506
|
-
return { handler: channelOpen }
|
|
533
|
+
changeState(channel, message.params.data.state);
|
|
534
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
535
|
+
return { handler: channelOpen };
|
|
507
536
|
}
|
|
508
537
|
if (message.method === 'channels.conflict') {
|
|
509
538
|
state.resolve({
|
|
510
539
|
accepted: false,
|
|
511
540
|
errorCode: message.params.data.error_code,
|
|
512
|
-
errorMessage: message.params.data.error_msg
|
|
513
|
-
})
|
|
514
|
-
return { handler: channelOpen }
|
|
541
|
+
errorMessage: message.params.data.error_msg,
|
|
542
|
+
});
|
|
543
|
+
return { handler: channelOpen };
|
|
515
544
|
}
|
|
516
545
|
if (message.method === 'channels.info') {
|
|
517
546
|
if (message.params.data.event === 'aborted_update') {
|
|
518
|
-
state.resolve({ accepted: false })
|
|
519
|
-
return { handler: channelOpen }
|
|
547
|
+
state.resolve({ accepted: false });
|
|
548
|
+
return { handler: channelOpen };
|
|
520
549
|
}
|
|
521
550
|
}
|
|
522
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
551
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
523
552
|
}
|
|
524
553
|
|
|
525
|
-
export async function awaitingDepositTx
|
|
526
|
-
channel: Channel,
|
|
554
|
+
export async function awaitingDepositTx(
|
|
555
|
+
channel: Channel,
|
|
556
|
+
message: ChannelMessage,
|
|
557
|
+
state: ChannelState,
|
|
527
558
|
): Promise<ChannelFsm | undefined> {
|
|
528
559
|
if (message.method === 'channels.sign.deposit_tx') {
|
|
529
|
-
const { sign } = state
|
|
560
|
+
const { sign } = state;
|
|
530
561
|
if (message.params.data.tx != null) {
|
|
531
|
-
const signedTx = await sign(
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
562
|
+
const signedTx = await sign(
|
|
563
|
+
message.params.data.tx,
|
|
564
|
+
{ updates: message.params.data.updates },
|
|
565
|
+
);
|
|
566
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { tx: signedTx } });
|
|
567
|
+
return { handler: awaitingDepositCompletion, state };
|
|
568
|
+
}
|
|
569
|
+
const signedTx = await appendSignature(
|
|
570
|
+
message.params.data.signed_tx,
|
|
571
|
+
async (tx) => sign(tx, { updates: message.params.data.updates }),
|
|
572
|
+
);
|
|
539
573
|
if (typeof signedTx === 'string') {
|
|
540
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { signed_tx: signedTx } })
|
|
541
|
-
return { handler: awaitingDepositCompletion, state }
|
|
574
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { signed_tx: signedTx } });
|
|
575
|
+
return { handler: awaitingDepositCompletion, state };
|
|
542
576
|
}
|
|
543
577
|
if (typeof signedTx === 'number') {
|
|
544
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { error: signedTx } })
|
|
545
|
-
return { handler: awaitingDepositCompletion, state }
|
|
578
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.deposit_tx', params: { error: signedTx } });
|
|
579
|
+
return { handler: awaitingDepositCompletion, state };
|
|
546
580
|
}
|
|
547
581
|
}
|
|
548
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
582
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
549
583
|
}
|
|
550
584
|
|
|
551
|
-
export function awaitingDepositCompletion
|
|
552
|
-
channel: Channel,
|
|
585
|
+
export function awaitingDepositCompletion(
|
|
586
|
+
channel: Channel,
|
|
587
|
+
message: ChannelMessage,
|
|
588
|
+
state: ChannelState,
|
|
553
589
|
): ChannelFsm {
|
|
554
590
|
if (message.method === 'channels.on_chain_tx') {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
return { handler: awaitingDepositCompletion, state }
|
|
591
|
+
state.onOnChainTx?.(message.params.data.tx);
|
|
592
|
+
return { handler: awaitingDepositCompletion, state };
|
|
559
593
|
}
|
|
560
594
|
if (message.method === 'channels.info') {
|
|
561
595
|
if (['own_deposit_locked', 'deposit_locked'].includes(message.params.data.event)) {
|
|
562
596
|
const callbacks: {
|
|
563
|
-
[key: string]: Function | undefined
|
|
597
|
+
[key: string]: Function | undefined;
|
|
564
598
|
} = {
|
|
565
599
|
own_deposit_locked: state.onOwnDepositLocked,
|
|
566
|
-
deposit_locked: state.onDepositLocked
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
callback()
|
|
571
|
-
}
|
|
572
|
-
return { handler: awaitingDepositCompletion, state }
|
|
600
|
+
deposit_locked: state.onDepositLocked,
|
|
601
|
+
};
|
|
602
|
+
callbacks[message.params.data.event]?.();
|
|
603
|
+
return { handler: awaitingDepositCompletion, state };
|
|
573
604
|
}
|
|
574
605
|
}
|
|
575
606
|
if (message.method === 'channels.update') {
|
|
576
|
-
changeState(channel, message.params.data.state)
|
|
577
|
-
state.resolve({ accepted: true, signedTx: message.params.data.state })
|
|
578
|
-
return { handler: channelOpen }
|
|
607
|
+
changeState(channel, message.params.data.state);
|
|
608
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
609
|
+
return { handler: channelOpen };
|
|
579
610
|
}
|
|
580
611
|
if (message.method === 'channels.conflict') {
|
|
581
612
|
state.resolve({
|
|
582
613
|
accepted: false,
|
|
583
614
|
errorCode: message.params.data.error_code,
|
|
584
|
-
errorMessage: message.params.data.error_msg
|
|
585
|
-
})
|
|
586
|
-
return { handler: channelOpen }
|
|
615
|
+
errorMessage: message.params.data.error_msg,
|
|
616
|
+
});
|
|
617
|
+
return { handler: channelOpen };
|
|
587
618
|
}
|
|
588
619
|
if (message.method === 'channels.info') {
|
|
589
620
|
if (message.params.data.event === 'aborted_update') {
|
|
590
|
-
state.resolve({ accepted: false })
|
|
591
|
-
return { handler: channelOpen }
|
|
621
|
+
state.resolve({ accepted: false });
|
|
622
|
+
return { handler: channelOpen };
|
|
592
623
|
}
|
|
593
624
|
}
|
|
594
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
625
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
595
626
|
}
|
|
596
627
|
|
|
597
|
-
export async function awaitingNewContractTx
|
|
598
|
-
channel: Channel,
|
|
628
|
+
export async function awaitingNewContractTx(
|
|
629
|
+
channel: Channel,
|
|
630
|
+
message: ChannelMessage,
|
|
631
|
+
state: ChannelState,
|
|
599
632
|
): Promise<ChannelFsm | undefined> {
|
|
600
633
|
if (message.method === 'channels.sign.update') {
|
|
601
634
|
if (message.params.data.tx != null) {
|
|
602
|
-
const signedTx = await state.sign(message.params.data.tx)
|
|
603
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } })
|
|
604
|
-
return { handler: awaitingNewContractCompletion, state }
|
|
635
|
+
const signedTx = await state.sign(message.params.data.tx);
|
|
636
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } });
|
|
637
|
+
return { handler: awaitingNewContractCompletion, state };
|
|
605
638
|
}
|
|
606
|
-
const signedTx = await appendSignature(
|
|
607
|
-
|
|
639
|
+
const signedTx = await appendSignature(
|
|
640
|
+
message.params.data.signed_tx,
|
|
641
|
+
async (tx) => state.sign(tx),
|
|
642
|
+
);
|
|
608
643
|
if (typeof signedTx === 'string') {
|
|
609
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } })
|
|
610
|
-
return { handler: awaitingNewContractCompletion, state }
|
|
644
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } });
|
|
645
|
+
return { handler: awaitingNewContractCompletion, state };
|
|
611
646
|
}
|
|
612
647
|
if (typeof signedTx === 'number') {
|
|
613
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } })
|
|
614
|
-
return { handler: awaitingNewContractCompletion, state }
|
|
648
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } });
|
|
649
|
+
return { handler: awaitingNewContractCompletion, state };
|
|
615
650
|
}
|
|
616
651
|
}
|
|
617
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
652
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
618
653
|
}
|
|
619
654
|
|
|
620
|
-
export function awaitingNewContractCompletion
|
|
621
|
-
channel: Channel,
|
|
655
|
+
export function awaitingNewContractCompletion(
|
|
656
|
+
channel: Channel,
|
|
657
|
+
message: ChannelMessage,
|
|
658
|
+
state: ChannelState,
|
|
622
659
|
): ChannelFsm {
|
|
623
|
-
const channelOptions = options.get(channel)
|
|
660
|
+
const channelOptions = options.get(channel);
|
|
624
661
|
if (message.method === 'channels.update') {
|
|
625
|
-
const { round } = unpackTx(message.params.data.state,
|
|
662
|
+
const { round } = unpackTx(message.params.data.state, Tag.SignedTx).tx.encodedTx.tx;
|
|
626
663
|
if (channelOptions?.role != null) {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
664
|
+
let role: null | 'initiatorId' | 'responderId' = null;
|
|
665
|
+
if (channelOptions.role === 'initiator') role = 'initiatorId';
|
|
666
|
+
if (channelOptions.role === 'responder') role = 'responderId';
|
|
630
667
|
if (role != null) {
|
|
631
|
-
const owner = channelOptions?.[role]
|
|
632
|
-
changeState(channel, message.params.data.state)
|
|
668
|
+
const owner = channelOptions?.[role];
|
|
669
|
+
changeState(channel, message.params.data.state);
|
|
633
670
|
state.resolve({
|
|
634
671
|
accepted: true,
|
|
635
672
|
address: encodeContractAddress(owner, round),
|
|
636
|
-
signedTx: message.params.data.state
|
|
637
|
-
})
|
|
638
|
-
return { handler: channelOpen }
|
|
673
|
+
signedTx: message.params.data.state,
|
|
674
|
+
});
|
|
675
|
+
return { handler: channelOpen };
|
|
639
676
|
}
|
|
640
677
|
}
|
|
641
678
|
}
|
|
@@ -643,123 +680,138 @@ export function awaitingNewContractCompletion (
|
|
|
643
680
|
state.resolve({
|
|
644
681
|
accepted: false,
|
|
645
682
|
errorCode: message.params.data.error_code,
|
|
646
|
-
errorMessage: message.params.data.error_msg
|
|
647
|
-
})
|
|
648
|
-
return { handler: channelOpen }
|
|
683
|
+
errorMessage: message.params.data.error_msg,
|
|
684
|
+
});
|
|
685
|
+
return { handler: channelOpen };
|
|
649
686
|
}
|
|
650
687
|
if (message.method === 'channels.info') {
|
|
651
688
|
if (message.params.data.event === 'aborted_update') {
|
|
652
|
-
state.resolve({ accepted: false })
|
|
653
|
-
return { handler: channelOpen }
|
|
689
|
+
state.resolve({ accepted: false });
|
|
690
|
+
return { handler: channelOpen };
|
|
654
691
|
}
|
|
655
692
|
}
|
|
656
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
693
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
657
694
|
}
|
|
658
695
|
|
|
659
|
-
export async function awaitingCallContractUpdateTx
|
|
660
|
-
channel: Channel,
|
|
696
|
+
export async function awaitingCallContractUpdateTx(
|
|
697
|
+
channel: Channel,
|
|
698
|
+
message: ChannelMessage,
|
|
699
|
+
state: ChannelState,
|
|
661
700
|
): Promise<ChannelFsm | undefined> {
|
|
662
701
|
if (message.method === 'channels.sign.update') {
|
|
663
702
|
if (message.params.data.tx != null) {
|
|
664
703
|
const signedTx = await state.sign(
|
|
665
|
-
message.params.data.tx,
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
704
|
+
message.params.data.tx,
|
|
705
|
+
{ updates: message.params.data.updates },
|
|
706
|
+
);
|
|
707
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } });
|
|
708
|
+
return { handler: awaitingCallContractCompletion, state };
|
|
669
709
|
}
|
|
670
710
|
const signedTx = await appendSignature(
|
|
671
711
|
message.params.data.signed_tx,
|
|
672
|
-
async tx =>
|
|
673
|
-
)
|
|
712
|
+
async (tx) => state.sign(tx, { updates: message.params.data.updates }),
|
|
713
|
+
);
|
|
674
714
|
if (typeof signedTx === 'string') {
|
|
675
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } })
|
|
676
|
-
return { handler: awaitingCallContractCompletion, state }
|
|
715
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } });
|
|
716
|
+
return { handler: awaitingCallContractCompletion, state };
|
|
677
717
|
}
|
|
678
718
|
if (typeof signedTx === 'number') {
|
|
679
|
-
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } })
|
|
680
|
-
return { handler: awaitingCallContractCompletion, state }
|
|
719
|
+
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { error: signedTx } });
|
|
720
|
+
return { handler: awaitingCallContractCompletion, state };
|
|
681
721
|
}
|
|
682
722
|
}
|
|
683
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
723
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
684
724
|
}
|
|
685
725
|
|
|
686
|
-
export async function awaitingCallContractForceProgressUpdate
|
|
687
|
-
channel: Channel,
|
|
726
|
+
export async function awaitingCallContractForceProgressUpdate(
|
|
727
|
+
channel: Channel,
|
|
728
|
+
message: ChannelMessage,
|
|
729
|
+
state: ChannelState,
|
|
688
730
|
): Promise<ChannelFsm | undefined> {
|
|
689
731
|
if (message.method === 'channels.sign.force_progress_tx') {
|
|
690
|
-
const signedTx = await appendSignature(
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
732
|
+
const signedTx = await appendSignature(
|
|
733
|
+
message.params.data.signed_tx,
|
|
734
|
+
async (tx) => state.sign(tx, { updates: message.params.data.updates }),
|
|
735
|
+
);
|
|
736
|
+
send(
|
|
737
|
+
channel,
|
|
738
|
+
{ jsonrpc: '2.0', method: 'channels.force_progress_sign', params: { signed_tx: signedTx } },
|
|
739
|
+
);
|
|
740
|
+
return { handler: awaitingForceProgressCompletion, state };
|
|
741
|
+
}
|
|
742
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
697
743
|
}
|
|
698
744
|
|
|
699
|
-
export function awaitingForceProgressCompletion
|
|
700
|
-
channel: Channel,
|
|
745
|
+
export function awaitingForceProgressCompletion(
|
|
746
|
+
channel: Channel,
|
|
747
|
+
message: ChannelMessage,
|
|
748
|
+
state: ChannelState,
|
|
701
749
|
): ChannelFsm {
|
|
702
750
|
if (message.method === 'channels.on_chain_tx') {
|
|
703
|
-
|
|
704
|
-
state.onOnChainTx(message.params.data)
|
|
705
|
-
}
|
|
751
|
+
state.onOnChainTx?.(message.params.data.tx);
|
|
706
752
|
emit(channel, 'onChainTx', message.params.data.tx, {
|
|
707
753
|
info: message.params.data.info,
|
|
708
|
-
type: message.params.data.type
|
|
709
|
-
})
|
|
710
|
-
state.resolve({ accepted: true, tx: message.params.data.tx })
|
|
754
|
+
type: message.params.data.type,
|
|
755
|
+
});
|
|
756
|
+
state.resolve({ accepted: true, tx: message.params.data.tx });
|
|
711
757
|
}
|
|
712
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
758
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
713
759
|
}
|
|
714
760
|
|
|
715
|
-
export function awaitingCallContractCompletion
|
|
716
|
-
channel: Channel,
|
|
761
|
+
export function awaitingCallContractCompletion(
|
|
762
|
+
channel: Channel,
|
|
763
|
+
message: ChannelMessage,
|
|
764
|
+
state: ChannelState,
|
|
717
765
|
): ChannelFsm {
|
|
718
766
|
if (message.method === 'channels.update') {
|
|
719
|
-
changeState(channel, message.params.data.state)
|
|
720
|
-
state.resolve({ accepted: true, signedTx: message.params.data.state })
|
|
721
|
-
return { handler: channelOpen }
|
|
767
|
+
changeState(channel, message.params.data.state);
|
|
768
|
+
state.resolve({ accepted: true, signedTx: message.params.data.state });
|
|
769
|
+
return { handler: channelOpen };
|
|
722
770
|
}
|
|
723
771
|
if (message.method === 'channels.conflict') {
|
|
724
772
|
state.resolve({
|
|
725
773
|
accepted: false,
|
|
726
774
|
errorCode: message.params.data.error_code,
|
|
727
|
-
errorMessage: message.params.data.error_msg
|
|
728
|
-
})
|
|
729
|
-
return { handler: channelOpen }
|
|
775
|
+
errorMessage: message.params.data.error_msg,
|
|
776
|
+
});
|
|
777
|
+
return { handler: channelOpen };
|
|
730
778
|
}
|
|
731
779
|
if (message.method === 'channels.info') {
|
|
732
780
|
if (message.params.data.event === 'aborted_update') {
|
|
733
|
-
state.resolve({ accepted: false })
|
|
734
|
-
return { handler: channelOpen }
|
|
781
|
+
state.resolve({ accepted: false });
|
|
782
|
+
return { handler: channelOpen };
|
|
735
783
|
}
|
|
736
784
|
}
|
|
737
|
-
return handleUnexpectedMessage(channel, message, state)
|
|
785
|
+
return handleUnexpectedMessage(channel, message, state);
|
|
738
786
|
}
|
|
739
787
|
|
|
740
|
-
export function awaitingCallsPruned
|
|
741
|
-
_channels: Channel[],
|
|
788
|
+
export function awaitingCallsPruned(
|
|
789
|
+
_channels: Channel[],
|
|
790
|
+
message: ChannelMessage,
|
|
791
|
+
state: ChannelState,
|
|
742
792
|
): ChannelFsm {
|
|
743
793
|
if (message.method === 'channels.calls_pruned.reply') {
|
|
744
|
-
state.resolve()
|
|
745
|
-
return { handler: channelOpen }
|
|
794
|
+
state.resolve();
|
|
795
|
+
return { handler: channelOpen };
|
|
746
796
|
}
|
|
747
|
-
state.reject(new UnexpectedChannelMessageError('Unexpected message received'))
|
|
748
|
-
return { handler: channelClosed }
|
|
797
|
+
state.reject(new UnexpectedChannelMessageError('Unexpected message received'));
|
|
798
|
+
return { handler: channelClosed };
|
|
749
799
|
}
|
|
750
800
|
|
|
751
|
-
export function channelClosed
|
|
752
|
-
_channel: Channel,
|
|
801
|
+
export function channelClosed(
|
|
802
|
+
_channel: Channel,
|
|
803
|
+
message: ChannelMessage,
|
|
804
|
+
state: ChannelState,
|
|
753
805
|
): ChannelFsm {
|
|
754
|
-
if (state == null) return { handler: channelClosed }
|
|
755
|
-
if (message.params.data.event === 'closing') return { handler: channelClosed, state }
|
|
806
|
+
if (state == null) return { handler: channelClosed };
|
|
807
|
+
if (message.params.data.event === 'closing') return { handler: channelClosed, state };
|
|
756
808
|
if (message.params.data.info === 'channel_closed') {
|
|
757
|
-
state.closeTx = message.params.data.tx
|
|
758
|
-
return { handler: channelClosed, state }
|
|
809
|
+
state.closeTx = message.params.data.tx;
|
|
810
|
+
return { handler: channelClosed, state };
|
|
759
811
|
}
|
|
760
812
|
if (message.params.data.event === 'closed_confirmed') {
|
|
761
|
-
state.resolve(state.closeTx)
|
|
762
|
-
return { handler: channelClosed }
|
|
813
|
+
state.resolve(state.closeTx);
|
|
814
|
+
return { handler: channelClosed };
|
|
763
815
|
}
|
|
764
|
-
return { handler: channelClosed, state }
|
|
816
|
+
return { handler: channelClosed, state };
|
|
765
817
|
}
|