@aeternity/aepp-sdk 9.0.1 → 11.0.0
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 -36
- 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.mjs +179 -0
- package/es/account/base.mjs.map +1 -0
- package/es/account/memory.mjs +99 -0
- package/es/account/memory.mjs.map +1 -0
- package/es/account/multiple.mjs +179 -0
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/aens.mjs +404 -0
- 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.mjs +207 -0
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/oracle.mjs +339 -0
- 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} +29 -9
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/node.mjs +442 -0
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/handlers.mjs +1110 -0
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +245 -472
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.mjs +283 -0
- 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.mjs +178 -0
- package/es/contract/ga/index.mjs.map +1 -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.mjs +188 -0
- package/es/node-pool/index.mjs.map +1 -0
- package/es/node.mjs +133 -0
- package/es/node.mjs.map +1 -0
- package/es/other.d.ts +1 -1
- 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 +363 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.mjs +606 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.mjs +760 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +107 -15
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/tx-object.mjs +283 -0
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/tx.mjs +938 -0
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/validator.mjs +247 -0
- 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} +27 -29
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
- 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} +29 -23
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
- 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.mjs +110 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/amount-formatter.mjs +139 -0
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/async-init.mjs +64 -0
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/bignumber.mjs +21 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -12
- 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.mjs +239 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.mjs +111 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.mjs +45 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.mjs +240 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/mptree.mjs +161 -0
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.mjs +43 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/semver-satisfies.mjs +16 -0
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/{string.js → string.mjs} +5 -14
- package/es/utils/string.mjs.map +1 -0
- package/es/utils/swagger.mjs +164 -0
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +55 -62
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +31 -22
- package/src/ae/aens.js +75 -77
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +27 -291
- package/src/ae/index.js +9 -7
- package/src/ae/oracle.js +51 -28
- 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 -67
- package/src/channel/handlers.js +30 -21
- package/src/channel/index.js +44 -20
- package/src/channel/internal.js +30 -24
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +41 -91
- package/src/contract/ga/helpers.js +10 -13
- package/src/contract/ga/index.js +42 -33
- package/src/index.js +9 -10
- package/src/node-pool/index.js +29 -17
- package/src/node.js +33 -36
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +126 -84
- package/src/tx/builder/index.js +83 -41
- package/src/tx/builder/schema.js +50 -40
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +232 -153
- package/src/tx/validator.js +34 -12
- 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 +107 -60
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
- 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 +3 -10
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +10 -144
- 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/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +75 -45
- package/es/account/base.js +0 -259
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -86
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -267
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -829
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -985
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -442
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -690
- 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 +0 -1119
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js +0 -1601
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -438
- 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 -517
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -742
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -316
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -120
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -307
- 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 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -204
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -228
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -355
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -686
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -695
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -297
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -1757
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -344
- 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 +0 -211
- 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 +0 -148
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -103
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js +0 -152
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -103
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -36
- 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 +0 -358
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -148
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -78
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -393
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js +0 -198
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -93
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js +0 -35
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -269
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/helpers.js +0 -140
- package/src/contract/aci/index.js +0 -191
- package/src/contract/aci/transformation.js +0 -464
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -110
package/es/node-pool/index.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
7
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
8
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
9
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
10
|
-
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
14
|
-
|
|
15
|
-
import _Map from "@babel/runtime-corejs3/core-js-stable/map";
|
|
16
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
17
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
18
|
-
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
19
|
-
import _entriesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/entries";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* NodePool module
|
|
23
|
-
* @module @aeternity/aepp-sdk/es/node-pool
|
|
24
|
-
* @export NodePool
|
|
25
|
-
* @example import { NodePool } from '@aeternity/aepp-sdk'
|
|
26
|
-
*/
|
|
27
|
-
import stampit from '@stamp/it';
|
|
28
|
-
import Joi from 'joi-browser';
|
|
29
|
-
import { getNetworkId } from '../node';
|
|
30
|
-
/**
|
|
31
|
-
* Node Pool Stamp
|
|
32
|
-
* This stamp allow you to make basic manipulation(add, remove, select) on list of nodes
|
|
33
|
-
* @function
|
|
34
|
-
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
35
|
-
* @rtype Stamp
|
|
36
|
-
* @param {Object} [options={}] - Initializer object
|
|
37
|
-
* @param {Array} [options.nodes] - Array with Node instances
|
|
38
|
-
* @return {Object} NodePool instance
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
export default stampit({
|
|
42
|
-
init: function init() {
|
|
43
|
-
var _this = this;
|
|
44
|
-
|
|
45
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
46
|
-
_ref$nodes = _ref.nodes,
|
|
47
|
-
nodes = _ref$nodes === void 0 ? [] : _ref$nodes;
|
|
48
|
-
|
|
49
|
-
this.pool = new _Map();
|
|
50
|
-
this.validateNodes(nodes);
|
|
51
|
-
|
|
52
|
-
_forEachInstanceProperty(nodes).call(nodes, function (node, i) {
|
|
53
|
-
var name = node.name,
|
|
54
|
-
instance = node.instance;
|
|
55
|
-
|
|
56
|
-
_this.addNode(name, instance, i === 0);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
if (nodes.length) this.selectNode(nodes[0].name);
|
|
60
|
-
},
|
|
61
|
-
propertyDescriptors: {
|
|
62
|
-
api: {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: false,
|
|
65
|
-
get: function get() {
|
|
66
|
-
if (!this.selectedNode || !this.selectedNode.instance) {
|
|
67
|
-
throw new Error('You can\'t use Node API. Node is not connected or not defined!');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this.selectedNode.instance.api;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
methods: {
|
|
75
|
-
/**
|
|
76
|
-
* Add Node
|
|
77
|
-
* @function
|
|
78
|
-
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
79
|
-
* @rtype (name: String, nodeInstance: Object, select: Boolean) => void
|
|
80
|
-
* @param {String} name - Node name
|
|
81
|
-
* @param {Object} node - Node instance
|
|
82
|
-
* @param {Boolean} select - Select this node as current
|
|
83
|
-
* @return {void}
|
|
84
|
-
* @example
|
|
85
|
-
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true) // add and select new node with name 'testNode'
|
|
86
|
-
*/
|
|
87
|
-
addNode: function addNode(name, node) {
|
|
88
|
-
var select = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
89
|
-
if (this.pool.has(name)) throw new Error("Node with name ".concat(name, " already exist"));
|
|
90
|
-
this.validateNodes([{
|
|
91
|
-
name: name,
|
|
92
|
-
instance: node
|
|
93
|
-
}]);
|
|
94
|
-
this.pool.set(name, {
|
|
95
|
-
name: name,
|
|
96
|
-
instance: node,
|
|
97
|
-
url: node.url,
|
|
98
|
-
internalUrl: node.internalUrl,
|
|
99
|
-
networkId: node.nodeNetworkId,
|
|
100
|
-
version: node.version,
|
|
101
|
-
consensusProtocolVersion: node.consensusProtocolVersion
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
if (select || !this.selectedNode) {
|
|
105
|
-
this.selectNode(name);
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Select Node
|
|
111
|
-
* @function
|
|
112
|
-
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
113
|
-
* @rtype (name: String) => void
|
|
114
|
-
* @param {String} name - Node name
|
|
115
|
-
* @return {void}
|
|
116
|
-
* @example
|
|
117
|
-
* nodePool.selectNode('testNode')
|
|
118
|
-
*/
|
|
119
|
-
selectNode: function selectNode(name) {
|
|
120
|
-
if (!this.pool.has(name)) throw new Error("Node with name ".concat(name, " not in pool"));
|
|
121
|
-
this.selectedNode = this.pool.get(name);
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Get NetworkId of current Node
|
|
126
|
-
* @function
|
|
127
|
-
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
128
|
-
* @rtype () => String
|
|
129
|
-
* @return {String}
|
|
130
|
-
* @example
|
|
131
|
-
* nodePool.getNetworkId()
|
|
132
|
-
*/
|
|
133
|
-
getNetworkId: getNetworkId,
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Check if you have selected node
|
|
137
|
-
* @function
|
|
138
|
-
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
139
|
-
* @rtype () => Boolean
|
|
140
|
-
* @return {Boolean}
|
|
141
|
-
* @example
|
|
142
|
-
* nodePool.isNodeConnected()
|
|
143
|
-
*/
|
|
144
|
-
isNodeConnected: function isNodeConnected() {
|
|
145
|
-
return !!this.selectedNode.instance;
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Get information about node
|
|
150
|
-
* @function
|
|
151
|
-
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
152
|
-
* @rtype () => Object
|
|
153
|
-
* @return {Object}
|
|
154
|
-
* @example
|
|
155
|
-
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
|
|
156
|
-
*/
|
|
157
|
-
getNodeInfo: function getNodeInfo() {
|
|
158
|
-
if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected');
|
|
159
|
-
return _objectSpread({
|
|
160
|
-
name: this.selectedNode.name
|
|
161
|
-
}, this.selectedNode.instance.getNodeInfo());
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Get array of available nodes
|
|
166
|
-
* @function
|
|
167
|
-
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
168
|
-
* @rtype () => Object[]
|
|
169
|
-
* @return {Object[]}
|
|
170
|
-
* @example
|
|
171
|
-
* nodePool.getNodesInPool()
|
|
172
|
-
*/
|
|
173
|
-
getNodesInPool: function getNodesInPool() {
|
|
174
|
-
var _context, _context2;
|
|
175
|
-
|
|
176
|
-
return _mapInstanceProperty(_context = _Array$from(_entriesInstanceProperty(_context2 = this.pool).call(_context2))).call(_context, function (_ref2) {
|
|
177
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
178
|
-
name = _ref3[0],
|
|
179
|
-
node = _ref3[1];
|
|
180
|
-
|
|
181
|
-
return _objectSpread({
|
|
182
|
-
name: name
|
|
183
|
-
}, node.instance.getNodeInfo());
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
validateNodes: function validateNodes(nodes) {
|
|
187
|
-
var _Joi$array$items$labe = Joi.array().items(Joi.object({
|
|
188
|
-
name: Joi.string().required(),
|
|
189
|
-
instance: Joi.object({
|
|
190
|
-
api: Joi.object().required(),
|
|
191
|
-
consensusProtocolVersion: Joi.number().required(),
|
|
192
|
-
genesisHash: Joi.string().required()
|
|
193
|
-
}).unknown()
|
|
194
|
-
})).label('node').validate(nodes),
|
|
195
|
-
error = _Joi$array$items$labe.error;
|
|
196
|
-
|
|
197
|
-
if (error) throw error;
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
props: {
|
|
201
|
-
selectedNode: {}
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/node-pool/index.js"],"names":["stampit","Joi","getNetworkId","init","nodes","pool","validateNodes","node","i","name","instance","addNode","length","selectNode","propertyDescriptors","api","enumerable","configurable","get","selectedNode","Error","methods","select","has","set","url","internalUrl","networkId","nodeNetworkId","version","consensusProtocolVersion","isNodeConnected","getNodeInfo","getNodesInPool","array","items","object","string","required","number","genesisHash","unknown","label","validate","error","props"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;AACA,OAAOC,GAAP,MA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vBY;AAwIrBC,EAAAA,KAAK,EAAE;AACL1B,IAAAA,YAAY,EAAE;AADT;AAxIc,CAAD,CAAtB","sourcesContent":["/**\n * NodePool module\n * @module @aeternity/aepp-sdk/es/node-pool\n * @export NodePool\n * @example import { NodePool } from '@aeternity/aepp-sdk'\n */\nimport stampit from '@stamp/it'\nimport Joi from 'joi-browser'\nimport { getNetworkId } from '../node'\n\n/**\n * Node Pool Stamp\n * This stamp allow you to make basic manipulation(add, remove, select) on list of nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Array} [options.nodes] - Array with Node instances\n * @return {Object} NodePool instance\n */\nexport default stampit({\n init ({ nodes = [] } = {}) {\n this.pool = new Map()\n this.validateNodes(nodes)\n\n nodes.forEach((node, i) => {\n const { name, instance } = node\n this.addNode(name, instance, i === 0)\n })\n if (nodes.length) this.selectNode(nodes[0].name)\n },\n propertyDescriptors: {\n api: {\n enumerable: true,\n configurable: false,\n get () {\n if (!this.selectedNode || !this.selectedNode.instance) {\n throw new Error('You can\\'t use Node API. Node is not connected or not defined!')\n }\n return this.selectedNode.instance.api\n }\n }\n },\n methods: {\n /**\n * Add Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String, nodeInstance: Object, select: Boolean) => void\n * @param {String} name - Node name\n * @param {Object} node - Node instance\n * @param {Boolean} select - Select this node as current\n * @return {void}\n * @example\n * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true) // add and select new node with name 'testNode'\n */\n addNode (name, node, select = false) {\n if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`)\n\n this.validateNodes([{ name, instance: node }])\n\n this.pool.set(name, {\n name,\n instance: node,\n url: node.url,\n internalUrl: node.internalUrl,\n networkId: node.nodeNetworkId,\n version: node.version,\n consensusProtocolVersion: node.consensusProtocolVersion\n })\n if (select || !this.selectedNode) {\n this.selectNode(name)\n }\n },\n /**\n * Select Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String) => void\n * @param {String} name - Node name\n * @return {void}\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode (name) {\n if (!this.pool.has(name)) throw new Error(`Node with name ${name} not in pool`)\n\n this.selectedNode = this.pool.get(name)\n },\n /**\n * Get NetworkId of current Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => String\n * @return {String}\n * @example\n * nodePool.getNetworkId()\n */\n getNetworkId,\n /**\n * Check if you have selected node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Boolean\n * @return {Boolean}\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected () {\n return !!this.selectedNode.instance\n },\n /**\n * Get information about node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object\n * @return {Object}\n * @example\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n */\n getNodeInfo () {\n if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected')\n return {\n name: this.selectedNode.name,\n ...this.selectedNode.instance.getNodeInfo()\n }\n },\n /**\n * Get array of available nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object[]\n * @return {Object[]}\n * @example\n * nodePool.getNodesInPool()\n */\n getNodesInPool () {\n return Array.from(this.pool.entries()).map(([name, node]) => ({\n name,\n ...node.instance.getNodeInfo()\n }))\n },\n validateNodes (nodes) {\n const { error } = Joi.array().items(\n Joi.object({\n name: Joi.string().required(),\n instance: Joi.object({\n api: Joi.object().required(),\n consensusProtocolVersion: Joi.number().required(),\n genesisHash: Joi.string().required()\n }).unknown()\n })\n ).label('node').validate(nodes)\n if (error) throw error\n }\n },\n props: {\n selectedNode: {}\n }\n})\n"],"file":"index.js"}
|
package/es/node.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
3
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
4
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
6
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* ISC License (ISC)
|
|
10
|
-
* Copyright (c) 2021 aeternity developers
|
|
11
|
-
*
|
|
12
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
13
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
14
|
-
* copyright notice and this permission notice appear in all copies.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
18
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
19
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
20
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
21
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
22
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Node module
|
|
27
|
-
* @module @aeternity/aepp-sdk/es/node
|
|
28
|
-
* @export Node
|
|
29
|
-
* @example import { Node } from '@aeternity/aepp-sdk'
|
|
30
|
-
*/
|
|
31
|
-
import AsyncInit from './utils/async-init';
|
|
32
|
-
import genSwaggerClient from './utils/swagger';
|
|
33
|
-
import semverSatisfies from './utils/semver-satisfies';
|
|
34
|
-
/**
|
|
35
|
-
* Obtain networkId from account or node
|
|
36
|
-
* @instance
|
|
37
|
-
* @category async
|
|
38
|
-
* @rtype () => networkId: String
|
|
39
|
-
* @return {String} NetworkId
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
export function getNetworkId() {
|
|
43
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
44
|
-
networkId = _ref.networkId,
|
|
45
|
-
_ref$force = _ref.force,
|
|
46
|
-
force = _ref$force === void 0 ? false : _ref$force;
|
|
47
|
-
|
|
48
|
-
if (!force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) throw new Error('networkId is not provided');
|
|
49
|
-
if (force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) return null;
|
|
50
|
-
return networkId || this.networkId || this.selectedNode.networkId;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* get consensus protocol version
|
|
54
|
-
* @param {Array} protocols Array of protocols
|
|
55
|
-
* @param {Number} height Height
|
|
56
|
-
* @return {Number} version Protocol version
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
function getConsensusProtocolVersion() {
|
|
60
|
-
return _getConsensusProtocolVersion.apply(this, arguments);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* {@link genSwaggerClient} based Node remote API Stamp
|
|
64
|
-
* @function
|
|
65
|
-
* @alias module:@aeternity/aepp-sdk/es/node
|
|
66
|
-
* @rtype Stamp
|
|
67
|
-
* @param {Object} [options={}] - Options
|
|
68
|
-
* @param {String} options.url - Base URL for Node
|
|
69
|
-
* @param {String} options.internalUrl - Base URL for internal requests
|
|
70
|
-
* @param {String} options.axiosConfig - Object with axios configuration. Example { config: {}, errorHandler: (err) => throw err }
|
|
71
|
-
* @return {Object} Node client
|
|
72
|
-
* @example Node({url: 'https://testnet.aeternity.io'})
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
function _getConsensusProtocolVersion() {
|
|
77
|
-
_getConsensusProtocolVersion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
78
|
-
var _context3;
|
|
79
|
-
|
|
80
|
-
var protocols,
|
|
81
|
-
height,
|
|
82
|
-
_args2 = arguments;
|
|
83
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context4) {
|
|
84
|
-
while (1) {
|
|
85
|
-
switch (_context4.prev = _context4.next) {
|
|
86
|
-
case 0:
|
|
87
|
-
protocols = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : [];
|
|
88
|
-
height = _args2.length > 1 ? _args2[1] : undefined;
|
|
89
|
-
|
|
90
|
-
if (protocols) {
|
|
91
|
-
_context4.next = 4;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
throw new Error('Protocols must be an array');
|
|
96
|
-
|
|
97
|
-
case 4:
|
|
98
|
-
if (height) {
|
|
99
|
-
_context4.next = 8;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_context4.next = 7;
|
|
104
|
-
return this.api.getCurrentKeyBlock();
|
|
105
|
-
|
|
106
|
-
case 7:
|
|
107
|
-
height = _context4.sent.height;
|
|
108
|
-
|
|
109
|
-
case 8:
|
|
110
|
-
if (!(height < 0)) {
|
|
111
|
-
_context4.next = 10;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
throw new Error('height must be a number >= 0');
|
|
116
|
-
|
|
117
|
-
case 10:
|
|
118
|
-
return _context4.abrupt("return", _reduceInstanceProperty(_context3 = _filterInstanceProperty(protocols).call(protocols, function (_ref3) {
|
|
119
|
-
var effectiveAtHeight = _ref3.effectiveAtHeight;
|
|
120
|
-
return height >= effectiveAtHeight;
|
|
121
|
-
})).call(_context3, function (acc, p) {
|
|
122
|
-
return p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc;
|
|
123
|
-
}, {
|
|
124
|
-
effectiveAtHeight: -1,
|
|
125
|
-
version: 0
|
|
126
|
-
}).version);
|
|
127
|
-
|
|
128
|
-
case 11:
|
|
129
|
-
case "end":
|
|
130
|
-
return _context4.stop();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}, _callee2, this);
|
|
134
|
-
}));
|
|
135
|
-
return _getConsensusProtocolVersion.apply(this, arguments);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
var Node = AsyncInit.compose({
|
|
139
|
-
init: function init(_ref2) {
|
|
140
|
-
var _this = this;
|
|
141
|
-
|
|
142
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
143
|
-
var url, internalUrl, ignoreVersion, client, _context, _yield$_this$api$getS, revision, genesisHash, networkId, protocols;
|
|
144
|
-
|
|
145
|
-
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
146
|
-
while (1) {
|
|
147
|
-
switch (_context2.prev = _context2.next) {
|
|
148
|
-
case 0:
|
|
149
|
-
url = _ref2.url, internalUrl = _ref2.internalUrl, ignoreVersion = _ref2.ignoreVersion;
|
|
150
|
-
|
|
151
|
-
if (url) {
|
|
152
|
-
_context2.next = 3;
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
throw new Error('"url" required');
|
|
157
|
-
|
|
158
|
-
case 3:
|
|
159
|
-
_this.url = url.replace(/\/$/, '');
|
|
160
|
-
_this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : _this.url;
|
|
161
|
-
_context2.next = 7;
|
|
162
|
-
return genSwaggerClient("".concat(_this.url, "/api?oas3"), {
|
|
163
|
-
internalUrl: _this.internalUrl
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
case 7:
|
|
167
|
-
client = _context2.sent;
|
|
168
|
-
_this.version = client.spec.info.version;
|
|
169
|
-
|
|
170
|
-
if (!(!semverSatisfies(_this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion)) {
|
|
171
|
-
_context2.next = 11;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
throw new Error("Unsupported node version ".concat(_this.version, ". ") + _concatInstanceProperty(_context = "Supported: >= ".concat(NODE_GE_VERSION, " < ")).call(_context, NODE_LT_VERSION));
|
|
176
|
-
|
|
177
|
-
case 11:
|
|
178
|
-
_this.api = client.api;
|
|
179
|
-
_context2.next = 14;
|
|
180
|
-
return _this.api.getStatus();
|
|
181
|
-
|
|
182
|
-
case 14:
|
|
183
|
-
_yield$_this$api$getS = _context2.sent;
|
|
184
|
-
revision = _yield$_this$api$getS.nodeRevision;
|
|
185
|
-
genesisHash = _yield$_this$api$getS.genesisKeyBlockHash;
|
|
186
|
-
networkId = _yield$_this$api$getS.networkId;
|
|
187
|
-
protocols = _yield$_this$api$getS.protocols;
|
|
188
|
-
_context2.next = 21;
|
|
189
|
-
return _this.getConsensusProtocolVersion(protocols);
|
|
190
|
-
|
|
191
|
-
case 21:
|
|
192
|
-
_this.consensusProtocolVersion = _context2.sent;
|
|
193
|
-
_this.nodeNetworkId = networkId;
|
|
194
|
-
return _context2.abrupt("return", _Object$assign(_this, {
|
|
195
|
-
revision: revision,
|
|
196
|
-
genesisHash: genesisHash
|
|
197
|
-
}));
|
|
198
|
-
|
|
199
|
-
case 24:
|
|
200
|
-
case "end":
|
|
201
|
-
return _context2.stop();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, _callee);
|
|
205
|
-
}))();
|
|
206
|
-
},
|
|
207
|
-
methods: {
|
|
208
|
-
getNodeInfo: function getNodeInfo() {
|
|
209
|
-
return {
|
|
210
|
-
url: this.url,
|
|
211
|
-
internalUrl: this.internalUrl,
|
|
212
|
-
nodeNetworkId: this.nodeNetworkId,
|
|
213
|
-
version: this.version,
|
|
214
|
-
consensusProtocolVersion: this.consensusProtocolVersion
|
|
215
|
-
};
|
|
216
|
-
},
|
|
217
|
-
getConsensusProtocolVersion: getConsensusProtocolVersion
|
|
218
|
-
},
|
|
219
|
-
props: {
|
|
220
|
-
version: null,
|
|
221
|
-
consensusProtocolVersion: null,
|
|
222
|
-
nodeNetworkId: null
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
var NODE_GE_VERSION = '6.0.0';
|
|
226
|
-
var NODE_LT_VERSION = '7.0.0';
|
|
227
|
-
export default Node;
|
|
228
|
-
//# sourceMappingURL=node.js.map
|
package/es/node.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/node.js"],"names":["AsyncInit","genSwaggerClient","semverSatisfies","getNetworkId","networkId","force","selectedNode","Error","getConsensusProtocolVersion","protocols","height","api","getCurrentKeyBlock","effectiveAtHeight","acc","p","version","Node","compose","init","url","internalUrl","ignoreVersion","replace","client","spec","info","NODE_GE_VERSION","NODE_LT_VERSION","getStatus","revision","nodeRevision","genesisHash","genesisKeyBlockHash","consensusProtocolVersion","nodeNetworkId","methods","getNodeInfo","props"],"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,SAAP,MAAsB,oBAAtB;AACA,OAAOC,gBAAP,MAA6B,iBAA7B;AACA,OAAOC,eAAP,MAA4B,0BAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAA0D;AAAA,iFAAJ,EAAI;AAAA,MAAjCC,SAAiC,QAAjCA,SAAiC;AAAA,wBAAtBC,KAAsB;AAAA,MAAtBA,KAAsB,2BAAd,KAAc;;AAC/D,MAAI,CAACA,KAAD,IAAU,CAACD,SAAX,IAAwB,CAAC,KAAKA,SAA9B,KAA4C,CAAC,KAAKE,YAAN,IAAsB,CAAC,KAAKA,YAAL,CAAkBF,SAArF,CAAJ,EAAqG,MAAM,IAAIG,KAAJ,CAAU,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BMC,cAAAA,WAjBN,yBAiBfC,mBAjBe;AAiBmB7B,cAAAA,SAjBnB,yBAiBmBA,SAjBnB;AAiB8BK,cAAAA,SAjB9B,yBAiB8BA,SAjB9B;AAAA;AAAA,qBAkBT,KAAI,CAACD,2BAAL,CAAiCC,SAAjC,CAlBS;;AAAA;AAkB/C,cAAA,KAAI,CAACyB,wBAlB0C;AAmB/C,cAAA,KAAI,CAACC,aAAL,GAAqB/B,SAArB;AAnB+C,gDAoBxC,eAAc,KAAd,EAAoB;AAAE0B,gBAAAA,QAAQ,EAARA,QAAF;AAAYE,gBAAAA,WAAW,EAAXA;AAAZ,eAApB,CApBwC;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBhD,GAtB4B;AAuB7BI,EAAAA,OAAO,EAAE;AACPC,IAAAA,WADO,yBACQ;AACb,aAAO;AACLjB,QAAAA,GAAG,EAAE,KAAKA,GADL;AAELC,QAAAA,WAAW,EAAE,KAAKA,WAFb;AAGLc,QAAAA,aAAa,EAAE,KAAKA,aAHf;AAILnB,QAAAA,OAAO,EAAE,KAAKA,OAJT;AAKLkB,QAAAA,wBAAwB,EAAE,KAAKA;AAL1B,OAAP;AAOD,KATM;AAUP1B,IAAAA,2BAA2B,EAA3BA;AAVO,GAvBoB;AAmC7B8B,EAAAA,KAAK,EAAE;AACLtB,IAAAA,OAAO,EAAE,IADJ;AAELkB,IAAAA,wBAAwB,EAAE,IAFrB;AAGLC,IAAAA,aAAa,EAAE;AAHV;AAnCsB,CAAlB,CAAb;AA0CA,IAAMR,eAAe,GAAG,OAAxB;AACA,IAAMC,eAAe,GAAG,OAAxB;AAEA,eAAeX,IAAf","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 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 * Node module\n * @module @aeternity/aepp-sdk/es/node\n * @export Node\n * @example import { Node } from '@aeternity/aepp-sdk'\n */\n\nimport AsyncInit from './utils/async-init'\nimport genSwaggerClient from './utils/swagger'\nimport semverSatisfies from './utils/semver-satisfies'\n\n/**\n * Obtain networkId from account or node\n * @instance\n * @category async\n * @rtype () => networkId: String\n * @return {String} NetworkId\n */\nexport function getNetworkId ({ networkId, force = false } = {}) {\n if (!force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) throw new Error('networkId is not provided')\n if (force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) return null\n return networkId || this.networkId || this.selectedNode.networkId\n}\n\n/**\n * get consensus protocol version\n * @param {Array} protocols Array of protocols\n * @param {Number} height Height\n * @return {Number} version Protocol version\n */\nasync function getConsensusProtocolVersion (protocols = [], height) {\n if (!protocols) throw new Error('Protocols must be an array')\n if (!height) height = (await this.api.getCurrentKeyBlock()).height\n if (height < 0) throw new Error('height must be a number >= 0')\n\n return protocols\n .filter(({ effectiveAtHeight }) => height >= effectiveAtHeight)\n .reduce(\n (acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,\n { effectiveAtHeight: -1, version: 0 }\n )\n .version\n}\n\n/**\n * {@link genSwaggerClient} based Node remote API Stamp\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node\n * @rtype Stamp\n * @param {Object} [options={}] - Options\n * @param {String} options.url - Base URL for Node\n * @param {String} options.internalUrl - Base URL for internal requests\n * @param {String} options.axiosConfig - Object with axios configuration. Example { config: {}, errorHandler: (err) => throw err }\n * @return {Object} Node client\n * @example Node({url: 'https://testnet.aeternity.io'})\n */\nconst Node = AsyncInit.compose({\n async init ({ url, internalUrl, ignoreVersion }) {\n if (!url) throw new Error('\"url\" required')\n this.url = url.replace(/\\/$/, '')\n this.internalUrl = internalUrl ? internalUrl.replace(/\\/$/, '') : this.url\n const client = await genSwaggerClient(`${this.url}/api?oas3`, { internalUrl: this.internalUrl })\n this.version = client.spec.info.version\n if (\n !semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&\n !ignoreVersion\n ) {\n throw new Error(\n `Unsupported node version ${this.version}. ` +\n `Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`\n )\n }\n this.api = client.api\n\n const { nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId, protocols } = await this.api.getStatus()\n this.consensusProtocolVersion = await this.getConsensusProtocolVersion(protocols)\n this.nodeNetworkId = networkId\n return Object.assign(this, { revision, genesisHash })\n },\n methods: {\n getNodeInfo () {\n return {\n url: this.url,\n internalUrl: this.internalUrl,\n nodeNetworkId: this.nodeNetworkId,\n version: this.version,\n consensusProtocolVersion: this.consensusProtocolVersion\n }\n },\n getConsensusProtocolVersion\n },\n props: {\n version: null,\n consensusProtocolVersion: null,\n nodeNetworkId: null\n }\n})\n\nconst NODE_GE_VERSION = '6.0.0'\nconst NODE_LT_VERSION = '7.0.0'\n\nexport default Node\n"],"file":"node.js"}
|