@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/internal.ts
CHANGED
|
@@ -15,331 +15,347 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { w3cwebsocket as W3CWebSocket } from 'websocket'
|
|
19
|
-
import { EventEmitter } from 'events'
|
|
20
|
-
import BigNumber from 'bignumber.js'
|
|
21
|
-
import Channel from '.'
|
|
22
|
-
import JsonBig from '../utils/json-big'
|
|
23
|
-
import { pascalToSnake } from '../utils/string'
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
18
|
+
import { w3cwebsocket as W3CWebSocket } from 'websocket';
|
|
19
|
+
import { EventEmitter } from 'events';
|
|
20
|
+
import BigNumber from 'bignumber.js';
|
|
21
|
+
import type Channel from '.';
|
|
22
|
+
import JsonBig from '../utils/json-big';
|
|
23
|
+
import { pascalToSnake } from '../utils/string';
|
|
24
|
+
import { Encoded } from '../utils/encoder';
|
|
25
|
+
import {
|
|
26
|
+
BaseError, ChannelCallError, ChannelPingTimedOutError, UnknownChannelStateError,
|
|
27
|
+
} from '../utils/errors';
|
|
26
28
|
|
|
27
29
|
interface ChannelAction {
|
|
28
|
-
guard: (channel: Channel, state?: ChannelFsm) => boolean
|
|
29
|
-
action: (channel: Channel, state?: ChannelFsm) => ChannelFsm
|
|
30
|
+
guard: (channel: Channel, state?: ChannelFsm) => boolean;
|
|
31
|
+
action: (channel: Channel, state?: ChannelFsm) => ChannelFsm;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
export type SignTxWithTag = (tag: string, tx:
|
|
34
|
+
export type SignTxWithTag = (tag: string, tx: Encoded.Transaction, options?: object) => (
|
|
35
|
+
Promise<Encoded.Transaction>
|
|
36
|
+
);
|
|
33
37
|
// TODO: SignTx shouldn't return number or null
|
|
34
|
-
export type SignTx = (tx:
|
|
38
|
+
export type SignTx = (tx: Encoded.Transaction, options?: object) => (
|
|
39
|
+
Promise<Encoded.Transaction | number | null>
|
|
40
|
+
);
|
|
35
41
|
|
|
36
42
|
export interface ChannelOptions {
|
|
37
|
-
existingFsmId?: string
|
|
38
|
-
url: string
|
|
39
|
-
role: 'initiator' | 'responder'
|
|
40
|
-
initiatorId:
|
|
41
|
-
responderId:
|
|
42
|
-
pushAmount: number
|
|
43
|
-
initiatorAmount: BigNumber
|
|
44
|
-
responderAmount: BigNumber
|
|
45
|
-
channelReserve?: BigNumber | number
|
|
46
|
-
signedTx?: string
|
|
47
|
-
ttl?: number
|
|
48
|
-
host: string
|
|
49
|
-
port: number
|
|
50
|
-
lockPeriod: number
|
|
51
|
-
existingChannelId?: string
|
|
52
|
-
offChainTx?: string
|
|
53
|
-
reconnectTx?: string
|
|
54
|
-
timeoutIdle?: number
|
|
55
|
-
timeoutFundingCreate?: number
|
|
56
|
-
timeoutFundingSign?: number
|
|
57
|
-
timeoutFundingLock?: number
|
|
58
|
-
timeoutSign?: number
|
|
59
|
-
timeoutAccept?: number
|
|
60
|
-
timeoutInitialized?: number
|
|
61
|
-
timeoutAwaitingOpen?: number
|
|
62
|
-
statePassword?: string
|
|
63
|
-
debug: boolean
|
|
64
|
-
sign: SignTxWithTag
|
|
65
|
-
offchainTx?: string
|
|
43
|
+
existingFsmId?: string;
|
|
44
|
+
url: string;
|
|
45
|
+
role: 'initiator' | 'responder';
|
|
46
|
+
initiatorId: Encoded.AccountAddress;
|
|
47
|
+
responderId: Encoded.AccountAddress;
|
|
48
|
+
pushAmount: number;
|
|
49
|
+
initiatorAmount: BigNumber;
|
|
50
|
+
responderAmount: BigNumber;
|
|
51
|
+
channelReserve?: BigNumber | number;
|
|
52
|
+
signedTx?: string;
|
|
53
|
+
ttl?: number;
|
|
54
|
+
host: string;
|
|
55
|
+
port: number;
|
|
56
|
+
lockPeriod: number;
|
|
57
|
+
existingChannelId?: string;
|
|
58
|
+
offChainTx?: string;
|
|
59
|
+
reconnectTx?: string;
|
|
60
|
+
timeoutIdle?: number;
|
|
61
|
+
timeoutFundingCreate?: number;
|
|
62
|
+
timeoutFundingSign?: number;
|
|
63
|
+
timeoutFundingLock?: number;
|
|
64
|
+
timeoutSign?: number;
|
|
65
|
+
timeoutAccept?: number;
|
|
66
|
+
timeoutInitialized?: number;
|
|
67
|
+
timeoutAwaitingOpen?: number;
|
|
68
|
+
statePassword?: string;
|
|
69
|
+
debug: boolean;
|
|
70
|
+
sign: SignTxWithTag;
|
|
71
|
+
offchainTx?: string;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
export interface ChannelHandler extends Function {
|
|
69
|
-
enter?: Function
|
|
75
|
+
enter?: Function;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
export interface ChannelState {
|
|
73
|
-
signedTx: any
|
|
74
|
-
resolve:
|
|
75
|
-
reject:
|
|
76
|
-
sign: SignTx
|
|
77
|
-
handler?: ChannelHandler
|
|
78
|
-
onOnChainTx?:
|
|
79
|
-
onOwnWithdrawLocked?:
|
|
80
|
-
onWithdrawLocked?:
|
|
81
|
-
onOwnDepositLocked?:
|
|
82
|
-
onDepositLocked?:
|
|
83
|
-
closeTx?: string
|
|
79
|
+
signedTx: any;
|
|
80
|
+
resolve: (r?: any) => void;
|
|
81
|
+
reject: (e: BaseError) => void;
|
|
82
|
+
sign: SignTx;
|
|
83
|
+
handler?: ChannelHandler;
|
|
84
|
+
onOnChainTx?: (tx: Encoded.Transaction) => void;
|
|
85
|
+
onOwnWithdrawLocked?: () => void;
|
|
86
|
+
onWithdrawLocked?: () => void;
|
|
87
|
+
onOwnDepositLocked?: () => void;
|
|
88
|
+
onDepositLocked?: () => void;
|
|
89
|
+
closeTx?: string;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
export interface ChannelFsm {
|
|
87
|
-
handler: ChannelHandler
|
|
93
|
+
handler: ChannelHandler;
|
|
88
94
|
state?: ChannelState | {
|
|
89
|
-
resolve: Function
|
|
90
|
-
reject: Function
|
|
91
|
-
}
|
|
95
|
+
resolve: Function;
|
|
96
|
+
reject: Function;
|
|
97
|
+
};
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
export interface ChannelMessage {
|
|
95
|
-
id?: number
|
|
96
|
-
jsonrpc: string
|
|
97
|
-
method: string
|
|
98
|
-
params: any
|
|
99
|
-
payload?: any
|
|
100
|
-
data?: any
|
|
101
|
-
error?: ChannelMessageError
|
|
101
|
+
id?: number;
|
|
102
|
+
jsonrpc: string;
|
|
103
|
+
method: string;
|
|
104
|
+
params: any;
|
|
105
|
+
payload?: any;
|
|
106
|
+
data?: any;
|
|
107
|
+
error?: ChannelMessageError;
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
interface ChannelMessageError {
|
|
105
|
-
code: number
|
|
106
|
-
message: string
|
|
111
|
+
code: number;
|
|
112
|
+
message: string;
|
|
107
113
|
data: [{
|
|
108
|
-
message: string
|
|
109
|
-
code: number
|
|
110
|
-
}]
|
|
111
|
-
request: ChannelMessage
|
|
114
|
+
message: string;
|
|
115
|
+
code: number;
|
|
116
|
+
}];
|
|
117
|
+
request: ChannelMessage;
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
// Send ping message every 10 seconds
|
|
115
|
-
const PING_TIMEOUT_MS = 10000
|
|
121
|
+
const PING_TIMEOUT_MS = 10000;
|
|
116
122
|
// Close connection if pong message is not received within 5 seconds
|
|
117
|
-
const PONG_TIMEOUT_MS = 5000
|
|
123
|
+
const PONG_TIMEOUT_MS = 5000;
|
|
118
124
|
|
|
119
125
|
// TODO: move to Channel instance to avoid is-null checks and for easier debugging
|
|
120
|
-
export const options = new WeakMap<Channel, ChannelOptions>()
|
|
121
|
-
export const status = new WeakMap<Channel, string>()
|
|
122
|
-
export const state = new WeakMap<Channel,
|
|
123
|
-
const fsm = new WeakMap<Channel, ChannelFsm>()
|
|
124
|
-
const websockets = new WeakMap<Channel, W3CWebSocket>()
|
|
125
|
-
export const eventEmitters = new WeakMap<Channel, EventEmitter>()
|
|
126
|
-
const messageQueue = new WeakMap<Channel, string[]>()
|
|
127
|
-
const messageQueueLocked = new WeakMap<Channel, boolean>()
|
|
128
|
-
const actionQueue = new WeakMap<Channel, ChannelAction[]>()
|
|
129
|
-
const actionQueueLocked = new WeakMap<Channel, boolean>()
|
|
130
|
-
const sequence = new WeakMap<Channel, number>()
|
|
131
|
-
export const channelId = new WeakMap<Channel, string>()
|
|
132
|
-
const rpcCallbacks = new WeakMap<Channel, Map<number, Function>>()
|
|
133
|
-
const pingTimeoutId = new WeakMap<Channel, NodeJS.Timeout>()
|
|
134
|
-
const pongTimeoutId = new WeakMap<Channel, NodeJS.Timeout>()
|
|
135
|
-
export const fsmId = new WeakMap<Channel, string>()
|
|
126
|
+
export const options = new WeakMap<Channel, ChannelOptions>();
|
|
127
|
+
export const status = new WeakMap<Channel, string>();
|
|
128
|
+
export const state = new WeakMap<Channel, Encoded.Transaction>();
|
|
129
|
+
const fsm = new WeakMap<Channel, ChannelFsm>();
|
|
130
|
+
const websockets = new WeakMap<Channel, W3CWebSocket>();
|
|
131
|
+
export const eventEmitters = new WeakMap<Channel, EventEmitter>();
|
|
132
|
+
const messageQueue = new WeakMap<Channel, string[]>();
|
|
133
|
+
const messageQueueLocked = new WeakMap<Channel, boolean>();
|
|
134
|
+
const actionQueue = new WeakMap<Channel, ChannelAction[]>();
|
|
135
|
+
const actionQueueLocked = new WeakMap<Channel, boolean>();
|
|
136
|
+
const sequence = new WeakMap<Channel, number>();
|
|
137
|
+
export const channelId = new WeakMap<Channel, string>();
|
|
138
|
+
const rpcCallbacks = new WeakMap<Channel, Map<number, Function>>();
|
|
139
|
+
const pingTimeoutId = new WeakMap<Channel, NodeJS.Timeout>();
|
|
140
|
+
const pongTimeoutId = new WeakMap<Channel, NodeJS.Timeout>();
|
|
141
|
+
export const fsmId = new WeakMap<Channel, string>();
|
|
136
142
|
|
|
137
|
-
export function emit
|
|
138
|
-
const [eventName, ...rest] = args
|
|
139
|
-
eventEmitters.get(channel)?.emit(eventName, ...rest)
|
|
143
|
+
export function emit(channel: Channel, ...args: any[]): void {
|
|
144
|
+
const [eventName, ...rest] = args;
|
|
145
|
+
eventEmitters.get(channel)?.emit(eventName, ...rest);
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
function enterState
|
|
148
|
+
function enterState(channel: Channel, nextState: ChannelFsm): void {
|
|
143
149
|
if (nextState == null) {
|
|
144
|
-
throw new UnknownChannelStateError()
|
|
150
|
+
throw new UnknownChannelStateError();
|
|
145
151
|
}
|
|
146
|
-
fsm.set(channel, nextState)
|
|
152
|
+
fsm.set(channel, nextState);
|
|
147
153
|
if (nextState?.handler?.enter != null) {
|
|
148
|
-
nextState.handler.enter(channel)
|
|
154
|
+
nextState.handler.enter(channel);
|
|
149
155
|
}
|
|
150
|
-
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
157
|
+
void dequeueAction(channel);
|
|
151
158
|
}
|
|
152
159
|
|
|
153
|
-
export function changeStatus
|
|
154
|
-
const prevStatus = status.get(channel)
|
|
160
|
+
export function changeStatus(channel: Channel, newStatus: string): void {
|
|
161
|
+
const prevStatus = status.get(channel);
|
|
155
162
|
if (newStatus !== prevStatus) {
|
|
156
|
-
status.set(channel, newStatus)
|
|
157
|
-
emit(channel, 'statusChanged', newStatus)
|
|
163
|
+
status.set(channel, newStatus);
|
|
164
|
+
emit(channel, 'statusChanged', newStatus);
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
167
|
|
|
161
|
-
export function changeState
|
|
162
|
-
state.set(channel, newState)
|
|
163
|
-
emit(channel, 'stateChanged', newState)
|
|
168
|
+
export function changeState(channel: Channel, newState: Encoded.Transaction): void {
|
|
169
|
+
state.set(channel, newState);
|
|
170
|
+
emit(channel, 'stateChanged', newState);
|
|
164
171
|
}
|
|
165
172
|
|
|
166
|
-
export function send
|
|
167
|
-
const debug: boolean = options.get(channel)?.debug ?? false
|
|
168
|
-
if (debug) console.log('Send message: ', message)
|
|
169
|
-
|
|
170
|
-
websockets.get(channel)?.send(JsonBig.stringify(message))
|
|
171
|
-
}
|
|
173
|
+
export function send(channel: Channel, message: ChannelMessage): void {
|
|
174
|
+
const debug: boolean = options.get(channel)?.debug ?? false;
|
|
175
|
+
if (debug) console.log('Send message: ', message);
|
|
172
176
|
|
|
173
|
-
|
|
174
|
-
const queue = actionQueue.get(channel) ?? []
|
|
175
|
-
actionQueue.set(channel, [
|
|
176
|
-
...queue,
|
|
177
|
-
{ guard, action }
|
|
178
|
-
])
|
|
179
|
-
void dequeueAction(channel)
|
|
177
|
+
websockets.get(channel)?.send(JsonBig.stringify(message));
|
|
180
178
|
}
|
|
181
179
|
|
|
182
|
-
async function dequeueAction
|
|
183
|
-
const locked = actionQueueLocked.get(channel)
|
|
184
|
-
const queue = actionQueue.get(channel) ?? []
|
|
180
|
+
async function dequeueAction(channel: Channel): Promise<void> {
|
|
181
|
+
const locked = actionQueueLocked.get(channel);
|
|
182
|
+
const queue = actionQueue.get(channel) ?? [];
|
|
185
183
|
if (Boolean(locked) || queue.length === 0) {
|
|
186
|
-
return
|
|
184
|
+
return;
|
|
187
185
|
}
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
const index = queue.findIndex((action: ChannelAction) => action.guard(channel,
|
|
186
|
+
const singleFsm = fsm.get(channel);
|
|
187
|
+
if (singleFsm == null) return;
|
|
188
|
+
const index = queue.findIndex((action: ChannelAction) => action.guard(channel, singleFsm));
|
|
191
189
|
if (index === -1) {
|
|
192
|
-
return
|
|
190
|
+
return;
|
|
193
191
|
}
|
|
194
|
-
actionQueue.set(channel, queue.filter((_: ChannelAction, i: number) => index !== i))
|
|
195
|
-
actionQueueLocked.set(channel, true)
|
|
196
|
-
const nextState: ChannelFsm = await Promise.resolve(queue[index].action(channel,
|
|
197
|
-
actionQueueLocked.set(channel, false)
|
|
198
|
-
enterState(channel, nextState)
|
|
192
|
+
actionQueue.set(channel, queue.filter((_: ChannelAction, i: number) => index !== i));
|
|
193
|
+
actionQueueLocked.set(channel, true);
|
|
194
|
+
const nextState: ChannelFsm = await Promise.resolve(queue[index].action(channel, singleFsm));
|
|
195
|
+
actionQueueLocked.set(channel, false);
|
|
196
|
+
enterState(channel, nextState);
|
|
199
197
|
}
|
|
200
198
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
199
|
+
export function enqueueAction(
|
|
200
|
+
channel: Channel,
|
|
201
|
+
guard: ChannelAction['guard'],
|
|
202
|
+
action: ChannelAction['action'],
|
|
203
|
+
): void {
|
|
204
|
+
const queue = actionQueue.get(channel) ?? [];
|
|
205
|
+
actionQueue.set(channel, [
|
|
206
|
+
...queue,
|
|
207
|
+
{ guard, action },
|
|
208
|
+
]);
|
|
209
|
+
void dequeueAction(channel);
|
|
206
210
|
}
|
|
207
211
|
|
|
208
|
-
async function
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
async function handleMessage(channel: Channel, message: string): Promise<void> {
|
|
213
|
+
const fsmState = fsm.get(channel);
|
|
214
|
+
if (fsmState == null) throw new UnknownChannelStateError();
|
|
215
|
+
const { handler, state: st } = fsmState;
|
|
216
|
+
enterState(channel, await Promise.resolve(handler(channel, message, st)));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function dequeueMessage(channel: Channel): Promise<void> {
|
|
220
|
+
const locked: boolean = messageQueueLocked.get(channel) ?? false;
|
|
221
|
+
if (locked) return;
|
|
222
|
+
const messages: string[] = messageQueue.get(channel) ?? [];
|
|
223
|
+
if (messages.length === 0) return;
|
|
224
|
+
messageQueueLocked.set(channel, true);
|
|
214
225
|
while (messages.length > 0) {
|
|
215
|
-
const message: string = messages.shift() ?? ''
|
|
226
|
+
const message: string = messages.shift() ?? '';
|
|
216
227
|
try {
|
|
217
|
-
await handleMessage(channel, message)
|
|
228
|
+
await handleMessage(channel, message);
|
|
218
229
|
} catch (error) {
|
|
219
|
-
console.error('Error handling incoming message:')
|
|
220
|
-
console.error(message)
|
|
221
|
-
console.error(error)
|
|
230
|
+
console.error('Error handling incoming message:');
|
|
231
|
+
console.error(message);
|
|
232
|
+
console.error(error);
|
|
222
233
|
}
|
|
223
234
|
}
|
|
224
|
-
messageQueueLocked.set(channel, false)
|
|
235
|
+
messageQueueLocked.set(channel, false);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function disconnect(channel: Channel): void {
|
|
239
|
+
websockets.get(channel)?.close();
|
|
240
|
+
const pingTimeoutIdValue = pingTimeoutId.get(channel);
|
|
241
|
+
const pongTimeoutIdValue = pongTimeoutId.get(channel);
|
|
242
|
+
if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue);
|
|
243
|
+
if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue);
|
|
225
244
|
}
|
|
226
245
|
|
|
227
|
-
function ping
|
|
228
|
-
const pingTimeoutIdValue = pingTimeoutId.get(channel)
|
|
229
|
-
const pongTimeoutIdValue = pongTimeoutId.get(channel)
|
|
230
|
-
if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue)
|
|
231
|
-
if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue)
|
|
246
|
+
function ping(channel: Channel): void {
|
|
247
|
+
const pingTimeoutIdValue = pingTimeoutId.get(channel);
|
|
248
|
+
const pongTimeoutIdValue = pongTimeoutId.get(channel);
|
|
249
|
+
if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue);
|
|
250
|
+
if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue);
|
|
232
251
|
pingTimeoutId.set(channel, setTimeout(() => {
|
|
233
252
|
send(channel, {
|
|
234
253
|
jsonrpc: '2.0',
|
|
235
254
|
method: 'channels.system',
|
|
236
255
|
params: {
|
|
237
|
-
action: 'ping'
|
|
238
|
-
}
|
|
239
|
-
})
|
|
256
|
+
action: 'ping',
|
|
257
|
+
},
|
|
258
|
+
});
|
|
240
259
|
pongTimeoutId.set(channel, setTimeout(() => {
|
|
241
|
-
disconnect(channel)
|
|
242
|
-
emit(channel, 'error', new ChannelPingTimedOutError())
|
|
243
|
-
}, PONG_TIMEOUT_MS))
|
|
244
|
-
}, PING_TIMEOUT_MS))
|
|
260
|
+
disconnect(channel);
|
|
261
|
+
emit(channel, 'error', new ChannelPingTimedOutError());
|
|
262
|
+
}, PONG_TIMEOUT_MS));
|
|
263
|
+
}, PING_TIMEOUT_MS));
|
|
245
264
|
}
|
|
246
265
|
|
|
247
|
-
function onMessage
|
|
248
|
-
const message = JsonBig.parse(data)
|
|
249
|
-
const debug: boolean = options.get(channel)?.debug ?? false
|
|
250
|
-
if (debug) console.log('Receive message: ', message)
|
|
266
|
+
function onMessage(channel: Channel, data: string): void {
|
|
267
|
+
const message = JsonBig.parse(data);
|
|
268
|
+
const debug: boolean = options.get(channel)?.debug ?? false;
|
|
269
|
+
if (debug) console.log('Receive message: ', message);
|
|
251
270
|
if (message.id != null) {
|
|
252
|
-
const callback = rpcCallbacks.get(channel)?.get(message.id)
|
|
271
|
+
const callback = rpcCallbacks.get(channel)?.get(message.id);
|
|
253
272
|
try {
|
|
254
|
-
callback?.(message)
|
|
273
|
+
callback?.(message);
|
|
255
274
|
} finally {
|
|
256
|
-
rpcCallbacks.get(channel)?.delete(message.id)
|
|
275
|
+
rpcCallbacks.get(channel)?.delete(message.id);
|
|
257
276
|
}
|
|
258
|
-
return
|
|
277
|
+
return;
|
|
259
278
|
}
|
|
260
279
|
if (message.method === 'channels.message') {
|
|
261
|
-
emit(channel, 'message', message.params.data.message)
|
|
262
|
-
return
|
|
280
|
+
emit(channel, 'message', message.params.data.message);
|
|
281
|
+
return;
|
|
263
282
|
}
|
|
264
283
|
if (message.method === 'channels.system.pong') {
|
|
265
284
|
if (
|
|
266
|
-
(message.params.channel_id === channelId.get(channel))
|
|
285
|
+
(message.params.channel_id === channelId.get(channel))
|
|
267
286
|
// Skip channelId check if channelId is not known yet
|
|
268
|
-
(channelId.get(channel) == null)
|
|
287
|
+
|| (channelId.get(channel) == null)
|
|
269
288
|
) {
|
|
270
|
-
ping(channel)
|
|
289
|
+
ping(channel);
|
|
271
290
|
}
|
|
272
|
-
return
|
|
291
|
+
return;
|
|
273
292
|
}
|
|
274
|
-
messageQueue.get(channel)?.push(message)
|
|
275
|
-
void dequeueMessage(channel)
|
|
293
|
+
messageQueue.get(channel)?.push(message);
|
|
294
|
+
void dequeueMessage(channel);
|
|
276
295
|
}
|
|
277
296
|
|
|
278
|
-
export async function call
|
|
279
|
-
return
|
|
280
|
-
const currentSequence: number = sequence.get(channel) ?? 0
|
|
281
|
-
const id = sequence.set(channel, currentSequence + 1).get(channel) ?? 1
|
|
282
|
-
rpcCallbacks.get(channel)?.set(
|
|
283
|
-
|
|
284
|
-
error?: ChannelMessageError }) => {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
websockets.get(channel)?.close()
|
|
297
|
-
const pingTimeoutIdValue = pingTimeoutId.get(channel)
|
|
298
|
-
const pongTimeoutIdValue = pongTimeoutId.get(channel)
|
|
299
|
-
if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue)
|
|
300
|
-
if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue)
|
|
297
|
+
export async function call(channel: Channel, method: string, params: any): Promise<any> {
|
|
298
|
+
return new Promise((resolve, reject) => {
|
|
299
|
+
const currentSequence: number = sequence.get(channel) ?? 0;
|
|
300
|
+
const id = sequence.set(channel, currentSequence + 1).get(channel) ?? 1;
|
|
301
|
+
rpcCallbacks.get(channel)?.set(
|
|
302
|
+
id,
|
|
303
|
+
(message: { result: PromiseLike<any>; error?: ChannelMessageError }) => {
|
|
304
|
+
if (message.error != null) {
|
|
305
|
+
const [{ message: details } = { message: '' }] = message.error.data ?? [];
|
|
306
|
+
return reject(new ChannelCallError(message.error.message + details));
|
|
307
|
+
}
|
|
308
|
+
return resolve(message.result);
|
|
309
|
+
},
|
|
310
|
+
);
|
|
311
|
+
send(channel, {
|
|
312
|
+
jsonrpc: '2.0', method, id, params,
|
|
313
|
+
});
|
|
314
|
+
});
|
|
301
315
|
}
|
|
302
316
|
|
|
303
|
-
export async function initialize
|
|
317
|
+
export async function initialize(
|
|
304
318
|
channel: Channel,
|
|
305
319
|
connectionHandler: Function,
|
|
306
320
|
openHandler: Function,
|
|
307
|
-
{ url, ...channelOptions }: ChannelOptions
|
|
321
|
+
{ url, ...channelOptions }: ChannelOptions,
|
|
308
322
|
): Promise<void> {
|
|
309
|
-
options.set(channel, { url, ...channelOptions })
|
|
310
|
-
fsm.set(channel, { handler: connectionHandler })
|
|
311
|
-
eventEmitters.set(channel, new EventEmitter())
|
|
312
|
-
sequence.set(channel, 0)
|
|
313
|
-
rpcCallbacks.set(channel, new Map())
|
|
314
|
-
messageQueue.set(channel, [])
|
|
323
|
+
options.set(channel, { url, ...channelOptions });
|
|
324
|
+
fsm.set(channel, { handler: connectionHandler });
|
|
325
|
+
eventEmitters.set(channel, new EventEmitter());
|
|
326
|
+
sequence.set(channel, 0);
|
|
327
|
+
rpcCallbacks.set(channel, new Map());
|
|
328
|
+
messageQueue.set(channel, []);
|
|
315
329
|
|
|
316
|
-
const wsUrl = new URL(url)
|
|
330
|
+
const wsUrl = new URL(url);
|
|
317
331
|
Object.entries(channelOptions)
|
|
318
332
|
.filter(([key]) => !['sign', 'debug'].includes(key))
|
|
319
|
-
.forEach(([key, value]) => wsUrl.searchParams.set(pascalToSnake(key), value))
|
|
320
|
-
wsUrl.searchParams.set('protocol', 'json-rpc')
|
|
321
|
-
changeStatus(channel, 'connecting')
|
|
322
|
-
const ws = new W3CWebSocket(wsUrl.toString())
|
|
323
|
-
await new Promise<void>((resolve, reject) =>
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
333
|
+
.forEach(([key, value]) => wsUrl.searchParams.set(pascalToSnake(key), value));
|
|
334
|
+
wsUrl.searchParams.set('protocol', 'json-rpc');
|
|
335
|
+
changeStatus(channel, 'connecting');
|
|
336
|
+
const ws = new W3CWebSocket(wsUrl.toString());
|
|
337
|
+
await new Promise<void>((resolve, reject) => {
|
|
338
|
+
Object.assign(ws, {
|
|
339
|
+
onerror: reject,
|
|
340
|
+
onopen: async () => {
|
|
341
|
+
resolve();
|
|
342
|
+
changeStatus(channel, 'connected');
|
|
343
|
+
if (channelOptions.reconnectTx != null) {
|
|
344
|
+
enterState(channel, { handler: openHandler });
|
|
345
|
+
const signedTx = (await call(channel, 'channels.get.offchain_state', {})).signed_tx;
|
|
346
|
+
changeState(channel, signedTx);
|
|
347
|
+
}
|
|
348
|
+
ping(channel);
|
|
349
|
+
},
|
|
350
|
+
onclose: () => {
|
|
351
|
+
changeStatus(channel, 'disconnected');
|
|
352
|
+
const pingTimeoutIdValue = pingTimeoutId.get(channel);
|
|
353
|
+
const pongTimeoutIdValue = pongTimeoutId.get(channel);
|
|
354
|
+
if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue);
|
|
355
|
+
if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue);
|
|
356
|
+
},
|
|
357
|
+
onmessage: ({ data }: { data: string }) => onMessage(channel, data),
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
websockets.set(channel, ws);
|
|
345
361
|
}
|
package/src/contract/Compiler.ts
CHANGED
|
@@ -14,18 +14,19 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
import { Compiler as CompilerApi, ErrorModel, CompilerError } from '../apis/compiler'
|
|
18
|
-
import { genErrorFormatterPolicy, genVersionCheckPolicy } from '../utils/autorest'
|
|
17
|
+
import { Compiler as CompilerApi, ErrorModel, CompilerError } from '../apis/compiler';
|
|
18
|
+
import { genErrorFormatterPolicy, genVersionCheckPolicy } from '../utils/autorest';
|
|
19
19
|
|
|
20
20
|
type GeneralCompilerError = ErrorModel & {
|
|
21
|
-
info?: object
|
|
22
|
-
parameter?: string
|
|
23
|
-
}
|
|
21
|
+
info?: object;
|
|
22
|
+
parameter?: string;
|
|
23
|
+
};
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Contract Compiler
|
|
27
27
|
*
|
|
28
28
|
* This class include api call's related to contract compiler functionality.
|
|
29
|
+
* @category contract
|
|
29
30
|
* @example Compiler('COMPILER_URL')
|
|
30
31
|
*/
|
|
31
32
|
export default class Compiler extends CompilerApi {
|
|
@@ -34,33 +35,33 @@ export default class Compiler extends CompilerApi {
|
|
|
34
35
|
* @param options - Options
|
|
35
36
|
* @param options.ignoreVersion - Don't check compiler version
|
|
36
37
|
*/
|
|
37
|
-
constructor
|
|
38
|
+
constructor(compilerUrl: string, { ignoreVersion }: { ignoreVersion?: boolean } = {}) {
|
|
38
39
|
super(compilerUrl, {
|
|
39
40
|
allowInsecureConnection: true,
|
|
40
41
|
additionalPolicies: [
|
|
41
42
|
genErrorFormatterPolicy((body: GeneralCompilerError | CompilerError[]) => {
|
|
42
|
-
let message = ''
|
|
43
|
+
let message = '';
|
|
43
44
|
if ('reason' in body) {
|
|
44
|
-
message +=
|
|
45
|
-
|
|
45
|
+
message += ` ${body.reason
|
|
46
|
+
}${body.parameter != null ? ` in ${body.parameter}` : ''
|
|
46
47
|
// TODO: revising after improving documentation https://github.com/aeternity/aesophia_http/issues/78
|
|
47
|
-
|
|
48
|
+
}${body.info != null ? ` (${JSON.stringify(body.info)})` : ''}`;
|
|
48
49
|
}
|
|
49
50
|
if (Array.isArray(body)) {
|
|
50
|
-
message +=
|
|
51
|
-
.map(e => `${e.type}:${e.pos.line}:${e.pos.col}: ${e.message}${e.context != null ? `(${e.context})` : ''}`)
|
|
52
|
-
.map(e => e.trim()) // TODO: remove after fixing https://github.com/aeternity/aesophia_http/issues/80
|
|
53
|
-
.join('\n')
|
|
51
|
+
message += `\n${body
|
|
52
|
+
.map((e) => `${e.type}:${e.pos.line}:${e.pos.col}: ${e.message}${e.context != null ? `(${e.context})` : ''}`)
|
|
53
|
+
.map((e) => e.trim()) // TODO: remove after fixing https://github.com/aeternity/aesophia_http/issues/80
|
|
54
|
+
.join('\n')}`;
|
|
54
55
|
}
|
|
55
|
-
return message
|
|
56
|
-
})
|
|
57
|
-
]
|
|
58
|
-
})
|
|
56
|
+
return message;
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
});
|
|
59
60
|
if (ignoreVersion !== true) {
|
|
60
|
-
const versionPromise = this.aPIVersion().then(({ apiVersion }) => apiVersion)
|
|
61
|
+
const versionPromise = this.aPIVersion().then(({ apiVersion }) => apiVersion);
|
|
61
62
|
this.pipeline.addPolicy(
|
|
62
|
-
genVersionCheckPolicy('compiler', '/api-version', versionPromise, '6.1.0', '7.0.0')
|
|
63
|
-
)
|
|
63
|
+
genVersionCheckPolicy('compiler', '/api-version', versionPromise, '6.1.0', '7.0.0'),
|
|
64
|
+
);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|