@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
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodePool module
|
|
3
|
+
* @module @aeternity/aepp-sdk/es/node-pool
|
|
4
|
+
* @export NodePool
|
|
5
|
+
* @example import { NodePool } from '@aeternity/aepp-sdk'
|
|
6
|
+
*/
|
|
7
|
+
import stampit from '@stamp/it';
|
|
8
|
+
import { getNetworkId } from "../node.mjs";
|
|
9
|
+
import { DisconnectedError, DuplicateNodeError, NodeNotFoundError, TypeError } from "../utils/errors.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* Node Pool Stamp
|
|
12
|
+
* This stamp allow you to make basic manipulation(add, remove, select) on list of nodes
|
|
13
|
+
* @function
|
|
14
|
+
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
15
|
+
* @rtype Stamp
|
|
16
|
+
* @param {Object} [options={}] - Initializer object
|
|
17
|
+
* @param {Array} [options.nodes] - Array with Node instances
|
|
18
|
+
* @return {Object} NodePool instance
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export default stampit({
|
|
22
|
+
init() {
|
|
23
|
+
let {
|
|
24
|
+
nodes = []
|
|
25
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26
|
+
this.pool = new Map();
|
|
27
|
+
this.validateNodes(nodes);
|
|
28
|
+
nodes.forEach((node, i) => {
|
|
29
|
+
const {
|
|
30
|
+
name,
|
|
31
|
+
instance
|
|
32
|
+
} = node;
|
|
33
|
+
this.addNode(name, instance, i === 0);
|
|
34
|
+
});
|
|
35
|
+
if (nodes.length) this.selectNode(nodes[0].name);
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
propertyDescriptors: {
|
|
39
|
+
api: {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: false,
|
|
42
|
+
|
|
43
|
+
get() {
|
|
44
|
+
if (!this.selectedNode || !this.selectedNode.instance) {
|
|
45
|
+
throw new NodeNotFoundError('You can\'t use Node API. Node is not connected or not defined!');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return this.selectedNode.instance.api;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
methods: {
|
|
54
|
+
/**
|
|
55
|
+
* Add Node
|
|
56
|
+
* @function
|
|
57
|
+
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
58
|
+
* @rtype (name: String, nodeInstance: Object, select: Boolean) => void
|
|
59
|
+
* @param {String} name - Node name
|
|
60
|
+
* @param {Object} node - Node instance
|
|
61
|
+
* @param {Boolean} select - Select this node as current
|
|
62
|
+
* @return {void}
|
|
63
|
+
* @example
|
|
64
|
+
* // add and select new node with name 'testNode'
|
|
65
|
+
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
|
|
66
|
+
*/
|
|
67
|
+
addNode(name, node) {
|
|
68
|
+
let select = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
69
|
+
if (this.pool.has(name)) throw new DuplicateNodeError(name);
|
|
70
|
+
this.validateNodes([{
|
|
71
|
+
name,
|
|
72
|
+
instance: node
|
|
73
|
+
}]);
|
|
74
|
+
this.pool.set(name, {
|
|
75
|
+
name,
|
|
76
|
+
instance: node,
|
|
77
|
+
url: node.url,
|
|
78
|
+
internalUrl: node.internalUrl,
|
|
79
|
+
networkId: node.nodeNetworkId,
|
|
80
|
+
version: node.version,
|
|
81
|
+
consensusProtocolVersion: node.consensusProtocolVersion
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (select || !this.selectedNode) {
|
|
85
|
+
this.selectNode(name);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Select Node
|
|
91
|
+
* @function
|
|
92
|
+
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
93
|
+
* @rtype (name: String) => void
|
|
94
|
+
* @param {String} name - Node name
|
|
95
|
+
* @return {void}
|
|
96
|
+
* @example
|
|
97
|
+
* nodePool.selectNode('testNode')
|
|
98
|
+
*/
|
|
99
|
+
selectNode(name) {
|
|
100
|
+
if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`);
|
|
101
|
+
this.selectedNode = this.pool.get(name);
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get NetworkId of current Node
|
|
106
|
+
* @function
|
|
107
|
+
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
108
|
+
* @rtype () => String
|
|
109
|
+
* @return {String}
|
|
110
|
+
* @example
|
|
111
|
+
* nodePool.getNetworkId()
|
|
112
|
+
*/
|
|
113
|
+
getNetworkId,
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Check if you have selected node
|
|
117
|
+
* @function
|
|
118
|
+
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
119
|
+
* @rtype () => Boolean
|
|
120
|
+
* @return {Boolean}
|
|
121
|
+
* @example
|
|
122
|
+
* nodePool.isNodeConnected()
|
|
123
|
+
*/
|
|
124
|
+
isNodeConnected() {
|
|
125
|
+
return !!this.selectedNode.instance;
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get information about node
|
|
130
|
+
* @function
|
|
131
|
+
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
132
|
+
* @rtype () => Object
|
|
133
|
+
* @return {Object}
|
|
134
|
+
* @example
|
|
135
|
+
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
|
|
136
|
+
*/
|
|
137
|
+
getNodeInfo() {
|
|
138
|
+
if (!this.isNodeConnected()) throw new DisconnectedError();
|
|
139
|
+
return {
|
|
140
|
+
name: this.selectedNode.name,
|
|
141
|
+
...this.selectedNode.instance.getNodeInfo()
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get array of available nodes
|
|
147
|
+
* @function
|
|
148
|
+
* @alias module:@aeternity/aepp-sdk/es/node-pool
|
|
149
|
+
* @rtype () => Object[]
|
|
150
|
+
* @return {Object[]}
|
|
151
|
+
* @example
|
|
152
|
+
* nodePool.getNodesInPool()
|
|
153
|
+
*/
|
|
154
|
+
getNodesInPool() {
|
|
155
|
+
return Array.from(this.pool.entries()).map(_ref => {
|
|
156
|
+
let [name, node] = _ref;
|
|
157
|
+
return {
|
|
158
|
+
name,
|
|
159
|
+
...node.instance.getNodeInfo()
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
validateNodes(nodes) {
|
|
165
|
+
// TODO: validate it on TypeScript level instead
|
|
166
|
+
// (to speedup development, save runtime resources)
|
|
167
|
+
if (!Array.isArray(nodes)) throw new TypeError('"nodes" should be an array');
|
|
168
|
+
const notObject = nodes.map(n => typeof n).find(t => t !== 'object');
|
|
169
|
+
if (notObject) throw new TypeError(`Each node should be an object, got ${notObject} instead`);
|
|
170
|
+
const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object');
|
|
171
|
+
|
|
172
|
+
if (notObject) {
|
|
173
|
+
throw new TypeError('Each node should have name (string), instance (object) ' + `fields, got ${JSON.stringify(wrongFields)} instead`);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const wrongInstanceFields = nodes.map(n => n.instance).find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' || typeof i.consensusProtocolVersion !== 'number');
|
|
177
|
+
|
|
178
|
+
if (wrongInstanceFields) {
|
|
179
|
+
throw new TypeError('Each node instance should have api (object), consensusProtocolVersion (number), ' + `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
},
|
|
184
|
+
props: {
|
|
185
|
+
selectedNode: {}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/node-pool/index.js"],"names":["stampit","getNetworkId","DisconnectedError","DuplicateNodeError","NodeNotFoundError","TypeError","init","nodes","pool","Map","validateNodes","forEach","node","i","name","instance","addNode","length","selectNode","propertyDescriptors","api","enumerable","configurable","get","selectedNode","methods","select","has","set","url","internalUrl","networkId","nodeNetworkId","version","consensusProtocolVersion","isNodeConnected","getNodeInfo","getNodesInPool","Array","from","entries","map","isArray","notObject","n","find","t","wrongFields","JSON","stringify","wrongInstanceFields","genesisHash","props"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;SACSC,Y;SACAC,iB,EAAmBC,kB,EAAoBC,iB,EAAmBC,S;AAEnE;AACA;AACA;AACA;AACA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,CAAC7B,QADc,EAEzB8B,IAFyB,CAEpBhC,CAAC,IAAI,OAAOA,CAAC,CAACO,GAAT,KAAiB,QAAjB,IAA6B,OAAOP,CAAC,CAACsC,WAAT,KAAyB,QAAtD,IACT,OAAOtC,CAAC,CAACqB,wBAAT,KAAsC,QAHd,CAA5B;;AAIA,UAAIgB,mBAAJ,EAAyB;AACvB,cAAM,IAAI7C,SAAJ,CACJ,qFACC,oCAAmC2C,IAAI,CAACC,SAAL,CAAeC,mBAAf,CAAoC,UAFpE,CAAN;AAID;AACF;;AA3HM,GAvBY;AAoJrBE,EAAAA,KAAK,EAAE;AACL5B,IAAAA,YAAY,EAAE;AADT;AApJc,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 { getNetworkId } from '../node'\nimport { DisconnectedError, DuplicateNodeError, NodeNotFoundError, TypeError } from '../utils/errors'\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 NodeNotFoundError('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 * // add and select new node with name 'testNode'\n * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)\n */\n addNode (name, node, select = false) {\n if (this.pool.has(name)) throw new DuplicateNodeError(name)\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 NodeNotFoundError(`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 DisconnectedError()\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 // TODO: validate it on TypeScript level instead\n // (to speedup development, save runtime resources)\n if (!Array.isArray(nodes)) throw new TypeError('\"nodes\" should be an array')\n const notObject = nodes.map(n => typeof n).find(t => t !== 'object')\n if (notObject) throw new TypeError(`Each node should be an object, got ${notObject} instead`)\n const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')\n if (notObject) {\n throw new TypeError(\n 'Each node should have name (string), instance (object) ' +\n `fields, got ${JSON.stringify(wrongFields)} instead`\n )\n }\n const wrongInstanceFields = nodes\n .map(n => n.instance)\n .find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||\n typeof i.consensusProtocolVersion !== 'number')\n if (wrongInstanceFields) {\n throw new TypeError(\n 'Each node instance should have api (object), consensusProtocolVersion (number), ' +\n `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`\n )\n }\n }\n },\n props: {\n selectedNode: {}\n }\n})\n"],"file":"index.mjs"}
|
package/es/node.mjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2021 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Node module
|
|
20
|
+
* @module @aeternity/aepp-sdk/es/node
|
|
21
|
+
* @export Node
|
|
22
|
+
* @example import { Node } from '@aeternity/aepp-sdk'
|
|
23
|
+
*/
|
|
24
|
+
import AsyncInit from "./utils/async-init.mjs";
|
|
25
|
+
import genSwaggerClient from "./utils/swagger.mjs";
|
|
26
|
+
import semverSatisfies from "./utils/semver-satisfies.mjs";
|
|
27
|
+
import { MissingParamError, UnsupportedVersionError } from "./utils/errors.mjs";
|
|
28
|
+
/**
|
|
29
|
+
* Obtain networkId from account or node
|
|
30
|
+
* @instance
|
|
31
|
+
* @category async
|
|
32
|
+
* @rtype () => networkId: String
|
|
33
|
+
* @return {String} NetworkId
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export function getNetworkId() {
|
|
37
|
+
var _this$selectedNode;
|
|
38
|
+
|
|
39
|
+
let {
|
|
40
|
+
networkId,
|
|
41
|
+
force = false
|
|
42
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
43
|
+
const res = networkId || this.networkId || ((_this$selectedNode = this.selectedNode) === null || _this$selectedNode === void 0 ? void 0 : _this$selectedNode.networkId);
|
|
44
|
+
if (!force && !res) throw new MissingParamError('networkId is not provided');
|
|
45
|
+
if (force && !res) return null;
|
|
46
|
+
return res;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* {@link genSwaggerClient} based Node remote API Stamp
|
|
50
|
+
* @function
|
|
51
|
+
* @alias module:@aeternity/aepp-sdk/es/node
|
|
52
|
+
* @rtype Stamp
|
|
53
|
+
* @param {Object} [options={}] - Options
|
|
54
|
+
* @param {String} options.url - Base URL for Node
|
|
55
|
+
* @param {String} options.internalUrl - Base URL for internal requests
|
|
56
|
+
* @param {Object} options.axiosConfig - Object with axios configuration
|
|
57
|
+
* @param {Object} options.axiosConfig.config
|
|
58
|
+
* @param {Function} options.axiosConfig.errorHandler - (err) => throw err
|
|
59
|
+
* @return {Object} Node client
|
|
60
|
+
* @example Node({url: 'https://testnet.aeternity.io'})
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
const Node = AsyncInit.compose({
|
|
64
|
+
async init(_ref) {
|
|
65
|
+
let {
|
|
66
|
+
url,
|
|
67
|
+
internalUrl,
|
|
68
|
+
ignoreVersion
|
|
69
|
+
} = _ref;
|
|
70
|
+
if (!url) throw new MissingParamError('"url" required');
|
|
71
|
+
this.url = url.replace(/\/$/, '');
|
|
72
|
+
this.internalUrl = internalUrl === null || internalUrl === void 0 ? void 0 : internalUrl.replace(/\/$/, '');
|
|
73
|
+
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
74
|
+
internalUrl: this.internalUrl,
|
|
75
|
+
responseInterceptor: response => {
|
|
76
|
+
if (response.ok) return;
|
|
77
|
+
return Object.assign(response, {
|
|
78
|
+
statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
this.version = client.spec.info.version;
|
|
83
|
+
|
|
84
|
+
if (!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion) {
|
|
85
|
+
throw new UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.api = client.api;
|
|
89
|
+
const {
|
|
90
|
+
nodeRevision: revision,
|
|
91
|
+
genesisKeyBlockHash: genesisHash,
|
|
92
|
+
networkId,
|
|
93
|
+
protocols,
|
|
94
|
+
topBlockHeight
|
|
95
|
+
} = await this.api.getStatus();
|
|
96
|
+
this.consensusProtocolVersion = protocols.filter(_ref2 => {
|
|
97
|
+
let {
|
|
98
|
+
effectiveAtHeight
|
|
99
|
+
} = _ref2;
|
|
100
|
+
return topBlockHeight >= effectiveAtHeight;
|
|
101
|
+
}).reduce((acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc, {
|
|
102
|
+
effectiveAtHeight: -1,
|
|
103
|
+
version: 0
|
|
104
|
+
}).version;
|
|
105
|
+
this.nodeNetworkId = networkId;
|
|
106
|
+
return Object.assign(this, {
|
|
107
|
+
revision,
|
|
108
|
+
genesisHash
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
methods: {
|
|
113
|
+
getNodeInfo() {
|
|
114
|
+
return {
|
|
115
|
+
url: this.url,
|
|
116
|
+
internalUrl: this.internalUrl,
|
|
117
|
+
nodeNetworkId: this.nodeNetworkId,
|
|
118
|
+
version: this.version,
|
|
119
|
+
consensusProtocolVersion: this.consensusProtocolVersion
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
},
|
|
124
|
+
props: {
|
|
125
|
+
version: null,
|
|
126
|
+
consensusProtocolVersion: null,
|
|
127
|
+
nodeNetworkId: null
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
const NODE_GE_VERSION = '6.2.0';
|
|
131
|
+
const NODE_LT_VERSION = '7.0.0';
|
|
132
|
+
export default Node;
|
|
133
|
+
//# sourceMappingURL=node.mjs.map
|
package/es/node.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node.js"],"names":["AsyncInit","genSwaggerClient","semverSatisfies","MissingParamError","UnsupportedVersionError","getNetworkId","networkId","force","res","selectedNode","Node","compose","init","url","internalUrl","ignoreVersion","replace","client","responseInterceptor","response","ok","Object","assign","statusText","URL","pathname","slice","body","reason","version","spec","info","NODE_GE_VERSION","NODE_LT_VERSION","api","nodeRevision","revision","genesisKeyBlockHash","genesisHash","protocols","topBlockHeight","getStatus","consensusProtocolVersion","filter","effectiveAtHeight","reduce","acc","p","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;OAEOA,S;OACAC,gB;OACAC,e;SACEC,iB,EAAmBC,uB;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAA0D;AAAA;;AAAA,MAAnC;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,KAAK,GAAG;AAArB,GAAmC,uEAAJ,EAAI;AAC/D,QAAMC,GAAG,GAAGF,SAAS,IAAI,KAAKA,SAAlB,2BAA+B,KAAKG,YAApC,uDAA+B,mBAAmBH,SAAlD,CAAZ;AACA,MAAI,CAACC,KAAD,IAAU,CAACC,GAAf,EAAoB,MAAM,IAAIL,iBAAJ,CAAsB,2BAAtB,CAAN;AACpB,MAAII,KAAK,IAAI,CAACC,GAAd,EAAmB,OAAO,IAAP;AACnB,SAAOA,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAME,IAAI,GAAGV,SAAS,CAACW,OAAV,CAAkB;AAC7B,QAAMC,IAAN,OAAiD;AAAA,QAArC;AAAEC,MAAAA,GAAF;AAAOC,MAAAA,WAAP;AAAoBC,MAAAA;AAApB,KAAqC;AAC/C,QAAI,CAACF,GAAL,EAAU,MAAM,IAAIV,iBAAJ,CAAsB,gBAAtB,CAAN;AACV,SAAKU,GAAL,GAAWA,GAAG,CAACG,OAAJ,CAAY,KAAZ,EAAmB,EAAnB,CAAX;AACA,SAAKF,WAAL,GAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,CAAEE,OAAb,CAAqB,KAArB,EAA4B,EAA5B,CAAnB;AACA,UAAMC,MAAM,GAAG,MAAMhB,gBAAgB,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EAI5B;AAAEF,MAAAA,iBAAiB,EAAE,CAAC,CAAtB;AAAyBf,MAAAA,OAAO,EAAE;AAAlC,KAJ4B,EAM7BA,OANH;AAOA,SAAKmB,aAAL,GAAqB1C,SAArB;AACA,WAAOe,MAAM,CAACC,MAAP,CAAc,IAAd,EAAoB;AAAEc,MAAAA,QAAF;AAAYE,MAAAA;AAAZ,KAApB,CAAP;AACD,GApC4B;;AAqC7BW,EAAAA,OAAO,EAAE;AACPC,IAAAA,WAAW,GAAI;AACb,aAAO;AACLrC,QAAAA,GAAG,EAAE,KAAKA,GADL;AAELC,QAAAA,WAAW,EAAE,KAAKA,WAFb;AAGLkC,QAAAA,aAAa,EAAE,KAAKA,aAHf;AAILnB,QAAAA,OAAO,EAAE,KAAKA,OAJT;AAKLa,QAAAA,wBAAwB,EAAE,KAAKA;AAL1B,OAAP;AAOD;;AATM,GArCoB;AAgD7BS,EAAAA,KAAK,EAAE;AACLtB,IAAAA,OAAO,EAAE,IADJ;AAELa,IAAAA,wBAAwB,EAAE,IAFrB;AAGLM,IAAAA,aAAa,EAAE;AAHV;AAhDsB,CAAlB,CAAb;AAuDA,MAAMhB,eAAe,GAAG,OAAxB;AACA,MAAMC,eAAe,GAAG,OAAxB;AAEA,eAAevB,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'\nimport { MissingParamError, UnsupportedVersionError } from './utils/errors'\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 const res = networkId || this.networkId || this.selectedNode?.networkId\n if (!force && !res) throw new MissingParamError('networkId is not provided')\n if (force && !res) return null\n return res\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 {Object} options.axiosConfig - Object with axios configuration\n * @param {Object} options.axiosConfig.config\n * @param {Function} options.axiosConfig.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 MissingParamError('\"url\" required')\n this.url = url.replace(/\\/$/, '')\n this.internalUrl = internalUrl?.replace(/\\/$/, '')\n const client = await genSwaggerClient(`${this.url}/api?oas3`, {\n internalUrl: this.internalUrl,\n responseInterceptor: response => {\n if (response.ok) return\n return Object.assign(response, {\n statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason\n })\n }\n })\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 UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION)\n }\n this.api = client.api\n\n const {\n nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId,\n protocols, topBlockHeight\n } = await this.api.getStatus()\n this.consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,\n { effectiveAtHeight: -1, version: 0 }\n )\n .version\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 },\n props: {\n version: null,\n consensusProtocolVersion: null,\n nodeNetworkId: null\n }\n})\n\nconst NODE_GE_VERSION = '6.2.0'\nconst NODE_LT_VERSION = '7.0.0'\n\nexport default Node\n"],"file":"node.mjs"}
|
package/es/other.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const pause: (duration: number) => Promise<
|
|
1
|
+
export declare const pause: (duration: number) => Promise<void>;
|
|
2
2
|
export declare const mapObject: (object: object, fn: (value: [string, any], index: number, array: Array<[string, any]>) => Array<[string, any]>) => object;
|
|
3
3
|
export declare const filterObject: (object: object, fn: (value: [string, any], index: number, array: Array<[string, any]>) => boolean) => object;
|
|
4
4
|
/**
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
5
|
+
import { writeId, readId, isNameValid, produceNameId, ensureNameValid, getMinimumNameFee, readInt, writeInt } from "./helpers.mjs";
|
|
6
|
+
import { InsufficientNameFeeError, IllegalArgumentError } from "../../utils/errors.mjs";
|
|
7
|
+
export class Field {
|
|
8
|
+
static serialize(value) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static deserialize(value) {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
export class Name extends Field {
|
|
18
|
+
static serialize(value) {
|
|
19
|
+
ensureNameValid(value);
|
|
20
|
+
return _Buffer.from(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static deserialize(value) {
|
|
24
|
+
return value.toString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
export class NameId extends Field {
|
|
29
|
+
static serialize(value) {
|
|
30
|
+
return writeId(isNameValid(value) ? produceNameId(value) : value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static deserialize(value) {
|
|
34
|
+
return readId(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
export class NameFee extends Field {
|
|
39
|
+
static serialize(value, _ref) {
|
|
40
|
+
var _value;
|
|
41
|
+
|
|
42
|
+
let {
|
|
43
|
+
name
|
|
44
|
+
} = _ref;
|
|
45
|
+
const minNameFee = getMinimumNameFee(name);
|
|
46
|
+
(_value = value) !== null && _value !== void 0 ? _value : value = minNameFee;
|
|
47
|
+
|
|
48
|
+
if (minNameFee.gt(value)) {
|
|
49
|
+
throw new InsufficientNameFeeError(value, minNameFee);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return writeInt(value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static deserialize(value) {
|
|
56
|
+
return readInt(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
export class Deposit extends Field {
|
|
61
|
+
static serialize(value, _ref2) {
|
|
62
|
+
let {
|
|
63
|
+
name
|
|
64
|
+
} = _ref2;
|
|
65
|
+
if (+value) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value} instead`);
|
|
66
|
+
return writeInt(0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static deserialize(value) {
|
|
70
|
+
return readInt(value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=field-types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/tx/builder/field-types.js"],"names":["writeId","readId","isNameValid","produceNameId","ensureNameValid","getMinimumNameFee","readInt","writeInt","InsufficientNameFeeError","IllegalArgumentError","Field","serialize","value","deserialize","Name","from","toString","NameId","NameFee","name","minNameFee","gt","Deposit"],"mappings":";;;;SACEA,O,EAASC,M,EAAQC,W,EAAaC,a,EAAeC,e,EAAiBC,iB,EAAmBC,O,EAASC,Q;SAEnFC,wB,EAA0BC,oB;AAEnC,OAAO,MAAMC,KAAN,CAAY;AACD,SAATC,SAAS,CAAEC,KAAF,EAAS;AACvB,WAAOA,KAAP;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAOA,KAAP;AACD;;AAPgB;AAUnB,OAAO,MAAME,IAAN,SAAmBJ,KAAnB,CAAyB;AACd,SAATC,SAAS,CAAEC,KAAF,EAAS;AACvBR,IAAAA,eAAe,CAACQ,KAAD,CAAf;AACA,WAAO,QAAOG,IAAP,CAAYH,KAAZ,CAAP;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAOA,KAAK,CAACI,QAAN,EAAP;AACD;;AAR6B;AAWhC,OAAO,MAAMC,MAAN,SAAqBP,KAArB,CAA2B;AAChB,SAATC,SAAS,CAAEC,KAAF,EAAS;AACvB,WAAOZ,OAAO,CAACE,WAAW,CAACU,KAAD,CAAX,GAAqBT,aAAa,CAACS,KAAD,CAAlC,GAA4CA,KAA7C,CAAd;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAOX,MAAM,CAACW,KAAD,CAAb;AACD;;AAP+B;AAUlC,OAAO,MAAMM,OAAN,SAAsBR,KAAtB,CAA4B;AACjB,SAATC,SAAS,CAAEC,KAAF,QAAmB;AAAA;;AAAA,QAAV;AAAEO,MAAAA;AAAF,KAAU;AACjC,UAAMC,UAAU,GAAGf,iBAAiB,CAACc,IAAD,CAApC;AACA,cAAAP,KAAK,UAAL,iCAAAA,KAAK,GAAKQ,UAAV;;AACA,QAAIA,UAAU,CAACC,EAAX,CAAcT,KAAd,CAAJ,EAA0B;AACxB,YAAM,IAAIJ,wBAAJ,CAA6BI,KAA7B,EAAoCQ,UAApC,CAAN;AACD;;AACD,WAAOb,QAAQ,CAACK,KAAD,CAAf;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAON,OAAO,CAACM,KAAD,CAAd;AACD;;AAZgC;AAenC,OAAO,MAAMU,OAAN,SAAsBZ,KAAtB,CAA4B;AACjB,SAATC,SAAS,CAAEC,KAAF,SAAmB;AAAA,QAAV;AAAEO,MAAAA;AAAF,KAAU;AACjC,QAAI,CAACP,KAAL,EAAY,MAAM,IAAIH,oBAAJ,CAA0B,oEAAmEG,KAAM,UAAnG,CAAN;AACZ,WAAOL,QAAQ,CAAC,CAAD,CAAf;AACD;;AAEiB,SAAXM,WAAW,CAAED,KAAF,EAAS;AACzB,WAAON,OAAO,CAACM,KAAD,CAAd;AACD;;AARgC","sourcesContent":["import {\n writeId, readId, isNameValid, produceNameId, ensureNameValid, getMinimumNameFee, readInt, writeInt\n} from './helpers'\nimport { InsufficientNameFeeError, IllegalArgumentError } from '../../utils/errors'\n\nexport class Field {\n static serialize (value) {\n return value\n }\n\n static deserialize (value) {\n return value\n }\n}\n\nexport class Name extends Field {\n static serialize (value) {\n ensureNameValid(value)\n return Buffer.from(value)\n }\n\n static deserialize (value) {\n return value.toString()\n }\n}\n\nexport class NameId extends Field {\n static serialize (value) {\n return writeId(isNameValid(value) ? produceNameId(value) : value)\n }\n\n static deserialize (value) {\n return readId(value)\n }\n}\n\nexport class NameFee extends Field {\n static serialize (value, { name }) {\n const minNameFee = getMinimumNameFee(name)\n value ??= minNameFee\n if (minNameFee.gt(value)) {\n throw new InsufficientNameFeeError(value, minNameFee)\n }\n return writeInt(value)\n }\n\n static deserialize (value) {\n return readInt(value)\n }\n}\n\nexport class Deposit extends Field {\n static serialize (value, { name }) {\n if (+value) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value} instead`)\n return writeInt(0)\n }\n\n static deserialize (value) {\n return readInt(value)\n }\n}\n"],"file":"field-types.mjs"}
|