@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.1
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/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/{base.js → base.mjs} +23 -11
- package/es/account/base.mjs.map +1 -0
- package/es/account/{memory.js → memory.mjs} +29 -14
- package/es/account/memory.mjs.map +1 -0
- package/es/account/{multiple.js → multiple.mjs} +14 -11
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/{aens.js → aens.mjs} +69 -59
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/{index.js → index.mjs} +12 -10
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/{oracle.js → oracle.mjs} +37 -20
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +28 -8
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/{node.js → node.mjs} +133 -90
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/{handlers.js → handlers.mjs} +18 -20
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +43 -22
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/{internal.js → internal.mjs} +51 -35
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/{index.js → index.mjs} +40 -28
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/encoder.d.ts +26 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/{index.js → index.mjs} +15 -12
- package/es/node-pool/index.mjs.map +1 -0
- package/es/{node.js → node.mjs} +17 -11
- package/es/node.mjs.map +1 -0
- package/es/tx/builder/constants.mjs +108 -0
- package/es/tx/builder/constants.mjs.map +1 -0
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +321 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/{index.js → index.mjs} +92 -74
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/{schema.js → schema.mjs} +16 -172
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +106 -14
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/{tx.js → tx.mjs} +15 -14
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/{validator.js → validator.mjs} +72 -33
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +10 -8
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +15 -8
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/{async-init.js → async-init.mjs} +8 -11
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -8
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/{crypto.js → crypto.mjs} +42 -156
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/encoder.mjs +106 -0
- package/es/utils/encoder.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/{json-big.js → json-big.mjs} +1 -1
- package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
- package/es/utils/{keystore.js → keystore.mjs} +63 -51
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/{mptree.js → mptree.mjs} +21 -12
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/{other.js → other.mjs} +2 -2
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
- package/es/utils/{string.js → string.mjs} +1 -1
- package/es/utils/{string.js.map → string.mjs.map} +1 -1
- package/es/utils/{swagger.js → swagger.mjs} +49 -15
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +49 -58
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +16 -6
- package/src/ae/aens.js +52 -58
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +21 -154
- package/src/ae/index.js +6 -4
- package/src/ae/oracle.js +33 -14
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -65
- package/src/channel/handlers.js +30 -20
- package/src/channel/index.js +46 -16
- package/src/channel/internal.js +35 -30
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +22 -113
- package/src/contract/ga/helpers.js +10 -6
- package/src/contract/ga/index.js +31 -24
- package/src/index.js +9 -8
- package/src/node-pool/index.js +13 -10
- package/src/node.js +11 -10
- package/src/tx/builder/constants.js +100 -0
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +99 -103
- package/src/tx/builder/index.js +81 -40
- package/src/tx/builder/schema.js +44 -132
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +110 -35
- package/src/tx/validator.js +25 -5
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +106 -57
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +1 -9
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +11 -155
- package/src/utils/encoder.ts +101 -0
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/swagger.js +68 -45
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -308
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -356
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -242
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -56
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -318
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js.map +0 -1
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/index.js +0 -310
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
package/src/ae/wallet.js
CHANGED
|
@@ -26,7 +26,7 @@ import Ae from './'
|
|
|
26
26
|
import Chain from '../chain/node'
|
|
27
27
|
import Tx from '../tx/tx'
|
|
28
28
|
import Contract from './contract'
|
|
29
|
-
import
|
|
29
|
+
import GeneralizedAccount from '../contract/ga'
|
|
30
30
|
import WalletRpc from '../utils/aepp-wallet-communication/rpc/wallet-rpc'
|
|
31
31
|
import Oracle from './oracle'
|
|
32
32
|
import Aens from './aens'
|
|
@@ -47,4 +47,4 @@ import Aens from './aens'
|
|
|
47
47
|
address: keypair.publicKey,
|
|
48
48
|
})
|
|
49
49
|
*/
|
|
50
|
-
export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens,
|
|
50
|
+
export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizedAccount, Chain)
|
package/src/chain/index.js
CHANGED
|
@@ -37,13 +37,32 @@ import { required } from '@stamp/required'
|
|
|
37
37
|
* @return {Object} Chain instance
|
|
38
38
|
*/
|
|
39
39
|
const Chain = stampit({
|
|
40
|
-
deepProps: {
|
|
40
|
+
deepProps: {
|
|
41
|
+
Ae: {
|
|
42
|
+
defaults: {
|
|
43
|
+
waitMined: true,
|
|
44
|
+
verify: true,
|
|
45
|
+
_expectedMineRate: 180000,
|
|
46
|
+
_microBlockCycle: 3000,
|
|
47
|
+
_maxPollInterval: 5000
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
methods: {
|
|
52
|
+
_getPollInterval (type) {
|
|
53
|
+
const base = {
|
|
54
|
+
block: this.Ae.defaults._expectedMineRate,
|
|
55
|
+
microblock: this.Ae.defaults._microBlockCycle
|
|
56
|
+
}[type]
|
|
57
|
+
if (!base) throw new Error(`Unknown poll type: ${type}`)
|
|
58
|
+
return Math.min(base / 3, this.Ae.defaults._maxPollInterval)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
41
61
|
}, required({
|
|
42
62
|
methods: {
|
|
43
63
|
sendTransaction: required,
|
|
44
64
|
height: required,
|
|
45
65
|
awaitHeight: required,
|
|
46
|
-
topBlock: required,
|
|
47
66
|
poll: required,
|
|
48
67
|
balance: required,
|
|
49
68
|
getBalance: required,
|
|
@@ -113,8 +132,10 @@ const Chain = stampit({
|
|
|
113
132
|
* @rtype (address: String, options?: Object) => balance: Number
|
|
114
133
|
* @param {String} address - The public account address to obtain the balance for
|
|
115
134
|
* @param {Object} [options={}] - Options
|
|
116
|
-
* @param {Number} options.height - The chain height at which to obtain the balance for (default:
|
|
117
|
-
*
|
|
135
|
+
* @param {Number} options.height - The chain height at which to obtain the balance for (default:
|
|
136
|
+
* top of chain)
|
|
137
|
+
* @param {String} options.hash - The block hash on which to obtain the balance for (default: top
|
|
138
|
+
* of chain)
|
|
118
139
|
* @return {Object} The transaction as it was mined
|
|
119
140
|
*/
|
|
120
141
|
|
|
@@ -126,7 +147,8 @@ const Chain = stampit({
|
|
|
126
147
|
* @category async
|
|
127
148
|
* @rtype (hash: String, info = false) => tx: Object
|
|
128
149
|
* @param {String} hash - Transaction hash
|
|
129
|
-
* @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and
|
|
150
|
+
* @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and
|
|
151
|
+
* ContractCall transaction's)
|
|
130
152
|
* @return {Object} Transaction
|
|
131
153
|
*/
|
|
132
154
|
|
|
@@ -239,7 +261,8 @@ const Chain = stampit({
|
|
|
239
261
|
* @param {String} tx - transaction to execute
|
|
240
262
|
* @param {String} accountAddress - address that will be used to execute transaction
|
|
241
263
|
* @param {String|Number} [options.top] - hash of block on which to make dry-run
|
|
242
|
-
* @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result
|
|
264
|
+
* @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result
|
|
265
|
+
* from the call
|
|
243
266
|
* @return {Object} Result
|
|
244
267
|
*/
|
|
245
268
|
|
package/src/chain/node.js
CHANGED
|
@@ -20,7 +20,17 @@ import verifyTransaction from '../tx/validator'
|
|
|
20
20
|
import NodePool from '../node-pool'
|
|
21
21
|
import { pause } from '../utils/other'
|
|
22
22
|
import { isNameValid, produceNameId, decode } from '../tx/builder/helpers'
|
|
23
|
-
import { DRY_RUN_ACCOUNT
|
|
23
|
+
import { DRY_RUN_ACCOUNT } from '../tx/builder/schema'
|
|
24
|
+
import {
|
|
25
|
+
AensPointerContextError,
|
|
26
|
+
DryRunError,
|
|
27
|
+
InvalidAensNameError,
|
|
28
|
+
InvalidTxError,
|
|
29
|
+
RequestTimedOutError,
|
|
30
|
+
TxTimedOutError,
|
|
31
|
+
TxNotInChainError,
|
|
32
|
+
ArgumentError
|
|
33
|
+
} from '../utils/errors'
|
|
24
34
|
|
|
25
35
|
/**
|
|
26
36
|
* ChainNode module
|
|
@@ -32,13 +42,13 @@ import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema'
|
|
|
32
42
|
*/
|
|
33
43
|
|
|
34
44
|
async function sendTransaction (tx, options = {}) {
|
|
35
|
-
const
|
|
36
|
-
if (verify) {
|
|
45
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
46
|
+
if (opt.verify) {
|
|
37
47
|
const validation = await verifyTransaction(tx, this.selectedNode.instance)
|
|
38
48
|
if (validation.length) {
|
|
39
49
|
const message = 'Transaction verification errors: ' +
|
|
40
50
|
validation.map(v => v.message).join(', ')
|
|
41
|
-
throw Object.assign(new
|
|
51
|
+
throw Object.assign(new InvalidTxError(message), {
|
|
42
52
|
code: 'TX_VERIFICATION_ERROR',
|
|
43
53
|
validation,
|
|
44
54
|
transaction: tx
|
|
@@ -47,9 +57,11 @@ async function sendTransaction (tx, options = {}) {
|
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
try {
|
|
50
|
-
const { txHash } = await this.api.postTransaction({ tx }
|
|
60
|
+
const { txHash } = await this.api.postTransaction({ tx }, {
|
|
61
|
+
__queue: `tx-${await this.address?.(options).catch(() => '')}`
|
|
62
|
+
})
|
|
51
63
|
|
|
52
|
-
if (waitMined) {
|
|
64
|
+
if (opt.waitMined) {
|
|
53
65
|
const txData = { ...await this.poll(txHash, options), rawTx: tx }
|
|
54
66
|
// wait for transaction confirmation
|
|
55
67
|
if (options.confirm) {
|
|
@@ -59,18 +71,21 @@ async function sendTransaction (tx, options = {}) {
|
|
|
59
71
|
}
|
|
60
72
|
return { hash: txHash, rawTx: tx }
|
|
61
73
|
} catch (error) {
|
|
62
|
-
throw Object.assign(error, {
|
|
74
|
+
throw Object.assign(error, {
|
|
75
|
+
rawTx: tx,
|
|
76
|
+
verifyTx: () => verifyTransaction(tx, this.selectedNode.instance)
|
|
77
|
+
})
|
|
63
78
|
}
|
|
64
79
|
}
|
|
65
80
|
|
|
66
81
|
async function waitForTxConfirm (txHash, options = { confirm: 3 }) {
|
|
67
82
|
options.confirm = options.confirm === true ? 3 : options.confirm
|
|
68
|
-
const { blockHeight } = await this.
|
|
83
|
+
const { blockHeight } = await this.api.getTransactionByHash(txHash)
|
|
69
84
|
const height = await this.awaitHeight(blockHeight + options.confirm, options)
|
|
70
|
-
const { blockHeight: newBlockHeight } = await this.
|
|
85
|
+
const { blockHeight: newBlockHeight } = await this.api.getTransactionByHash(txHash)
|
|
71
86
|
switch (newBlockHeight) {
|
|
72
87
|
case -1:
|
|
73
|
-
throw new
|
|
88
|
+
throw new TxNotInChainError(txHash)
|
|
74
89
|
case blockHeight:
|
|
75
90
|
return height
|
|
76
91
|
default:
|
|
@@ -100,6 +115,9 @@ async function getBalance (address, { height, hash, format = AE_AMOUNT_FORMATS.A
|
|
|
100
115
|
return formatAmount(balance, { targetDenomination: format }).toString()
|
|
101
116
|
}
|
|
102
117
|
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated use `sdk.api.getTransactionByHash/getTransactionInfoByHash` instead
|
|
120
|
+
*/
|
|
103
121
|
async function tx (hash, info = true) {
|
|
104
122
|
const tx = await this.api.getTransactionByHash(hash)
|
|
105
123
|
if (['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx'].includes(tx.tx.type) && info && tx.blockHeight !== -1) {
|
|
@@ -111,45 +129,36 @@ async function tx (hash, info = true) {
|
|
|
111
129
|
}
|
|
112
130
|
|
|
113
131
|
async function height () {
|
|
114
|
-
|
|
115
|
-
if (!this._heightPromise) {
|
|
116
|
-
this._heightPromise = this.api.getCurrentKeyBlockHeight()
|
|
117
|
-
}
|
|
118
|
-
return (await this._heightPromise).height
|
|
119
|
-
} finally {
|
|
120
|
-
delete this._heightPromise
|
|
121
|
-
}
|
|
132
|
+
return (await this.api.getCurrentKeyBlockHeight()).height
|
|
122
133
|
}
|
|
123
134
|
|
|
124
|
-
async function awaitHeight (
|
|
135
|
+
async function awaitHeight (
|
|
136
|
+
height,
|
|
137
|
+
{ interval = this._getPollInterval('block'), attempts = 20 } = {}
|
|
138
|
+
) {
|
|
125
139
|
let currentHeight
|
|
126
140
|
for (let i = 0; i < attempts; i++) {
|
|
127
141
|
if (i) await pause(interval)
|
|
128
142
|
currentHeight = await this.height()
|
|
129
143
|
if (currentHeight >= height) return currentHeight
|
|
130
144
|
}
|
|
131
|
-
throw new
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @deprecated
|
|
136
|
-
*/
|
|
137
|
-
async function topBlock () {
|
|
138
|
-
return this.api.getTopHeader()
|
|
145
|
+
throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height)
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
async function poll (th, { blocks = 10, interval =
|
|
148
|
+
async function poll (th, { blocks = 10, interval = this._getPollInterval('microblock') } = {}) {
|
|
142
149
|
const max = await this.height() + blocks
|
|
143
150
|
do {
|
|
144
|
-
const tx = await this.
|
|
145
|
-
if (tx
|
|
146
|
-
return tx
|
|
147
|
-
}
|
|
151
|
+
const tx = await this.api.getTransactionByHash(th)
|
|
152
|
+
if (tx.blockHeight !== -1) return tx
|
|
148
153
|
await pause(interval)
|
|
149
154
|
} while (await this.height() < max)
|
|
150
|
-
|
|
155
|
+
const status = this.api.getCheckTxInPool && (await this.api.getCheckTxInPool(th)).status
|
|
156
|
+
throw new TxTimedOutError(blocks, th, status)
|
|
151
157
|
}
|
|
152
158
|
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated use `sdk.api.getTransactionInfoByHash` instead
|
|
161
|
+
*/
|
|
153
162
|
async function getTxInfo (hash) {
|
|
154
163
|
const result = await this.api.getTransactionInfoByHash(hash)
|
|
155
164
|
return result.callInfo || result
|
|
@@ -166,7 +175,7 @@ async function getCurrentGeneration () {
|
|
|
166
175
|
async function getGeneration (hashOrHeight) {
|
|
167
176
|
if (typeof hashOrHeight === 'string') return this.api.getGenerationByHash(hashOrHeight)
|
|
168
177
|
if (typeof hashOrHeight === 'number') return this.api.getGenerationByHeight(hashOrHeight)
|
|
169
|
-
throw new
|
|
178
|
+
throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight)
|
|
170
179
|
}
|
|
171
180
|
|
|
172
181
|
async function getMicroBlockTransactions (hash) {
|
|
@@ -176,30 +185,53 @@ async function getMicroBlockTransactions (hash) {
|
|
|
176
185
|
async function getKeyBlock (hashOrHeight) {
|
|
177
186
|
if (typeof hashOrHeight === 'string') return this.api.getKeyBlockByHash(hashOrHeight)
|
|
178
187
|
if (typeof hashOrHeight === 'number') return this.api.getKeyBlockByHeight(hashOrHeight)
|
|
179
|
-
throw new
|
|
188
|
+
throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight)
|
|
180
189
|
}
|
|
181
190
|
|
|
182
191
|
async function getMicroBlockHeader (hash) {
|
|
183
192
|
return this.api.getMicroBlockHeaderByHash(hash)
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
async function
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
async function txDryRunHandler (key) {
|
|
196
|
+
const rs = this._txDryRun[key]
|
|
197
|
+
delete this._txDryRun[key]
|
|
198
|
+
|
|
199
|
+
let dryRunRes
|
|
200
|
+
try {
|
|
201
|
+
dryRunRes = await this.api.protectedDryRunTxs({
|
|
202
|
+
top: rs[0].top,
|
|
203
|
+
txEvents: rs[0].txEvents,
|
|
204
|
+
txs: rs.map(req => ({ tx: req.tx })),
|
|
205
|
+
accounts: Array.from(new Set(rs.map(req => req.accountAddress)))
|
|
206
|
+
.map(pubKey => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount }))
|
|
195
207
|
})
|
|
208
|
+
} catch (error) {
|
|
209
|
+
rs.forEach(({ reject }) => reject(error))
|
|
210
|
+
return
|
|
211
|
+
}
|
|
196
212
|
|
|
197
|
-
|
|
213
|
+
const { results, txEvents } = dryRunRes
|
|
214
|
+
results.forEach(({ result, reason, ...resultPayload }, idx) => {
|
|
215
|
+
const { resolve, reject, tx, options, accountAddress } = rs[idx]
|
|
216
|
+
if (result === 'ok') return resolve({ ...resultPayload, txEvents })
|
|
217
|
+
reject(Object.assign(
|
|
218
|
+
new DryRunError(reason), { tx, accountAddress, options }
|
|
219
|
+
))
|
|
220
|
+
})
|
|
221
|
+
}
|
|
198
222
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
223
|
+
async function txDryRun (tx, accountAddress, { top, txEvents, combine }) {
|
|
224
|
+
const key = combine ? [top, txEvents].join() : 'immediate'
|
|
225
|
+
this._txDryRun ??= {}
|
|
226
|
+
this._txDryRun[key] ??= []
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
this._txDryRun[key].push({ tx, accountAddress, top, txEvents, resolve, reject })
|
|
229
|
+
if (!combine) {
|
|
230
|
+
txDryRunHandler.call(this, key)
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
this._txDryRun[key].timeout ??= setTimeout(txDryRunHandler.bind(this, key))
|
|
234
|
+
})
|
|
203
235
|
}
|
|
204
236
|
|
|
205
237
|
async function getContractByteCode (contractId) {
|
|
@@ -217,42 +249,41 @@ async function getName (name) {
|
|
|
217
249
|
/**
|
|
218
250
|
* Resolve AENS name and return name hash
|
|
219
251
|
* @param {String} nameOrId
|
|
220
|
-
* @param {String}
|
|
252
|
+
* @param {String} key in AENS pointers record
|
|
221
253
|
* @param {Object} [options]
|
|
222
254
|
* @param {Boolean} [options.verify] To ensure that name exist and have a corresponding pointer
|
|
223
|
-
*
|
|
255
|
+
* // TODO: avoid that to don't trust to current api gateway
|
|
256
|
+
* @param {Boolean} [options.resolveByNode] Enables pointer resolving using node
|
|
224
257
|
* @return {String} Address or AENS name hash
|
|
225
258
|
*/
|
|
226
|
-
async function resolveName (nameOrId,
|
|
259
|
+
async function resolveName (nameOrId, key, { verify, resolveByNode } = {}) {
|
|
227
260
|
if (!nameOrId || typeof nameOrId !== 'string') {
|
|
228
|
-
throw new
|
|
229
|
-
}
|
|
230
|
-
const prefixes = Object.keys(NAME_ID_KEY)
|
|
231
|
-
if (!prefixes.includes(prefix)) {
|
|
232
|
-
throw new Error(`Invalid prefix ${prefix}, should be one of [${prefixes}]`)
|
|
261
|
+
throw new InvalidAensNameError(`Name or address should be a string: ${nameOrId}`)
|
|
233
262
|
}
|
|
234
263
|
try {
|
|
235
|
-
decode(nameOrId
|
|
264
|
+
decode(nameOrId)
|
|
236
265
|
return nameOrId
|
|
237
266
|
} catch (error) {}
|
|
238
267
|
if (isNameValid(nameOrId)) {
|
|
239
268
|
if (verify || resolveByNode) {
|
|
240
|
-
const name = await this.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
269
|
+
const name = await this.api.getNameEntryByName(nameOrId)
|
|
270
|
+
const pointer = name.pointers.find(pointer => pointer.key === key)
|
|
271
|
+
if (!pointer) {
|
|
272
|
+
throw new AensPointerContextError(`Name ${nameOrId} don't have pointers for ${key}`)
|
|
273
|
+
}
|
|
244
274
|
if (resolveByNode) return pointer.id
|
|
245
275
|
}
|
|
246
276
|
return produceNameId(nameOrId)
|
|
247
277
|
}
|
|
248
|
-
throw new
|
|
278
|
+
throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`)
|
|
249
279
|
}
|
|
250
280
|
|
|
251
281
|
/**
|
|
252
282
|
* ChainNode Stamp
|
|
253
283
|
*
|
|
254
284
|
* This is implementation of {@link module:@aeternity/aepp-sdk/es/chain--Chain}
|
|
255
|
-
* composed with {@link module:@aeternity/aepp-sdk/es/contract/node--ContractNodeAPI} and
|
|
285
|
+
* composed with {@link module:@aeternity/aepp-sdk/es/contract/node--ContractNodeAPI} and
|
|
286
|
+
* {@link module:@aeternity/aepp-sdk/es/oracle/node--OracleNodeAPI}
|
|
256
287
|
* @function
|
|
257
288
|
* @alias module:@aeternity/aepp-sdk/es/chain/node
|
|
258
289
|
* @rtype Stamp
|
|
@@ -266,7 +297,6 @@ const ChainNode = Chain.compose(NodePool, {
|
|
|
266
297
|
balance,
|
|
267
298
|
getBalance,
|
|
268
299
|
getAccount,
|
|
269
|
-
topBlock,
|
|
270
300
|
tx,
|
|
271
301
|
height,
|
|
272
302
|
awaitHeight,
|
package/src/channel/handlers.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { generateKeyPair, encodeContractAddress
|
|
18
|
+
import { generateKeyPair, encodeContractAddress } from '../utils/crypto'
|
|
19
19
|
import {
|
|
20
20
|
options,
|
|
21
21
|
changeStatus,
|
|
@@ -28,20 +28,23 @@ import {
|
|
|
28
28
|
fsmId
|
|
29
29
|
} from './internal'
|
|
30
30
|
import { unpackTx, buildTx } from '../tx/builder'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
import { encode } from '../tx/builder/helpers'
|
|
32
|
+
import {
|
|
33
|
+
IllegalArgumentError,
|
|
34
|
+
InsufficientBalanceError,
|
|
35
|
+
ChannelConnectionError,
|
|
36
|
+
UnexpectedChannelMessageError
|
|
37
|
+
} from '../utils/errors'
|
|
35
38
|
|
|
36
39
|
async function appendSignature (tx, signFn) {
|
|
37
40
|
const { signatures, encodedTx } = unpackTx(tx).tx
|
|
38
|
-
const result = await signFn(
|
|
41
|
+
const result = await signFn(encode(encodedTx.rlpEncoded, 'tx'))
|
|
39
42
|
if (typeof result === 'string') {
|
|
40
43
|
const { tx: signedTx, txType } = unpackTx(result)
|
|
41
|
-
return
|
|
44
|
+
return buildTx({
|
|
42
45
|
signatures: signatures.concat(signedTx.signatures),
|
|
43
46
|
encodedTx: signedTx.encodedTx.rlpEncoded
|
|
44
|
-
}, txType).
|
|
47
|
+
}, txType).tx
|
|
45
48
|
}
|
|
46
49
|
return result
|
|
47
50
|
}
|
|
@@ -49,7 +52,7 @@ async function appendSignature (tx, signFn) {
|
|
|
49
52
|
function handleUnexpectedMessage (channel, message, state) {
|
|
50
53
|
if (state && state.reject) {
|
|
51
54
|
state.reject(Object.assign(
|
|
52
|
-
new
|
|
55
|
+
new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`),
|
|
53
56
|
{ wsMessage: message }
|
|
54
57
|
))
|
|
55
58
|
}
|
|
@@ -75,7 +78,7 @@ export function awaitingConnection (channel, message, state) {
|
|
|
75
78
|
return { handler: awaitingConnection }
|
|
76
79
|
}
|
|
77
80
|
if (message.method === 'channels.error') {
|
|
78
|
-
emit(channel, 'error', new
|
|
81
|
+
emit(channel, 'error', new ChannelConnectionError(message.payload.message))
|
|
79
82
|
return { handler: channelClosed }
|
|
80
83
|
}
|
|
81
84
|
}
|
|
@@ -102,7 +105,9 @@ export async function awaitingChannelCreateTx (channel, message, state) {
|
|
|
102
105
|
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { tx: signedTx } })
|
|
103
106
|
return { handler: awaitingOnChainTx }
|
|
104
107
|
}
|
|
105
|
-
const signedTx = await appendSignature(
|
|
108
|
+
const signedTx = await appendSignature(
|
|
109
|
+
message.params.data.signed_tx, tx => options.get(channel).sign(tag, tx)
|
|
110
|
+
)
|
|
106
111
|
send(channel, { jsonrpc: '2.0', method: `channels.${tag}`, params: { signed_tx: signedTx } })
|
|
107
112
|
return { handler: awaitingOnChainTx }
|
|
108
113
|
}
|
|
@@ -249,17 +254,17 @@ export async function awaitingOffChainTx (channel, message, state) {
|
|
|
249
254
|
}
|
|
250
255
|
}
|
|
251
256
|
if (message.method === 'channels.error') {
|
|
252
|
-
state.reject(new
|
|
257
|
+
state.reject(new ChannelConnectionError(message.data.message))
|
|
253
258
|
return { handler: channelOpen }
|
|
254
259
|
}
|
|
255
260
|
if (message.error) {
|
|
256
261
|
const { data = [] } = message.error
|
|
257
262
|
if (data.find(i => i.code === 1001)) {
|
|
258
|
-
state.reject(new
|
|
263
|
+
state.reject(new InsufficientBalanceError('Insufficient balance'))
|
|
259
264
|
} else if (data.find(i => i.code === 1002)) {
|
|
260
|
-
state.reject(new
|
|
265
|
+
state.reject(new IllegalArgumentError('Amount cannot be negative'))
|
|
261
266
|
} else {
|
|
262
|
-
state.reject(new
|
|
267
|
+
state.reject(new ChannelConnectionError(message.error.message))
|
|
263
268
|
}
|
|
264
269
|
return { handler: channelOpen }
|
|
265
270
|
}
|
|
@@ -301,7 +306,7 @@ export function awaitingOffChainUpdate (channel, message, state) {
|
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
308
|
if (message.error) {
|
|
304
|
-
state.reject(new
|
|
309
|
+
state.reject(new ChannelConnectionError(message.error.message))
|
|
305
310
|
return { handler: channelOpen }
|
|
306
311
|
}
|
|
307
312
|
return handleUnexpectedMessage(channel, message, state)
|
|
@@ -385,7 +390,7 @@ export function awaitingLeave (channel, message, state) {
|
|
|
385
390
|
return { handler: channelClosed }
|
|
386
391
|
}
|
|
387
392
|
if (message.method === 'channels.error') {
|
|
388
|
-
state.reject(new
|
|
393
|
+
state.reject(new ChannelConnectionError(message.data.message))
|
|
389
394
|
return { handler: channelOpen }
|
|
390
395
|
}
|
|
391
396
|
return handleUnexpectedMessage(channel, message, state)
|
|
@@ -574,11 +579,16 @@ export function awaitingNewContractCompletion (channel, message, state) {
|
|
|
574
579
|
export async function awaitingCallContractUpdateTx (channel, message, state) {
|
|
575
580
|
if (message.method === 'channels.sign.update') {
|
|
576
581
|
if (message.params.data.tx) {
|
|
577
|
-
const signedTx = await state.sign(
|
|
582
|
+
const signedTx = await state.sign(
|
|
583
|
+
message.params.data.tx, { updates: message.params.data.updates }
|
|
584
|
+
)
|
|
578
585
|
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { tx: signedTx } })
|
|
579
586
|
return { handler: awaitingCallContractCompletion, state }
|
|
580
587
|
}
|
|
581
|
-
const signedTx = await appendSignature(
|
|
588
|
+
const signedTx = await appendSignature(
|
|
589
|
+
message.params.data.signed_tx,
|
|
590
|
+
tx => state.sign(tx, { updates: message.params.data.updates })
|
|
591
|
+
)
|
|
582
592
|
if (typeof signedTx === 'string') {
|
|
583
593
|
send(channel, { jsonrpc: '2.0', method: 'channels.update', params: { signed_tx: signedTx } })
|
|
584
594
|
return { handler: awaitingCallContractCompletion, state }
|
|
@@ -644,7 +654,7 @@ export function awaitingCallsPruned (channels, message, state) {
|
|
|
644
654
|
state.resolve()
|
|
645
655
|
return { handler: channelOpen }
|
|
646
656
|
}
|
|
647
|
-
state.reject(new
|
|
657
|
+
state.reject(new UnexpectedChannelMessageError('Unexpected message received'))
|
|
648
658
|
return { handler: channelClosed }
|
|
649
659
|
}
|
|
650
660
|
|
package/src/channel/index.js
CHANGED
|
@@ -338,7 +338,8 @@ function shutdown (sign) {
|
|
|
338
338
|
* @param {Number} amount - Amount of tokens to withdraw
|
|
339
339
|
* @param {Function} sign - Function which verifies and signs withdraw transaction
|
|
340
340
|
* @param {Object} [callbacks]
|
|
341
|
-
* @param {Function} [callbacks.onOnChainTx] - Called when withdraw transaction has been posted
|
|
341
|
+
* @param {Function} [callbacks.onOnChainTx] - Called when withdraw transaction has been posted
|
|
342
|
+
* on chain
|
|
342
343
|
* @param {Function} [callbacks.onOwnWithdrawLocked]
|
|
343
344
|
* @param {Function} [callbacks.onWithdrawLocked]
|
|
344
345
|
* @return {Promise<Object>}
|
|
@@ -407,7 +408,8 @@ function withdraw (amount, sign, { onOnChainTx, onOwnWithdrawLocked, onWithdrawL
|
|
|
407
408
|
* @param {Number} amount - Amount of tokens to deposit
|
|
408
409
|
* @param {Function} sign - Function which verifies and signs deposit transaction
|
|
409
410
|
* @param {Object} [callbacks]
|
|
410
|
-
* @param {Function} [callbacks.onOnChainTx] - Called when deposit transaction has been posted
|
|
411
|
+
* @param {Function} [callbacks.onOnChainTx] - Called when deposit transaction has been posted
|
|
412
|
+
* on chain
|
|
411
413
|
* @param {Function} [callbacks.onOwnDepositLocked]
|
|
412
414
|
* @param {Function} [callbacks.onDepositLocked]
|
|
413
415
|
* @return {Promise<Object>}
|
|
@@ -597,7 +599,11 @@ function callContract ({ amount, callData, contract, abiVersion }, sign) {
|
|
|
597
599
|
* }
|
|
598
600
|
* })
|
|
599
601
|
*/
|
|
600
|
-
function forceProgress (
|
|
602
|
+
function forceProgress (
|
|
603
|
+
{ amount, callData, contract, abiVersion, gas = 1000000, gasPrice = 1000000000, nonce },
|
|
604
|
+
sign,
|
|
605
|
+
{ onOnChainTx } = {}
|
|
606
|
+
) {
|
|
601
607
|
return new Promise((resolve, reject) => {
|
|
602
608
|
enqueueAction(
|
|
603
609
|
this,
|
|
@@ -800,23 +806,42 @@ async function reconnect (options, txParams) {
|
|
|
800
806
|
* @param {String} options.initiatorId - Initiator's public key
|
|
801
807
|
* @param {String} options.responderId - Responder's public key
|
|
802
808
|
* @param {Number} options.pushAmount - Initial deposit in favour of the responder by the initiator
|
|
803
|
-
* @param {Number} options.initiatorAmount - Amount of tokens the initiator has committed to
|
|
804
|
-
*
|
|
809
|
+
* @param {Number} options.initiatorAmount - Amount of tokens the initiator has committed to
|
|
810
|
+
* the channel
|
|
811
|
+
* @param {Number} options.responderAmount - Amount of tokens the responder has committed to
|
|
812
|
+
* the channel
|
|
805
813
|
* @param {Number} options.channelReserve - The minimum amount both peers need to maintain
|
|
806
814
|
* @param {Number} [options.ttl] - Minimum block height to include the channel_create_tx
|
|
807
815
|
* @param {String} options.host - Host of the responder's node
|
|
808
816
|
* @param {Number} options.port - The port of the responders node
|
|
809
817
|
* @param {Number} options.lockPeriod - Amount of blocks for disputing a solo close
|
|
810
|
-
* @param {Number} [options.existingChannelId] - Existing channel id (required if reestablishing a
|
|
811
|
-
*
|
|
812
|
-
* @param {Number} [options.
|
|
813
|
-
*
|
|
814
|
-
* @param {Number} [options.
|
|
815
|
-
*
|
|
816
|
-
* @param {Number} [options.
|
|
817
|
-
*
|
|
818
|
-
* @param {Number} [options.
|
|
819
|
-
*
|
|
818
|
+
* @param {Number} [options.existingChannelId] - Existing channel id (required if reestablishing a
|
|
819
|
+
* channel)
|
|
820
|
+
* @param {Number} [options.offchainTx] - Offchain transaction (required if reestablishing
|
|
821
|
+
* a channel)
|
|
822
|
+
* @param {Number} [options.timeoutIdle] - The time waiting for a new event to be initiated
|
|
823
|
+
* (default: 600000)
|
|
824
|
+
* @param {Number} [options.timeoutFundingCreate] - The time waiting for the initiator to produce
|
|
825
|
+
* the create channel transaction after the noise session had been established (default: 120000)
|
|
826
|
+
* @param {Number} [options.timeoutFundingSign] - The time frame the other client has to sign an
|
|
827
|
+
* off-chain update after our client had initiated and signed it. This applies only for double
|
|
828
|
+
* signed on-chain intended updates: channel create transaction, deposit, withdrawal and etc.
|
|
829
|
+
* (default: 120000)
|
|
830
|
+
* @param {Number} [options.timeoutFundingLock] - The time frame the other client has to confirm an
|
|
831
|
+
* on-chain transaction reaching maturity (passing minimum depth) after the local node has detected
|
|
832
|
+
* this. This applies only for double signed on-chain intended updates: channel create transaction,
|
|
833
|
+
* deposit, withdrawal and etc. (default: 360000)
|
|
834
|
+
* @param {Number} [options.timeoutSign] - The time frame the client has to return a signed
|
|
835
|
+
* off-chain update or to decline it. This applies for all off-chain updates (default: 500000)
|
|
836
|
+
* @param {Number} [options.timeoutAccept] - The time frame the other client has to react to an
|
|
837
|
+
* event. This applies for all off-chain updates that are not meant to land on-chain, as well as
|
|
838
|
+
* some special cases: opening a noise connection, mutual closing acknowledgement and
|
|
839
|
+
* reestablishing an existing channel (default: 120000)
|
|
840
|
+
* @param {Number} [options.timeoutInitialized] - the time frame the responder has to accept an
|
|
841
|
+
* incoming noise session. Applicable only for initiator (default: timeout_accept's value)
|
|
842
|
+
* @param {Number} [options.timeoutAwaitingOpen] - The time frame the initiator has to start an
|
|
843
|
+
* outgoing noise session to the responder's node. Applicable only for responder (default:
|
|
844
|
+
* timeout_idle's value)
|
|
820
845
|
* @param {Number} [options.debug=false] - Log websocket communication
|
|
821
846
|
* @param {Function} options.sign - Function which verifies and signs transactions
|
|
822
847
|
* @return {Promise<Object>} Channel instance
|
|
@@ -838,7 +863,12 @@ async function reconnect (options, txParams) {
|
|
|
838
863
|
*/
|
|
839
864
|
const Channel = AsyncInit.compose({
|
|
840
865
|
async init (options) {
|
|
841
|
-
initialize(
|
|
866
|
+
await initialize(
|
|
867
|
+
this,
|
|
868
|
+
options.existingFsmId ? handlers.awaitingReconnection : handlers.awaitingConnection,
|
|
869
|
+
handlers.channelOpen,
|
|
870
|
+
options
|
|
871
|
+
)
|
|
842
872
|
},
|
|
843
873
|
methods: {
|
|
844
874
|
on,
|