@chain-registry/client 1.19.2 → 1.20.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/main/client.js +277 -0
- package/main/index.js +8 -30
- package/main/utils.js +110 -0
- package/package.json +3 -3
- package/types/client.d.ts +43 -0
- package/types/index.d.ts +2 -4
- package/types/utils.d.ts +28 -0
- package/CHANGELOG.md +0 -256
- package/main/chain-info.js +0 -57
- package/main/chain-util.js +0 -88
- package/main/fetcher.js +0 -229
- package/main/registry.js +0 -88
- package/types/chain-info.d.ts +0 -19
- package/types/chain-util.d.ts +0 -24
- package/types/fetcher.d.ts +0 -30
- package/types/registry.d.ts +0 -14
package/CHANGELOG.md
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [1.19.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.19.1...@chain-registry/client@1.19.2) (2024-02-27)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## [1.19.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.19.0...@chain-registry/client@1.19.1) (2024-02-26)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [1.19.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.18.4...@chain-registry/client@1.19.0) (2024-01-25)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## [1.18.4](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.18.3...@chain-registry/client@1.18.4) (2024-01-19)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## [1.18.3](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.18.2...@chain-registry/client@1.18.3) (2024-01-19)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## [1.18.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.18.1...@chain-registry/client@1.18.2) (2024-01-19)
|
|
47
|
-
|
|
48
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
## [1.18.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.18.0...@chain-registry/client@1.18.1) (2024-01-17)
|
|
55
|
-
|
|
56
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
# [1.18.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.17.1...@chain-registry/client@1.18.0) (2023-12-20)
|
|
63
|
-
|
|
64
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
## [1.17.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.17.0...@chain-registry/client@1.17.1) (2023-12-15)
|
|
71
|
-
|
|
72
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
# [1.17.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.16.0...@chain-registry/client@1.17.0) (2023-12-15)
|
|
79
|
-
|
|
80
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
# [1.16.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.15.0...@chain-registry/client@1.16.0) (2023-12-15)
|
|
87
|
-
|
|
88
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# [1.15.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.14.2...@chain-registry/client@1.15.0) (2023-09-15)
|
|
95
|
-
|
|
96
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
## [1.14.2](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.14.1...@chain-registry/client@1.14.2) (2023-07-30)
|
|
103
|
-
|
|
104
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
## [1.14.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.14.0...@chain-registry/client@1.14.1) (2023-07-12)
|
|
111
|
-
|
|
112
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# [1.14.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.13.0...@chain-registry/client@1.14.0) (2023-07-11)
|
|
119
|
-
|
|
120
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
# [1.13.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.12.0...@chain-registry/client@1.13.0) (2023-07-08)
|
|
127
|
-
|
|
128
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
# [1.12.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.11.0...@chain-registry/client@1.12.0) (2023-06-27)
|
|
135
|
-
|
|
136
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
# [1.11.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.10.1...@chain-registry/client@1.11.0) (2023-04-20)
|
|
143
|
-
|
|
144
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
## [1.10.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.10.0...@chain-registry/client@1.10.1) (2023-04-18)
|
|
151
|
-
|
|
152
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
# [1.10.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.9.0...@chain-registry/client@1.10.0) (2023-04-18)
|
|
159
|
-
|
|
160
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
# [1.9.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.8.0...@chain-registry/client@1.9.0) (2023-03-29)
|
|
167
|
-
|
|
168
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
# [1.8.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.7.0...@chain-registry/client@1.8.0) (2023-03-02)
|
|
175
|
-
|
|
176
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
# [1.7.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.6.0...@chain-registry/client@1.7.0) (2023-02-23)
|
|
183
|
-
|
|
184
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
# [1.6.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.5.0...@chain-registry/client@1.6.0) (2023-02-08)
|
|
191
|
-
|
|
192
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
# [1.5.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.4.1...@chain-registry/client@1.5.0) (2022-12-08)
|
|
199
|
-
|
|
200
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
## [1.4.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.4.0...@chain-registry/client@1.4.1) (2022-11-16)
|
|
207
|
-
|
|
208
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
# [1.4.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.3.0...@chain-registry/client@1.4.0) (2022-11-10)
|
|
215
|
-
|
|
216
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
# [1.3.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.2.1...@chain-registry/client@1.3.0) (2022-11-10)
|
|
223
|
-
|
|
224
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
## [1.2.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.2.0...@chain-registry/client@1.2.1) (2022-10-27)
|
|
231
|
-
|
|
232
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
# [1.2.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.1.0...@chain-registry/client@1.2.0) (2022-10-20)
|
|
239
|
-
|
|
240
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
# [1.1.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.0.1...@chain-registry/client@1.1.0) (2022-10-20)
|
|
247
|
-
|
|
248
|
-
**Note:** Version bump only for package @chain-registry/client
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
## 1.0.1 (2022-10-20)
|
|
255
|
-
|
|
256
|
-
**Note:** Version bump only for package @chain-registry/client
|
package/main/chain-info.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.ChainInfo = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
var _utils = require("@chain-registry/utils");
|
|
12
|
-
var ChainInfo = exports.ChainInfo = /*#__PURE__*/function () {
|
|
13
|
-
function ChainInfo(options) {
|
|
14
|
-
(0, _classCallCheck2["default"])(this, ChainInfo);
|
|
15
|
-
(0, _defineProperty2["default"])(this, "chainName", void 0);
|
|
16
|
-
(0, _defineProperty2["default"])(this, "fetcher", void 0);
|
|
17
|
-
(0, _defineProperty2["default"])(this, "_chain", void 0);
|
|
18
|
-
(0, _defineProperty2["default"])(this, "_assetList", void 0);
|
|
19
|
-
(0, _defineProperty2["default"])(this, "_assetLists", void 0);
|
|
20
|
-
(0, _defineProperty2["default"])(this, "_ibcData", []);
|
|
21
|
-
this.chainName = options.chainName;
|
|
22
|
-
this.fetcher = options.fetcher;
|
|
23
|
-
this.refresh();
|
|
24
|
-
}
|
|
25
|
-
(0, _createClass2["default"])(ChainInfo, [{
|
|
26
|
-
key: "refresh",
|
|
27
|
-
value: function refresh() {
|
|
28
|
-
this._assetList = this.fetcher.getChainAssetList(this.chainName);
|
|
29
|
-
this._ibcData = this.fetcher.getChainIbcData(this.chainName);
|
|
30
|
-
this._chain = this.fetcher.getChain(this.chainName);
|
|
31
|
-
var supportedChains = this._ibcData.reduce(function (m, v) {
|
|
32
|
-
if (!m.includes(v.chain_1.chain_name)) m.push(v.chain_1.chain_name);
|
|
33
|
-
if (!m.includes(v.chain_2.chain_name)) m.push(v.chain_2.chain_name);
|
|
34
|
-
return m;
|
|
35
|
-
}, []);
|
|
36
|
-
this._assetLists = this.fetcher.assetLists.filter(function (list) {
|
|
37
|
-
return supportedChains.includes(list.chain_name);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}, {
|
|
41
|
-
key: "chain",
|
|
42
|
-
get: function get() {
|
|
43
|
-
return this._chain;
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
key: "nativeAssetList",
|
|
47
|
-
get: function get() {
|
|
48
|
-
return this._assetList;
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "assetLists",
|
|
52
|
-
get: function get() {
|
|
53
|
-
return (0, _utils.getAssetLists)(this.chainName, this._ibcData, this._assetLists);
|
|
54
|
-
}
|
|
55
|
-
}]);
|
|
56
|
-
return ChainInfo;
|
|
57
|
-
}();
|
package/main/chain-util.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.ChainRegistryChainUtil = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
var _utils = require("@chain-registry/utils");
|
|
13
|
-
var ChainRegistryChainUtil = exports.ChainRegistryChainUtil = /*#__PURE__*/function () {
|
|
14
|
-
function ChainRegistryChainUtil(options) {
|
|
15
|
-
(0, _classCallCheck2["default"])(this, ChainRegistryChainUtil);
|
|
16
|
-
(0, _defineProperty2["default"])(this, "chainName", void 0);
|
|
17
|
-
(0, _defineProperty2["default"])(this, "chainInfo", void 0);
|
|
18
|
-
(0, _defineProperty2["default"])(this, "_assets", []);
|
|
19
|
-
this.chainName = options.chainName;
|
|
20
|
-
this.chainInfo = options.chainInfo;
|
|
21
|
-
this._assets = [{
|
|
22
|
-
assets: [].concat((0, _toConsumableArray2["default"])(this.chainInfo.nativeAssetList.assets), (0, _toConsumableArray2["default"])(this.chainInfo.assetLists.flatMap(function (_ref) {
|
|
23
|
-
var assets = _ref.assets;
|
|
24
|
-
return assets;
|
|
25
|
-
}))),
|
|
26
|
-
chain_name: this.chainName
|
|
27
|
-
}];
|
|
28
|
-
}
|
|
29
|
-
(0, _createClass2["default"])(ChainRegistryChainUtil, [{
|
|
30
|
-
key: "getAssetByDenom",
|
|
31
|
-
value: function getAssetByDenom(denom) {
|
|
32
|
-
return (0, _utils.getAssetByDenom)(this._assets, denom, this.chainName);
|
|
33
|
-
}
|
|
34
|
-
}, {
|
|
35
|
-
key: "getDenomByCoinGeckoId",
|
|
36
|
-
value: function getDenomByCoinGeckoId(coinGeckoId) {
|
|
37
|
-
return (0, _utils.getDenomByCoinGeckoId)(this._assets, coinGeckoId, this.chainName);
|
|
38
|
-
}
|
|
39
|
-
}, {
|
|
40
|
-
key: "getCoinGeckoIdByDenom",
|
|
41
|
-
value: function getCoinGeckoIdByDenom(coinGeckoId) {
|
|
42
|
-
return (0, _utils.getCoinGeckoIdByDenom)(this._assets, coinGeckoId, {
|
|
43
|
-
chainName: this.chainName
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
key: "getSymbolByChainDenom",
|
|
48
|
-
value: function getSymbolByChainDenom(denom) {
|
|
49
|
-
return (0, _utils.getSymbolByChainDenom)(this._assets, denom, this.chainName);
|
|
50
|
-
}
|
|
51
|
-
}, {
|
|
52
|
-
key: "getChainDenomBySymbol",
|
|
53
|
-
value: function getChainDenomBySymbol(token) {
|
|
54
|
-
return (0, _utils.getChainDenomBySymbol)(this._assets, token, this.chainName);
|
|
55
|
-
}
|
|
56
|
-
}, {
|
|
57
|
-
key: "getExponentByDenom",
|
|
58
|
-
value: function getExponentByDenom(denom) {
|
|
59
|
-
return (0, _utils.getExponentByDenom)(this._assets, denom, this.chainName);
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
|
-
key: "convertCoinGeckoPricesToDenomPriceMap",
|
|
63
|
-
value: function convertCoinGeckoPricesToDenomPriceMap(prices) {
|
|
64
|
-
return (0, _utils.convertCoinGeckoPricesToDenomPriceMap)(this._assets, prices);
|
|
65
|
-
}
|
|
66
|
-
}, {
|
|
67
|
-
key: "noDecimals",
|
|
68
|
-
value: function noDecimals(num) {
|
|
69
|
-
return (0, _utils.noDecimals)(num);
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: "convertBaseUnitsToDollarValue",
|
|
73
|
-
value: function convertBaseUnitsToDollarValue(prices, symbol, amount) {
|
|
74
|
-
return (0, _utils.convertBaseUnitsToDollarValue)(this._assets, prices, symbol, amount, this.chainName);
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "convertDollarValueToDenomUnits",
|
|
78
|
-
value: function convertDollarValueToDenomUnits(prices, symbol, value) {
|
|
79
|
-
return (0, _utils.convertDollarValueToDenomUnits)(this._assets, prices, symbol, value, this.chainName);
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "convertBaseUnitsToDisplayUnits",
|
|
83
|
-
value: function convertBaseUnitsToDisplayUnits(symbol, amount) {
|
|
84
|
-
return (0, _utils.convertBaseUnitsToDisplayUnits)(this._assets, symbol, amount, this.chainName);
|
|
85
|
-
}
|
|
86
|
-
}]);
|
|
87
|
-
return ChainRegistryChainUtil;
|
|
88
|
-
}();
|
package/main/fetcher.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.ChainRegistryFetcher = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
var _utils = require("@chain-registry/utils");
|
|
14
|
-
var _bfsPath = require("bfs-path");
|
|
15
|
-
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
16
|
-
var _chainInfo = require("./chain-info");
|
|
17
|
-
var fetchUrl = function fetchUrl(url) {
|
|
18
|
-
return (0, _crossFetch["default"])(url).then(function (res) {
|
|
19
|
-
if (res.status >= 400) {
|
|
20
|
-
throw new Error('Bad response');
|
|
21
|
-
}
|
|
22
|
-
return res.json();
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
// QUESTION: should ChainRegistryFetcher just be ChainRegistry?
|
|
26
|
-
var ChainRegistryFetcher = exports.ChainRegistryFetcher = /*#__PURE__*/function () {
|
|
27
|
-
function ChainRegistryFetcher() {
|
|
28
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
29
|
-
(0, _classCallCheck2["default"])(this, ChainRegistryFetcher);
|
|
30
|
-
(0, _defineProperty2["default"])(this, "urls", []);
|
|
31
|
-
(0, _defineProperty2["default"])(this, "_assetLists", []);
|
|
32
|
-
(0, _defineProperty2["default"])(this, "_chains", []);
|
|
33
|
-
(0, _defineProperty2["default"])(this, "_ibcData", []);
|
|
34
|
-
(0, _defineProperty2["default"])(this, "chainInfoList", []);
|
|
35
|
-
//
|
|
36
|
-
if (options.chains) {
|
|
37
|
-
this._chains = options.chains;
|
|
38
|
-
}
|
|
39
|
-
if (options.assetLists) {
|
|
40
|
-
this._assetLists = options.assetLists;
|
|
41
|
-
}
|
|
42
|
-
if (options.ibcData) {
|
|
43
|
-
this._ibcData = options.ibcData;
|
|
44
|
-
}
|
|
45
|
-
if (options.urls) {
|
|
46
|
-
this.urls = options.urls;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
(0, _createClass2["default"])(ChainRegistryFetcher, [{
|
|
50
|
-
key: "chains",
|
|
51
|
-
get: function get() {
|
|
52
|
-
return this._chains;
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
key: "assetLists",
|
|
56
|
-
get: function get() {
|
|
57
|
-
return this._assetLists;
|
|
58
|
-
}
|
|
59
|
-
}, {
|
|
60
|
-
key: "ibcData",
|
|
61
|
-
get: function get() {
|
|
62
|
-
return this._ibcData;
|
|
63
|
-
}
|
|
64
|
-
}, {
|
|
65
|
-
key: "getChain",
|
|
66
|
-
value: function getChain(chainName) {
|
|
67
|
-
return this._chains.find(function (chain) {
|
|
68
|
-
return chain.chain_name === chainName;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: "getChainAssetList",
|
|
73
|
-
value: function getChainAssetList(chainName) {
|
|
74
|
-
return this._assetLists.find(function (list) {
|
|
75
|
-
return list.chain_name === chainName;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}, {
|
|
79
|
-
key: "getGeneratedAssetLists",
|
|
80
|
-
value: function getGeneratedAssetLists(chainName) {
|
|
81
|
-
return (0, _utils.getAssetLists)(chainName, this._ibcData, this._assetLists);
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: "getChainIbcData",
|
|
85
|
-
value: function getChainIbcData(chainName) {
|
|
86
|
-
return this._ibcData.filter(function (info) {
|
|
87
|
-
return info.chain_1.chain_name === chainName || info.chain_2.chain_name === chainName;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}, {
|
|
91
|
-
key: "getChainInfo",
|
|
92
|
-
value: function getChainInfo(chainName) {
|
|
93
|
-
var chainInfo = this.chainInfoList.find(function (it) {
|
|
94
|
-
return it.chainName === chainName;
|
|
95
|
-
});
|
|
96
|
-
if (!chainInfo) {
|
|
97
|
-
chainInfo = new _chainInfo.ChainInfo({
|
|
98
|
-
chainName: chainName,
|
|
99
|
-
fetcher: this
|
|
100
|
-
});
|
|
101
|
-
this.chainInfoList.push(chainInfo);
|
|
102
|
-
}
|
|
103
|
-
return chainInfo;
|
|
104
|
-
}
|
|
105
|
-
}, {
|
|
106
|
-
key: "upsertChain",
|
|
107
|
-
value: function upsertChain(data) {
|
|
108
|
-
var found = this._chains.find(function (chain) {
|
|
109
|
-
return chain.chain_name === data.chain_name && chain.network_type === data.network_type;
|
|
110
|
-
});
|
|
111
|
-
if (!found) {
|
|
112
|
-
this._chains.push(data);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
this._chains = this._chains.map(function (chain) {
|
|
116
|
-
if (chain.chain_name === data.chain_name && chain.network_type === data.network_type) {
|
|
117
|
-
return data;
|
|
118
|
-
} else {
|
|
119
|
-
return chain;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
key: "updateAssetList",
|
|
125
|
-
value: function updateAssetList(data) {
|
|
126
|
-
var found = this._assetLists.find(function (list) {
|
|
127
|
-
return list.chain_name === data.chain_name;
|
|
128
|
-
});
|
|
129
|
-
if (!found) {
|
|
130
|
-
this._assetLists.push(data);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
this._assetLists = this._assetLists.map(function (list) {
|
|
134
|
-
if (list.chain_name === data.chain_name) {
|
|
135
|
-
return data;
|
|
136
|
-
} else {
|
|
137
|
-
return list;
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "upsertIbcData",
|
|
143
|
-
value: function upsertIbcData(data) {
|
|
144
|
-
var found = this._ibcData.find(function (info) {
|
|
145
|
-
return info.chain_1.chain_name === data.chain_1.chain_name && info.chain_2.chain_name === data.chain_2.chain_name;
|
|
146
|
-
});
|
|
147
|
-
if (!found) {
|
|
148
|
-
this._ibcData.push(data);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
this._ibcData = this._ibcData.map(function (info) {
|
|
152
|
-
if (info.chain_1.chain_name === data.chain_1.chain_name && info.chain_2.chain_name === data.chain_2.chain_name) {
|
|
153
|
-
return data;
|
|
154
|
-
} else {
|
|
155
|
-
return info;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}, {
|
|
160
|
-
key: "update",
|
|
161
|
-
value: function update(data) {
|
|
162
|
-
if (!data.$schema) throw new Error('not a registered JSON schema type');
|
|
163
|
-
var type = (0, _bfsPath.basename)(data.$schema, '.schema.json');
|
|
164
|
-
switch (type) {
|
|
165
|
-
case 'chain':
|
|
166
|
-
this.upsertChain(data);
|
|
167
|
-
break;
|
|
168
|
-
case 'assetlist':
|
|
169
|
-
this.updateAssetList(data);
|
|
170
|
-
break;
|
|
171
|
-
case 'ibc_data':
|
|
172
|
-
this.upsertIbcData(data);
|
|
173
|
-
break;
|
|
174
|
-
default:
|
|
175
|
-
throw new Error('unknown schema type');
|
|
176
|
-
}
|
|
177
|
-
this.chainInfoList.forEach(function (chainInfo) {
|
|
178
|
-
chainInfo.refresh();
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}, {
|
|
182
|
-
key: "fetch",
|
|
183
|
-
value: function () {
|
|
184
|
-
var _fetch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(url) {
|
|
185
|
-
var data;
|
|
186
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
187
|
-
while (1) switch (_context.prev = _context.next) {
|
|
188
|
-
case 0:
|
|
189
|
-
_context.next = 2;
|
|
190
|
-
return fetchUrl(url);
|
|
191
|
-
case 2:
|
|
192
|
-
data = _context.sent;
|
|
193
|
-
this.update(data);
|
|
194
|
-
case 4:
|
|
195
|
-
case "end":
|
|
196
|
-
return _context.stop();
|
|
197
|
-
}
|
|
198
|
-
}, _callee, this);
|
|
199
|
-
}));
|
|
200
|
-
function fetch(_x) {
|
|
201
|
-
return _fetch.apply(this, arguments);
|
|
202
|
-
}
|
|
203
|
-
return fetch;
|
|
204
|
-
}()
|
|
205
|
-
}, {
|
|
206
|
-
key: "fetchUrls",
|
|
207
|
-
value: function () {
|
|
208
|
-
var _fetchUrls = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
209
|
-
var _this = this;
|
|
210
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
211
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
212
|
-
case 0:
|
|
213
|
-
return _context2.abrupt("return", Promise.all(this.urls.map(function (url) {
|
|
214
|
-
return _this.fetch(url);
|
|
215
|
-
})));
|
|
216
|
-
case 1:
|
|
217
|
-
case "end":
|
|
218
|
-
return _context2.stop();
|
|
219
|
-
}
|
|
220
|
-
}, _callee2, this);
|
|
221
|
-
}));
|
|
222
|
-
function fetchUrls() {
|
|
223
|
-
return _fetchUrls.apply(this, arguments);
|
|
224
|
-
}
|
|
225
|
-
return fetchUrls;
|
|
226
|
-
}()
|
|
227
|
-
}]);
|
|
228
|
-
return ChainRegistryFetcher;
|
|
229
|
-
}();
|