@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/es/channel/index.mjs
CHANGED
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { snakeToPascal } from "../utils/string.mjs";
|
|
18
18
|
import { buildTx, unpackTx } from "../tx/builder/index.mjs";
|
|
19
|
-
import {
|
|
19
|
+
import { MIN_GAS_PRICE, Tag } from "../tx/builder/constants.mjs";
|
|
20
20
|
import * as handlers from "./handlers.mjs";
|
|
21
21
|
import { eventEmitters, status as channelStatus, state as channelState, initialize, enqueueAction, send, channelId, call, disconnect as channelDisconnect, fsmId as channelFsmId } from "./internal.mjs";
|
|
22
22
|
import { UnknownChannelStateError, ChannelError } from "../utils/errors.mjs";
|
|
23
|
+
import { pause } from "../utils/other.mjs";
|
|
23
24
|
|
|
24
25
|
function snakeToPascalObjKeys(obj) {
|
|
25
26
|
return Object.entries(obj).reduce((result, _ref) => {
|
|
@@ -165,7 +166,7 @@ export default class Channel {
|
|
|
165
166
|
|
|
166
167
|
|
|
167
168
|
async state() {
|
|
168
|
-
return
|
|
169
|
+
return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
|
|
169
170
|
}
|
|
170
171
|
/**
|
|
171
172
|
* Get current round
|
|
@@ -186,16 +187,16 @@ export default class Channel {
|
|
|
186
187
|
const {
|
|
187
188
|
txType,
|
|
188
189
|
tx
|
|
189
|
-
} = unpackTx(state,
|
|
190
|
+
} = unpackTx(state, Tag.SignedTx).tx.encodedTx;
|
|
190
191
|
|
|
191
192
|
switch (txType) {
|
|
192
|
-
case
|
|
193
|
+
case Tag.ChannelCreateTx:
|
|
193
194
|
return 1;
|
|
194
195
|
|
|
195
|
-
case
|
|
196
|
-
case
|
|
197
|
-
case
|
|
198
|
-
return
|
|
196
|
+
case Tag.ChannelOffChainTx:
|
|
197
|
+
case Tag.ChannelWithdrawTx:
|
|
198
|
+
case Tag.ChannelDepositTx:
|
|
199
|
+
return tx.round;
|
|
199
200
|
|
|
200
201
|
default:
|
|
201
202
|
return null;
|
|
@@ -230,7 +231,7 @@ export default class Channel {
|
|
|
230
231
|
* The update is a change to be applied on top of the latest state.
|
|
231
232
|
*
|
|
232
233
|
* Sender and receiver are the channel parties. Both the initiator and responder
|
|
233
|
-
* can take those roles. Any public key outside
|
|
234
|
+
* can take those roles. Any public key outside the channel is considered invalid.
|
|
234
235
|
*
|
|
235
236
|
* @param from - Sender's public address
|
|
236
237
|
* @param to - Receiver's public address
|
|
@@ -255,8 +256,8 @@ export default class Channel {
|
|
|
255
256
|
|
|
256
257
|
async update(from, to, amount, sign) {
|
|
257
258
|
let metadata = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
258
|
-
return
|
|
259
|
-
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen,
|
|
259
|
+
return new Promise((resolve, reject) => {
|
|
260
|
+
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
260
261
|
send(channel, {
|
|
261
262
|
jsonrpc: '2.0',
|
|
262
263
|
method: 'channels.update.new',
|
|
@@ -313,7 +314,7 @@ export default class Channel {
|
|
|
313
314
|
/**
|
|
314
315
|
* Get balances
|
|
315
316
|
*
|
|
316
|
-
* The accounts
|
|
317
|
+
* The accounts param contains a list of addresses to fetch balances of.
|
|
317
318
|
* Those can be either account balances or a contract ones, encoded as an account addresses.
|
|
318
319
|
*
|
|
319
320
|
* If a certain account address had not being found in the state tree - it is simply
|
|
@@ -361,8 +362,8 @@ export default class Channel {
|
|
|
361
362
|
|
|
362
363
|
|
|
363
364
|
async leave() {
|
|
364
|
-
return
|
|
365
|
-
enqueueAction(this, (channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen,
|
|
365
|
+
return new Promise((resolve, reject) => {
|
|
366
|
+
enqueueAction(this, (channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
366
367
|
send(channel, {
|
|
367
368
|
jsonrpc: '2.0',
|
|
368
369
|
method: 'channels.leave',
|
|
@@ -395,7 +396,7 @@ export default class Channel {
|
|
|
395
396
|
|
|
396
397
|
|
|
397
398
|
async shutdown(sign) {
|
|
398
|
-
return
|
|
399
|
+
return new Promise((resolve, reject) => {
|
|
399
400
|
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
400
401
|
send(channel, {
|
|
401
402
|
jsonrpc: '2.0',
|
|
@@ -470,7 +471,7 @@ export default class Channel {
|
|
|
470
471
|
onOwnWithdrawLocked,
|
|
471
472
|
onWithdrawLocked
|
|
472
473
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
473
|
-
return
|
|
474
|
+
return new Promise((resolve, reject) => {
|
|
474
475
|
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
475
476
|
send(channel, {
|
|
476
477
|
jsonrpc: '2.0',
|
|
@@ -551,7 +552,7 @@ export default class Channel {
|
|
|
551
552
|
onOwnDepositLocked,
|
|
552
553
|
onDepositLocked
|
|
553
554
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
554
|
-
return
|
|
555
|
+
return new Promise((resolve, reject) => {
|
|
555
556
|
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
556
557
|
send(channel, {
|
|
557
558
|
jsonrpc: '2.0',
|
|
@@ -618,7 +619,7 @@ export default class Channel {
|
|
|
618
619
|
vmVersion,
|
|
619
620
|
abiVersion
|
|
620
621
|
} = _ref3;
|
|
621
|
-
return
|
|
622
|
+
return new Promise((resolve, reject) => {
|
|
622
623
|
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
623
624
|
send(channel, {
|
|
624
625
|
jsonrpc: '2.0',
|
|
@@ -689,7 +690,7 @@ export default class Channel {
|
|
|
689
690
|
contract,
|
|
690
691
|
abiVersion
|
|
691
692
|
} = _ref4;
|
|
692
|
-
return
|
|
693
|
+
return new Promise((resolve, reject) => {
|
|
693
694
|
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
694
695
|
send(channel, {
|
|
695
696
|
jsonrpc: '2.0',
|
|
@@ -750,12 +751,12 @@ export default class Channel {
|
|
|
750
751
|
contract,
|
|
751
752
|
abiVersion,
|
|
752
753
|
gasLimit = 1000000,
|
|
753
|
-
gasPrice =
|
|
754
|
+
gasPrice = MIN_GAS_PRICE
|
|
754
755
|
} = _ref5;
|
|
755
756
|
let {
|
|
756
757
|
onOnChainTx
|
|
757
758
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
758
|
-
return
|
|
759
|
+
return new Promise((resolve, reject) => {
|
|
759
760
|
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
760
761
|
send(channel, {
|
|
761
762
|
jsonrpc: '2.0',
|
|
@@ -788,7 +789,7 @@ export default class Channel {
|
|
|
788
789
|
* dry-run a contract call. It takes the exact same arguments as a call would
|
|
789
790
|
* and returns the call object.
|
|
790
791
|
*
|
|
791
|
-
* The call is executed in the channel's state but it does not impact the state
|
|
792
|
+
* The call is executed in the channel's state, but it does not impact the state
|
|
792
793
|
* whatsoever. It uses as an environment the latest channel's state and the current
|
|
793
794
|
* top of the blockchain as seen by the node.
|
|
794
795
|
*
|
|
@@ -819,7 +820,7 @@ export default class Channel {
|
|
|
819
820
|
contract,
|
|
820
821
|
abiVersion
|
|
821
822
|
} = _ref6;
|
|
822
|
-
return
|
|
823
|
+
return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
|
|
823
824
|
amount,
|
|
824
825
|
call_data: callData,
|
|
825
826
|
contract_id: contract,
|
|
@@ -855,14 +856,14 @@ export default class Channel {
|
|
|
855
856
|
contract,
|
|
856
857
|
round
|
|
857
858
|
} = _ref7;
|
|
858
|
-
return
|
|
859
|
+
return snakeToPascalObjKeys(await call(this, 'channels.get.contract_call', {
|
|
859
860
|
caller_id: caller,
|
|
860
861
|
contract_id: contract,
|
|
861
862
|
round
|
|
862
863
|
}));
|
|
863
864
|
}
|
|
864
865
|
/**
|
|
865
|
-
* Get
|
|
866
|
+
* Get the latest contract state
|
|
866
867
|
*
|
|
867
868
|
* @param contract - Address of the contract
|
|
868
869
|
* @example
|
|
@@ -880,7 +881,7 @@ export default class Channel {
|
|
|
880
881
|
const result = await call(this, 'channels.get.contract', {
|
|
881
882
|
pubkey: contract
|
|
882
883
|
});
|
|
883
|
-
return
|
|
884
|
+
return snakeToPascalObjKeys({ ...result,
|
|
884
885
|
contract: snakeToPascalObjKeys(result.contract)
|
|
885
886
|
});
|
|
886
887
|
}
|
|
@@ -895,7 +896,7 @@ export default class Channel {
|
|
|
895
896
|
|
|
896
897
|
|
|
897
898
|
async cleanContractCalls() {
|
|
898
|
-
return
|
|
899
|
+
return new Promise((resolve, reject) => {
|
|
899
900
|
enqueueAction(this, (_channel, state) => (state === null || state === void 0 ? void 0 : state.handler) === handlers.channelOpen, channel => {
|
|
900
901
|
send(channel, {
|
|
901
902
|
jsonrpc: '2.0',
|
|
@@ -933,14 +934,25 @@ export default class Channel {
|
|
|
933
934
|
*/
|
|
934
935
|
|
|
935
936
|
|
|
936
|
-
sendMessage(message, recipient) {
|
|
937
|
-
|
|
937
|
+
async sendMessage(message, recipient) {
|
|
938
|
+
const info = typeof message === 'object' ? JSON.stringify(message) : message;
|
|
939
|
+
|
|
940
|
+
if (this.status() === 'connecting') {
|
|
941
|
+
await new Promise(resolve => {
|
|
942
|
+
const onStatusChanged = status => {
|
|
943
|
+
if (status === 'connecting') return;
|
|
944
|
+
resolve();
|
|
945
|
+
this.off('statusChanged', onStatusChanged);
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
this.on('statusChanged', onStatusChanged);
|
|
949
|
+
}); // For some reason we can't immediately send a message when connection is
|
|
950
|
+
// established. Thus we wait 500ms which seems to work.
|
|
938
951
|
|
|
939
|
-
|
|
940
|
-
info = JSON.stringify(message);
|
|
952
|
+
await pause(500);
|
|
941
953
|
}
|
|
942
954
|
|
|
943
|
-
|
|
955
|
+
send(this, {
|
|
944
956
|
jsonrpc: '2.0',
|
|
945
957
|
method: 'channels.message',
|
|
946
958
|
params: {
|
|
@@ -948,29 +960,14 @@ export default class Channel {
|
|
|
948
960
|
to: recipient
|
|
949
961
|
}
|
|
950
962
|
});
|
|
951
|
-
|
|
952
|
-
if (this.status() === 'connecting') {
|
|
953
|
-
const onStatusChanged = status => {
|
|
954
|
-
if (status !== 'connecting') {
|
|
955
|
-
// For some reason we can't immediately send a message when connection is
|
|
956
|
-
// established. Thus we wait 500ms which seems to work.
|
|
957
|
-
setTimeout(() => doSend(this), 500);
|
|
958
|
-
this.off('statusChanged', onStatusChanged);
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
this.on('statusChanged', onStatusChanged);
|
|
963
|
-
} else {
|
|
964
|
-
doSend(this);
|
|
965
|
-
}
|
|
966
963
|
}
|
|
967
964
|
|
|
968
965
|
static async reconnect(options, txParams) {
|
|
969
966
|
const {
|
|
970
967
|
sign
|
|
971
968
|
} = options;
|
|
972
|
-
return
|
|
973
|
-
reconnectTx: await sign('reconnect', buildTx(txParams,
|
|
969
|
+
return Channel.initialize({ ...options,
|
|
970
|
+
reconnectTx: await sign('reconnect', buildTx(txParams, Tag.ChannelClientReconnectTx).tx)
|
|
974
971
|
});
|
|
975
972
|
}
|
|
976
973
|
|
package/es/channel/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["snakeToPascal","buildTx","unpackTx","TX_TYPE","handlers","eventEmitters","status","channelStatus","state","channelState","initialize","enqueueAction","send","channelId","call","disconnect","channelDisconnect","fsmId","channelFsmId","UnknownChannelStateError","ChannelError","snakeToPascalObjKeys","obj","Object","entries","reduce","result","key","val","Channel","options","channel","existingFsmId","awaitingReconnection","awaitingConnection","channelOpen","on","eventName","callback","eventEmitter","get","off","removeListener","round","txType","tx","signed","encodedTx","channelCreate","channelOffChain","channelWithdraw","channelDeposit","id","update","from","to","amount","sign","metadata","Promise","resolve","reject","_channel","handler","_state","jsonrpc","method","params","meta","awaitingOffChainTx","poi","accounts","contracts","balances","fromEntries","map","item","account","balance","leave","awaitingLeave","shutdown","awaitingShutdownTx","withdraw","onOnChainTx","onOwnWithdrawLocked","onWithdrawLocked","awaitingWithdrawTx","deposit","onOwnDepositLocked","onDepositLocked","awaitingDepositTx","createContract","code","callData","vmVersion","abiVersion","call_data","vm_version","abi_version","awaitingNewContractTx","callContract","contract","contract_id","awaitingCallContractUpdateTx","forceProgress","gasLimit","gasPrice","gas_price","gas","awaitingCallContractForceProgressUpdate","callContractStatic","getContractCall","caller","caller_id","getContractState","pubkey","cleanContractCalls","awaitingCallsPruned","sendMessage","message","recipient","info","JSON","stringify","doSend","onStatusChanged","setTimeout","reconnect","txParams","reconnectTx","channelReconnect"],"sources":["../../src/channel/index.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport BigNumber from 'bignumber.js'\nimport { snakeToPascal } from '../utils/string'\nimport { buildTx, unpackTx } from '../tx/builder'\nimport { TX_TYPE } from '../tx/builder/schema'\nimport * as handlers from './handlers'\nimport {\n eventEmitters,\n status as channelStatus,\n state as channelState,\n initialize,\n enqueueAction,\n send,\n channelId,\n call,\n disconnect as channelDisconnect,\n fsmId as channelFsmId,\n SignTx,\n ChannelOptions,\n ChannelState,\n ChannelMessage\n} from './internal'\nimport { UnknownChannelStateError, ChannelError } from '../utils/errors'\nimport { EncodedData } from '../utils/encoder'\n\nfunction snakeToPascalObjKeys<Type> (obj: object): Type {\n return Object.entries(obj).reduce((result, [key, val]) => ({\n ...result,\n [snakeToPascal(key)]: val\n }), {}) as Type\n}\n\ntype EventCallback = (...args: any[]) => void\n\ninterface CallContractOptions {\n amount?: number | BigNumber\n callData?: string\n abiVersion?: number\n contract?: string\n returnValue?: any\n gasUsed?: number | BigNumber\n gasPrice?: number | BigNumber\n height?: number\n callerNonce?: number\n log?: any\n returnType?: string\n}\n\ninterface Contract {\n abiVersion: number\n active: boolean\n deposit: number | BigNumber\n id: string\n ownerId: string\n referrerIds: string[]\n vmVersion: number\n}\n\n/**\n * Channel\n * @example\n * ```js\n * await Channel.initialize({\n * url: 'ws://localhost:3001',\n * role: 'initiator'\n * initiatorId: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * responderId: 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',\n * initiatorAmount: 1e18,\n * responderAmount: 1e18,\n * pushAmount: 0,\n * channelReserve: 0,\n * ttl: 1000,\n * host: 'localhost',\n * port: 3002,\n * lockPeriod: 10,\n * async sign (tag, tx) => await account.signTransaction(tx)\n * })\n * ```\n */\nexport default class Channel {\n /**\n * @param options - Channel params\n * @param options.url - Channel url (for example: \"ws://localhost:3001\")\n * @param options.role - Participant role (\"initiator\" or \"responder\")\n * @param options.initiatorId - Initiator's public key\n * @param options.responderId - Responder's public key\n * @param options.pushAmount - Initial deposit in favour of the responder by the initiator\n * @param options.initiatorAmount - Amount of coins the initiator has committed to\n * the channel\n * @param options.responderAmount - Amount of coins the responder has committed to\n * the channel\n * @param options.channelReserve - The minimum amount both peers need to maintain\n * @param options.ttl - Minimum block height to include the channel_create_tx\n * @param options.host - Host of the responder's node\n * @param options.port - The port of the responders node\n * @param options.lockPeriod - Amount of blocks for disputing a solo close\n * @param options.existingChannelId - Existing channel id (required if reestablishing a\n * channel)\n * @param options.offchainTx - Offchain transaction (required if reestablishing\n * a channel)\n * @param options.timeoutIdle - The time waiting for a new event to be initiated\n * (default: 600000)\n * @param options.timeoutFundingCreate - The time waiting for the initiator to produce\n * the create channel transaction after the noise session had been established (default: 120000)\n * @param options.timeoutFundingSign - The time frame the other client has to sign an\n * off-chain update after our client had initiated and signed it. This applies only for double\n * signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.\n * (default: 120000)\n * @param options.timeoutFundingLock - The time frame the other client has to confirm an\n * on-chain transaction reaching maturity (passing minimum depth) after the local node has\n * detected this. This applies only for double signed on-chain intended updates: channel create\n * transaction, deposit, withdrawal and etc. (default: 360000)\n * @param options.timeoutSign - The time frame the client has to return a signed\n * off-chain update or to decline it. This applies for all off-chain updates (default: 500000)\n * @param options.timeoutAccept - The time frame the other client has to react to an\n * event. This applies for all off-chain updates that are not meant to land on-chain, as well as\n * some special cases: opening a noise connection, mutual closing acknowledgement and\n * reestablishing an existing channel (default: 120000)\n * @param options.timeoutInitialized - the time frame the responder has to accept an\n * incoming noise session. Applicable only for initiator (default: timeout_accept's value)\n * @param options.timeoutAwaitingOpen - The time frame the initiator has to start an\n * outgoing noise session to the responder's node. Applicable only for responder (default:\n * timeout_idle's value)\n * @param options.debug=false - Log websocket communication\n * @param options.sign - Function which verifies and signs transactions\n */\n static async initialize (options: ChannelOptions): Promise<Channel> {\n const channel = new Channel()\n await initialize(\n channel,\n options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection,\n handlers.channelOpen,\n options\n )\n return channel\n }\n\n /**\n * Register event listener function\n *\n * Possible events:\n *\n * - \"error\"\n * - \"onChainTx\"\n * - \"ownWithdrawLocked\"\n * - \"withdrawLocked\"\n * - \"ownDepositLocked\"\n * - \"depositLocked\"\n *\n * TODO: the event list looks outdated\n *\n * @param eventName - Event name\n * @param callback - Callback function\n */\n // TODO define specific callback type depending on the event name\n on (eventName: string, callback: EventCallback): void {\n const eventEmitter = eventEmitters.get(this)\n if (eventEmitter == null) throw new UnknownChannelStateError()\n eventEmitter.on(eventName, callback)\n }\n\n /**\n * Remove event listener function\n * @param eventName - Event name\n * @param callback - Callback function\n */\n off (eventName: string, callback: EventCallback): void {\n const eventEmitter = eventEmitters.get(this)\n if (eventEmitter == null) throw new UnknownChannelStateError()\n eventEmitter.removeListener(eventName, callback)\n }\n\n /**\n * Close the connection\n */\n disconnect (): void {\n return channelDisconnect(this)\n }\n\n /**\n * Get current status\n *\n */\n status (): string {\n const status = channelStatus.get(this)\n if (status == null) throw new UnknownChannelStateError()\n return status\n }\n\n /**\n * Get current state\n */\n async state (): Promise<ChannelState> {\n return await snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}))\n }\n\n /**\n * Get current round\n *\n * If round cannot be determined (for example when channel has not been opened)\n * it will return `null`.\n *\n */\n round (): number | null {\n const state = channelState.get(this)\n if (state == null) {\n return null\n }\n const { txType, tx } = unpackTx(state, TX_TYPE.signed).tx.encodedTx\n switch (txType) {\n case TX_TYPE.channelCreate:\n return 1\n case TX_TYPE.channelOffChain:\n case TX_TYPE.channelWithdraw:\n case TX_TYPE.channelDeposit:\n return +tx.round\n default:\n return null\n }\n }\n\n /**\n * Get channel id\n *\n */\n id (): string {\n const id = channelId.get(this)\n if (id == null) throw new ChannelError('Channel is not initialized')\n return id\n }\n\n /**\n * Get channel's fsm id\n *\n */\n fsmId (): string {\n const id = channelFsmId.get(this)\n if (id == null) throw new ChannelError('Channel is not initialized')\n return id\n }\n\n /**\n * Trigger a transfer update\n *\n * The transfer update is moving coins from one channel account to another.\n * The update is a change to be applied on top of the latest state.\n *\n * Sender and receiver are the channel parties. Both the initiator and responder\n * can take those roles. Any public key outside of the channel is considered invalid.\n *\n * @param from - Sender's public address\n * @param to - Receiver's public address\n * @param amount - Transaction amount\n * @param sign - Function which verifies and signs offchain transaction\n * @param metadata - Metadata\n\n * @example\n * ```js\n * channel.update(\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',\n * 10,\n * async (tx) => await account.signTransaction(tx)\n * ).then(({ accepted, signedTx }) =>\n * if (accepted) {\n * console.log('Update has been accepted')\n * }\n * )\n * ```\n */\n async update (\n from: string,\n to: string,\n amount: number | BigNumber,\n sign: SignTx,\n metadata: string[] = []): Promise<{\n accepted: boolean\n signedTx?: string\n errorCode?: number\n errorMessage?: string\n }> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel, _state) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.update.new',\n params: { from, to, amount, meta: metadata }\n })\n return {\n handler: handlers.awaitingOffChainTx,\n state: {\n resolve,\n reject,\n sign\n }\n }\n }\n )\n })\n }\n\n /**\n * Get proof of inclusion\n *\n * If a certain address of an account or a contract is not found\n * in the state tree - the response is an error.\n *\n * @param addresses - Addresses\n * @param addresses.accounts - List of account addresses to include in poi\n * @param addresses.contracts - List of contract addresses to include in poi\n * @example\n * ```js\n * channel.poi({\n * accounts: [\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'\n * ],\n * contracts: ['ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA']\n * }).then(poi => console.log(poi))\n * ```\n */\n async poi (\n { accounts, contracts }: { accounts: string[], contracts?: string[] }\n ): Promise<EncodedData<'pi'>> {\n return (await call(this, 'channels.get.poi', { accounts, contracts })).poi\n }\n\n /**\n * Get balances\n *\n * The accounts paramcontains a list of addresses to fetch balances of.\n * Those can be either account balances or a contract ones, encoded as an account addresses.\n *\n * If a certain account address had not being found in the state tree - it is simply\n * skipped in the response.\n *\n * @param accounts - List of addresses to fetch balances from\n * @example\n * ```js\n * channel.balances([\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'\n * 'ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA'\n * ]).then(balances =>\n * console.log(balances['ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'])\n * )\n * ```\n */\n async balances (accounts: Array<EncodedData<'ak'>>): Promise<{ [key: EncodedData<'ak'>]: string }> {\n return Object.fromEntries(\n (await call(this, 'channels.get.balances', { accounts }))\n .map((item: {\n account: EncodedData<'ak'>\n balance: string\n }) => [item.account, item.balance])\n )\n }\n\n /**\n * Leave channel\n *\n * It is possible to leave a channel and then later reestablish the channel\n * off-chain state and continue operation. When a leave method is called,\n * the channel fsm passes it on to the peer fsm, reports the current mutually\n * signed state and then terminates.\n *\n * The channel can be reestablished by instantiating another Channel instance\n * with two extra params: existingChannelId and offchainTx (returned from leave\n * method as channelId and signedTx respectively).\n *\n * @example\n * ```js\n * channel.leave().then(({ channelId, signedTx }) => {\n * console.log(channelId)\n * console.log(signedTx)\n * })\n * ```\n */\n async leave (): Promise<{ channelId: string, signedTx: string }> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (channel, state) => state?.handler === handlers.channelOpen,\n (channel, _state) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.leave', params: {} })\n return {\n handler: handlers.awaitingLeave,\n state: { resolve, reject }\n }\n })\n })\n }\n\n /**\n * Trigger mutual close\n *\n * At any moment after the channel is opened, a closing procedure can be triggered.\n * This can be done by either of the parties. The process is similar to the off-chain updates.\n *\n * @param sign - Function which verifies and signs mutual close transaction\n * @example\n * ```js\n * channel.shutdown(\n * async (tx) => await account.signTransaction(tx)\n * ).then(tx => console.log('on_chain_tx', tx))\n * ```\n */\n async shutdown (sign: Function): Promise<string> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.shutdown', params: {} })\n return {\n handler: handlers.awaitingShutdownTx,\n state: {\n sign,\n resolve,\n reject\n }\n }\n }\n )\n })\n }\n\n /**\n * Withdraw coins from the channel\n *\n * After the channel had been opened any of the participants can initiate a withdrawal.\n * The process closely resembles the update. The most notable difference is that the\n * transaction has been co-signed: it is channel_withdraw_tx and after the procedure\n * is finished - it is being posted on-chain.\n *\n * Any of the participants can initiate a withdrawal. The only requirements are:\n *\n * - Channel is already opened\n * - No off-chain update/deposit/withdrawal is currently being performed\n * - Channel is not being closed or in a solo closing state\n * - The withdrawal amount must be equal to or greater than zero, and cannot exceed\n * the available balance on the channel (minus the channel_reserve)\n *\n * After the other party had signed the withdraw transaction, the transaction is posted\n * on-chain and onOnChainTx callback is called with on-chain transaction as first argument.\n * After computing transaction hash it can be tracked on the chain: entering the mempool,\n * block inclusion and a number of confirmations.\n *\n * After the minimum_depth block confirmations onOwnWithdrawLocked callback is called\n * (without any arguments).\n *\n * When the other party had confirmed that the block height needed is reached\n * onWithdrawLocked callback is called (without any arguments).\n *\n * @param amount - Amount of coins to withdraw\n * @param sign - Function which verifies and signs withdraw transaction\n * @param callbacks - Callbacks\n * @param callbacks.onOnChainTx - Called when withdraw transaction has been posted\n * on chain\n * @param callbacks.onOwnWithdrawLocked\n * @param callbacks.onWithdrawLocked\n * @example\n * ```js\n * channel.withdraw(\n * 100,\n * async (tx) => await account.signTransaction(tx),\n * { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }\n * ).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Withdrawal has been accepted')\n * } else {\n * console.log('Withdrawal has been rejected')\n * }\n * })\n * ```\n */\n async withdraw (\n amount: number | BigNumber,\n sign: SignTx,\n { onOnChainTx, onOwnWithdrawLocked, onWithdrawLocked }:\n { onOnChainTx?: Function, onOwnWithdrawLocked?: Function, onWithdrawLocked?: Function } = {}\n ): Promise<{ accepted: boolean, signedTx: string }> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } })\n return {\n handler: handlers.awaitingWithdrawTx,\n state: {\n sign,\n resolve,\n reject,\n onOnChainTx,\n onOwnWithdrawLocked,\n onWithdrawLocked\n }\n }\n }\n )\n })\n }\n\n /**\n * Deposit coins into the channel\n *\n * After the channel had been opened any of the participants can initiate a deposit.\n * The process closely resembles the update. The most notable difference is that the\n * transaction has been co-signed: it is channel_deposit_tx and after the procedure\n * is finished - it is being posted on-chain.\n *\n * Any of the participants can initiate a deposit. The only requirements are:\n *\n * - Channel is already opened\n * - No off-chain update/deposit/withdrawal is currently being performed\n * - Channel is not being closed or in a solo closing state\n * - The deposit amount must be equal to or greater than zero, and cannot exceed\n * the available balance on the channel (minus the channel_reserve)\n *\n * After the other party had signed the deposit transaction, the transaction is posted\n * on-chain and onOnChainTx callback is called with on-chain transaction as first argument.\n * After computing transaction hash it can be tracked on the chain: entering the mempool,\n * block inclusion and a number of confirmations.\n *\n * After the minimum_depth block confirmations onOwnDepositLocked callback is called\n * (without any arguments).\n *\n * When the other party had confirmed that the block height needed is reached\n * onDepositLocked callback is called (without any arguments).\n *\n * @param amount - Amount of coins to deposit\n * @param sign - Function which verifies and signs deposit transaction\n * @param callbacks - Callbacks\n * @param callbacks.onOnChainTx - Called when deposit transaction has been posted\n * on chain\n * @param callbacks.onOwnDepositLocked\n * @param callbacks.onDepositLocked\n * @example\n * ```js\n * channel.deposit(\n * 100,\n * async (tx) => await account.signTransaction(tx),\n * { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }\n * ).then(({ accepted, state }) => {\n * if (accepted) {\n * console.log('Deposit has been accepted')\n * console.log('The new state is:', state)\n * } else {\n * console.log('Deposit has been rejected')\n * }\n * })\n * ```\n */\n async deposit (\n amount: number | BigNumber,\n sign: SignTx,\n { onOnChainTx, onOwnDepositLocked, onDepositLocked }:\n { onOnChainTx?: Function, onOwnDepositLocked?: Function, onDepositLocked?: Function } = {}\n ): Promise<{ accepted: boolean, state: ChannelState }> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.deposit', params: { amount } })\n return {\n handler: handlers.awaitingDepositTx,\n state: {\n sign,\n resolve,\n reject,\n onOnChainTx,\n onOwnDepositLocked,\n onDepositLocked\n }\n }\n }\n )\n })\n }\n\n /**\n * Trigger create contract update\n *\n * The create contract update is creating a contract inside the channel's internal state tree.\n * The update is a change to be applied on top of the latest state.\n *\n * That would create a contract with the poster being the owner of it. Poster commits initially\n * a deposit amount of coins to the new contract.\n *\n * @param options - Options\n * @param options.code - Api encoded compiled AEVM byte code\n * @param options.callData - Api encoded compiled AEVM call data for the code\n * @param options.deposit - Initial amount the owner of the contract commits to it\n * @param options.vmVersion - Version of the Virtual Machine\n * @param options.abiVersion - Version of the Application Binary Interface\n * @param sign - Function which verifies and signs create contract transaction\n * @example\n * ```js\n * channel.createContract({\n * code: 'cb_HKtpipK4aCgYb17wZ...',\n * callData: 'cb_1111111111111111...',\n * deposit: 10,\n * vmVersion: 3,\n * abiVersion: 1\n * }).then(({ accepted, signedTx, address }) => {\n * if (accepted) {\n * console.log('New contract has been created')\n * console.log('Contract address:', address)\n * } else {\n * console.log('New contract has been rejected')\n * }\n * })\n * ```\n */\n async createContract (\n { code, callData, deposit, vmVersion, abiVersion }: {\n code: string\n callData: string\n deposit: number | BigNumber\n vmVersion: number\n abiVersion: number\n },\n sign: SignTx\n ): Promise<{ accepted: boolean, signedTx: string, address: string }> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.update.new_contract',\n params: {\n code,\n call_data: callData,\n deposit,\n vm_version: vmVersion,\n abi_version: abiVersion\n }\n })\n return {\n handler: handlers.awaitingNewContractTx,\n state: {\n sign,\n resolve,\n reject\n }\n }\n }\n )\n })\n }\n\n /**\n * Trigger call a contract update\n *\n * The call contract update is calling a preexisting contract inside the channel's\n * internal state tree. The update is a change to be applied on top of the latest state.\n *\n * That would call a contract with the poster being the caller of it. Poster commits\n * an amount of coins to the contract.\n *\n * The call would also create a call object inside the channel state tree. It contains\n * the result of the contract call.\n *\n * It is worth mentioning that the gas is not consumed, because this is an off-chain\n * contract call. It would be consumed if it were an on-chain one. This could happen\n * if a call with a similar computation amount is to be forced on-chain.\n *\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @param sign - Function which verifies and signs contract call transaction\n * @example\n * ```js\n * channel.callContract({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract called succesfully')\n * } else {\n * console.log('Contract call has been rejected')\n * }\n * })\n * ```\n */\n async callContract (\n { amount, callData, contract, abiVersion }: CallContractOptions,\n sign: SignTx\n ): Promise<{ accepted: boolean, signedTx: string }> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.update.call_contract',\n params: {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion\n }\n })\n return {\n handler: handlers.awaitingCallContractUpdateTx,\n state: { resolve, reject, sign }\n }\n }\n )\n })\n }\n\n /**\n * Trigger a force progress contract call\n * This call is going on-chain\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @param options.gasPrice=1000000000]\n * @param options.gasLimit=1000000]\n * @param sign - Function which verifies and signs contract force progress transaction\n * @param callbacks - Callbacks\n * @example\n * ```js\n * channel.forceProgress({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1,\n * gasPrice: 1000005554\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract force progress call successful')\n * } else {\n * console.log('Contract force progress call has been rejected')\n * }\n * })\n * ```\n */\n async forceProgress (\n { amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = 1000000000 }: {\n amount: number\n callData: string\n contract: string\n abiVersion: number\n gasLimit?: number\n gasPrice?: number\n },\n sign: SignTx,\n { onOnChainTx }: { onOnChainTx?: Function } = {}\n ): Promise<{ accepted: boolean, signedTx: string, tx: EncodedData<'tx'> | Uint8Array }> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.force_progress',\n params: {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n gas_price: gasPrice,\n gas: gasLimit\n }\n })\n return {\n handler: handlers.awaitingCallContractForceProgressUpdate,\n state: { resolve, reject, sign, onOnChainTx }\n }\n }\n )\n })\n }\n\n /**\n * Call contract using dry-run\n *\n * In order to get the result of a potential contract call, one might need to\n * dry-run a contract call. It takes the exact same arguments as a call would\n * and returns the call object.\n *\n * The call is executed in the channel's state but it does not impact the state\n * whatsoever. It uses as an environment the latest channel's state and the current\n * top of the blockchain as seen by the node.\n *\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @example\n * ```js\n * channel.callContractStatic({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ returnValue, gasUsed }) => {\n * console.log('Returned value:', returnValue)\n * console.log('Gas used:', gasUsed)\n * })\n * ```\n */\n async callContractStatic (\n { amount, callData, contract, abiVersion }:\n { amount: number, callData: string, contract: string, abiVersion: number }\n ): Promise<CallContractOptions> {\n return await snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion\n }))\n }\n\n /**\n * Get contract call result\n *\n * The combination of a caller, contract and a round of execution determines the\n * contract call. Providing an incorrect set of those results in an error response.\n *\n * @param options - Options\n * @param options.caller - Address of contract caller\n * @param options.contract - Address of the contract\n * @param options.round - Round when contract was called\n * @example\n * ```js\n * channel.getContractCall({\n * caller: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * round: 3\n * }).then(({ returnType, returnValue }) => {\n * if (returnType === 'ok') console.log(returnValue)\n * })\n * ```\n */\n async getContractCall (\n { caller, contract, round }: { caller: string, contract: string, round: number }\n ): Promise<{\n returnType: string\n returnValue: string\n gasPrice: number | BigNumber\n gasUsed: number | BigNumber\n height: number\n log: string\n }> {\n return await snakeToPascalObjKeys(\n await call(this, 'channels.get.contract_call', {\n caller_id: caller,\n contract_id: contract,\n round\n })\n )\n }\n\n /**\n * Get contract latest state\n *\n * @param contract - Address of the contract\n * @example\n * ```js\n * channel.getContractState(\n * 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa'\n * ).then(({ contract }) => {\n * console.log('deposit:', contract.deposit)\n * })\n * ```\n */\n async getContractState (\n contract: string\n ): Promise<{ contract: Contract, contractState: object }> {\n const result = await call(this, 'channels.get.contract', { pubkey: contract })\n return await snakeToPascalObjKeys({\n ...result,\n contract: snakeToPascalObjKeys(result.contract)\n })\n }\n\n /**\n * Clean up all locally stored contract calls\n *\n * Contract calls are kept locally in order for the participant to be able to look them up.\n * They consume memory and in order for the participant to free it - one can prune all messages.\n * This cleans up all locally stored contract calls and those will no longer be available for\n * fetching and inspection.\n */\n async cleanContractCalls (): Promise<void> {\n return await new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.clean_contract_calls',\n params: {}\n })\n return {\n handler: handlers.awaitingCallsPruned,\n state: { resolve, reject }\n }\n }\n )\n })\n }\n\n /**\n * Send generic message\n *\n * If message is an object it will be serialized into JSON string\n * before sending.\n *\n * If there is ongoing update that has not yet been finished the message\n * will be sent after that update is finalized.\n *\n * @param message - Message\n * @param recipient - Address of the recipient\n * @example\n * ```js\n * channel.sendMessage(\n * 'hello world',\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'\n * )\n * ```\n */\n sendMessage (message: string | ChannelMessage, recipient: string): void {\n let info = message\n if (typeof message === 'object') {\n info = JSON.stringify(message)\n }\n const doSend = (channel: Channel): void => send(channel, {\n jsonrpc: '2.0',\n method: 'channels.message',\n params: { info, to: recipient }\n })\n if (this.status() === 'connecting') {\n const onStatusChanged = (status: string): void => {\n if (status !== 'connecting') {\n // For some reason we can't immediately send a message when connection is\n // established. Thus we wait 500ms which seems to work.\n setTimeout(() => doSend(this), 500)\n this.off('statusChanged', onStatusChanged)\n }\n }\n this.on('statusChanged', onStatusChanged)\n } else {\n doSend(this)\n }\n }\n\n static async reconnect (options: ChannelOptions, txParams: any): Promise<Channel> {\n const { sign } = options\n\n return await Channel.initialize({\n ...options,\n reconnectTx: await sign('reconnect', buildTx(txParams, TX_TYPE.channelReconnect).tx)\n })\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;SAESA,a;SACAC,O,EAASC,Q;SACTC,O;OACF,KAAKC,Q;SAEVC,a,EACAC,MAAM,IAAIC,a,EACVC,KAAK,IAAIC,Y,EACTC,U,EACAC,a,EACAC,I,EACAC,S,EACAC,I,EACAC,UAAU,IAAIC,iB,EACdC,KAAK,IAAIC,Y;SAMFC,wB,EAA0BC,Y;;AAGnC,SAASC,oBAAT,CAAqCC,GAArC,EAAwD;EACtD,OAAOC,MAAM,CAACC,OAAP,CAAeF,GAAf,EAAoBG,MAApB,CAA2B,CAACC,MAAD;IAAA,IAAS,CAACC,GAAD,EAAMC,GAAN,CAAT;IAAA,OAAyB,EACzD,GAAGF,MADsD;MAEzD,CAAC1B,aAAa,CAAC2B,GAAD,CAAd,GAAsBC;IAFmC,CAAzB;EAAA,CAA3B,EAGH,EAHG,CAAP;AAID;;AA4BD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,OAAN,CAAc;EAC3B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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b;IAkBD,CAnBY,CAAb;EAoBD;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;EACe,MAAPE,OAAO,CACXhC,MADW,EAEXC,IAFW,EAK0C;IAAA,IAFrD;MAAE2B,WAAF;MAAeK,kBAAf;MAAmCC;IAAnC,CAEqD,uEADmC,EACnC;IACrD,OAAO,MAAM,IAAI/B,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MAC5ClD,aAAa,CACX,IADW,EAEX,CAACmD,QAAD,EAAWtD,KAAX,KAAqB,CAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEuD,OAAP,MAAmB3D,QAAQ,CAAC+B,WAFtC,EAGVJ,OAAD,IAAa;QACXnB,IAAI,CAACmB,OAAD,EAAU;UAAEkC,OAAO,EAAE,KAAX;UAAkBC,MAAM,EAAE,kBAA1B;UAA8CC,MAAM,EAAE;YAAEX;UAAF;QAAtD,CAAV,CAAJ;QACA,OAAO;UACLO,OAAO,EAAE3D,QAAQ,CAACuF,iBADb;UAELnF,KAAK,EAAE;YACLiD,IADK;YAELG,OAFK;YAGLC,MAHK;YAILuB,WAJK;YAKLK,kBALK;YAMLC;UANK;QAFF,CAAP;MAWD,CAhBU,CAAb;IAkBD,CAnBY,CAAb;EAoBD;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;EACsB,MAAdE,cAAc,QAQlBnC,IARkB,EASiD;IAAA,IARnE;MAAEo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AD8C;MAEvDC,MAAM,EAAE,kBAF+C;MAGvDC,MAAM,EAAE;QAAEuD,IAAF;QAAQnE,EAAE,EAAEkE;MAAZ;IAH+C,CAAV,CAA/C;;IAKA,IAAI,KAAKnH,MAAL,OAAkB,YAAtB,EAAoC;MAClC,MAAMwH,eAAe,GAAIxH,MAAD,IAA0B;QAChD,IAAIA,MAAM,KAAK,YAAf,EAA6B;UAC3B;UACA;UACAyH,UAAU,CAAC,MAAMF,MAAM,CAAC,IAAD,CAAb,EAAqB,GAArB,CAAV;UACA,KAAKpF,GAAL,CAAS,eAAT,EAA0BqF,eAA1B;QACD;MACF,CAPD;;MAQA,KAAK1F,EAAL,CAAQ,eAAR,EAAyB0F,eAAzB;IACD,CAVD,MAUO;MACLD,MAAM,CAAC,IAAD,CAAN;IACD;EACF;;EAEqB,aAATG,SAAS,CAAElG,OAAF,EAA2BmG,QAA3B,EAA4D;IAChF,MAAM;MAAExE;IAAF,IAAW3B,OAAjB;IAEA,OAAO,MAAMD,OAAO,CAACnB,UAAR,CAAmB,EAC9B,GAAGoB,OAD2B;MAE9BoG,WAAW,EAAE,MAAMzE,IAAI,CAAC,WAAD,EAAcxD,OAAO,CAACgI,QAAD,EAAW9H,OAAO,CAACgI,gBAAnB,CAAP,CAA4CtF,EAA1D;IAFO,CAAnB,CAAb;EAID;;AA/3B0B"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["snakeToPascal","buildTx","unpackTx","MIN_GAS_PRICE","Tag","handlers","eventEmitters","status","channelStatus","state","channelState","initialize","enqueueAction","send","channelId","call","disconnect","channelDisconnect","fsmId","channelFsmId","UnknownChannelStateError","ChannelError","pause","snakeToPascalObjKeys","obj","Object","entries","reduce","result","key","val","Channel","options","channel","existingFsmId","awaitingReconnection","awaitingConnection","channelOpen","on","eventName","callback","eventEmitter","get","off","removeListener","round","txType","tx","SignedTx","encodedTx","ChannelCreateTx","ChannelOffChainTx","ChannelWithdrawTx","ChannelDepositTx","id","update","from","to","amount","sign","metadata","Promise","resolve","reject","_channel","handler","jsonrpc","method","params","meta","awaitingOffChainTx","poi","accounts","contracts","balances","fromEntries","map","item","account","balance","leave","awaitingLeave","shutdown","awaitingShutdownTx","withdraw","onOnChainTx","onOwnWithdrawLocked","onWithdrawLocked","awaitingWithdrawTx","deposit","onOwnDepositLocked","onDepositLocked","awaitingDepositTx","createContract","code","callData","vmVersion","abiVersion","call_data","vm_version","abi_version","awaitingNewContractTx","callContract","contract","contract_id","awaitingCallContractUpdateTx","forceProgress","gasLimit","gasPrice","gas_price","gas","awaitingCallContractForceProgressUpdate","callContractStatic","getContractCall","caller","caller_id","getContractState","pubkey","cleanContractCalls","awaitingCallsPruned","sendMessage","message","recipient","info","JSON","stringify","onStatusChanged","reconnect","txParams","reconnectTx","ChannelClientReconnectTx"],"sources":["../../src/channel/index.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport BigNumber from 'bignumber.js';\nimport { snakeToPascal } from '../utils/string';\nimport { buildTx, unpackTx } from '../tx/builder';\nimport { MIN_GAS_PRICE, Tag } from '../tx/builder/constants';\nimport * as handlers from './handlers';\nimport {\n eventEmitters,\n status as channelStatus,\n state as channelState,\n initialize,\n enqueueAction,\n send,\n channelId,\n call,\n disconnect as channelDisconnect,\n fsmId as channelFsmId,\n SignTx,\n ChannelOptions,\n ChannelState,\n} from './internal';\nimport { UnknownChannelStateError, ChannelError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport { ContractCallReturnType } from '../apis/node';\nimport { pause } from '../utils/other';\n\nfunction snakeToPascalObjKeys<Type>(obj: object): Type {\n return Object.entries(obj).reduce((result, [key, val]) => ({\n ...result,\n [snakeToPascal(key)]: val,\n }), {}) as Type;\n}\n\ntype EventCallback = (...args: any[]) => void;\n\ninterface CallContractOptions {\n amount?: number | BigNumber;\n callData?: Encoded.ContractBytearray;\n abiVersion?: number;\n contract?: Encoded.ContractAddress;\n returnValue?: any;\n gasUsed?: number | BigNumber;\n gasPrice?: number | BigNumber;\n height?: number;\n callerNonce?: number;\n log?: any;\n returnType?: ContractCallReturnType;\n}\n\ninterface Contract {\n abiVersion: number;\n active: boolean;\n deposit: number | BigNumber;\n id: string;\n ownerId: string;\n referrerIds: string[];\n vmVersion: number;\n}\n\n/**\n * Channel\n * @example\n * ```js\n * await Channel.initialize({\n * url: 'ws://localhost:3001',\n * role: 'initiator'\n * initiatorId: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * responderId: 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',\n * initiatorAmount: 1e18,\n * responderAmount: 1e18,\n * pushAmount: 0,\n * channelReserve: 0,\n * ttl: 1000,\n * host: 'localhost',\n * port: 3002,\n * lockPeriod: 10,\n * async sign (tag, tx) => await account.signTransaction(tx)\n * })\n * ```\n */\nexport default class Channel {\n /**\n * @param options - Channel params\n * @param options.url - Channel url (for example: \"ws://localhost:3001\")\n * @param options.role - Participant role (\"initiator\" or \"responder\")\n * @param options.initiatorId - Initiator's public key\n * @param options.responderId - Responder's public key\n * @param options.pushAmount - Initial deposit in favour of the responder by the initiator\n * @param options.initiatorAmount - Amount of coins the initiator has committed to\n * the channel\n * @param options.responderAmount - Amount of coins the responder has committed to\n * the channel\n * @param options.channelReserve - The minimum amount both peers need to maintain\n * @param options.ttl - Minimum block height to include the channel_create_tx\n * @param options.host - Host of the responder's node\n * @param options.port - The port of the responders node\n * @param options.lockPeriod - Amount of blocks for disputing a solo close\n * @param options.existingChannelId - Existing channel id (required if reestablishing a\n * channel)\n * @param options.offchainTx - Offchain transaction (required if reestablishing\n * a channel)\n * @param options.timeoutIdle - The time waiting for a new event to be initiated\n * (default: 600000)\n * @param options.timeoutFundingCreate - The time waiting for the initiator to produce\n * the create channel transaction after the noise session had been established (default: 120000)\n * @param options.timeoutFundingSign - The time frame the other client has to sign an\n * off-chain update after our client had initiated and signed it. This applies only for double\n * signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.\n * (default: 120000)\n * @param options.timeoutFundingLock - The time frame the other client has to confirm an\n * on-chain transaction reaching maturity (passing minimum depth) after the local node has\n * detected this. This applies only for double signed on-chain intended updates: channel create\n * transaction, deposit, withdrawal and etc. (default: 360000)\n * @param options.timeoutSign - The time frame the client has to return a signed\n * off-chain update or to decline it. This applies for all off-chain updates (default: 500000)\n * @param options.timeoutAccept - The time frame the other client has to react to an\n * event. This applies for all off-chain updates that are not meant to land on-chain, as well as\n * some special cases: opening a noise connection, mutual closing acknowledgement and\n * reestablishing an existing channel (default: 120000)\n * @param options.timeoutInitialized - the time frame the responder has to accept an\n * incoming noise session. Applicable only for initiator (default: timeout_accept's value)\n * @param options.timeoutAwaitingOpen - The time frame the initiator has to start an\n * outgoing noise session to the responder's node. Applicable only for responder (default:\n * timeout_idle's value)\n * @param options.debug=false - Log websocket communication\n * @param options.sign - Function which verifies and signs transactions\n */\n static async initialize(options: ChannelOptions): Promise<Channel> {\n const channel = new Channel();\n await initialize(\n channel,\n options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection,\n handlers.channelOpen,\n options,\n );\n return channel;\n }\n\n /**\n * Register event listener function\n *\n * Possible events:\n *\n * - \"error\"\n * - \"onChainTx\"\n * - \"ownWithdrawLocked\"\n * - \"withdrawLocked\"\n * - \"ownDepositLocked\"\n * - \"depositLocked\"\n *\n * TODO: the event list looks outdated\n *\n * @param eventName - Event name\n * @param callback - Callback function\n */\n // TODO define specific callback type depending on the event name\n on(eventName: string, callback: EventCallback): void {\n const eventEmitter = eventEmitters.get(this);\n if (eventEmitter == null) throw new UnknownChannelStateError();\n eventEmitter.on(eventName, callback);\n }\n\n /**\n * Remove event listener function\n * @param eventName - Event name\n * @param callback - Callback function\n */\n off(eventName: string, callback: EventCallback): void {\n const eventEmitter = eventEmitters.get(this);\n if (eventEmitter == null) throw new UnknownChannelStateError();\n eventEmitter.removeListener(eventName, callback);\n }\n\n /**\n * Close the connection\n */\n disconnect(): void {\n return channelDisconnect(this);\n }\n\n /**\n * Get current status\n *\n */\n status(): string {\n const status = channelStatus.get(this);\n if (status == null) throw new UnknownChannelStateError();\n return status;\n }\n\n /**\n * Get current state\n */\n async state(): Promise<ChannelState> {\n return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));\n }\n\n /**\n * Get current round\n *\n * If round cannot be determined (for example when channel has not been opened)\n * it will return `null`.\n *\n */\n round(): number | null {\n const state = channelState.get(this);\n if (state == null) {\n return null;\n }\n const { txType, tx } = unpackTx(state, Tag.SignedTx).tx.encodedTx;\n switch (txType) {\n case Tag.ChannelCreateTx:\n return 1;\n case Tag.ChannelOffChainTx:\n case Tag.ChannelWithdrawTx:\n case Tag.ChannelDepositTx:\n return tx.round;\n default:\n return null;\n }\n }\n\n /**\n * Get channel id\n *\n */\n id(): string {\n const id = channelId.get(this);\n if (id == null) throw new ChannelError('Channel is not initialized');\n return id;\n }\n\n /**\n * Get channel's fsm id\n *\n */\n fsmId(): string {\n const id = channelFsmId.get(this);\n if (id == null) throw new ChannelError('Channel is not initialized');\n return id;\n }\n\n /**\n * Trigger a transfer update\n *\n * The transfer update is moving coins from one channel account to another.\n * The update is a change to be applied on top of the latest state.\n *\n * Sender and receiver are the channel parties. Both the initiator and responder\n * can take those roles. Any public key outside the channel is considered invalid.\n *\n * @param from - Sender's public address\n * @param to - Receiver's public address\n * @param amount - Transaction amount\n * @param sign - Function which verifies and signs offchain transaction\n * @param metadata - Metadata\n\n * @example\n * ```js\n * channel.update(\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E',\n * 10,\n * async (tx) => await account.signTransaction(tx)\n * ).then(({ accepted, signedTx }) =>\n * if (accepted) {\n * console.log('Update has been accepted')\n * }\n * )\n * ```\n */\n async update(\n from: Encoded.AccountAddress,\n to: Encoded.AccountAddress,\n amount: number | BigNumber,\n sign: SignTx,\n metadata: string[] = [],\n ): Promise<{\n accepted: boolean;\n signedTx?: Encoded.Transaction;\n errorCode?: number;\n errorMessage?: string;\n }> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.update.new',\n params: {\n from, to, amount, meta: metadata,\n },\n });\n return {\n handler: handlers.awaitingOffChainTx,\n state: {\n resolve,\n reject,\n sign,\n },\n };\n },\n );\n });\n }\n\n /**\n * Get proof of inclusion\n *\n * If a certain address of an account or a contract is not found\n * in the state tree - the response is an error.\n *\n * @param addresses - Addresses\n * @param addresses.accounts - List of account addresses to include in poi\n * @param addresses.contracts - List of contract addresses to include in poi\n * @example\n * ```js\n * channel.poi({\n * accounts: [\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'\n * ],\n * contracts: ['ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA']\n * }).then(poi => console.log(poi))\n * ```\n */\n async poi(\n { accounts, contracts }: {\n accounts: Encoded.AccountAddress[];\n contracts?: Encoded.ContractAddress[];\n },\n ): Promise<Encoded.Poi> {\n return (await call(this, 'channels.get.poi', { accounts, contracts })).poi;\n }\n\n /**\n * Get balances\n *\n * The accounts param contains a list of addresses to fetch balances of.\n * Those can be either account balances or a contract ones, encoded as an account addresses.\n *\n * If a certain account address had not being found in the state tree - it is simply\n * skipped in the response.\n *\n * @param accounts - List of addresses to fetch balances from\n * @example\n * ```js\n * channel.balances([\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * 'ak_V6an1xhec1xVaAhLuak7QoEbi6t7w5hEtYWp9bMKaJ19i6A9E'\n * 'ct_2dCUAWYZdrWfACz3a2faJeKVTVrfDYxCQHCqAt5zM15f3u2UfA'\n * ]).then(balances =>\n * console.log(balances['ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'])\n * )\n * ```\n */\n async balances(\n accounts: Encoded.AccountAddress[],\n ): Promise<{ [key: Encoded.AccountAddress]: string }> {\n return Object.fromEntries(\n (await call(this, 'channels.get.balances', { accounts }))\n .map((item: {\n account: Encoded.AccountAddress;\n balance: string;\n }) => [item.account, item.balance]),\n );\n }\n\n /**\n * Leave channel\n *\n * It is possible to leave a channel and then later reestablish the channel\n * off-chain state and continue operation. When a leave method is called,\n * the channel fsm passes it on to the peer fsm, reports the current mutually\n * signed state and then terminates.\n *\n * The channel can be reestablished by instantiating another Channel instance\n * with two extra params: existingChannelId and offchainTx (returned from leave\n * method as channelId and signedTx respectively).\n *\n * @example\n * ```js\n * channel.leave().then(({ channelId, signedTx }) => {\n * console.log(channelId)\n * console.log(signedTx)\n * })\n * ```\n */\n async leave(): Promise<{ channelId: string; signedTx: Encoded.Transaction }> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.leave', params: {} });\n return {\n handler: handlers.awaitingLeave,\n state: { resolve, reject },\n };\n },\n );\n });\n }\n\n /**\n * Trigger mutual close\n *\n * At any moment after the channel is opened, a closing procedure can be triggered.\n * This can be done by either of the parties. The process is similar to the off-chain updates.\n *\n * @param sign - Function which verifies and signs mutual close transaction\n * @example\n * ```js\n * channel.shutdown(\n * async (tx) => await account.signTransaction(tx)\n * ).then(tx => console.log('on_chain_tx', tx))\n * ```\n */\n async shutdown(sign: Function): Promise<Encoded.Transaction> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.shutdown', params: {} });\n return {\n handler: handlers.awaitingShutdownTx,\n state: {\n sign,\n resolve,\n reject,\n },\n };\n },\n );\n });\n }\n\n /**\n * Withdraw coins from the channel\n *\n * After the channel had been opened any of the participants can initiate a withdrawal.\n * The process closely resembles the update. The most notable difference is that the\n * transaction has been co-signed: it is channel_withdraw_tx and after the procedure\n * is finished - it is being posted on-chain.\n *\n * Any of the participants can initiate a withdrawal. The only requirements are:\n *\n * - Channel is already opened\n * - No off-chain update/deposit/withdrawal is currently being performed\n * - Channel is not being closed or in a solo closing state\n * - The withdrawal amount must be equal to or greater than zero, and cannot exceed\n * the available balance on the channel (minus the channel_reserve)\n *\n * After the other party had signed the withdraw transaction, the transaction is posted\n * on-chain and onOnChainTx callback is called with on-chain transaction as first argument.\n * After computing transaction hash it can be tracked on the chain: entering the mempool,\n * block inclusion and a number of confirmations.\n *\n * After the minimum_depth block confirmations onOwnWithdrawLocked callback is called\n * (without any arguments).\n *\n * When the other party had confirmed that the block height needed is reached\n * onWithdrawLocked callback is called (without any arguments).\n *\n * @param amount - Amount of coins to withdraw\n * @param sign - Function which verifies and signs withdraw transaction\n * @param callbacks - Callbacks\n * @param callbacks.onOnChainTx - Called when withdraw transaction has been posted\n * on chain\n * @param callbacks.onOwnWithdrawLocked\n * @param callbacks.onWithdrawLocked\n * @example\n * ```js\n * channel.withdraw(\n * 100,\n * async (tx) => await account.signTransaction(tx),\n * { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }\n * ).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Withdrawal has been accepted')\n * } else {\n * console.log('Withdrawal has been rejected')\n * }\n * })\n * ```\n */\n async withdraw(\n amount: number | BigNumber,\n sign: SignTx,\n { onOnChainTx, onOwnWithdrawLocked, onWithdrawLocked }:\n Pick<ChannelState, 'onOnChainTx' | 'onOwnWithdrawLocked' | 'onWithdrawLocked'> = {},\n ): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } });\n return {\n handler: handlers.awaitingWithdrawTx,\n state: {\n sign,\n resolve,\n reject,\n onOnChainTx,\n onOwnWithdrawLocked,\n onWithdrawLocked,\n },\n };\n },\n );\n });\n }\n\n /**\n * Deposit coins into the channel\n *\n * After the channel had been opened any of the participants can initiate a deposit.\n * The process closely resembles the update. The most notable difference is that the\n * transaction has been co-signed: it is channel_deposit_tx and after the procedure\n * is finished - it is being posted on-chain.\n *\n * Any of the participants can initiate a deposit. The only requirements are:\n *\n * - Channel is already opened\n * - No off-chain update/deposit/withdrawal is currently being performed\n * - Channel is not being closed or in a solo closing state\n * - The deposit amount must be equal to or greater than zero, and cannot exceed\n * the available balance on the channel (minus the channel_reserve)\n *\n * After the other party had signed the deposit transaction, the transaction is posted\n * on-chain and onOnChainTx callback is called with on-chain transaction as first argument.\n * After computing transaction hash it can be tracked on the chain: entering the mempool,\n * block inclusion and a number of confirmations.\n *\n * After the minimum_depth block confirmations onOwnDepositLocked callback is called\n * (without any arguments).\n *\n * When the other party had confirmed that the block height needed is reached\n * onDepositLocked callback is called (without any arguments).\n *\n * @param amount - Amount of coins to deposit\n * @param sign - Function which verifies and signs deposit transaction\n * @param callbacks - Callbacks\n * @param callbacks.onOnChainTx - Called when deposit transaction has been posted\n * on chain\n * @param callbacks.onOwnDepositLocked\n * @param callbacks.onDepositLocked\n * @example\n * ```js\n * channel.deposit(\n * 100,\n * async (tx) => await account.signTransaction(tx),\n * { onOnChainTx: (tx) => console.log('on_chain_tx', tx) }\n * ).then(({ accepted, state }) => {\n * if (accepted) {\n * console.log('Deposit has been accepted')\n * console.log('The new state is:', state)\n * } else {\n * console.log('Deposit has been rejected')\n * }\n * })\n * ```\n */\n async deposit(\n amount: number | BigNumber,\n sign: SignTx,\n { onOnChainTx, onOwnDepositLocked, onDepositLocked }:\n Pick<ChannelState, 'onOnChainTx' | 'onOwnDepositLocked' | 'onDepositLocked'> = {},\n ): Promise<{ accepted: boolean; state: ChannelState }> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, { jsonrpc: '2.0', method: 'channels.deposit', params: { amount } });\n return {\n handler: handlers.awaitingDepositTx,\n state: {\n sign,\n resolve,\n reject,\n onOnChainTx,\n onOwnDepositLocked,\n onDepositLocked,\n },\n };\n },\n );\n });\n }\n\n /**\n * Trigger create contract update\n *\n * The create contract update is creating a contract inside the channel's internal state tree.\n * The update is a change to be applied on top of the latest state.\n *\n * That would create a contract with the poster being the owner of it. Poster commits initially\n * a deposit amount of coins to the new contract.\n *\n * @param options - Options\n * @param options.code - Api encoded compiled AEVM byte code\n * @param options.callData - Api encoded compiled AEVM call data for the code\n * @param options.deposit - Initial amount the owner of the contract commits to it\n * @param options.vmVersion - Version of the Virtual Machine\n * @param options.abiVersion - Version of the Application Binary Interface\n * @param sign - Function which verifies and signs create contract transaction\n * @example\n * ```js\n * channel.createContract({\n * code: 'cb_HKtpipK4aCgYb17wZ...',\n * callData: 'cb_1111111111111111...',\n * deposit: 10,\n * vmVersion: 3,\n * abiVersion: 1\n * }).then(({ accepted, signedTx, address }) => {\n * if (accepted) {\n * console.log('New contract has been created')\n * console.log('Contract address:', address)\n * } else {\n * console.log('New contract has been rejected')\n * }\n * })\n * ```\n */\n async createContract(\n {\n code, callData, deposit, vmVersion, abiVersion,\n }: {\n code: Encoded.ContractBytearray;\n callData: Encoded.ContractBytearray;\n deposit: number | BigNumber;\n vmVersion: number;\n abiVersion: number;\n },\n sign: SignTx,\n ): Promise<{\n accepted: boolean; signedTx: Encoded.Transaction; address: Encoded.ContractAddress;\n }> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.update.new_contract',\n params: {\n code,\n call_data: callData,\n deposit,\n vm_version: vmVersion,\n abi_version: abiVersion,\n },\n });\n return {\n handler: handlers.awaitingNewContractTx,\n state: {\n sign,\n resolve,\n reject,\n },\n };\n },\n );\n });\n }\n\n /**\n * Trigger call a contract update\n *\n * The call contract update is calling a preexisting contract inside the channel's\n * internal state tree. The update is a change to be applied on top of the latest state.\n *\n * That would call a contract with the poster being the caller of it. Poster commits\n * an amount of coins to the contract.\n *\n * The call would also create a call object inside the channel state tree. It contains\n * the result of the contract call.\n *\n * It is worth mentioning that the gas is not consumed, because this is an off-chain\n * contract call. It would be consumed if it were an on-chain one. This could happen\n * if a call with a similar computation amount is to be forced on-chain.\n *\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @param sign - Function which verifies and signs contract call transaction\n * @example\n * ```js\n * channel.callContract({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract called succesfully')\n * } else {\n * console.log('Contract call has been rejected')\n * }\n * })\n * ```\n */\n async callContract(\n {\n amount, callData, contract, abiVersion,\n }: CallContractOptions,\n sign: SignTx,\n ): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.update.call_contract',\n params: {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n },\n });\n return {\n handler: handlers.awaitingCallContractUpdateTx,\n state: { resolve, reject, sign },\n };\n },\n );\n });\n }\n\n /**\n * Trigger a force progress contract call\n * This call is going on-chain\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @param options.gasPrice=1000000000]\n * @param options.gasLimit=1000000]\n * @param sign - Function which verifies and signs contract force progress transaction\n * @param callbacks - Callbacks\n * @example\n * ```js\n * channel.forceProgress({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1,\n * gasPrice: 1000005554\n * }).then(({ accepted, signedTx }) => {\n * if (accepted) {\n * console.log('Contract force progress call successful')\n * } else {\n * console.log('Contract force progress call has been rejected')\n * }\n * })\n * ```\n */\n async forceProgress(\n {\n amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = MIN_GAS_PRICE,\n }: {\n amount: number;\n callData: Encoded.ContractBytearray;\n contract: Encoded.ContractAddress;\n abiVersion: number;\n gasLimit?: number;\n gasPrice?: number;\n },\n sign: SignTx,\n { onOnChainTx }: Pick<ChannelState, 'onOnChainTx'> = {},\n ): Promise<{\n accepted: boolean;\n signedTx: Encoded.Transaction;\n tx: Encoded.Transaction | Uint8Array;\n }> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.force_progress',\n params: {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n gas_price: gasPrice,\n gas: gasLimit,\n },\n });\n return {\n handler: handlers.awaitingCallContractForceProgressUpdate,\n state: {\n resolve, reject, sign, onOnChainTx,\n },\n };\n },\n );\n });\n }\n\n /**\n * Call contract using dry-run\n *\n * In order to get the result of a potential contract call, one might need to\n * dry-run a contract call. It takes the exact same arguments as a call would\n * and returns the call object.\n *\n * The call is executed in the channel's state, but it does not impact the state\n * whatsoever. It uses as an environment the latest channel's state and the current\n * top of the blockchain as seen by the node.\n *\n * @param options - Options\n * @param options.amount - Amount the caller of the contract commits to it\n * @param options.callData - ABI encoded compiled AEVM call data for the code\n * @param options.contract - Address of the contract to call\n * @param options.abiVersion - Version of the ABI\n * @example\n * ```js\n * channel.callContractStatic({\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * callData: 'cb_1111111111111111...',\n * amount: 0,\n * abiVersion: 1\n * }).then(({ returnValue, gasUsed }) => {\n * console.log('Returned value:', returnValue)\n * console.log('Gas used:', gasUsed)\n * })\n * ```\n */\n async callContractStatic(\n {\n amount, callData, contract, abiVersion,\n }: {\n amount: number;\n callData: Encoded.ContractBytearray;\n contract: Encoded.ContractAddress;\n abiVersion: number;\n },\n ): Promise<CallContractOptions> {\n return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {\n amount,\n call_data: callData,\n contract_id: contract,\n abi_version: abiVersion,\n }));\n }\n\n /**\n * Get contract call result\n *\n * The combination of a caller, contract and a round of execution determines the\n * contract call. Providing an incorrect set of those results in an error response.\n *\n * @param options - Options\n * @param options.caller - Address of contract caller\n * @param options.contract - Address of the contract\n * @param options.round - Round when contract was called\n * @example\n * ```js\n * channel.getContractCall({\n * caller: 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH',\n * contract: 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa',\n * round: 3\n * }).then(({ returnType, returnValue }) => {\n * if (returnType === 'ok') console.log(returnValue)\n * })\n * ```\n */\n async getContractCall(\n { caller, contract, round }: {\n caller: Encoded.AccountAddress;\n contract: Encoded.ContractAddress;\n round: number;\n },\n ): Promise<{\n returnType: ContractCallReturnType;\n returnValue: string;\n gasPrice: number | BigNumber;\n gasUsed: number | BigNumber;\n height: number;\n log: string;\n }> {\n return snakeToPascalObjKeys(\n await call(this, 'channels.get.contract_call', {\n caller_id: caller,\n contract_id: contract,\n round,\n }),\n );\n }\n\n /**\n * Get the latest contract state\n *\n * @param contract - Address of the contract\n * @example\n * ```js\n * channel.getContractState(\n * 'ct_9sRA9AVE4BYTAkh5RNfJYmwQe1NZ4MErasQLXZkFWG43TPBqa'\n * ).then(({ contract }) => {\n * console.log('deposit:', contract.deposit)\n * })\n * ```\n */\n async getContractState(\n contract: Encoded.ContractAddress,\n ): Promise<{ contract: Contract; contractState: object }> {\n const result = await call(this, 'channels.get.contract', { pubkey: contract });\n return snakeToPascalObjKeys({\n ...result,\n contract: snakeToPascalObjKeys(result.contract),\n });\n }\n\n /**\n * Clean up all locally stored contract calls\n *\n * Contract calls are kept locally in order for the participant to be able to look them up.\n * They consume memory and in order for the participant to free it - one can prune all messages.\n * This cleans up all locally stored contract calls and those will no longer be available for\n * fetching and inspection.\n */\n async cleanContractCalls(): Promise<void> {\n return new Promise((resolve, reject) => {\n enqueueAction(\n this,\n (_channel, state) => state?.handler === handlers.channelOpen,\n (channel) => {\n send(channel, {\n jsonrpc: '2.0',\n method: 'channels.clean_contract_calls',\n params: {},\n });\n return {\n handler: handlers.awaitingCallsPruned,\n state: { resolve, reject },\n };\n },\n );\n });\n }\n\n /**\n * Send generic message\n *\n * If message is an object it will be serialized into JSON string\n * before sending.\n *\n * If there is ongoing update that has not yet been finished the message\n * will be sent after that update is finalized.\n *\n * @param message - Message\n * @param recipient - Address of the recipient\n * @example\n * ```js\n * channel.sendMessage(\n * 'hello world',\n * 'ak_Y1NRjHuoc3CGMYMvCmdHSBpJsMDR6Ra2t5zjhRcbtMeXXLpLH'\n * )\n * ```\n */\n async sendMessage(\n message: string | object,\n recipient: Encoded.AccountAddress,\n ): Promise<void> {\n const info = typeof message === 'object' ? JSON.stringify(message) : message;\n if (this.status() === 'connecting') {\n await new Promise<void>((resolve) => {\n const onStatusChanged = (status: string): void => {\n if (status === 'connecting') return;\n resolve();\n this.off('statusChanged', onStatusChanged);\n };\n this.on('statusChanged', onStatusChanged);\n });\n // For some reason we can't immediately send a message when connection is\n // established. Thus we wait 500ms which seems to work.\n await pause(500);\n }\n send(this, {\n jsonrpc: '2.0',\n method: 'channels.message',\n params: { info, to: recipient },\n });\n }\n\n static async reconnect(options: ChannelOptions, txParams: any): Promise<Channel> {\n const { sign } = options;\n\n return Channel.initialize({\n ...options,\n reconnectTx: await sign('reconnect', buildTx(txParams, Tag.ChannelClientReconnectTx).tx),\n });\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;SAESA,a;SACAC,O,EAASC,Q;SACTC,a,EAAeC,G;OACjB,KAAKC,Q;SAEVC,a,EACAC,MAAM,IAAIC,a,EACVC,KAAK,IAAIC,Y,EACTC,U,EACAC,a,EACAC,I,EACAC,S,EACAC,I,EACAC,UAAU,IAAIC,iB,EACdC,KAAK,IAAIC,Y;SAKFC,wB,EAA0BC,Y;SAG1BC,K;;AAET,SAASC,oBAAT,CAAoCC,GAApC,EAAuD;EACrD,OAAOC,MAAM,CAACC,OAAP,CAAeF,GAAf,EAAoBG,MAApB,CAA2B,CAACC,MAAD;IAAA,IAAS,CAACC,GAAD,EAAMC,GAAN,CAAT;IAAA,OAAyB,EACzD,GAAGF,MADsD;MAEzD,CAAC5B,aAAa,CAAC6B,GAAD,CAAd,GAAsBC;IAFmC,CAAzB;EAAA,CAA3B,EAGH,EAHG,CAAP;AAID;;AA4BD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,OAAN,CAAc;EAC3B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACyB,aAAVpB,UAAU,CAACqB,OAAD,EAA4C;IACjE,MAAMC,OAAO,GAAG,IAAIF,OAAJ,EAAhB;IACA,MAAMpB,UAAU,CACdsB,OADc,EAEdD,OAAO,CAACE,aAAR,IAAyB,IAAzB,GAAgC7B,QAAQ,CAAC8B,oBAAzC,GAAgE9B,QAAQ,CAAC+B,kBAF3D,EAGd/B,QAAQ,CAACgC,WAHK,EAIdL,OAJc,CAAhB;IAMA,OAAOC,OAAP;EACD;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE;;;EACAK,EAAE,CAACC,SAAD,EAAoBC,QAApB,EAAmD;IACnD,MAAMC,YAAY,GAAGnC,aAAa,CAACoC,GAAd,CAAkB,IAAlB,CAArB;IACA,IAAID,YAAY,IAAI,IAApB,EAA0B,MAAM,IAAIrB,wBAAJ,EAAN;IAC1BqB,YAAY,CAACH,EAAb,CAAgBC,SAAhB,EAA2BC,QAA3B;EACD;EAED;AACF;AACA;AACA;AACA;;;EACEG,GAAG,CAACJ,SAAD,EAAoBC,QAApB,EAAmD;IACpD,MAAMC,YAAY,GAAGnC,aAA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AACA;;;EACmB,MAAXyD,WAAW,CACfC,OADe,EAEfC,SAFe,EAGA;IACf,MAAMC,IAAI,GAAG,OAAOF,OAAP,KAAmB,QAAnB,GAA8BG,IAAI,CAACC,SAAL,CAAeJ,OAAf,CAA9B,GAAwDA,OAArE;;IACA,IAAI,KAAKlH,MAAL,OAAkB,YAAtB,EAAoC;MAClC,MAAM,IAAIsD,OAAJ,CAAmBC,OAAD,IAAa;QACnC,MAAMgE,eAAe,GAAIvH,MAAD,IAA0B;UAChD,IAAIA,MAAM,KAAK,YAAf,EAA6B;UAC7BuD,OAAO;UACP,KAAKnB,GAAL,CAAS,eAAT,EAA0BmF,eAA1B;QACD,CAJD;;QAKA,KAAKxF,EAAL,CAAQ,eAAR,EAAyBwF,eAAzB;MACD,CAPK,CAAN,CADkC,CASlC;MACA;;MACA,MAAMxG,KAAK,CAAC,GAAD,CAAX;IACD;;IACDT,IAAI,CAAC,IAAD,EAAO;MACTqD,OAAO,EAAE,KADA;MAETC,MAAM,EAAE,kBAFC;MAGTC,MAAM,EAAE;QAAEuD,IAAF;QAAQlE,EAAE,EAAEiE;MAAZ;IAHC,CAAP,CAAJ;EAKD;;EAEqB,aAATK,SAAS,CAAC/F,OAAD,EAA0BgG,QAA1B,EAA2D;IAC/E,MAAM;MAAErE;IAAF,IAAW3B,OAAjB;IAEA,OAAOD,OAAO,CAACpB,UAAR,CAAmB,EACxB,GAAGqB,OADqB;MAExBiG,WAAW,EAAE,MAAMtE,IAAI,CAAC,WAAD,EAAc1D,OAAO,CAAC+H,QAAD,EAAW5H,GAAG,CAAC8H,wBAAf,CAAP,CAAgDnF,EAA9D;IAFC,CAAnB,CAAP;EAID;;AAh6B0B"}
|
package/es/channel/internal.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
|
-
import Channel from '.';
|
|
5
|
-
import {
|
|
4
|
+
import type Channel from '.';
|
|
5
|
+
import { Encoded } from '../utils/encoder';
|
|
6
|
+
import { BaseError } from '../utils/errors';
|
|
6
7
|
interface ChannelAction {
|
|
7
8
|
guard: (channel: Channel, state?: ChannelFsm) => boolean;
|
|
8
9
|
action: (channel: Channel, state?: ChannelFsm) => ChannelFsm;
|
|
9
10
|
}
|
|
10
|
-
export declare type SignTxWithTag = (tag: string, tx:
|
|
11
|
-
export declare type SignTx = (tx:
|
|
11
|
+
export declare type SignTxWithTag = (tag: string, tx: Encoded.Transaction, options?: object) => (Promise<Encoded.Transaction>);
|
|
12
|
+
export declare type SignTx = (tx: Encoded.Transaction, options?: object) => (Promise<Encoded.Transaction | number | null>);
|
|
12
13
|
export interface ChannelOptions {
|
|
13
14
|
existingFsmId?: string;
|
|
14
15
|
url: string;
|
|
15
16
|
role: 'initiator' | 'responder';
|
|
16
|
-
initiatorId:
|
|
17
|
-
responderId:
|
|
17
|
+
initiatorId: Encoded.AccountAddress;
|
|
18
|
+
responderId: Encoded.AccountAddress;
|
|
18
19
|
pushAmount: number;
|
|
19
20
|
initiatorAmount: BigNumber;
|
|
20
21
|
responderAmount: BigNumber;
|
|
@@ -45,15 +46,15 @@ export interface ChannelHandler extends Function {
|
|
|
45
46
|
}
|
|
46
47
|
export interface ChannelState {
|
|
47
48
|
signedTx: any;
|
|
48
|
-
resolve:
|
|
49
|
-
reject:
|
|
49
|
+
resolve: (r?: any) => void;
|
|
50
|
+
reject: (e: BaseError) => void;
|
|
50
51
|
sign: SignTx;
|
|
51
52
|
handler?: ChannelHandler;
|
|
52
|
-
onOnChainTx?:
|
|
53
|
-
onOwnWithdrawLocked?:
|
|
54
|
-
onWithdrawLocked?:
|
|
55
|
-
onOwnDepositLocked?:
|
|
56
|
-
onDepositLocked?:
|
|
53
|
+
onOnChainTx?: (tx: Encoded.Transaction) => void;
|
|
54
|
+
onOwnWithdrawLocked?: () => void;
|
|
55
|
+
onWithdrawLocked?: () => void;
|
|
56
|
+
onOwnDepositLocked?: () => void;
|
|
57
|
+
onDepositLocked?: () => void;
|
|
57
58
|
closeTx?: string;
|
|
58
59
|
}
|
|
59
60
|
export interface ChannelFsm {
|
|
@@ -91,10 +92,10 @@ export declare const channelId: WeakMap<Channel, string>;
|
|
|
91
92
|
export declare const fsmId: WeakMap<Channel, string>;
|
|
92
93
|
export declare function emit(channel: Channel, ...args: any[]): void;
|
|
93
94
|
export declare function changeStatus(channel: Channel, newStatus: string): void;
|
|
94
|
-
export declare function changeState(channel: Channel, newState:
|
|
95
|
+
export declare function changeState(channel: Channel, newState: Encoded.Transaction): void;
|
|
95
96
|
export declare function send(channel: Channel, message: ChannelMessage): void;
|
|
96
97
|
export declare function enqueueAction(channel: Channel, guard: ChannelAction['guard'], action: ChannelAction['action']): void;
|
|
97
|
-
export declare function call(channel: Channel, method: string, params: any): Promise<any>;
|
|
98
98
|
export declare function disconnect(channel: Channel): void;
|
|
99
|
+
export declare function call(channel: Channel, method: string, params: any): Promise<any>;
|
|
99
100
|
export declare function initialize(channel: Channel, connectionHandler: Function, openHandler: Function, { url, ...channelOptions }: ChannelOptions): Promise<void>;
|
|
100
101
|
export {};
|