@chain-registry/utils 0.11.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.1](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@1.0.0...@chain-registry/utils@1.0.1) (2022-10-20)
7
+
8
+ **Note:** Version bump only for package @chain-registry/utils
9
+
10
+
11
+
12
+
13
+
14
+ # [1.0.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.11.0...@chain-registry/utils@1.0.0) (2022-09-29)
15
+
16
+ **Note:** Version bump only for package @chain-registry/utils
17
+
18
+
19
+
20
+
21
+
6
22
  # [0.11.0](https://github.com/cosmology-tech/chain-registry/compare/@chain-registry/utils@0.10.2...@chain-registry/utils@0.11.0) (2022-09-20)
7
23
 
8
24
  **Note:** Version bump only for package @chain-registry/utils
package/README.md CHANGED
@@ -13,90 +13,6 @@
13
13
  </p>
14
14
 
15
15
  Utility functions for the chain-registry
16
-
17
-
18
- ## Usage
19
-
20
- ```js
21
- import { ChainRegistryFetcher, ChainRegistryFetcherOptions } from '@chain-registry/utils';
22
-
23
- const options: ChainRegistryFetcherOptions = {
24
- urls: [
25
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/chain.json',
26
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/assetlist.json',
27
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/assetlist.json',
28
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/secretnetwork/assetlist.json',
29
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/juno-osmosis.json',
30
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/osmosis-secretnetwork.json'
31
- ]
32
- };
33
- const registry = new ChainRegistry(options);
34
- await registry.fetchUrls();
35
- ```
36
-
37
- ## Fetching Schemata
38
-
39
- We currently only support fetching JSON schemas as defined in https://github.com/cosmos/chain-registry. Supported are `assetlist.schema.json`, `chain.schema.json` and `ibc_data.schema.json`.
40
-
41
- ### fetchUrls
42
-
43
- You can set the `ChainRegistry.urls` property and call `ChainRegistry.fetchUrls()`
44
-
45
- ```js
46
- registry.urls = [
47
- // urls to fetch
48
- ];
49
- await registry.fetchUrls();
50
- ```
51
-
52
- ### fetch
53
-
54
- Or, you can simply call `ChainRegistry.fetch()`
55
-
56
- ```js
57
- await registry.fetch('https://some-json-schema.com/some-schema.json');
58
- ```
59
-
60
- ## Asset lists
61
-
62
- You can get generated asset lists directly from the registry:
63
-
64
- ```js
65
- // generated asset lists
66
- const generated: AssetList[] = registry.getGeneratedAssetLists('osmosis');
67
- ```
68
-
69
- You can get generated `AssetList[]` objects directly from the `ChainRegistry` via the `assetLists` method:
70
-
71
- ```js
72
- // you can also get generated assets from ChainInfo object
73
- const chainInfo: Chain = registry.getChainInfo('osmosis');
74
- const generatedAssets: AssetList[] = chainInfo.assetLists;
75
- ```
76
- ## Chain info
77
-
78
- You can get `Chain` object directly from the `ChainRegistry` via the `getChain` method:
79
-
80
- ```js
81
- // get Chain from registry
82
- const chain: Chain = registry.getChain('osmosis');
83
- ```
84
-
85
- or get the `ChainInfo` object:
86
-
87
- ```js
88
- const chainInfo: ChainInfo = registry.getChainInfo('osmosis');
89
-
90
- // AssetList[] of the generated assets
91
- const assetes: AssetList[] = chainInfo.assetLists;
92
-
93
- // Chain
94
- const chain: Chain = chainInfo.chain;
95
-
96
- // AssetList[] of the native assets
97
- const assetes: AssetList[] = chainInfo.nativeAssetLists;
98
- ```
99
-
100
16
  ## Credits
101
17
 
102
18
  🛠 Built by Cosmology — if you like our tools, please consider delegating to [our validator ⚛️](https://cosmology.tech/validator)
package/main/utils.js CHANGED
@@ -5,11 +5,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.ibcDenom = exports.getWasmChannel = exports.getTransferChannel = exports.getNonTransferChannel = exports.getIbcInfo = exports.getIbcDenomByBaseForCw20 = exports.getIbcDenomByBase = exports.getIbcAssets = exports.getCw20Assets = exports.getAssetLists = void 0;
8
+ exports.ibcDenom = exports.getWasmChannel = exports.getTransferChannel = exports.getNonTransferChannel = exports.getIbcInfo = exports.getIbcDenomByBase = exports.getIbcAssets = exports.getIbcAssetPath = exports.getCw20Assets = exports.getAssetLists = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
11
 
10
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
13
 
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
15
 
14
16
  var _sha = require("sha.js");
15
17
 
@@ -32,7 +34,7 @@ var ibcDenom = function ibcDenom(paths, coinMinimalDenom) {
32
34
  try {
33
35
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
34
36
  var path = _step.value;
35
- prefixes.push("".concat(path.portId, "/").concat(path.channelId));
37
+ prefixes.push("".concat(path.port_id, "/").concat(path.channel_id));
36
38
  }
37
39
  } catch (err) {
38
40
  _iterator.e(err);
@@ -83,105 +85,111 @@ var getWasmChannel = function getWasmChannel(info) {
83
85
 
84
86
  exports.getWasmChannel = getWasmChannel;
85
87
 
86
- var getIbcDenomByBase = function getIbcDenomByBase(ibc, chain, counterparty, assets, base) {
88
+ var getIbcAssetPath = function getIbcAssetPath(ibc, chain, counterparty, assets, base) {
89
+ var _asset$traces$filter, _asset$traces, _asset$traces$filter2;
90
+
87
91
  var ibcInfo = getIbcInfo(ibc, chain, counterparty);
88
92
 
89
- if (ibcInfo) {
90
- var channel = getTransferChannel(ibcInfo);
93
+ if (!ibcInfo) {
94
+ return [];
95
+ }
91
96
 
92
- if (!channel) {
93
- return;
94
- }
97
+ var channel = base.startsWith('cw20:') ? getWasmChannel(ibcInfo) : getTransferChannel(ibcInfo);
98
+
99
+ if (!channel) {
100
+ return [];
101
+ }
95
102
 
96
- var channelInfo;
103
+ var channelInfo;
97
104
 
98
- if (ibcInfo.chain_1.chain_name === chain) {
99
- channelInfo = channel.chain_1;
100
- } else {
101
- channelInfo = channel.chain_2;
102
- }
105
+ if (ibcInfo.chain_1.chain_name === chain) {
106
+ channelInfo = channel.chain_1;
107
+ } else {
108
+ channelInfo = channel.chain_2;
109
+ }
103
110
 
104
- var assetList = assets.find(function (_ref) {
105
- var chain_name = _ref.chain_name;
106
- return chain_name === counterparty;
107
- });
111
+ var memo = [channelInfo];
112
+ var assetList = assets.find(function (_ref) {
113
+ var chain_name = _ref.chain_name;
114
+ return chain_name === counterparty;
115
+ });
108
116
 
109
- if (!assetList) {
110
- return;
111
- }
117
+ if (!assetList) {
118
+ return memo;
119
+ }
112
120
 
113
- var assetInfo = assetList.assets.find(function (asset) {
114
- return asset.base === base;
115
- }); // if (!assetInfo) {
116
- // console.warn('missing referrenced asset');
117
- // }
118
-
119
- var traces = [];
120
-
121
- if (assetInfo.traces && assetInfo.traces.length) {
122
- [].push.apply(traces, assetInfo.traces);
123
- } // console.log(transition);
124
- // if (transition.length) {
125
- // return ibcDenom(
126
- // [
127
- // {
128
- // portId: 'transfer',
129
- // channelId: assetInfo.ibc.source_channel
130
- // },
131
- // {
132
- // portId: channelInfo.port_id,
133
- // channelId: channelInfo.channel_id
134
- // }
135
- // ],
136
- // base
137
- // );
138
- // }
139
-
140
-
141
- return ibcDenom([{
142
- portId: channelInfo.port_id,
143
- channelId: channelInfo.channel_id
144
- }], base);
121
+ var asset = assetList.assets.find(function (asset) {
122
+ return asset.base === base;
123
+ });
124
+
125
+ if (!asset) {
126
+ console.log("no ".concat(base, " found in ").concat(counterparty));
127
+ return memo;
128
+ }
129
+
130
+ var traces = (_asset$traces$filter = (_asset$traces = asset.traces) === null || _asset$traces === void 0 ? void 0 : (_asset$traces$filter2 = _asset$traces.filter) === null || _asset$traces$filter2 === void 0 ? void 0 : _asset$traces$filter2.call(_asset$traces, function (trace) {
131
+ return trace.type === 'ibc' || trace.type === 'ibc-cw20';
132
+ })) !== null && _asset$traces$filter !== void 0 ? _asset$traces$filter : [];
133
+
134
+ if (!traces.length) {
135
+ return memo;
136
+ }
137
+
138
+ if (traces.length > 1) {
139
+ throw new Error('contact maintainers: multi-hop not yet supported');
145
140
  }
141
+
142
+ var _traces = (0, _slicedToArray2["default"])(traces, 1),
143
+ trace = _traces[0];
144
+
145
+ return [].concat(memo, (0, _toConsumableArray2["default"])(getIbcAssetPath(ibc, counterparty, trace.counterparty.chain_name, assets, trace.counterparty.base_denom // base
146
+ )));
146
147
  };
147
148
 
148
- exports.getIbcDenomByBase = getIbcDenomByBase;
149
+ exports.getIbcAssetPath = getIbcAssetPath;
149
150
 
150
- var getIbcDenomByBaseForCw20 = function getIbcDenomByBaseForCw20(ibc, chain, counterparty, assets, base) {
151
+ var getIbcDenomByBase = function getIbcDenomByBase(ibc, chain, counterparty, assets, base) {
151
152
  var ibcInfo = getIbcInfo(ibc, chain, counterparty);
152
153
 
153
154
  if (ibcInfo) {
154
- var channel = getWasmChannel(ibcInfo);
155
+ var _asset$traces2, _asset$traces2$find, _ibcTrace$counterpart, _ibcTrace$counterpart2;
156
+
157
+ var channel = base.startsWith('cw20:') ? getWasmChannel(ibcInfo) : getTransferChannel(ibcInfo);
155
158
 
156
159
  if (!channel) {
157
160
  return;
158
161
  }
159
162
 
160
- var channelInfo;
163
+ var ibcPath = getIbcAssetPath(ibc, chain, counterparty, assets, base);
164
+ var assetList = assets.find(function (_ref2) {
165
+ var chain_name = _ref2.chain_name;
166
+ return chain_name === counterparty;
167
+ });
161
168
 
162
- if (ibcInfo.chain_1.chain_name === chain) {
163
- channelInfo = channel.chain_1;
164
- } else {
165
- channelInfo = channel.chain_2;
169
+ if (!assetList) {
170
+ console.warn("missing asset list for ".concat(counterparty)); // could be incorrect...
171
+
172
+ return ibcDenom(ibcPath, base);
166
173
  }
167
174
 
168
- var assetInfo = assets.find(function (_ref2) {
169
- var chain_name = _ref2.chain_name;
170
- return chain_name === counterparty;
175
+ var asset = assetList.assets.find(function (asset) {
176
+ return asset.base === base;
171
177
  });
172
178
 
173
- if (!assetInfo) {
174
- return;
179
+ if (!asset) {
180
+ console.warn("no ".concat(base, " found in ").concat(counterparty));
181
+ return ibcDenom(ibcPath, base);
175
182
  }
176
183
 
177
- return ibcDenom([{
178
- portId: channelInfo.port_id,
179
- channelId: channelInfo.channel_id
180
- }], base);
184
+ var ibcTrace = (_asset$traces2 = asset.traces) === null || _asset$traces2 === void 0 ? void 0 : (_asset$traces2$find = _asset$traces2.find) === null || _asset$traces2$find === void 0 ? void 0 : _asset$traces2$find.call(_asset$traces2, function (trace) {
185
+ return trace.type === 'ibc';
186
+ });
187
+ var baseDenom = (_ibcTrace$counterpart = ibcTrace === null || ibcTrace === void 0 ? void 0 : (_ibcTrace$counterpart2 = ibcTrace.counterparty) === null || _ibcTrace$counterpart2 === void 0 ? void 0 : _ibcTrace$counterpart2.base_denom) !== null && _ibcTrace$counterpart !== void 0 ? _ibcTrace$counterpart : asset.base;
188
+ return ibcDenom(ibcPath, baseDenom);
181
189
  }
182
190
  };
183
191
 
184
- exports.getIbcDenomByBaseForCw20 = getIbcDenomByBaseForCw20;
192
+ exports.getIbcDenomByBase = getIbcDenomByBase;
185
193
 
186
194
  var getIbcAssets = function getIbcAssets(chainName, ibc, assets) {
187
195
  var chainIbcInfo = ibc.filter(function (i) {
@@ -296,7 +304,7 @@ var getCw20Assets = function getCw20Assets(chainName, ibc, assets) {
296
304
  var cw20Assets = counterpartyAssets.assets.filter(function (a) {
297
305
  return a.base.startsWith('cw20:');
298
306
  }).map(function (asset) {
299
- var denom = getIbcDenomByBaseForCw20(ibc, chainName, counterparty, //
307
+ var denom = getIbcDenomByBase(ibc, chainName, counterparty, //
300
308
  assets, asset.base);
301
309
 
302
310
  var newAsset = _objectSpread({}, asset);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/utils",
3
- "version": "0.11.0",
3
+ "version": "1.0.1",
4
4
  "description": "Chain Registry Utils",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmology-tech/chain-registry",
@@ -73,10 +73,8 @@
73
73
  },
74
74
  "dependencies": {
75
75
  "@babel/runtime": "^7.19.0",
76
- "@chain-registry/types": "^0.11.0",
77
- "bfs-path": "^1.0.2",
78
- "cross-fetch": "^3.1.5",
76
+ "@chain-registry/types": "^0.11.1",
79
77
  "sha.js": "^2.4.11"
80
78
  },
81
- "gitHead": "7227af2939d83bdf4e68bd530aa68c14ae5aa18b"
79
+ "gitHead": "1dc04b938a9bbfb226dc3f91092c98c2c2d4c15a"
82
80
  }
package/types/utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AssetList, IBCInfo } from '@chain-registry/types';
2
2
  export declare const ibcDenom: (paths: {
3
- portId: string;
4
- channelId: string;
3
+ port_id: string;
4
+ channel_id: string;
5
5
  }[], coinMinimalDenom: string) => string;
6
6
  export declare const getIbcInfo: (ibc: IBCInfo[], chain: string, counterparty: string) => IBCInfo;
7
7
  export declare const getTransferChannel: (info: IBCInfo) => {
@@ -43,8 +43,8 @@ export declare const getWasmChannel: (info: IBCInfo) => {
43
43
  version: string;
44
44
  tags?: object;
45
45
  };
46
+ export declare const getIbcAssetPath: (ibc: IBCInfo[], chain: string, counterparty: string, assets: AssetList[], base: string) => any;
46
47
  export declare const getIbcDenomByBase: (ibc: IBCInfo[], chain: string, counterparty: string, assets: AssetList[], base: string) => string;
47
- export declare const getIbcDenomByBaseForCw20: (ibc: IBCInfo[], chain: string, counterparty: string, assets: AssetList[], base: string) => string;
48
48
  export declare const getIbcAssets: (chainName: string, ibc: IBCInfo[], assets: AssetList[]) => {
49
49
  chain_name: string;
50
50
  assets: any;
package/main/registry.js DELETED
@@ -1,313 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.ChainRegistryFetcher = exports.ChainInfo = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
-
20
- var _bfsPath = require("bfs-path");
21
-
22
- var _crossFetch = _interopRequireDefault(require("cross-fetch"));
23
-
24
- var _utils = require("./utils");
25
-
26
- var fetchUrl = function fetchUrl(url) {
27
- return (0, _crossFetch["default"])(url).then(function (res) {
28
- if (res.status >= 400) {
29
- throw new Error('Bad response');
30
- }
31
-
32
- return res.json();
33
- });
34
- };
35
-
36
- var ChainInfo = /*#__PURE__*/function () {
37
- function ChainInfo(options) {
38
- (0, _classCallCheck2["default"])(this, ChainInfo);
39
- (0, _defineProperty2["default"])(this, "chain_name", void 0);
40
- (0, _defineProperty2["default"])(this, "fetcher", void 0);
41
- (0, _defineProperty2["default"])(this, "_asset_list", void 0);
42
- (0, _defineProperty2["default"])(this, "_asset_lists", void 0);
43
- (0, _defineProperty2["default"])(this, "_chain", void 0);
44
- (0, _defineProperty2["default"])(this, "_ibc_data", []);
45
- this.chain_name = options.chain_name;
46
- this.fetcher = options.fetcher;
47
- this.refresh();
48
- }
49
-
50
- (0, _createClass2["default"])(ChainInfo, [{
51
- key: "refresh",
52
- value: function refresh() {
53
- this._asset_list = this.fetcher.getChainAssetList(this.chain_name);
54
- this._ibc_data = this.fetcher.getChainIbcData(this.chain_name);
55
- this._chain = this.fetcher.getChain(this.chain_name);
56
-
57
- var supportedChains = this._ibc_data.reduce(function (m, v) {
58
- if (!m.includes(v.chain_1.chain_name)) m.push(v.chain_1.chain_name);
59
- if (!m.includes(v.chain_2.chain_name)) m.push(v.chain_2.chain_name);
60
- return m;
61
- }, []);
62
-
63
- this._asset_lists = this.fetcher.assetLists.filter(function (list) {
64
- return supportedChains.includes(list.chain_name);
65
- });
66
- }
67
- }, {
68
- key: "nativeAssetLists",
69
- get: function get() {
70
- return this._asset_list;
71
- }
72
- }, {
73
- key: "chain",
74
- get: function get() {
75
- return this._chain;
76
- }
77
- }, {
78
- key: "assetLists",
79
- get: function get() {
80
- return (0, _utils.getAssetLists)(this.chain_name, this._ibc_data, this._asset_lists);
81
- }
82
- }]);
83
- return ChainInfo;
84
- }(); // QUESTION: should ChainRegistryFetcher just be ChainRegistry?
85
-
86
-
87
- exports.ChainInfo = ChainInfo;
88
-
89
- var ChainRegistryFetcher = /*#__PURE__*/function () {
90
- function ChainRegistryFetcher() {
91
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92
- (0, _classCallCheck2["default"])(this, ChainRegistryFetcher);
93
- (0, _defineProperty2["default"])(this, "_asset_lists", []);
94
- (0, _defineProperty2["default"])(this, "_chains", []);
95
- (0, _defineProperty2["default"])(this, "_ibc_data", []);
96
- (0, _defineProperty2["default"])(this, "urls", []);
97
-
98
- //
99
- if (options.assetLists) {
100
- this._asset_lists = options.assetLists;
101
- }
102
-
103
- if (options.chains) {
104
- this._chains = options.chains;
105
- }
106
-
107
- if (options.ibcData) {
108
- this._ibc_data = options.ibcData;
109
- }
110
-
111
- if (options.urls) {
112
- this.urls = options.urls;
113
- }
114
- }
115
-
116
- (0, _createClass2["default"])(ChainRegistryFetcher, [{
117
- key: "assetLists",
118
- get: function get() {
119
- return this._asset_lists;
120
- }
121
- }, {
122
- key: "getChainAssetList",
123
- value: function getChainAssetList(chainName) {
124
- return this._asset_lists.find(function (list) {
125
- return list.chain_name === chainName;
126
- });
127
- }
128
- }, {
129
- key: "getGeneratedAssetLists",
130
- value: function getGeneratedAssetLists(chainName) {
131
- return (0, _utils.getAssetLists)(chainName, this._ibc_data, this._asset_lists);
132
- }
133
- }, {
134
- key: "chains",
135
- get: function get() {
136
- return this._chains;
137
- }
138
- }, {
139
- key: "getChain",
140
- value: function getChain(chainName) {
141
- return this._chains.find(function (chain) {
142
- return chain.chain_name === chainName;
143
- });
144
- }
145
- }, {
146
- key: "ibcData",
147
- get: function get() {
148
- return this._ibc_data;
149
- }
150
- }, {
151
- key: "getChainIbcData",
152
- value: function getChainIbcData(chainName) {
153
- return this._ibc_data.filter(function (info) {
154
- return info.chain_1.chain_name === chainName || info.chain_2.chain_name === chainName;
155
- });
156
- }
157
- }, {
158
- key: "getChainInfo",
159
- value: function getChainInfo(chainName) {
160
- return new ChainInfo({
161
- chain_name: chainName,
162
- fetcher: this
163
- });
164
- }
165
- }, {
166
- key: "upsertChain",
167
- value: function upsertChain(data) {
168
- var found = this._chains.find(function (chain) {
169
- return chain.chain_name === data.chain_name && chain.network_type === data.network_type;
170
- });
171
-
172
- if (!found) {
173
- this._chains.push(data);
174
-
175
- return;
176
- }
177
-
178
- this._chains = this._chains.map(function (chain) {
179
- if (chain.chain_name === data.chain_name && chain.network_type === data.network_type) {
180
- return data;
181
- } else {
182
- return chain;
183
- }
184
- });
185
- }
186
- }, {
187
- key: "updateAssetList",
188
- value: function updateAssetList(data) {
189
- var found = this._asset_lists.find(function (list) {
190
- return list.chain_name === data.chain_name;
191
- });
192
-
193
- if (!found) {
194
- this._asset_lists.push(data);
195
-
196
- return;
197
- }
198
-
199
- this._asset_lists = this._asset_lists.map(function (list) {
200
- if (list.chain_name === data.chain_name) {
201
- return data;
202
- } else {
203
- return list;
204
- }
205
- });
206
- }
207
- }, {
208
- key: "upsertIbcData",
209
- value: function upsertIbcData(data) {
210
- var found = this._ibc_data.find(function (info) {
211
- return info.chain_1.chain_name === data.chain_1.chain_name && info.chain_2.chain_name === data.chain_2.chain_name;
212
- });
213
-
214
- if (!found) {
215
- this._ibc_data.push(data);
216
-
217
- return;
218
- }
219
-
220
- this._ibc_data = this._ibc_data.map(function (info) {
221
- if (info.chain_1.chain_name === data.chain_1.chain_name && info.chain_2.chain_name === data.chain_2.chain_name) {
222
- return data;
223
- } else {
224
- return info;
225
- }
226
- });
227
- }
228
- }, {
229
- key: "update",
230
- value: function update(data) {
231
- if (!data.$schema) throw new Error('not a registered JSON schema type');
232
- var type = (0, _bfsPath.basename)(data.$schema, '.schema.json');
233
-
234
- switch (type) {
235
- case 'chain':
236
- this.upsertChain(data);
237
- break;
238
-
239
- case 'assetlist':
240
- this.updateAssetList(data);
241
- break;
242
-
243
- case 'ibc_data':
244
- this.upsertIbcData(data);
245
- break;
246
-
247
- default:
248
- throw new Error('unknown schema type');
249
- }
250
- }
251
- }, {
252
- key: "fetch",
253
- value: function () {
254
- var _fetch = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(url) {
255
- var data;
256
- return _regenerator["default"].wrap(function _callee$(_context) {
257
- while (1) {
258
- switch (_context.prev = _context.next) {
259
- case 0:
260
- _context.next = 2;
261
- return fetchUrl(url);
262
-
263
- case 2:
264
- data = _context.sent;
265
- this.update(data);
266
-
267
- case 4:
268
- case "end":
269
- return _context.stop();
270
- }
271
- }
272
- }, _callee, this);
273
- }));
274
-
275
- function fetch(_x) {
276
- return _fetch.apply(this, arguments);
277
- }
278
-
279
- return fetch;
280
- }()
281
- }, {
282
- key: "fetchUrls",
283
- value: function () {
284
- var _fetchUrls = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
285
- var _this = this;
286
-
287
- return _regenerator["default"].wrap(function _callee2$(_context2) {
288
- while (1) {
289
- switch (_context2.prev = _context2.next) {
290
- case 0:
291
- return _context2.abrupt("return", Promise.all(this.urls.map(function (url) {
292
- return _this.fetch(url);
293
- })));
294
-
295
- case 1:
296
- case "end":
297
- return _context2.stop();
298
- }
299
- }
300
- }, _callee2, this);
301
- }));
302
-
303
- function fetchUrls() {
304
- return _fetchUrls.apply(this, arguments);
305
- }
306
-
307
- return fetchUrls;
308
- }()
309
- }]);
310
- return ChainRegistryFetcher;
311
- }();
312
-
313
- exports.ChainRegistryFetcher = ChainRegistryFetcher;