@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
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* @example import { Chain } from '@aeternity/aepp-sdk'
|
|
23
23
|
*/
|
|
24
24
|
import stampit from '@stamp/it';
|
|
25
|
-
import
|
|
25
|
+
import _stampRequired from '@stamp/required';
|
|
26
26
|
/**
|
|
27
27
|
* Basic Chain Stamp
|
|
28
28
|
*
|
|
@@ -35,21 +35,37 @@ import { required } from '@stamp/required';
|
|
|
35
35
|
* @return {Object} Chain instance
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
|
+
const {
|
|
39
|
+
required
|
|
40
|
+
} = _stampRequired;
|
|
38
41
|
const Chain = stampit({
|
|
39
42
|
deepProps: {
|
|
40
43
|
Ae: {
|
|
41
44
|
defaults: {
|
|
42
45
|
waitMined: true,
|
|
43
|
-
verify: true
|
|
46
|
+
verify: true,
|
|
47
|
+
_expectedMineRate: 180000,
|
|
48
|
+
_microBlockCycle: 3000,
|
|
49
|
+
_maxPollInterval: 5000
|
|
44
50
|
}
|
|
45
51
|
}
|
|
52
|
+
},
|
|
53
|
+
methods: {
|
|
54
|
+
_getPollInterval(type) {
|
|
55
|
+
const base = {
|
|
56
|
+
block: this.Ae.defaults._expectedMineRate,
|
|
57
|
+
microblock: this.Ae.defaults._microBlockCycle
|
|
58
|
+
}[type];
|
|
59
|
+
if (!base) throw new Error(`Unknown poll type: ${type}`);
|
|
60
|
+
return Math.min(base / 3, this.Ae.defaults._maxPollInterval);
|
|
61
|
+
}
|
|
62
|
+
|
|
46
63
|
}
|
|
47
64
|
}, required({
|
|
48
65
|
methods: {
|
|
49
66
|
sendTransaction: required,
|
|
50
67
|
height: required,
|
|
51
68
|
awaitHeight: required,
|
|
52
|
-
topBlock: required,
|
|
53
69
|
poll: required,
|
|
54
70
|
balance: required,
|
|
55
71
|
getBalance: required,
|
|
@@ -118,8 +134,10 @@ const Chain = stampit({
|
|
|
118
134
|
* @rtype (address: String, options?: Object) => balance: Number
|
|
119
135
|
* @param {String} address - The public account address to obtain the balance for
|
|
120
136
|
* @param {Object} [options={}] - Options
|
|
121
|
-
* @param {Number} options.height - The chain height at which to obtain the balance for (default:
|
|
122
|
-
*
|
|
137
|
+
* @param {Number} options.height - The chain height at which to obtain the balance for (default:
|
|
138
|
+
* top of chain)
|
|
139
|
+
* @param {String} options.hash - The block hash on which to obtain the balance for (default: top
|
|
140
|
+
* of chain)
|
|
123
141
|
* @return {Object} The transaction as it was mined
|
|
124
142
|
*/
|
|
125
143
|
|
|
@@ -131,7 +149,8 @@ const Chain = stampit({
|
|
|
131
149
|
* @category async
|
|
132
150
|
* @rtype (hash: String, info = false) => tx: Object
|
|
133
151
|
* @param {String} hash - Transaction hash
|
|
134
|
-
* @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and
|
|
152
|
+
* @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and
|
|
153
|
+
* ContractCall transaction's)
|
|
135
154
|
* @return {Object} Transaction
|
|
136
155
|
*/
|
|
137
156
|
|
|
@@ -244,9 +263,10 @@ const Chain = stampit({
|
|
|
244
263
|
* @param {String} tx - transaction to execute
|
|
245
264
|
* @param {String} accountAddress - address that will be used to execute transaction
|
|
246
265
|
* @param {String|Number} [options.top] - hash of block on which to make dry-run
|
|
247
|
-
* @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result
|
|
266
|
+
* @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result
|
|
267
|
+
* from the call
|
|
248
268
|
* @return {Object} Result
|
|
249
269
|
*/
|
|
250
270
|
|
|
251
271
|
export default Chain;
|
|
252
|
-
//# sourceMappingURL=index.
|
|
272
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/chain/index.js"],"names":["stampit","Chain","deepProps","Ae","defaults","waitMined","verify","_expectedMineRate","_microBlockCycle","_maxPollInterval","methods","_getPollInterval","type","base","block","microblock","Error","Math","min","required","sendTransaction","height","awaitHeight","poll","balance","getBalance","tx","getTxInfo","mempool","txDryRun","getAccount"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,2BAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACA,MAAMC,KAAK,GAAGD,OAAO,CAAC;AACpBE,EAAAA,SAAS,EAAE;AACTC,IAAAA,EAAE,EAAE;AACFC,MAAAA,QAAQ,EAAE;AACRC,QAAAA,SAAS,EAAE,IADH;AAERC,QAAAA,MAAM,EAAE,IAFA;AAGRC,QAAAA,iBAAiB,EAAE,MAHX;AAIRC,QAAAA,gBAAgB,EAAE,IAJV;AAKRC,QAAAA,gBAAgB,EAAE;AALV;AADR;AADK,GADS;AAYpBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,gBAAgB,CAAEC,IAAF,EAAQ;AACtB,YAAMC,IAAI,GAAG;AACXC,QAAAA,KAAK,EAAE,KAAKX,EAAL,CAAQC,QAAR,CAAiBG,iBADb;AAEXQ,QAAAA,UAAU,EAAE,KAAKZ,EAAL,CAAQC,QAAR,CAAiBI;AAFlB,QAGXI,IAHW,CAAb;AAIA,UAAI,CAACC,IAAL,EAAW,MAAM,IAAIG,KAAJ,CAAW,sBAAqBJ,IAAK,EAArC,CAAN;AACX,aAAOK,IAAI,CAACC,GAAL,CAASL,IAAI,GAAG,CAAhB,EAAmB,KAAKV,EAAL,CAAQC,QAAR,CAAiBK,gBAApC,CAAP;AACD;;AARM;AAZW,CAAD,EAsBlBU,QAAQ,CAAC;AACVT,EAAAA,OAAO,EAAE;AACPU,IAAAA,eAAe,EAAED,QADV;AAEPE,IAAAA,MAAM,EAAEF,QAFD;AAGPG,IAAAA,WAAW,EAAEH,QAHN;AAIPI,IAAAA,IAAI,EAAEJ,QAJC;AAKPK,IAAAA,OAAO,EAAEL,QALF;AAMPM,IAAAA,UAAU,EAAEN,QANL;AAOPO,IAAAA,EAAE,EAAEP,QAPG;AAQPQ,IAAAA,SAAS,EAAER,QARJ;AASPS,IAAAA,OAAO,EAAET,QATF;AAUPU,IAAAA,QAAQ,EAAEV,QAVH;AAWPW,IAAAA,UAAU,EAAEX;AAXL;AADC,CAAD,CAtBU,CAArB;AAsCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAelB,KAAf","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 */\n\n/**\n * Chain module\n * @module @aeternity/aepp-sdk/es/chain\n * @export Chain\n * @example import { Chain } from '@aeternity/aepp-sdk'\n */\n\nimport stampit from '@stamp/it'\nimport { required } from '@stamp/required'\n\n/**\n * Basic Chain Stamp\n *\n * Attempting to create instances from the Stamp without overwriting all\n * abstract methods using composition will result in an exception.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/chain\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} Chain instance\n */\nconst Chain = stampit({\n deepProps: {\n Ae: {\n defaults: {\n waitMined: true,\n verify: true,\n _expectedMineRate: 180000,\n _microBlockCycle: 3000,\n _maxPollInterval: 5000\n }\n }\n },\n methods: {\n _getPollInterval (type) {\n const base = {\n block: this.Ae.defaults._expectedMineRate,\n microblock: this.Ae.defaults._microBlockCycle\n }[type]\n if (!base) throw new Error(`Unknown poll type: ${type}`)\n return Math.min(base / 3, this.Ae.defaults._maxPollInterval)\n }\n }\n}, required({\n methods: {\n sendTransaction: required,\n height: required,\n awaitHeight: required,\n poll: required,\n balance: required,\n getBalance: required,\n tx: required,\n getTxInfo: required,\n mempool: required,\n txDryRun: required,\n getAccount: required\n }\n}))\n\n/**\n * Submit a signed transaction for mining\n * @function sendTransaction\n * @instance\n * @abstract\n * @category async\n * @rtype (tx: String, options?: Object) => tx: Promise[Object]|txHash: Promise[String]\n * @param {String} tx - Transaction to submit\n * @param {String} [options={}] - Options to pass to the implementation\n * @param {String} [options.verify=true] - Verify transaction before broadcast.\n * @return {Object} Transaction\n */\n\n/**\n * Obtain current height of the chain\n * @function height\n * @instance\n * @abstract\n * @category async\n * @rtype () => height: Number\n * @return {Number} Current chain height\n */\n\n/**\n * Wait for the chain to reach a specific height\n * @function awaitHeight\n * @instance\n * @abstract\n * @category async\n * @rtype (height: Number, options?: Object) => height: Number\n * @param {Object} [options={}] - Options\n * @param {Number} options.interval - Interval (in ms) at which to poll the chain\n * @param {Number} options.attempts - Number of polling attempts after which to fail\n * @return {Number} Current chain height\n */\n\n/**\n * Wait for a transaction to be mined\n * @function poll\n * @instance\n * @abstract\n * @category async\n * @rtype (th: String, options?: Object) => tx: Object\n * @param {Object} [options={}] - Options\n * @param {Number} options.interval - Interval (in ms) at which to poll the chain\n * @param {Number} options.blocks - Number of blocks mined after which to fail\n * @return {Object} The transaction as it was mined\n */\n\n/**\n * Request the balance of specified account\n * @function balance\n * @instance\n * @abstract\n * @category async\n * @rtype (address: String, options?: Object) => balance: Number\n * @param {String} address - The public account address to obtain the balance for\n * @param {Object} [options={}] - Options\n * @param {Number} options.height - The chain height at which to obtain the balance for (default:\n * top of chain)\n * @param {String} options.hash - The block hash on which to obtain the balance for (default: top\n * of chain)\n * @return {Object} The transaction as it was mined\n */\n\n/**\n * Obtain a transaction based on its hash\n * @function tx\n * @instance\n * @abstract\n * @category async\n * @rtype (hash: String, info = false) => tx: Object\n * @param {String} hash - Transaction hash\n * @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and\n * ContractCall transaction's)\n * @return {Object} Transaction\n */\n\n/**\n * Obtain a transaction info based on its hash\n * @function getTxInfo\n * @instance\n * @abstract\n * @category async\n * @rtype (hash: String) => tx: Object\n * @param {String} hash - Transaction hash\n * @return {Object} Transaction\n */\n\n/**\n * Obtain transaction's from mempool\n * @function mempool\n * @instance\n * @abstract\n * @category async\n * @rtype () => txs: [...Object]\n * @return {Object[]} Transactions\n */\n\n/**\n * Obtain current generation\n * @function getCurrentGeneration\n * @instance\n * @abstract\n * @category async\n * @rtype () => generation: Object\n * @return {Object} Current Generation\n */\n\n/**\n * Get generation by hash or height\n * @function getGeneration\n * @instance\n * @abstract\n * @category async\n * @rtype (hashOrHeight) => generation: Object\n * @param {String|Number} hashOrHeight - Generation hash or height\n * @return {Object} Generation\n */\n\n/**\n * Wait for transaction confirmation\n * @function waitForTxConfirm\n * @instance\n * @abstract\n * @category async\n * @rtype (txHash: String, { confirm: Number | Boolean } = { confirm: 3 }) => Promise<Number>\n * @param {String} txHash - Transaction hash\n * @param {Object} [options] - options\n * @param {Number} [options.confirm=3] - Number of blocks to wait for transaction confirmation\n * @return {Promise<Number>} Current Height\n */\n\n/**\n * Get micro block transactions\n * @function getMicroBlockTransactions\n * @instance\n * @abstract\n * @category async\n * @rtype (hash) => txs: [...Object]\n * @return {Object[]} Transactions\n */\n\n/**\n * Get key block\n * @function getKeyBlock\n * @instance\n * @abstract\n * @category async\n * @rtype (hashOrHeight) => keyBlock: Object\n * @return {Object} Key Block\n */\n\n/**\n * Get micro block header\n * @function getMicroBlockHeader\n * @instance\n * @abstract\n * @category async\n * @rtype (hash) => header: Object\n * @return {Object} Micro block header\n */\n\n/**\n * Get account by account public key\n * @function getAccount\n * @instance\n * @abstract\n * @category async\n * @rtype (address, { hash, height }) => account: Object\n * @param {String} address - Account public key\n * @param {Object} [options={}] - Options\n * @param {Number} [options.height] - Get account on specific block by block height\n * @param {String} [options.hash] - Get account on specific block by block hash\n * @return {Object} Account\n */\n\n/**\n * Transaction dry-run\n * @function txDryRun\n * @instance\n * @abstract\n * @category async\n * @rtype (tx, accountAddress, options) => result: Object\n * @param {String} tx - transaction to execute\n * @param {String} accountAddress - address that will be used to execute transaction\n * @param {String|Number} [options.top] - hash of block on which to make dry-run\n * @param {Boolean} [options.txEvents] - collect and return on-chain tx events that would result\n * from the call\n * @return {Object} Result\n */\n\nexport default Chain\n"],"file":"index.mjs"}
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
import Chain from
|
|
18
|
-
import { AE_AMOUNT_FORMATS, formatAmount } from
|
|
19
|
-
import verifyTransaction from
|
|
20
|
-
import NodePool from
|
|
21
|
-
import { pause } from
|
|
22
|
-
import { isNameValid, produceNameId, decode } from
|
|
23
|
-
import { DRY_RUN_ACCOUNT
|
|
17
|
+
import Chain from "./index.mjs";
|
|
18
|
+
import { AE_AMOUNT_FORMATS, formatAmount } from "../utils/amount-formatter.mjs";
|
|
19
|
+
import verifyTransaction from "../tx/validator.mjs";
|
|
20
|
+
import NodePool from "../node-pool/index.mjs";
|
|
21
|
+
import { pause } from "../utils/other.mjs";
|
|
22
|
+
import { isNameValid, produceNameId, decode } from "../tx/builder/helpers.mjs";
|
|
23
|
+
import { DRY_RUN_ACCOUNT } from "../tx/builder/schema.mjs";
|
|
24
|
+
import { AensPointerContextError, DryRunError, InvalidAensNameError, InvalidTxError, RequestTimedOutError, TxTimedOutError, TxNotInChainError, ArgumentError } from "../utils/errors.mjs";
|
|
24
25
|
/**
|
|
25
26
|
* ChainNode module
|
|
26
27
|
*
|
|
@@ -32,19 +33,16 @@ import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema';
|
|
|
32
33
|
|
|
33
34
|
async function sendTransaction(tx) {
|
|
34
35
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
35
|
-
const {
|
|
36
|
-
waitMined,
|
|
37
|
-
verify
|
|
38
|
-
} = { ...this.Ae.defaults,
|
|
36
|
+
const opt = { ...this.Ae.defaults,
|
|
39
37
|
...options
|
|
40
38
|
};
|
|
41
39
|
|
|
42
|
-
if (verify) {
|
|
40
|
+
if (opt.verify) {
|
|
43
41
|
const validation = await verifyTransaction(tx, this.selectedNode.instance);
|
|
44
42
|
|
|
45
43
|
if (validation.length) {
|
|
46
44
|
const message = 'Transaction verification errors: ' + validation.map(v => v.message).join(', ');
|
|
47
|
-
throw Object.assign(new
|
|
45
|
+
throw Object.assign(new InvalidTxError(message), {
|
|
48
46
|
code: 'TX_VERIFICATION_ERROR',
|
|
49
47
|
validation,
|
|
50
48
|
transaction: tx
|
|
@@ -53,13 +51,17 @@ async function sendTransaction(tx) {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
try {
|
|
54
|
+
var _this$address;
|
|
55
|
+
|
|
56
56
|
const {
|
|
57
57
|
txHash
|
|
58
58
|
} = await this.api.postTransaction({
|
|
59
59
|
tx
|
|
60
|
+
}, {
|
|
61
|
+
__queue: `tx-${await ((_this$address = this.address) === null || _this$address === void 0 ? void 0 : _this$address.call(this, options).catch(() => ''))}`
|
|
60
62
|
});
|
|
61
63
|
|
|
62
|
-
if (waitMined) {
|
|
64
|
+
if (opt.waitMined) {
|
|
63
65
|
const txData = { ...(await this.poll(txHash, options)),
|
|
64
66
|
rawTx: tx
|
|
65
67
|
}; // wait for transaction confirmation
|
|
@@ -92,15 +94,15 @@ async function waitForTxConfirm(txHash) {
|
|
|
92
94
|
options.confirm = options.confirm === true ? 3 : options.confirm;
|
|
93
95
|
const {
|
|
94
96
|
blockHeight
|
|
95
|
-
} = await this.
|
|
97
|
+
} = await this.api.getTransactionByHash(txHash);
|
|
96
98
|
const height = await this.awaitHeight(blockHeight + options.confirm, options);
|
|
97
99
|
const {
|
|
98
100
|
blockHeight: newBlockHeight
|
|
99
|
-
} = await this.
|
|
101
|
+
} = await this.api.getTransactionByHash(txHash);
|
|
100
102
|
|
|
101
103
|
switch (newBlockHeight) {
|
|
102
104
|
case -1:
|
|
103
|
-
throw new
|
|
105
|
+
throw new TxNotInChainError(txHash);
|
|
104
106
|
|
|
105
107
|
case blockHeight:
|
|
106
108
|
return height;
|
|
@@ -160,6 +162,10 @@ async function getBalance(address) {
|
|
|
160
162
|
targetDenomination: format
|
|
161
163
|
}).toString();
|
|
162
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated use `sdk.api.getTransactionByHash/getTransactionInfoByHash` instead
|
|
167
|
+
*/
|
|
168
|
+
|
|
163
169
|
|
|
164
170
|
async function tx(hash) {
|
|
165
171
|
let info = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
@@ -177,20 +183,12 @@ async function tx(hash) {
|
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
async function height() {
|
|
180
|
-
|
|
181
|
-
if (!this._heightPromise) {
|
|
182
|
-
this._heightPromise = this.api.getCurrentKeyBlockHeight();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return (await this._heightPromise).height;
|
|
186
|
-
} finally {
|
|
187
|
-
delete this._heightPromise;
|
|
188
|
-
}
|
|
186
|
+
return (await this.api.getCurrentKeyBlockHeight()).height;
|
|
189
187
|
}
|
|
190
188
|
|
|
191
189
|
async function awaitHeight(height) {
|
|
192
190
|
let {
|
|
193
|
-
interval =
|
|
191
|
+
interval = this._getPollInterval('block'),
|
|
194
192
|
attempts = 20
|
|
195
193
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
196
194
|
let currentHeight;
|
|
@@ -201,37 +199,29 @@ async function awaitHeight(height) {
|
|
|
201
199
|
if (currentHeight >= height) return currentHeight;
|
|
202
200
|
}
|
|
203
201
|
|
|
204
|
-
throw new
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* @deprecated
|
|
208
|
-
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
async function topBlock() {
|
|
212
|
-
return this.api.getTopHeader();
|
|
202
|
+
throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height);
|
|
213
203
|
}
|
|
214
204
|
|
|
215
205
|
async function poll(th) {
|
|
216
206
|
let {
|
|
217
207
|
blocks = 10,
|
|
218
|
-
interval =
|
|
219
|
-
allowUnsynced = false
|
|
208
|
+
interval = this._getPollInterval('microblock')
|
|
220
209
|
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
221
210
|
const max = (await this.height()) + blocks;
|
|
222
211
|
|
|
223
212
|
do {
|
|
224
|
-
const tx = await this.
|
|
225
|
-
|
|
226
|
-
if (tx && (tx.blockHeight !== -1 || allowUnsynced && tx.height)) {
|
|
227
|
-
return tx;
|
|
228
|
-
}
|
|
229
|
-
|
|
213
|
+
const tx = await this.api.getTransactionByHash(th);
|
|
214
|
+
if (tx.blockHeight !== -1) return tx;
|
|
230
215
|
await pause(interval);
|
|
231
216
|
} while ((await this.height()) < max);
|
|
232
217
|
|
|
233
|
-
|
|
218
|
+
const status = this.api.getCheckTxInPool && (await this.api.getCheckTxInPool(th)).status;
|
|
219
|
+
throw new TxTimedOutError(blocks, th, status);
|
|
234
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* @deprecated use `sdk.api.getTransactionInfoByHash` instead
|
|
223
|
+
*/
|
|
224
|
+
|
|
235
225
|
|
|
236
226
|
async function getTxInfo(hash) {
|
|
237
227
|
const result = await this.api.getTransactionInfoByHash(hash);
|
|
@@ -249,7 +239,7 @@ async function getCurrentGeneration() {
|
|
|
249
239
|
async function getGeneration(hashOrHeight) {
|
|
250
240
|
if (typeof hashOrHeight === 'string') return this.api.getGenerationByHash(hashOrHeight);
|
|
251
241
|
if (typeof hashOrHeight === 'number') return this.api.getGenerationByHeight(hashOrHeight);
|
|
252
|
-
throw new
|
|
242
|
+
throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight);
|
|
253
243
|
}
|
|
254
244
|
|
|
255
245
|
async function getMicroBlockTransactions(hash) {
|
|
@@ -259,37 +249,97 @@ async function getMicroBlockTransactions(hash) {
|
|
|
259
249
|
async function getKeyBlock(hashOrHeight) {
|
|
260
250
|
if (typeof hashOrHeight === 'string') return this.api.getKeyBlockByHash(hashOrHeight);
|
|
261
251
|
if (typeof hashOrHeight === 'number') return this.api.getKeyBlockByHeight(hashOrHeight);
|
|
262
|
-
throw new
|
|
252
|
+
throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight);
|
|
263
253
|
}
|
|
264
254
|
|
|
265
255
|
async function getMicroBlockHeader(hash) {
|
|
266
256
|
return this.api.getMicroBlockHeaderByHash(hash);
|
|
267
257
|
}
|
|
268
258
|
|
|
269
|
-
async function
|
|
259
|
+
async function txDryRunHandler(key) {
|
|
260
|
+
const rs = this._txDryRun[key];
|
|
261
|
+
delete this._txDryRun[key];
|
|
262
|
+
let dryRunRes;
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
dryRunRes = await this.api.protectedDryRunTxs({
|
|
266
|
+
top: rs[0].top,
|
|
267
|
+
txEvents: rs[0].txEvents,
|
|
268
|
+
txs: rs.map(req => ({
|
|
269
|
+
tx: req.tx
|
|
270
|
+
})),
|
|
271
|
+
accounts: Array.from(new Set(rs.map(req => req.accountAddress))).map(pubKey => ({
|
|
272
|
+
pubKey,
|
|
273
|
+
amount: DRY_RUN_ACCOUNT.amount
|
|
274
|
+
}))
|
|
275
|
+
});
|
|
276
|
+
} catch (error) {
|
|
277
|
+
rs.forEach(_ref => {
|
|
278
|
+
let {
|
|
279
|
+
reject
|
|
280
|
+
} = _ref;
|
|
281
|
+
return reject(error);
|
|
282
|
+
});
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
270
286
|
const {
|
|
271
|
-
results
|
|
287
|
+
results,
|
|
288
|
+
txEvents
|
|
289
|
+
} = dryRunRes;
|
|
290
|
+
results.forEach((_ref2, idx) => {
|
|
291
|
+
let {
|
|
272
292
|
result,
|
|
273
293
|
reason,
|
|
274
294
|
...resultPayload
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
tx
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
295
|
+
} = _ref2;
|
|
296
|
+
const {
|
|
297
|
+
resolve,
|
|
298
|
+
reject,
|
|
299
|
+
tx,
|
|
300
|
+
options,
|
|
301
|
+
accountAddress
|
|
302
|
+
} = rs[idx];
|
|
303
|
+
if (result === 'ok') return resolve({ ...resultPayload,
|
|
304
|
+
txEvents
|
|
305
|
+
});
|
|
306
|
+
reject(Object.assign(new DryRunError(reason), {
|
|
307
|
+
tx,
|
|
308
|
+
accountAddress,
|
|
309
|
+
options
|
|
310
|
+
}));
|
|
285
311
|
});
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function txDryRun(tx, accountAddress, _ref3) {
|
|
315
|
+
var _this$_txDryRun, _this$_txDryRun2, _this$_txDryRun2$key;
|
|
316
|
+
|
|
317
|
+
let {
|
|
318
|
+
top,
|
|
319
|
+
txEvents,
|
|
320
|
+
combine
|
|
321
|
+
} = _ref3;
|
|
322
|
+
const key = combine ? [top, txEvents].join() : 'immediate';
|
|
323
|
+
(_this$_txDryRun = this._txDryRun) !== null && _this$_txDryRun !== void 0 ? _this$_txDryRun : this._txDryRun = {};
|
|
324
|
+
(_this$_txDryRun2$key = (_this$_txDryRun2 = this._txDryRun)[key]) !== null && _this$_txDryRun2$key !== void 0 ? _this$_txDryRun2$key : _this$_txDryRun2[key] = [];
|
|
325
|
+
return new Promise((resolve, reject) => {
|
|
326
|
+
var _this$_txDryRun$key, _this$_txDryRun$key$t;
|
|
327
|
+
|
|
328
|
+
this._txDryRun[key].push({
|
|
329
|
+
tx,
|
|
330
|
+
accountAddress,
|
|
331
|
+
top,
|
|
332
|
+
txEvents,
|
|
333
|
+
resolve,
|
|
334
|
+
reject
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
if (!combine) {
|
|
338
|
+
txDryRunHandler.call(this, key);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
(_this$_txDryRun$key$t = (_this$_txDryRun$key = this._txDryRun[key]).timeout) !== null && _this$_txDryRun$key$t !== void 0 ? _this$_txDryRun$key$t : _this$_txDryRun$key.timeout = setTimeout(txDryRunHandler.bind(this, key));
|
|
293
343
|
});
|
|
294
344
|
}
|
|
295
345
|
|
|
@@ -307,59 +357,53 @@ async function getName(name) {
|
|
|
307
357
|
/**
|
|
308
358
|
* Resolve AENS name and return name hash
|
|
309
359
|
* @param {String} nameOrId
|
|
310
|
-
* @param {String}
|
|
360
|
+
* @param {String} key in AENS pointers record
|
|
311
361
|
* @param {Object} [options]
|
|
312
362
|
* @param {Boolean} [options.verify] To ensure that name exist and have a corresponding pointer
|
|
313
|
-
*
|
|
363
|
+
* // TODO: avoid that to don't trust to current api gateway
|
|
364
|
+
* @param {Boolean} [options.resolveByNode] Enables pointer resolving using node
|
|
314
365
|
* @return {String} Address or AENS name hash
|
|
315
366
|
*/
|
|
316
367
|
|
|
317
368
|
|
|
318
|
-
async function resolveName(nameOrId,
|
|
369
|
+
async function resolveName(nameOrId, key) {
|
|
319
370
|
let {
|
|
320
371
|
verify,
|
|
321
372
|
resolveByNode
|
|
322
373
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
323
374
|
|
|
324
375
|
if (!nameOrId || typeof nameOrId !== 'string') {
|
|
325
|
-
throw new
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const prefixes = Object.keys(NAME_ID_KEY);
|
|
329
|
-
|
|
330
|
-
if (!prefixes.includes(prefix)) {
|
|
331
|
-
throw new Error(`Invalid prefix ${prefix}, should be one of [${prefixes}]`);
|
|
376
|
+
throw new InvalidAensNameError(`Name or address should be a string: ${nameOrId}`);
|
|
332
377
|
}
|
|
333
378
|
|
|
334
379
|
try {
|
|
335
|
-
decode(nameOrId
|
|
380
|
+
decode(nameOrId);
|
|
336
381
|
return nameOrId;
|
|
337
382
|
} catch (error) {}
|
|
338
383
|
|
|
339
384
|
if (isNameValid(nameOrId)) {
|
|
340
385
|
if (verify || resolveByNode) {
|
|
341
|
-
const name = await this.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
});
|
|
349
|
-
if (!pointer) throw new Error(`Name ${nameOrId} don't have pointers for ${prefix}`);
|
|
386
|
+
const name = await this.api.getNameEntryByName(nameOrId);
|
|
387
|
+
const pointer = name.pointers.find(pointer => pointer.key === key);
|
|
388
|
+
|
|
389
|
+
if (!pointer) {
|
|
390
|
+
throw new AensPointerContextError(`Name ${nameOrId} don't have pointers for ${key}`);
|
|
391
|
+
}
|
|
392
|
+
|
|
350
393
|
if (resolveByNode) return pointer.id;
|
|
351
394
|
}
|
|
352
395
|
|
|
353
396
|
return produceNameId(nameOrId);
|
|
354
397
|
}
|
|
355
398
|
|
|
356
|
-
throw new
|
|
399
|
+
throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`);
|
|
357
400
|
}
|
|
358
401
|
/**
|
|
359
402
|
* ChainNode Stamp
|
|
360
403
|
*
|
|
361
404
|
* This is implementation of {@link module:@aeternity/aepp-sdk/es/chain--Chain}
|
|
362
|
-
* composed with {@link module:@aeternity/aepp-sdk/es/contract/node--ContractNodeAPI} and
|
|
405
|
+
* composed with {@link module:@aeternity/aepp-sdk/es/contract/node--ContractNodeAPI} and
|
|
406
|
+
* {@link module:@aeternity/aepp-sdk/es/oracle/node--OracleNodeAPI}
|
|
363
407
|
* @function
|
|
364
408
|
* @alias module:@aeternity/aepp-sdk/es/chain/node
|
|
365
409
|
* @rtype Stamp
|
|
@@ -375,7 +419,6 @@ const ChainNode = Chain.compose(NodePool, {
|
|
|
375
419
|
balance,
|
|
376
420
|
getBalance,
|
|
377
421
|
getAccount,
|
|
378
|
-
topBlock,
|
|
379
422
|
tx,
|
|
380
423
|
height,
|
|
381
424
|
awaitHeight,
|
|
@@ -396,4 +439,4 @@ const ChainNode = Chain.compose(NodePool, {
|
|
|
396
439
|
}
|
|
397
440
|
});
|
|
398
441
|
export default ChainNode;
|
|
399
|
-
//# sourceMappingURL=node.
|
|
442
|
+
//# sourceMappingURL=node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/chain/node.js"],"names":["Chain","AE_AMOUNT_FORMATS","formatAmount","verifyTransaction","NodePool","pause","isNameValid","produceNameId","decode","DRY_RUN_ACCOUNT","AensPointerContextError","DryRunError","InvalidAensNameError","InvalidTxError","RequestTimedOutError","TxTimedOutError","TxNotInChainError","ArgumentError","sendTransaction","tx","options","opt","Ae","defaults","verify","validation","selectedNode","instance","length","message","map","v","join","Object","assign","code","transaction","txHash","api","postTransaction","__queue","address","catch","waitMined","txData","poll","rawTx","confirm","confirmationHeight","waitForTxConfirm","hash","error","verifyTx","blockHeight","getTransactionByHash","height","awaitHeight","newBlockHeight","getAccount","getAccountByPubkeyAndHeight","getAccountByPubkeyAndHash","getAccountByPubkey","balance","format","AETTOS","targetDenomination","toString","getBalance","_","info","includes","type","getTxInfo","e","getCurrentKeyBlockHeight","interval","_getPollInterval","attempts","currentHeight","i","th","blocks","max","status","getCheckTxInPool","result","getTransactionInfoByHash","callInfo","mempool","getPendingTransactions","getCurrentGeneration","getGeneration","hashOrHeight","getGenerationByHash","getGenerationByHeight","getMicroBlockTransactions","getMicroBlockTransactionsByHash","transactions","getKeyBlock","getKeyBlockByHash","getKeyBlockByHeight","getMicroBlockHeader","getMicroBlockHeaderByHash","txDryRunHandler","key","rs","_txDryRun","dryRunRes","protectedDryRunTxs","top","txEvents","txs","req","accounts","Array","from","Set","accountAddress","pubKey","amount","forEach","reject","results","idx","reason","resultPayload","resolve","txDryRun","combine","Promise","push","call","timeout","setTimeout","bind","getContractByteCode","contractId","getContractCode","getContract","getName","name","getNameEntryByName","resolveName","nameOrId","resolveByNode","pointer","pointers","find","id","ChainNode","compose","methods"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;OACOA,K;SACEC,iB,EAAmBC,Y;OACrBC,iB;OACAC,Q;SACEC,K;SACAC,W,EAAaC,a,EAAeC,M;SAC5BC,e;SAEPC,uB,EACAC,W,EACAC,oB,EACAC,c,EACAC,oB,EACAC,e,EACAC,iB,EACAC,a;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,eAAeC,eAAf,CAAgCC,EAAhC,EAAkD;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AAChD,QAAMC,GAAG,GAAG,EAAE,GAAG,KAAKC,EAAL,CAAQC,QAAb;AAAuB,OAAGH;AAA1B,GAAZ;;AACA,MAAIC,GAAG,CAACG,MAAR,EAAgB;AACd,UAAMC,UAAU,GAAG,MAAMtB,iBAAiB,CAACgB,EAAD,EAAK,KAAKO,YAAL,CAAkBC,QAAvB,CAA1C;;AACA,QAAIF,UAAU,CAACG,MAAf,EAAuB;AACrB,YAAMC,OAAO,GAAG,sCACdJ,UAAU,CAACK,GAAX,CAAeC,CAAC,IAAIA,CAAC,CAACF,OAAtB,EAA+BG,IAA/B,CAAoC,IAApC,CADF;AAEA,YAAMC,MAAM,CAACC,MAAP,CAAc,IAAIrB,cAAJ,CAAmBgB,OAAnB,CAAd,EAA2C;AAC/CM,QAAAA,IAAI,EAAE,uBADyC;AAE/CV,QAAAA,UAF+C;AAG/CW,QAAAA,WAAW,EAAEjB;AAHkC,OAA3C,CAAN;AAKD;AACF;;AAED,MA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G,GAAL,CAASuG,kBAAT,CAA4BE,QAA5B,CAAnB;AACA,YAAME,OAAO,GAAGL,IAAI,CAACM,QAAL,CAAcC,IAAd,CAAmBF,OAAO,IAAIA,OAAO,CAACzC,GAAR,KAAgBA,GAA9C,CAAhB;;AACA,UAAI,CAACyC,OAAL,EAAc;AACZ,cAAM,IAAIvI,uBAAJ,CAA6B,QAAOqI,QAAS,4BAA2BvC,GAAI,EAA5E,CAAN;AACD;;AACD,UAAIwC,aAAJ,EAAmB,OAAOC,OAAO,CAACG,EAAf;AACpB;;AACD,WAAO7I,aAAa,CAACwI,QAAD,CAApB;AACD;;AACD,QAAM,IAAInI,oBAAJ,CAA0B,4BAA2BmI,QAAS,EAA9D,CAAN;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,MAAMM,SAAS,GAAGrJ,KAAK,CAACsJ,OAAN,CAAclJ,QAAd,EAAwB;AACxCmJ,EAAAA,OAAO,EAAE;AACPrI,IAAAA,eADO;AAEP4C,IAAAA,OAFO;AAGPK,IAAAA,UAHO;AAIPT,IAAAA,UAJO;AAKPvC,IAAAA,EALO;AAMPoC,IAAAA,MANO;AAOPC,IAAAA,WAPO;AAQPX,IAAAA,IARO;AASP2B,IAAAA,SATO;AAUPgB,IAAAA,OAVO;AAWPE,IAAAA,oBAXO;AAYPC,IAAAA,aAZO;AAaPU,IAAAA,mBAbO;AAcPN,IAAAA,yBAdO;AAePG,IAAAA,WAfO;AAgBP6B,IAAAA,QAhBO;AAiBPQ,IAAAA,mBAjBO;AAkBPG,IAAAA,WAlBO;AAmBPC,IAAAA,OAnBO;AAoBP1F,IAAAA,gBApBO;AAqBP6F,IAAAA;AArBO;AAD+B,CAAxB,CAAlB;AA0BA,eAAeO,SAAf","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 Chain from './'\nimport { AE_AMOUNT_FORMATS, formatAmount } from '../utils/amount-formatter'\nimport verifyTransaction from '../tx/validator'\nimport NodePool from '../node-pool'\nimport { pause } from '../utils/other'\nimport { isNameValid, produceNameId, decode } from '../tx/builder/helpers'\nimport { DRY_RUN_ACCOUNT } from '../tx/builder/schema'\nimport {\n AensPointerContextError,\n DryRunError,\n InvalidAensNameError,\n InvalidTxError,\n RequestTimedOutError,\n TxTimedOutError,\n TxNotInChainError,\n ArgumentError\n} from '../utils/errors'\n\n/**\n * ChainNode module\n *\n * This is the complement to {@link module:@aeternity/aepp-sdk/es/chain}.\n * @module @aeternity/aepp-sdk/es/chain/node\n * @export ChainNode\n * @example import { ChainNode } from '@aeternity/aepp-sdk'\n */\n\nasync function sendTransaction (tx, options = {}) {\n const opt = { ...this.Ae.defaults, ...options }\n if (opt.verify) {\n const validation = await verifyTransaction(tx, this.selectedNode.instance)\n if (validation.length) {\n const message = 'Transaction verification errors: ' +\n validation.map(v => v.message).join(', ')\n throw Object.assign(new InvalidTxError(message), {\n code: 'TX_VERIFICATION_ERROR',\n validation,\n transaction: tx\n })\n }\n }\n\n try {\n const { txHash } = await this.api.postTransaction({ tx }, {\n __queue: `tx-${await this.address?.(options).catch(() => '')}`\n })\n\n if (opt.waitMined) {\n const txData = { ...await this.poll(txHash, options), rawTx: tx }\n // wait for transaction confirmation\n if (options.confirm) {\n return { ...txData, confirmationHeight: await this.waitForTxConfirm(txHash, options) }\n }\n return txData\n }\n return { hash: txHash, rawTx: tx }\n } catch (error) {\n throw Object.assign(error, {\n rawTx: tx,\n verifyTx: () => verifyTransaction(tx, this.selectedNode.instance)\n })\n }\n}\n\nasync function waitForTxConfirm (txHash, options = { confirm: 3 }) {\n options.confirm = options.confirm === true ? 3 : options.confirm\n const { blockHeight } = await this.api.getTransactionByHash(txHash)\n const height = await this.awaitHeight(blockHeight + options.confirm, options)\n const { blockHeight: newBlockHeight } = await this.api.getTransactionByHash(txHash)\n switch (newBlockHeight) {\n case -1:\n throw new TxNotInChainError(txHash)\n case blockHeight:\n return height\n default:\n return waitForTxConfirm(txHash, options)\n }\n}\n\nasync function getAccount (address, { height, hash } = {}) {\n if (height) return this.api.getAccountByPubkeyAndHeight(address, height)\n if (hash) return this.api.getAccountByPubkeyAndHash(address, hash)\n return this.api.getAccountByPubkey(address)\n}\n\n/**\n * @function\n * @deprecated\n */\nasync function balance (address, { height, hash, format = AE_AMOUNT_FORMATS.AETTOS } = {}) {\n const { balance } = await this.getAccount(address, { hash, height })\n\n return formatAmount(balance, { targetDenomination: format }).toString()\n}\n\nasync function getBalance (address, { height, hash, format = AE_AMOUNT_FORMATS.AETTOS } = {}) {\n const { balance } = await this.getAccount(address, { hash, height }).catch(_ => ({ balance: 0 }))\n\n return formatAmount(balance, { targetDenomination: format }).toString()\n}\n\n/**\n * @deprecated use `sdk.api.getTransactionByHash/getTransactionInfoByHash` instead\n */\nasync function tx (hash, info = true) {\n const tx = await this.api.getTransactionByHash(hash)\n if (['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx'].includes(tx.tx.type) && info && tx.blockHeight !== -1) {\n try {\n return { ...tx, ...await this.getTxInfo(hash) }\n } catch (e) {}\n }\n return tx\n}\n\nasync function height () {\n return (await this.api.getCurrentKeyBlockHeight()).height\n}\n\nasync function awaitHeight (\n height,\n { interval = this._getPollInterval('block'), attempts = 20 } = {}\n) {\n let currentHeight\n for (let i = 0; i < attempts; i++) {\n if (i) await pause(interval)\n currentHeight = await this.height()\n if (currentHeight >= height) return currentHeight\n }\n throw new RequestTimedOutError((attempts - 1) * interval, currentHeight, height)\n}\n\nasync function poll (th, { blocks = 10, interval = this._getPollInterval('microblock') } = {}) {\n const max = await this.height() + blocks\n do {\n const tx = await this.api.getTransactionByHash(th)\n if (tx.blockHeight !== -1) return tx\n await pause(interval)\n } while (await this.height() < max)\n const status = this.api.getCheckTxInPool && (await this.api.getCheckTxInPool(th)).status\n throw new TxTimedOutError(blocks, th, status)\n}\n\n/**\n * @deprecated use `sdk.api.getTransactionInfoByHash` instead\n */\nasync function getTxInfo (hash) {\n const result = await this.api.getTransactionInfoByHash(hash)\n return result.callInfo || result\n}\n\nasync function mempool () {\n return this.api.getPendingTransactions()\n}\n\nasync function getCurrentGeneration () {\n return this.api.getCurrentGeneration()\n}\n\nasync function getGeneration (hashOrHeight) {\n if (typeof hashOrHeight === 'string') return this.api.getGenerationByHash(hashOrHeight)\n if (typeof hashOrHeight === 'number') return this.api.getGenerationByHeight(hashOrHeight)\n throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight)\n}\n\nasync function getMicroBlockTransactions (hash) {\n return (await this.api.getMicroBlockTransactionsByHash(hash)).transactions\n}\n\nasync function getKeyBlock (hashOrHeight) {\n if (typeof hashOrHeight === 'string') return this.api.getKeyBlockByHash(hashOrHeight)\n if (typeof hashOrHeight === 'number') return this.api.getKeyBlockByHeight(hashOrHeight)\n throw new ArgumentError('hashOrHeight', 'a string or number', hashOrHeight)\n}\n\nasync function getMicroBlockHeader (hash) {\n return this.api.getMicroBlockHeaderByHash(hash)\n}\n\nasync function txDryRunHandler (key) {\n const rs = this._txDryRun[key]\n delete this._txDryRun[key]\n\n let dryRunRes\n try {\n dryRunRes = await this.api.protectedDryRunTxs({\n top: rs[0].top,\n txEvents: rs[0].txEvents,\n txs: rs.map(req => ({ tx: req.tx })),\n accounts: Array.from(new Set(rs.map(req => req.accountAddress)))\n .map(pubKey => ({ pubKey, amount: DRY_RUN_ACCOUNT.amount }))\n })\n } catch (error) {\n rs.forEach(({ reject }) => reject(error))\n return\n }\n\n const { results, txEvents } = dryRunRes\n results.forEach(({ result, reason, ...resultPayload }, idx) => {\n const { resolve, reject, tx, options, accountAddress } = rs[idx]\n if (result === 'ok') return resolve({ ...resultPayload, txEvents })\n reject(Object.assign(\n new DryRunError(reason), { tx, accountAddress, options }\n ))\n })\n}\n\nasync function txDryRun (tx, accountAddress, { top, txEvents, combine }) {\n const key = combine ? [top, txEvents].join() : 'immediate'\n this._txDryRun ??= {}\n this._txDryRun[key] ??= []\n return new Promise((resolve, reject) => {\n this._txDryRun[key].push({ tx, accountAddress, top, txEvents, resolve, reject })\n if (!combine) {\n txDryRunHandler.call(this, key)\n return\n }\n this._txDryRun[key].timeout ??= setTimeout(txDryRunHandler.bind(this, key))\n })\n}\n\nasync function getContractByteCode (contractId) {\n return this.api.getContractCode(contractId)\n}\n\nasync function getContract (contractId) {\n return this.api.getContract(contractId)\n}\n\nasync function getName (name) {\n return this.api.getNameEntryByName(name)\n}\n\n/**\n * Resolve AENS name and return name hash\n * @param {String} nameOrId\n * @param {String} key in AENS pointers record\n * @param {Object} [options]\n * @param {Boolean} [options.verify] To ensure that name exist and have a corresponding pointer\n * // TODO: avoid that to don't trust to current api gateway\n * @param {Boolean} [options.resolveByNode] Enables pointer resolving using node\n * @return {String} Address or AENS name hash\n */\nasync function resolveName (nameOrId, key, { verify, resolveByNode } = {}) {\n if (!nameOrId || typeof nameOrId !== 'string') {\n throw new InvalidAensNameError(`Name or address should be a string: ${nameOrId}`)\n }\n try {\n decode(nameOrId)\n return nameOrId\n } catch (error) {}\n if (isNameValid(nameOrId)) {\n if (verify || resolveByNode) {\n const name = await this.api.getNameEntryByName(nameOrId)\n const pointer = name.pointers.find(pointer => pointer.key === key)\n if (!pointer) {\n throw new AensPointerContextError(`Name ${nameOrId} don't have pointers for ${key}`)\n }\n if (resolveByNode) return pointer.id\n }\n return produceNameId(nameOrId)\n }\n throw new InvalidAensNameError(`Invalid name or address: ${nameOrId}`)\n}\n\n/**\n * ChainNode Stamp\n *\n * This is implementation of {@link module:@aeternity/aepp-sdk/es/chain--Chain}\n * composed with {@link module:@aeternity/aepp-sdk/es/contract/node--ContractNodeAPI} and\n * {@link module:@aeternity/aepp-sdk/es/oracle/node--OracleNodeAPI}\n * @function\n * @alias module:@aeternity/aepp-sdk/es/chain/node\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} ChainNode instance\n * @example ChainNode({url: 'https://testnet.aeternity.io/'})\n */\nconst ChainNode = Chain.compose(NodePool, {\n methods: {\n sendTransaction,\n balance,\n getBalance,\n getAccount,\n tx,\n height,\n awaitHeight,\n poll,\n getTxInfo,\n mempool,\n getCurrentGeneration,\n getGeneration,\n getMicroBlockHeader,\n getMicroBlockTransactions,\n getKeyBlock,\n txDryRun,\n getContractByteCode,\n getContract,\n getName,\n waitForTxConfirm,\n resolveName\n }\n})\n\nexport default ChainNode\n"],"file":"node.mjs"}
|
|
@@ -14,30 +14,28 @@
|
|
|
14
14
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
|
-
import { generateKeyPair, encodeContractAddress
|
|
18
|
-
import { options, changeStatus, changeState, call, send, emit, channelId, disconnect, fsmId } from
|
|
19
|
-
import { unpackTx, buildTx } from
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return `tx_${encodeBase64Check(rlpBinary)}`;
|
|
23
|
-
}
|
|
17
|
+
import { generateKeyPair, encodeContractAddress } from "../utils/crypto.mjs";
|
|
18
|
+
import { options, changeStatus, changeState, call, send, emit, channelId, disconnect, fsmId } from "./internal.mjs";
|
|
19
|
+
import { unpackTx, buildTx } from "../tx/builder/index.mjs";
|
|
20
|
+
import { encode } from "../tx/builder/helpers.mjs";
|
|
21
|
+
import { IllegalArgumentError, InsufficientBalanceError, ChannelConnectionError, UnexpectedChannelMessageError } from "../utils/errors.mjs";
|
|
24
22
|
|
|
25
23
|
async function appendSignature(tx, signFn) {
|
|
26
24
|
const {
|
|
27
25
|
signatures,
|
|
28
26
|
encodedTx
|
|
29
27
|
} = unpackTx(tx).tx;
|
|
30
|
-
const result = await signFn(
|
|
28
|
+
const result = await signFn(encode(encodedTx.rlpEncoded, 'tx'));
|
|
31
29
|
|
|
32
30
|
if (typeof result === 'string') {
|
|
33
31
|
const {
|
|
34
32
|
tx: signedTx,
|
|
35
33
|
txType
|
|
36
34
|
} = unpackTx(result);
|
|
37
|
-
return
|
|
35
|
+
return buildTx({
|
|
38
36
|
signatures: signatures.concat(signedTx.signatures),
|
|
39
37
|
encodedTx: signedTx.encodedTx.rlpEncoded
|
|
40
|
-
}, txType).
|
|
38
|
+
}, txType).tx;
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
return result;
|
|
@@ -45,7 +43,7 @@ async function appendSignature(tx, signFn) {
|
|
|
45
43
|
|
|
46
44
|
function handleUnexpectedMessage(channel, message, state) {
|
|
47
45
|
if (state && state.reject) {
|
|
48
|
-
state.reject(Object.assign(new
|
|
46
|
+
state.reject(Object.assign(new UnexpectedChannelMessageError(`Unexpected message received:\n\n${JSON.stringify(message)}`), {
|
|
49
47
|
wsMessage: message
|
|
50
48
|
}));
|
|
51
49
|
}
|
|
@@ -86,7 +84,7 @@ export function awaitingConnection(channel, message, state) {
|
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
if (message.method === 'channels.error') {
|
|
89
|
-
emit(channel, 'error', new
|
|
87
|
+
emit(channel, 'error', new ChannelConnectionError(message.payload.message));
|
|
90
88
|
return {
|
|
91
89
|
handler: channelClosed
|
|
92
90
|
};
|
|
@@ -355,7 +353,7 @@ export async function awaitingOffChainTx(channel, message, state) {
|
|
|
355
353
|
}
|
|
356
354
|
|
|
357
355
|
if (message.method === 'channels.error') {
|
|
358
|
-
state.reject(new
|
|
356
|
+
state.reject(new ChannelConnectionError(message.data.message));
|
|
359
357
|
return {
|
|
360
358
|
handler: channelOpen
|
|
361
359
|
};
|
|
@@ -367,11 +365,11 @@ export async function awaitingOffChainTx(channel, message, state) {
|
|
|
367
365
|
} = message.error;
|
|
368
366
|
|
|
369
367
|
if (data.find(i => i.code === 1001)) {
|
|
370
|
-
state.reject(new
|
|
368
|
+
state.reject(new InsufficientBalanceError('Insufficient balance'));
|
|
371
369
|
} else if (data.find(i => i.code === 1002)) {
|
|
372
|
-
state.reject(new
|
|
370
|
+
state.reject(new IllegalArgumentError('Amount cannot be negative'));
|
|
373
371
|
} else {
|
|
374
|
-
state.reject(new
|
|
372
|
+
state.reject(new ChannelConnectionError(message.error.message));
|
|
375
373
|
}
|
|
376
374
|
|
|
377
375
|
return {
|
|
@@ -438,7 +436,7 @@ export function awaitingOffChainUpdate(channel, message, state) {
|
|
|
438
436
|
}
|
|
439
437
|
|
|
440
438
|
if (message.error) {
|
|
441
|
-
state.reject(new
|
|
439
|
+
state.reject(new ChannelConnectionError(message.error.message));
|
|
442
440
|
return {
|
|
443
441
|
handler: channelOpen
|
|
444
442
|
};
|
|
@@ -591,7 +589,7 @@ export function awaitingLeave(channel, message, state) {
|
|
|
591
589
|
}
|
|
592
590
|
|
|
593
591
|
if (message.method === 'channels.error') {
|
|
594
|
-
state.reject(new
|
|
592
|
+
state.reject(new ChannelConnectionError(message.data.message));
|
|
595
593
|
return {
|
|
596
594
|
handler: channelOpen
|
|
597
595
|
};
|
|
@@ -1075,7 +1073,7 @@ export function awaitingCallsPruned(channels, message, state) {
|
|
|
1075
1073
|
};
|
|
1076
1074
|
}
|
|
1077
1075
|
|
|
1078
|
-
state.reject(new
|
|
1076
|
+
state.reject(new UnexpectedChannelMessageError('Unexpected message received'));
|
|
1079
1077
|
return {
|
|
1080
1078
|
handler: channelClosed
|
|
1081
1079
|
};
|
|
@@ -1109,4 +1107,4 @@ export function channelClosed(channel, message, state) {
|
|
|
1109
1107
|
state
|
|
1110
1108
|
};
|
|
1111
1109
|
}
|
|
1112
|
-
//# sourceMappingURL=handlers.
|
|
1110
|
+
//# sourceMappingURL=handlers.mjs.map
|