@chain-registry/client 1.20.0 → 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +168 -0
- package/main/chain-info.js +57 -0
- package/main/{utils.js → chain-util.js} +15 -12
- package/main/fetcher.js +229 -0
- package/main/index.js +30 -8
- package/main/registry.js +88 -0
- package/package.json +4 -4
- package/types/chain-info.d.ts +19 -0
- package/types/{utils.d.ts → chain-util.d.ts} +7 -7
- package/types/fetcher.d.ts +30 -0
- package/types/index.d.ts +4 -2
- package/types/registry.d.ts +14 -0
- package/main/client.js +0 -277
- package/types/client.d.ts +0 -43
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
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.21.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.21.0...@chain-registry/client@1.21.1) (2024-03-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **client:** clear mock after tests ([c6dc7f3](https://github.com/cosmology-tech/chain-registry/commit/c6dc7f32e7fad26312ca93343bb9d1a166a3665f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [1.21.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.20.1...@chain-registry/client@1.21.0) (2024-03-20)
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- revert client package ([2534ca7](https://github.com/cosmology-tech/chain-registry/commit/2534ca747f0559bceca0a1bfa455a5c6e7e78ee7))
|
|
22
|
+
|
|
23
|
+
## 1.20.1 (2024-03-20)
|
|
24
|
+
|
|
25
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
26
|
+
|
|
27
|
+
# [1.20.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/client@1.19.2...@chain-registry/client@1.20.0) (2024-03-19)
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
- clear nock after tests ([cecb348](https://github.com/cosmology-tech/chain-registry/commit/cecb3489733e8d46d6ac604c6296694f48634fdf))
|
|
32
|
+
- increase fetch timeout ([4b81273](https://github.com/cosmology-tech/chain-registry/commit/4b8127380cc23e550b6ae7bc4b2961f9d7c9db8f))
|
|
33
|
+
- tests ([6d38a34](https://github.com/cosmology-tech/chain-registry/commit/6d38a342add4d101ca8f770c42c0f5de36eedc99))
|
|
34
|
+
- update utils to new client ([6712608](https://github.com/cosmology-tech/chain-registry/commit/671260861b20b1236d327ae6a01652531a0eb5d9))
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
- update ChainRegistryClient class ([a377f83](https://github.com/cosmology-tech/chain-registry/commit/a377f836eb5e57b0a58d1fb93d359f1befff8d93))
|
|
39
|
+
- update client tests ([0c829f5](https://github.com/cosmology-tech/chain-registry/commit/0c829f52322d30345508245cfab202bce6eeaaa9))
|
|
40
|
+
- update types ([78070ca](https://github.com/cosmology-tech/chain-registry/commit/78070ca382706ca59caf00dafc7a9c7856c8f447))
|
|
41
|
+
|
|
42
|
+
## [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)
|
|
43
|
+
|
|
44
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
45
|
+
|
|
46
|
+
## [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)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
49
|
+
|
|
50
|
+
# [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)
|
|
51
|
+
|
|
52
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
53
|
+
|
|
54
|
+
## [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)
|
|
55
|
+
|
|
56
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
57
|
+
|
|
58
|
+
## [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)
|
|
59
|
+
|
|
60
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
61
|
+
|
|
62
|
+
## [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)
|
|
63
|
+
|
|
64
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
65
|
+
|
|
66
|
+
## [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)
|
|
67
|
+
|
|
68
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
69
|
+
|
|
70
|
+
# [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)
|
|
71
|
+
|
|
72
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
73
|
+
|
|
74
|
+
## [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)
|
|
75
|
+
|
|
76
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
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
|
+
# [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)
|
|
83
|
+
|
|
84
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
85
|
+
|
|
86
|
+
# [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)
|
|
87
|
+
|
|
88
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
89
|
+
|
|
90
|
+
## [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)
|
|
91
|
+
|
|
92
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
93
|
+
|
|
94
|
+
## [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)
|
|
95
|
+
|
|
96
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
97
|
+
|
|
98
|
+
# [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)
|
|
99
|
+
|
|
100
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
101
|
+
|
|
102
|
+
# [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)
|
|
103
|
+
|
|
104
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
105
|
+
|
|
106
|
+
# [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)
|
|
107
|
+
|
|
108
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
109
|
+
|
|
110
|
+
# [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)
|
|
111
|
+
|
|
112
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
113
|
+
|
|
114
|
+
## [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)
|
|
115
|
+
|
|
116
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
117
|
+
|
|
118
|
+
# [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)
|
|
119
|
+
|
|
120
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
121
|
+
|
|
122
|
+
# [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)
|
|
123
|
+
|
|
124
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
125
|
+
|
|
126
|
+
# [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)
|
|
127
|
+
|
|
128
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
129
|
+
|
|
130
|
+
# [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)
|
|
131
|
+
|
|
132
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
133
|
+
|
|
134
|
+
# [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)
|
|
135
|
+
|
|
136
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
137
|
+
|
|
138
|
+
# [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)
|
|
139
|
+
|
|
140
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
141
|
+
|
|
142
|
+
## [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)
|
|
143
|
+
|
|
144
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
145
|
+
|
|
146
|
+
# [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)
|
|
147
|
+
|
|
148
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
149
|
+
|
|
150
|
+
# [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)
|
|
151
|
+
|
|
152
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
153
|
+
|
|
154
|
+
## [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)
|
|
155
|
+
|
|
156
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
157
|
+
|
|
158
|
+
# [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)
|
|
159
|
+
|
|
160
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
161
|
+
|
|
162
|
+
# [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)
|
|
163
|
+
|
|
164
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
165
|
+
|
|
166
|
+
## 1.0.1 (2022-10-20)
|
|
167
|
+
|
|
168
|
+
**Note:** Version bump only for package @chain-registry/client
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
}();
|
|
@@ -4,25 +4,29 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.ChainRegistryChainUtil = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
12
|
var _utils = require("@chain-registry/utils");
|
|
13
|
-
var
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
(0, _classCallCheck2["default"])(this, ChainRegistryUtils);
|
|
17
|
-
(0, _defineProperty2["default"])(this, "_chainName", void 0);
|
|
13
|
+
var ChainRegistryChainUtil = exports.ChainRegistryChainUtil = /*#__PURE__*/function () {
|
|
14
|
+
function ChainRegistryChainUtil(options) {
|
|
15
|
+
(0, _classCallCheck2["default"])(this, ChainRegistryChainUtil);
|
|
18
16
|
(0, _defineProperty2["default"])(this, "_assets", []);
|
|
17
|
+
(0, _defineProperty2["default"])(this, "_chainName", void 0);
|
|
18
|
+
var chainName = options.chainName,
|
|
19
|
+
chainInfo = options.chainInfo;
|
|
19
20
|
this._chainName = options.chainName;
|
|
20
21
|
this._assets = [{
|
|
21
|
-
assets: [].concat((0, _toConsumableArray2["default"])(
|
|
22
|
-
|
|
22
|
+
assets: [].concat((0, _toConsumableArray2["default"])(chainInfo.nativeAssetList.assets), (0, _toConsumableArray2["default"])(chainInfo.assetLists.flatMap(function (_ref) {
|
|
23
|
+
var assets = _ref.assets;
|
|
24
|
+
return assets;
|
|
25
|
+
}))),
|
|
26
|
+
chain_name: chainName
|
|
23
27
|
}];
|
|
24
28
|
}
|
|
25
|
-
(0, _createClass2["default"])(
|
|
29
|
+
(0, _createClass2["default"])(ChainRegistryChainUtil, [{
|
|
26
30
|
key: "getAssetByDenom",
|
|
27
31
|
value: function getAssetByDenom(denom) {
|
|
28
32
|
return (0, _utils.getAssetByDenom)(this._assets, denom, this._chainName);
|
|
@@ -105,6 +109,5 @@ var ChainRegistryUtils = /*#__PURE__*/function () {
|
|
|
105
109
|
return (0, _utils.convertDisplayUnitToBaseUnit)(this._assets, symbol, amount, this._chainName);
|
|
106
110
|
}
|
|
107
111
|
}]);
|
|
108
|
-
return
|
|
109
|
-
}();
|
|
110
|
-
exports.ChainRegistryUtils = ChainRegistryUtils;
|
|
112
|
+
return ChainRegistryChainUtil;
|
|
113
|
+
}();
|
package/main/fetcher.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
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
|
+
}();
|
package/main/index.js
CHANGED
|
@@ -3,25 +3,47 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var
|
|
7
|
-
Object.keys(
|
|
6
|
+
var _chainInfo = require("./chain-info");
|
|
7
|
+
Object.keys(_chainInfo).forEach(function (key) {
|
|
8
8
|
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] ===
|
|
9
|
+
if (key in exports && exports[key] === _chainInfo[key]) return;
|
|
10
10
|
Object.defineProperty(exports, key, {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
get: function get() {
|
|
13
|
-
return
|
|
13
|
+
return _chainInfo[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
|
-
var
|
|
18
|
-
Object.keys(
|
|
17
|
+
var _chainUtil = require("./chain-util");
|
|
18
|
+
Object.keys(_chainUtil).forEach(function (key) {
|
|
19
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] ===
|
|
20
|
+
if (key in exports && exports[key] === _chainUtil[key]) return;
|
|
21
21
|
Object.defineProperty(exports, key, {
|
|
22
22
|
enumerable: true,
|
|
23
23
|
get: function get() {
|
|
24
|
-
return
|
|
24
|
+
return _chainUtil[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _fetcher = require("./fetcher");
|
|
29
|
+
Object.keys(_fetcher).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _fetcher[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _fetcher[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _registry = require("./registry");
|
|
40
|
+
Object.keys(_registry).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _registry[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _registry[key];
|
|
25
47
|
}
|
|
26
48
|
});
|
|
27
49
|
});
|
package/main/registry.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ChainRegistryClient = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
var _chainUtil = require("./chain-util");
|
|
18
|
+
var _fetcher = require("./fetcher");
|
|
19
|
+
var _excluded = ["chainNames", "assetListNames", "ibcNamePairs", "baseUrl"];
|
|
20
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
23
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
24
|
+
var ChainRegistryClient = exports.ChainRegistryClient = /*#__PURE__*/function (_ChainRegistryFetcher) {
|
|
25
|
+
(0, _inherits2["default"])(ChainRegistryClient, _ChainRegistryFetcher);
|
|
26
|
+
function ChainRegistryClient(options) {
|
|
27
|
+
var _this;
|
|
28
|
+
(0, _classCallCheck2["default"])(this, ChainRegistryClient);
|
|
29
|
+
var chainNames = options.chainNames,
|
|
30
|
+
assetListNames = options.assetListNames,
|
|
31
|
+
ibcNamePairs = options.ibcNamePairs,
|
|
32
|
+
baseUrl = options.baseUrl,
|
|
33
|
+
restOptions = (0, _objectWithoutProperties2["default"])(options, _excluded);
|
|
34
|
+
_this = _callSuper(this, ChainRegistryClient, [restOptions]);
|
|
35
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_options", {
|
|
36
|
+
chainNames: [],
|
|
37
|
+
baseUrl: 'https://raw.githubusercontent.com/cosmos/chain-registry/master'
|
|
38
|
+
});
|
|
39
|
+
_this._options = _objectSpread(_objectSpread({}, _this._options), {}, {
|
|
40
|
+
chainNames: chainNames || _this._options.chainNames,
|
|
41
|
+
assetListNames: assetListNames || _this._options.assetListNames,
|
|
42
|
+
ibcNamePairs: ibcNamePairs || _this._options.ibcNamePairs,
|
|
43
|
+
baseUrl: baseUrl || _this._options.baseUrl
|
|
44
|
+
});
|
|
45
|
+
_this.generateUrls();
|
|
46
|
+
return _this;
|
|
47
|
+
}
|
|
48
|
+
(0, _createClass2["default"])(ChainRegistryClient, [{
|
|
49
|
+
key: "generateUrls",
|
|
50
|
+
value: function generateUrls() {
|
|
51
|
+
var _this$_options = this._options,
|
|
52
|
+
chainNames = _this$_options.chainNames,
|
|
53
|
+
assetListNames = _this$_options.assetListNames,
|
|
54
|
+
ibcNamePairs = _this$_options.ibcNamePairs,
|
|
55
|
+
baseUrl = _this$_options.baseUrl;
|
|
56
|
+
var chainUrls = chainNames.map(function (chain) {
|
|
57
|
+
return "".concat(baseUrl, "/").concat(chain, "/chain.json");
|
|
58
|
+
});
|
|
59
|
+
var assetlistUrls = (assetListNames || chainNames).map(function (chain) {
|
|
60
|
+
return "".concat(baseUrl, "/").concat(chain, "/assetlist.json");
|
|
61
|
+
});
|
|
62
|
+
var namePairs = ibcNamePairs;
|
|
63
|
+
if (!namePairs) {
|
|
64
|
+
namePairs = [];
|
|
65
|
+
for (var i = 0; i < chainNames.length; i++) {
|
|
66
|
+
for (var j = i + 1; j < chainNames.length; j++) {
|
|
67
|
+
namePairs.push([chainNames[i], chainNames[j]]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
var ibcUrls = namePairs.map(function (namePair) {
|
|
72
|
+
var fileName = namePair[0].localeCompare(namePair[1]) <= 0 ? "".concat(namePair[0], "-").concat(namePair[1], ".json") : "".concat(namePair[1], "-").concat(namePair[0], ".json");
|
|
73
|
+
return "".concat(baseUrl, "/_IBC/").concat(fileName);
|
|
74
|
+
});
|
|
75
|
+
this.urls = (0, _toConsumableArray2["default"])(new Set([].concat((0, _toConsumableArray2["default"])(chainUrls), (0, _toConsumableArray2["default"])(assetlistUrls), (0, _toConsumableArray2["default"])(ibcUrls), (0, _toConsumableArray2["default"])(this.urls || []))));
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "getChainUtil",
|
|
79
|
+
value: function getChainUtil(chainName) {
|
|
80
|
+
var chainInfo = this.getChainInfo(chainName);
|
|
81
|
+
return new _chainUtil.ChainRegistryChainUtil({
|
|
82
|
+
chainName: chainName,
|
|
83
|
+
chainInfo: chainInfo
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}]);
|
|
87
|
+
return ChainRegistryClient;
|
|
88
|
+
}(_fetcher.ChainRegistryFetcher);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chain-registry/client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
4
4
|
"description": "Chain Registry Client",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/cosmology-tech/chain-registry",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@babel/runtime": "^7.21.0",
|
|
78
|
-
"@chain-registry/types": "^0.18.
|
|
79
|
-
"@chain-registry/utils": "^1.19.
|
|
78
|
+
"@chain-registry/types": "^0.18.3",
|
|
79
|
+
"@chain-registry/utils": "^1.19.2",
|
|
80
80
|
"bfs-path": "^1.0.2",
|
|
81
81
|
"cross-fetch": "^3.1.5"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "3da58f4178fd61379a8358fca13f9d53f85d25cc"
|
|
84
84
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AssetList, Chain, IBCInfo } from '@chain-registry/types';
|
|
2
|
+
import { ChainRegistryFetcher } from './fetcher';
|
|
3
|
+
export interface ChainInfoOptions {
|
|
4
|
+
chainName: string;
|
|
5
|
+
fetcher: ChainRegistryFetcher;
|
|
6
|
+
}
|
|
7
|
+
export declare class ChainInfo {
|
|
8
|
+
chainName: string;
|
|
9
|
+
fetcher: ChainRegistryFetcher;
|
|
10
|
+
protected _chain: Chain;
|
|
11
|
+
protected _assetList: AssetList;
|
|
12
|
+
protected _assetLists: AssetList[];
|
|
13
|
+
protected _ibcData: IBCInfo[];
|
|
14
|
+
constructor(options: ChainInfoOptions);
|
|
15
|
+
refresh(): void;
|
|
16
|
+
get chain(): Chain;
|
|
17
|
+
get nativeAssetList(): AssetList;
|
|
18
|
+
get assetLists(): any[];
|
|
19
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Asset
|
|
1
|
+
import { Asset } from '@chain-registry/types';
|
|
2
2
|
import type { Denom, Exponent, DenomPriceMap, CoinGeckoUSDPrice } from '@chain-registry/utils';
|
|
3
|
-
|
|
3
|
+
import { ChainInfo } from './chain-info';
|
|
4
|
+
export interface ChainRegistryChainUtilOptions {
|
|
4
5
|
chainName: string;
|
|
5
|
-
|
|
6
|
-
ibcAssetList?: AssetList;
|
|
6
|
+
chainInfo: ChainInfo;
|
|
7
7
|
}
|
|
8
|
-
export declare class
|
|
9
|
-
private _chainName;
|
|
8
|
+
export declare class ChainRegistryChainUtil {
|
|
10
9
|
private _assets;
|
|
11
|
-
|
|
10
|
+
private _chainName;
|
|
11
|
+
constructor(options: ChainRegistryChainUtilOptions);
|
|
12
12
|
getAssetByDenom(denom: Denom): Asset | undefined;
|
|
13
13
|
getAssetBySymbol(symbol: string): Asset | undefined;
|
|
14
14
|
getDenomByCoinGeckoId(coinGeckoId: string): Denom | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AssetList, Chain, ChainRegistry, IBCInfo } from '@chain-registry/types';
|
|
2
|
+
import { ChainInfo } from './chain-info';
|
|
3
|
+
export interface ChainRegistryFetcherOptions {
|
|
4
|
+
assetLists?: AssetList[];
|
|
5
|
+
chains?: Chain[];
|
|
6
|
+
ibcData?: IBCInfo[];
|
|
7
|
+
urls?: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare class ChainRegistryFetcher implements ChainRegistry {
|
|
10
|
+
urls: string[];
|
|
11
|
+
protected _assetLists: AssetList[];
|
|
12
|
+
protected _chains: Chain[];
|
|
13
|
+
protected _ibcData: IBCInfo[];
|
|
14
|
+
private chainInfoList;
|
|
15
|
+
constructor(options?: ChainRegistryFetcherOptions);
|
|
16
|
+
get chains(): Chain[];
|
|
17
|
+
get assetLists(): AssetList[];
|
|
18
|
+
get ibcData(): IBCInfo[];
|
|
19
|
+
getChain(chainName: string): Chain;
|
|
20
|
+
getChainAssetList(chainName: string): AssetList;
|
|
21
|
+
getGeneratedAssetLists(chainName: string): AssetList[];
|
|
22
|
+
getChainIbcData(chainName: string): IBCInfo[];
|
|
23
|
+
getChainInfo(chainName: string): ChainInfo;
|
|
24
|
+
upsertChain(data: Chain): void;
|
|
25
|
+
updateAssetList(data: AssetList): void;
|
|
26
|
+
upsertIbcData(data: IBCInfo): void;
|
|
27
|
+
update(data: Chain | AssetList | IBCInfo): void;
|
|
28
|
+
fetch(url: any): Promise<void>;
|
|
29
|
+
fetchUrls(): Promise<void[]>;
|
|
30
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChainRegistryChainUtil } from './chain-util';
|
|
2
|
+
import { ChainRegistryFetcher, ChainRegistryFetcherOptions } from './fetcher';
|
|
3
|
+
export interface ChainRegistryClientOptions extends ChainRegistryFetcherOptions {
|
|
4
|
+
chainNames: string[];
|
|
5
|
+
assetListNames?: string[];
|
|
6
|
+
ibcNamePairs?: string[][];
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class ChainRegistryClient extends ChainRegistryFetcher {
|
|
10
|
+
protected _options: ChainRegistryClientOptions;
|
|
11
|
+
constructor(options: ChainRegistryClientOptions);
|
|
12
|
+
generateUrls(): void;
|
|
13
|
+
getChainUtil(chainName: string): ChainRegistryChainUtil;
|
|
14
|
+
}
|
package/main/client.js
DELETED
|
@@ -1,277 +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.ChainRegistryClient = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
15
|
-
var _bfsPath = require("bfs-path");
|
|
16
|
-
var _utils = require("@chain-registry/utils");
|
|
17
|
-
var _utils2 = require("./utils");
|
|
18
|
-
var DEFAULT_BASE_URL = 'https://raw.githubusercontent.com/cosmos/chain-registry/master';
|
|
19
|
-
var ChainRegistryClient = /*#__PURE__*/function () {
|
|
20
|
-
function ChainRegistryClient() {
|
|
21
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22
|
-
(0, _classCallCheck2["default"])(this, ChainRegistryClient);
|
|
23
|
-
(0, _defineProperty2["default"])(this, "_allUrls", []);
|
|
24
|
-
(0, _defineProperty2["default"])(this, "_baseUrl", DEFAULT_BASE_URL);
|
|
25
|
-
(0, _defineProperty2["default"])(this, "_chainNames", []);
|
|
26
|
-
(0, _defineProperty2["default"])(this, "_notFoundUrls", []);
|
|
27
|
-
(0, _defineProperty2["default"])(this, "_chains", []);
|
|
28
|
-
(0, _defineProperty2["default"])(this, "_assetLists", []);
|
|
29
|
-
(0, _defineProperty2["default"])(this, "_ibcInfo", []);
|
|
30
|
-
var urls = options.urls,
|
|
31
|
-
chainNames = options.chainNames,
|
|
32
|
-
baseUrl = options.baseUrl;
|
|
33
|
-
this._baseUrl = baseUrl !== null && baseUrl !== void 0 ? baseUrl : this._baseUrl;
|
|
34
|
-
this._allUrls = this.generateUrls({
|
|
35
|
-
urls: urls,
|
|
36
|
-
chainNames: chainNames
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
(0, _createClass2["default"])(ChainRegistryClient, [{
|
|
40
|
-
key: "urls",
|
|
41
|
-
get: function get() {
|
|
42
|
-
return this._allUrls;
|
|
43
|
-
}
|
|
44
|
-
}, {
|
|
45
|
-
key: "chains",
|
|
46
|
-
get: function get() {
|
|
47
|
-
return this._chains;
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
key: "assetLists",
|
|
51
|
-
get: function get() {
|
|
52
|
-
return this._assetLists;
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
key: "ibcInfo",
|
|
56
|
-
get: function get() {
|
|
57
|
-
return this._ibcInfo;
|
|
58
|
-
}
|
|
59
|
-
}, {
|
|
60
|
-
key: "getChain",
|
|
61
|
-
value: function getChain(chainName) {
|
|
62
|
-
return this._chains.find(function (_ref) {
|
|
63
|
-
var chain_name = _ref.chain_name;
|
|
64
|
-
return chain_name === chainName;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "getChainAssetList",
|
|
69
|
-
value: function getChainAssetList(chainName) {
|
|
70
|
-
return this._assetLists.find(function (_ref2) {
|
|
71
|
-
var chain_name = _ref2.chain_name;
|
|
72
|
-
return chain_name === chainName;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
key: "getChainIbcInfo",
|
|
77
|
-
value: function getChainIbcInfo(chainName) {
|
|
78
|
-
return this._ibcInfo.filter(function (info) {
|
|
79
|
-
return info.chain_1.chain_name === chainName || info.chain_2.chain_name === chainName;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}, {
|
|
83
|
-
key: "getChainIbcAssetList",
|
|
84
|
-
value: function getChainIbcAssetList(chainName) {
|
|
85
|
-
return (0, _utils.getAssetLists)(chainName, this._ibcInfo, this._assetLists)[0];
|
|
86
|
-
}
|
|
87
|
-
}, {
|
|
88
|
-
key: "getChainFullData",
|
|
89
|
-
value: function getChainFullData(chainName) {
|
|
90
|
-
return {
|
|
91
|
-
chain: this.getChain(chainName),
|
|
92
|
-
assetList: this.getChainAssetList(chainName),
|
|
93
|
-
ibcInfo: this.getChainIbcInfo(chainName),
|
|
94
|
-
ibcAssetList: this.getChainIbcAssetList(chainName)
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: "getChainUtils",
|
|
99
|
-
value: function getChainUtils(chainName) {
|
|
100
|
-
return new _utils2.ChainRegistryUtils({
|
|
101
|
-
chainName: chainName,
|
|
102
|
-
assetList: this.getChainAssetList(chainName),
|
|
103
|
-
ibcAssetList: this.getChainIbcAssetList(chainName)
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}, {
|
|
107
|
-
key: "fetch",
|
|
108
|
-
value: function () {
|
|
109
|
-
var _fetch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
110
|
-
var _this = this;
|
|
111
|
-
var options,
|
|
112
|
-
urls,
|
|
113
|
-
newUrls,
|
|
114
|
-
responses,
|
|
115
|
-
_args = arguments;
|
|
116
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
117
|
-
while (1) switch (_context.prev = _context.next) {
|
|
118
|
-
case 0:
|
|
119
|
-
options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
120
|
-
urls = [];
|
|
121
|
-
if (Object.keys(options).length === 0) {
|
|
122
|
-
urls = this._allUrls;
|
|
123
|
-
} else {
|
|
124
|
-
newUrls = this.generateUrls(options);
|
|
125
|
-
urls = newUrls;
|
|
126
|
-
this._allUrls = (0, _toConsumableArray2["default"])(new Set([].concat((0, _toConsumableArray2["default"])(this._allUrls), (0, _toConsumableArray2["default"])(newUrls))));
|
|
127
|
-
}
|
|
128
|
-
_context.next = 5;
|
|
129
|
-
return Promise.all(urls.map(function (url) {
|
|
130
|
-
return _this.fetchUrl(url);
|
|
131
|
-
}));
|
|
132
|
-
case 5:
|
|
133
|
-
responses = _context.sent;
|
|
134
|
-
responses.filter(Boolean).forEach(function (data) {
|
|
135
|
-
return _this.save(data);
|
|
136
|
-
});
|
|
137
|
-
case 7:
|
|
138
|
-
case "end":
|
|
139
|
-
return _context.stop();
|
|
140
|
-
}
|
|
141
|
-
}, _callee, this);
|
|
142
|
-
}));
|
|
143
|
-
function fetch() {
|
|
144
|
-
return _fetch.apply(this, arguments);
|
|
145
|
-
}
|
|
146
|
-
return fetch;
|
|
147
|
-
}()
|
|
148
|
-
}, {
|
|
149
|
-
key: "formatChainUrl",
|
|
150
|
-
value: function formatChainUrl(chainName) {
|
|
151
|
-
return "".concat(this._baseUrl, "/").concat(chainName, "/chain.json");
|
|
152
|
-
}
|
|
153
|
-
}, {
|
|
154
|
-
key: "formatAssetListUrl",
|
|
155
|
-
value: function formatAssetListUrl(chainName) {
|
|
156
|
-
return "".concat(this._baseUrl, "/").concat(chainName, "/assetlist.json");
|
|
157
|
-
}
|
|
158
|
-
}, {
|
|
159
|
-
key: "formatIbcUrl",
|
|
160
|
-
value: function formatIbcUrl(chain1, chain2) {
|
|
161
|
-
return "".concat(this._baseUrl, "/_IBC/").concat(chain1, "-").concat(chain2, ".json");
|
|
162
|
-
}
|
|
163
|
-
}, {
|
|
164
|
-
key: "generateNamePairs",
|
|
165
|
-
value: function generateNamePairs(chainNames) {
|
|
166
|
-
var pairs = [];
|
|
167
|
-
for (var i = 0; i < chainNames.length; i++) {
|
|
168
|
-
for (var j = i + 1; j < chainNames.length; j++) {
|
|
169
|
-
pairs.push([chainNames[i], chainNames[j]].sort());
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return pairs;
|
|
173
|
-
}
|
|
174
|
-
}, {
|
|
175
|
-
key: "generateUrls",
|
|
176
|
-
value: function generateUrls(_ref3) {
|
|
177
|
-
var _this2 = this;
|
|
178
|
-
var _ref3$urls = _ref3.urls,
|
|
179
|
-
urls = _ref3$urls === void 0 ? [] : _ref3$urls,
|
|
180
|
-
_ref3$chainNames = _ref3.chainNames,
|
|
181
|
-
chainNames = _ref3$chainNames === void 0 ? [] : _ref3$chainNames;
|
|
182
|
-
var chainUrls = chainNames.map(function (chain) {
|
|
183
|
-
return _this2.formatChainUrl(chain);
|
|
184
|
-
});
|
|
185
|
-
var assetListUrls = chainNames.map(function (chain) {
|
|
186
|
-
return _this2.formatAssetListUrl(chain);
|
|
187
|
-
});
|
|
188
|
-
this._chainNames = (0, _toConsumableArray2["default"])(new Set([].concat((0, _toConsumableArray2["default"])(this._chainNames), (0, _toConsumableArray2["default"])(chainNames))));
|
|
189
|
-
var allPairs = this.generateNamePairs(this._chainNames);
|
|
190
|
-
var newPairs = allPairs.filter(function (pair) {
|
|
191
|
-
return !_this2._ibcInfo.some(function (info) {
|
|
192
|
-
return info.chain_1.chain_name === pair[0] && info.chain_2.chain_name === pair[1];
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
var ibcUrls = newPairs.map(function (pair) {
|
|
196
|
-
return _this2.formatIbcUrl(pair[0], pair[1]);
|
|
197
|
-
});
|
|
198
|
-
var allUrls = (0, _toConsumableArray2["default"])(new Set([].concat((0, _toConsumableArray2["default"])(chainUrls), (0, _toConsumableArray2["default"])(assetListUrls), (0, _toConsumableArray2["default"])(ibcUrls), (0, _toConsumableArray2["default"])(urls))));
|
|
199
|
-
return allUrls.filter(function (url) {
|
|
200
|
-
return !_this2._notFoundUrls.includes(url);
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}, {
|
|
204
|
-
key: "fetchUrl",
|
|
205
|
-
value: function () {
|
|
206
|
-
var _fetchUrl = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(url) {
|
|
207
|
-
var _this3 = this;
|
|
208
|
-
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
209
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
210
|
-
case 0:
|
|
211
|
-
return _context2.abrupt("return", (0, _crossFetch["default"])(url).then(function (res) {
|
|
212
|
-
if (res.status === 404) {
|
|
213
|
-
console.error("Failed to fetch ".concat(url, " with status 404"));
|
|
214
|
-
_this3._notFoundUrls.push(url);
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
if (res.status >= 400) {
|
|
218
|
-
throw new Error("Failed to fetch ".concat(url, " with status ").concat(res.status));
|
|
219
|
-
}
|
|
220
|
-
return res.json();
|
|
221
|
-
}));
|
|
222
|
-
case 1:
|
|
223
|
-
case "end":
|
|
224
|
-
return _context2.stop();
|
|
225
|
-
}
|
|
226
|
-
}, _callee2);
|
|
227
|
-
}));
|
|
228
|
-
function fetchUrl(_x) {
|
|
229
|
-
return _fetchUrl.apply(this, arguments);
|
|
230
|
-
}
|
|
231
|
-
return fetchUrl;
|
|
232
|
-
}()
|
|
233
|
-
}, {
|
|
234
|
-
key: "upsert",
|
|
235
|
-
value: function upsert(array, element, filterFn) {
|
|
236
|
-
var res = array.find(filterFn);
|
|
237
|
-
if (!res) {
|
|
238
|
-
return [].concat((0, _toConsumableArray2["default"])(array), [element]);
|
|
239
|
-
}
|
|
240
|
-
return array.map(function (item) {
|
|
241
|
-
if (filterFn(item)) {
|
|
242
|
-
return element;
|
|
243
|
-
}
|
|
244
|
-
return item;
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}, {
|
|
248
|
-
key: "save",
|
|
249
|
-
value: function save(data) {
|
|
250
|
-
if (!data.$schema) {
|
|
251
|
-
throw new Error('Invalid data: Missing $schema property');
|
|
252
|
-
}
|
|
253
|
-
var type = (0, _bfsPath.basename)(data.$schema, '.schema.json');
|
|
254
|
-
switch (type) {
|
|
255
|
-
case 'chain':
|
|
256
|
-
this._chains = this.upsert(this._chains, data, function (chain) {
|
|
257
|
-
return chain.chain_name === data.chain_name && chain.network_type === data.network_type;
|
|
258
|
-
});
|
|
259
|
-
break;
|
|
260
|
-
case 'assetlist':
|
|
261
|
-
this._assetLists = this.upsert(this._assetLists, data, function (assetList) {
|
|
262
|
-
return assetList.chain_name === data.chain_name;
|
|
263
|
-
});
|
|
264
|
-
break;
|
|
265
|
-
case 'ibc_data':
|
|
266
|
-
this._ibcInfo = this.upsert(this._ibcInfo, data, function (info) {
|
|
267
|
-
return info.chain_1.chain_name === data.chain_1.chain_name && info.chain_2.chain_name === data.chain_2.chain_name;
|
|
268
|
-
});
|
|
269
|
-
break;
|
|
270
|
-
default:
|
|
271
|
-
throw new Error("Unsupported json schema: ".concat(data.$schema));
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}]);
|
|
275
|
-
return ChainRegistryClient;
|
|
276
|
-
}();
|
|
277
|
-
exports.ChainRegistryClient = ChainRegistryClient;
|
package/types/client.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AssetList, Chain, IBCInfo } from '@chain-registry/types';
|
|
2
|
-
import { ChainRegistryUtils } from './utils';
|
|
3
|
-
export interface FetchOptions {
|
|
4
|
-
urls?: string[];
|
|
5
|
-
chainNames?: string[];
|
|
6
|
-
}
|
|
7
|
-
export interface ChainRegistryClientOptions extends FetchOptions {
|
|
8
|
-
baseUrl?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class ChainRegistryClient {
|
|
11
|
-
private _allUrls;
|
|
12
|
-
private _baseUrl;
|
|
13
|
-
private _chainNames;
|
|
14
|
-
private _notFoundUrls;
|
|
15
|
-
private _chains;
|
|
16
|
-
private _assetLists;
|
|
17
|
-
private _ibcInfo;
|
|
18
|
-
constructor(options?: ChainRegistryClientOptions);
|
|
19
|
-
get urls(): string[];
|
|
20
|
-
get chains(): Chain[];
|
|
21
|
-
get assetLists(): AssetList[];
|
|
22
|
-
get ibcInfo(): IBCInfo[];
|
|
23
|
-
getChain(chainName: string): Chain | undefined;
|
|
24
|
-
getChainAssetList(chainName: string): AssetList | undefined;
|
|
25
|
-
getChainIbcInfo(chainName: string): IBCInfo[];
|
|
26
|
-
getChainIbcAssetList(chainName: string): AssetList;
|
|
27
|
-
getChainFullData(chainName: string): {
|
|
28
|
-
chain: Chain;
|
|
29
|
-
assetList: AssetList;
|
|
30
|
-
ibcInfo: IBCInfo[];
|
|
31
|
-
ibcAssetList: AssetList;
|
|
32
|
-
};
|
|
33
|
-
getChainUtils(chainName: string): ChainRegistryUtils;
|
|
34
|
-
fetch(options?: FetchOptions): Promise<void>;
|
|
35
|
-
private formatChainUrl;
|
|
36
|
-
private formatAssetListUrl;
|
|
37
|
-
private formatIbcUrl;
|
|
38
|
-
private generateNamePairs;
|
|
39
|
-
private generateUrls;
|
|
40
|
-
private fetchUrl;
|
|
41
|
-
private upsert;
|
|
42
|
-
private save;
|
|
43
|
-
}
|