@chain-registry/client 1.53.148 → 2.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/README.md +1 -1
- package/chain-info.d.ts +3 -3
- package/chain-info.js +5 -5
- package/chain-util.js +1 -1
- package/esm/chain-info.js +5 -5
- package/esm/chain-util.js +1 -1
- package/esm/fetcher.js +36 -20
- package/esm/registry.js +1 -1
- package/fetcher.d.ts +8 -8
- package/fetcher.js +36 -20
- package/package.json +4 -4
- package/registry.js +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<img height="20" src="https://github.com/hyperweb-io/chain-registry/actions/workflows/run-tests.yml/badge.svg" />
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://github.com/hyperweb-io/chain-registry/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
|
|
12
|
-
<a href="https://www.npmjs.com/package/@chain-registry/client"><img height="20" src="https://img.shields.io/github/package-json/v/hyperweb-io/chain-registry?filename=
|
|
12
|
+
<a href="https://www.npmjs.com/package/@chain-registry/client"><img height="20" src="https://img.shields.io/github/package-json/v/hyperweb-io/chain-registry?filename=v2%2Fpackages%2Fclient%2Fpackage.json"></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
The `@chain-registry/client` package provides a client for dynamically fetching and managing chain and asset data from the Cosmos chain registry. This tool is essential for developers who need to access up-to-date blockchain information, including asset lists and IBC data.
|
package/chain-info.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AssetList, Chain,
|
|
1
|
+
import { AssetList, Chain, IBCData } from '@chain-registry/types';
|
|
2
2
|
import { ChainRegistryFetcher } from './fetcher';
|
|
3
3
|
export interface ChainInfoOptions {
|
|
4
4
|
chainName: string;
|
|
@@ -10,10 +10,10 @@ export declare class ChainInfo {
|
|
|
10
10
|
protected _chain: Chain;
|
|
11
11
|
protected _assetList: AssetList;
|
|
12
12
|
protected _assetLists: AssetList[];
|
|
13
|
-
protected _ibcData:
|
|
13
|
+
protected _ibcData: IBCData[];
|
|
14
14
|
constructor(options: ChainInfoOptions);
|
|
15
15
|
refresh(): void;
|
|
16
16
|
get chain(): Chain;
|
|
17
17
|
get nativeAssetList(): AssetList;
|
|
18
|
-
get assetLists():
|
|
18
|
+
get assetLists(): AssetList[];
|
|
19
19
|
}
|
package/chain-info.js
CHANGED
|
@@ -19,13 +19,13 @@ class ChainInfo {
|
|
|
19
19
|
this._ibcData = this.fetcher.getChainIbcData(this.chainName);
|
|
20
20
|
this._chain = this.fetcher.getChain(this.chainName);
|
|
21
21
|
const supportedChains = this._ibcData.reduce((m, v) => {
|
|
22
|
-
if (!m.includes(v.
|
|
23
|
-
m.push(v.
|
|
24
|
-
if (!m.includes(v.
|
|
25
|
-
m.push(v.
|
|
22
|
+
if (!m.includes(v.chain1.chainName))
|
|
23
|
+
m.push(v.chain1.chainName);
|
|
24
|
+
if (!m.includes(v.chain1.chainName))
|
|
25
|
+
m.push(v.chain1.chainName);
|
|
26
26
|
return m;
|
|
27
27
|
}, []);
|
|
28
|
-
this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.
|
|
28
|
+
this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.chainName));
|
|
29
29
|
}
|
|
30
30
|
get chain() {
|
|
31
31
|
return this._chain;
|
package/chain-util.js
CHANGED
package/esm/chain-info.js
CHANGED
|
@@ -16,13 +16,13 @@ export class ChainInfo {
|
|
|
16
16
|
this._ibcData = this.fetcher.getChainIbcData(this.chainName);
|
|
17
17
|
this._chain = this.fetcher.getChain(this.chainName);
|
|
18
18
|
const supportedChains = this._ibcData.reduce((m, v) => {
|
|
19
|
-
if (!m.includes(v.
|
|
20
|
-
m.push(v.
|
|
21
|
-
if (!m.includes(v.
|
|
22
|
-
m.push(v.
|
|
19
|
+
if (!m.includes(v.chain1.chainName))
|
|
20
|
+
m.push(v.chain1.chainName);
|
|
21
|
+
if (!m.includes(v.chain1.chainName))
|
|
22
|
+
m.push(v.chain1.chainName);
|
|
23
23
|
return m;
|
|
24
24
|
}, []);
|
|
25
|
-
this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.
|
|
25
|
+
this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.chainName));
|
|
26
26
|
}
|
|
27
27
|
get chain() {
|
|
28
28
|
return this._chain;
|
package/esm/chain-util.js
CHANGED
package/esm/fetcher.js
CHANGED
|
@@ -2,6 +2,19 @@ import { getAssetLists } from '@chain-registry/utils';
|
|
|
2
2
|
import { basename } from 'bfs-path';
|
|
3
3
|
import fetch from 'cross-fetch';
|
|
4
4
|
import { ChainInfo } from './chain-info';
|
|
5
|
+
const keysToCamel = (o) => {
|
|
6
|
+
if (o === Object(o) && !Array.isArray(o) && typeof o !== 'function') {
|
|
7
|
+
const n = {};
|
|
8
|
+
Object.keys(o).forEach((k) => {
|
|
9
|
+
n[k.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : '')] = keysToCamel(o[k]);
|
|
10
|
+
});
|
|
11
|
+
return n;
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(o)) {
|
|
14
|
+
return o.map((i) => keysToCamel(i));
|
|
15
|
+
}
|
|
16
|
+
return o;
|
|
17
|
+
};
|
|
5
18
|
const fetchUrl = (url) => {
|
|
6
19
|
return fetch(url).then((res) => {
|
|
7
20
|
if (res.status >= 400) {
|
|
@@ -42,17 +55,17 @@ export class ChainRegistryFetcher {
|
|
|
42
55
|
return this._ibcData;
|
|
43
56
|
}
|
|
44
57
|
getChain(chainName) {
|
|
45
|
-
return this._chains.find((chain) => chain.
|
|
58
|
+
return this._chains.find((chain) => chain.chainName === chainName);
|
|
46
59
|
}
|
|
47
60
|
getChainAssetList(chainName) {
|
|
48
|
-
return this._assetLists.find((list) => list.
|
|
61
|
+
return this._assetLists.find((list) => list.chainName === chainName);
|
|
49
62
|
}
|
|
50
63
|
getGeneratedAssetLists(chainName) {
|
|
51
64
|
return getAssetLists(chainName, this._ibcData, this._assetLists);
|
|
52
65
|
}
|
|
53
66
|
getChainIbcData(chainName) {
|
|
54
|
-
return this._ibcData.filter((info) => info.
|
|
55
|
-
info.
|
|
67
|
+
return this._ibcData.filter((info) => info.chain1.chainName === chainName ||
|
|
68
|
+
info.chain2.chainName === chainName);
|
|
56
69
|
}
|
|
57
70
|
getChainInfo(chainName) {
|
|
58
71
|
let chainInfo = this.chainInfoList.find((it) => it.chainName === chainName);
|
|
@@ -67,17 +80,18 @@ export class ChainRegistryFetcher {
|
|
|
67
80
|
}
|
|
68
81
|
upsertChain(data) {
|
|
69
82
|
const found = this._chains.find((chain) => {
|
|
70
|
-
return (chain.
|
|
71
|
-
chain.
|
|
83
|
+
return (chain.chainName === data.chainName &&
|
|
84
|
+
chain.networkType === data.networkType);
|
|
72
85
|
});
|
|
86
|
+
const convertedData = keysToCamel(data);
|
|
73
87
|
if (!found) {
|
|
74
|
-
this._chains.push(
|
|
88
|
+
this._chains.push(convertedData);
|
|
75
89
|
return;
|
|
76
90
|
}
|
|
77
91
|
this._chains = this._chains.map((chain) => {
|
|
78
|
-
if (chain.
|
|
79
|
-
chain.
|
|
80
|
-
return
|
|
92
|
+
if (chain.chainName === data.chainName &&
|
|
93
|
+
chain.networkType === data.networkType) {
|
|
94
|
+
return convertedData;
|
|
81
95
|
}
|
|
82
96
|
else {
|
|
83
97
|
return chain;
|
|
@@ -86,15 +100,16 @@ export class ChainRegistryFetcher {
|
|
|
86
100
|
}
|
|
87
101
|
updateAssetList(data) {
|
|
88
102
|
const found = this._assetLists.find((list) => {
|
|
89
|
-
return list.
|
|
103
|
+
return list.chainName === data.chainName;
|
|
90
104
|
});
|
|
105
|
+
const convertedData = keysToCamel(data);
|
|
91
106
|
if (!found) {
|
|
92
|
-
this._assetLists.push(
|
|
107
|
+
this._assetLists.push(convertedData);
|
|
93
108
|
return;
|
|
94
109
|
}
|
|
95
110
|
this._assetLists = this._assetLists.map((list) => {
|
|
96
|
-
if (list.
|
|
97
|
-
return
|
|
111
|
+
if (list.chainName === data.chainName) {
|
|
112
|
+
return convertedData;
|
|
98
113
|
}
|
|
99
114
|
else {
|
|
100
115
|
return list;
|
|
@@ -103,17 +118,18 @@ export class ChainRegistryFetcher {
|
|
|
103
118
|
}
|
|
104
119
|
upsertIbcData(data) {
|
|
105
120
|
const found = this._ibcData.find((info) => {
|
|
106
|
-
return (info.
|
|
107
|
-
info.
|
|
121
|
+
return (info.chain1.chainName === data.chain1.chainName &&
|
|
122
|
+
info.chain2.chainName === data.chain2.chainName);
|
|
108
123
|
});
|
|
124
|
+
const convertedData = keysToCamel(data);
|
|
109
125
|
if (!found) {
|
|
110
|
-
this._ibcData.push(
|
|
126
|
+
this._ibcData.push(convertedData);
|
|
111
127
|
return;
|
|
112
128
|
}
|
|
113
129
|
this._ibcData = this._ibcData.map((info) => {
|
|
114
|
-
if (info.
|
|
115
|
-
info.
|
|
116
|
-
return
|
|
130
|
+
if (info.chain1.chainName === data.chain1.chainName &&
|
|
131
|
+
info.chain2.chainName === data.chain2.chainName) {
|
|
132
|
+
return convertedData;
|
|
117
133
|
}
|
|
118
134
|
else {
|
|
119
135
|
return info;
|
package/esm/registry.js
CHANGED
|
@@ -3,7 +3,7 @@ import { ChainRegistryFetcher } from './fetcher';
|
|
|
3
3
|
export class ChainRegistryClient extends ChainRegistryFetcher {
|
|
4
4
|
_options = {
|
|
5
5
|
chainNames: [],
|
|
6
|
-
baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/
|
|
6
|
+
baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/camel'
|
|
7
7
|
};
|
|
8
8
|
constructor(options) {
|
|
9
9
|
const { chainNames, assetListNames, ibcNamePairs, baseUrl, ...restOptions } = options;
|
package/fetcher.d.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { AssetList, Chain,
|
|
1
|
+
import { AssetList, Chain, IBCData } from '@chain-registry/types';
|
|
2
2
|
import { ChainInfo } from './chain-info';
|
|
3
3
|
export interface ChainRegistryFetcherOptions {
|
|
4
4
|
assetLists?: AssetList[];
|
|
5
5
|
chains?: Chain[];
|
|
6
|
-
ibcData?:
|
|
6
|
+
ibcData?: IBCData[];
|
|
7
7
|
urls?: string[];
|
|
8
8
|
}
|
|
9
|
-
export declare class ChainRegistryFetcher
|
|
9
|
+
export declare class ChainRegistryFetcher {
|
|
10
10
|
urls: string[];
|
|
11
11
|
protected _assetLists: AssetList[];
|
|
12
12
|
protected _chains: Chain[];
|
|
13
|
-
protected _ibcData:
|
|
13
|
+
protected _ibcData: IBCData[];
|
|
14
14
|
private chainInfoList;
|
|
15
15
|
constructor(options?: ChainRegistryFetcherOptions);
|
|
16
16
|
get chains(): Chain[];
|
|
17
17
|
get assetLists(): AssetList[];
|
|
18
|
-
get ibcData():
|
|
18
|
+
get ibcData(): IBCData[];
|
|
19
19
|
getChain(chainName: string): Chain;
|
|
20
20
|
getChainAssetList(chainName: string): AssetList;
|
|
21
21
|
getGeneratedAssetLists(chainName: string): AssetList[];
|
|
22
|
-
getChainIbcData(chainName: string):
|
|
22
|
+
getChainIbcData(chainName: string): IBCData[];
|
|
23
23
|
getChainInfo(chainName: string): ChainInfo;
|
|
24
24
|
upsertChain(data: Chain): void;
|
|
25
25
|
updateAssetList(data: AssetList): void;
|
|
26
|
-
upsertIbcData(data:
|
|
27
|
-
update(data: Chain | AssetList |
|
|
26
|
+
upsertIbcData(data: IBCData): void;
|
|
27
|
+
update(data: Chain | AssetList | IBCData): void;
|
|
28
28
|
fetch(url: string): Promise<void>;
|
|
29
29
|
fetchUrls(): Promise<void[]>;
|
|
30
30
|
}
|
package/fetcher.js
CHANGED
|
@@ -8,6 +8,19 @@ const utils_1 = require("@chain-registry/utils");
|
|
|
8
8
|
const bfs_path_1 = require("bfs-path");
|
|
9
9
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
10
10
|
const chain_info_1 = require("./chain-info");
|
|
11
|
+
const keysToCamel = (o) => {
|
|
12
|
+
if (o === Object(o) && !Array.isArray(o) && typeof o !== 'function') {
|
|
13
|
+
const n = {};
|
|
14
|
+
Object.keys(o).forEach((k) => {
|
|
15
|
+
n[k.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : '')] = keysToCamel(o[k]);
|
|
16
|
+
});
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
else if (Array.isArray(o)) {
|
|
20
|
+
return o.map((i) => keysToCamel(i));
|
|
21
|
+
}
|
|
22
|
+
return o;
|
|
23
|
+
};
|
|
11
24
|
const fetchUrl = (url) => {
|
|
12
25
|
return (0, cross_fetch_1.default)(url).then((res) => {
|
|
13
26
|
if (res.status >= 400) {
|
|
@@ -48,17 +61,17 @@ class ChainRegistryFetcher {
|
|
|
48
61
|
return this._ibcData;
|
|
49
62
|
}
|
|
50
63
|
getChain(chainName) {
|
|
51
|
-
return this._chains.find((chain) => chain.
|
|
64
|
+
return this._chains.find((chain) => chain.chainName === chainName);
|
|
52
65
|
}
|
|
53
66
|
getChainAssetList(chainName) {
|
|
54
|
-
return this._assetLists.find((list) => list.
|
|
67
|
+
return this._assetLists.find((list) => list.chainName === chainName);
|
|
55
68
|
}
|
|
56
69
|
getGeneratedAssetLists(chainName) {
|
|
57
70
|
return (0, utils_1.getAssetLists)(chainName, this._ibcData, this._assetLists);
|
|
58
71
|
}
|
|
59
72
|
getChainIbcData(chainName) {
|
|
60
|
-
return this._ibcData.filter((info) => info.
|
|
61
|
-
info.
|
|
73
|
+
return this._ibcData.filter((info) => info.chain1.chainName === chainName ||
|
|
74
|
+
info.chain2.chainName === chainName);
|
|
62
75
|
}
|
|
63
76
|
getChainInfo(chainName) {
|
|
64
77
|
let chainInfo = this.chainInfoList.find((it) => it.chainName === chainName);
|
|
@@ -73,17 +86,18 @@ class ChainRegistryFetcher {
|
|
|
73
86
|
}
|
|
74
87
|
upsertChain(data) {
|
|
75
88
|
const found = this._chains.find((chain) => {
|
|
76
|
-
return (chain.
|
|
77
|
-
chain.
|
|
89
|
+
return (chain.chainName === data.chainName &&
|
|
90
|
+
chain.networkType === data.networkType);
|
|
78
91
|
});
|
|
92
|
+
const convertedData = keysToCamel(data);
|
|
79
93
|
if (!found) {
|
|
80
|
-
this._chains.push(
|
|
94
|
+
this._chains.push(convertedData);
|
|
81
95
|
return;
|
|
82
96
|
}
|
|
83
97
|
this._chains = this._chains.map((chain) => {
|
|
84
|
-
if (chain.
|
|
85
|
-
chain.
|
|
86
|
-
return
|
|
98
|
+
if (chain.chainName === data.chainName &&
|
|
99
|
+
chain.networkType === data.networkType) {
|
|
100
|
+
return convertedData;
|
|
87
101
|
}
|
|
88
102
|
else {
|
|
89
103
|
return chain;
|
|
@@ -92,15 +106,16 @@ class ChainRegistryFetcher {
|
|
|
92
106
|
}
|
|
93
107
|
updateAssetList(data) {
|
|
94
108
|
const found = this._assetLists.find((list) => {
|
|
95
|
-
return list.
|
|
109
|
+
return list.chainName === data.chainName;
|
|
96
110
|
});
|
|
111
|
+
const convertedData = keysToCamel(data);
|
|
97
112
|
if (!found) {
|
|
98
|
-
this._assetLists.push(
|
|
113
|
+
this._assetLists.push(convertedData);
|
|
99
114
|
return;
|
|
100
115
|
}
|
|
101
116
|
this._assetLists = this._assetLists.map((list) => {
|
|
102
|
-
if (list.
|
|
103
|
-
return
|
|
117
|
+
if (list.chainName === data.chainName) {
|
|
118
|
+
return convertedData;
|
|
104
119
|
}
|
|
105
120
|
else {
|
|
106
121
|
return list;
|
|
@@ -109,17 +124,18 @@ class ChainRegistryFetcher {
|
|
|
109
124
|
}
|
|
110
125
|
upsertIbcData(data) {
|
|
111
126
|
const found = this._ibcData.find((info) => {
|
|
112
|
-
return (info.
|
|
113
|
-
info.
|
|
127
|
+
return (info.chain1.chainName === data.chain1.chainName &&
|
|
128
|
+
info.chain2.chainName === data.chain2.chainName);
|
|
114
129
|
});
|
|
130
|
+
const convertedData = keysToCamel(data);
|
|
115
131
|
if (!found) {
|
|
116
|
-
this._ibcData.push(
|
|
132
|
+
this._ibcData.push(convertedData);
|
|
117
133
|
return;
|
|
118
134
|
}
|
|
119
135
|
this._ibcData = this._ibcData.map((info) => {
|
|
120
|
-
if (info.
|
|
121
|
-
info.
|
|
122
|
-
return
|
|
136
|
+
if (info.chain1.chainName === data.chain1.chainName &&
|
|
137
|
+
info.chain2.chainName === data.chain2.chainName) {
|
|
138
|
+
return convertedData;
|
|
123
139
|
}
|
|
124
140
|
else {
|
|
125
141
|
return info;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chain-registry/client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Chain Registry Client",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/hyperweb-io/chain-registry",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"supertest": "6.3.3"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@chain-registry/types": "^0.
|
|
39
|
-
"@chain-registry/utils": "^
|
|
38
|
+
"@chain-registry/types": "^2.0.1",
|
|
39
|
+
"@chain-registry/utils": "^2.0.1",
|
|
40
40
|
"bfs-path": "^1.0.2",
|
|
41
41
|
"cross-fetch": "^3.1.5"
|
|
42
42
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"interchain",
|
|
48
48
|
"tokens"
|
|
49
49
|
],
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "305d26dcd259fd31a0e30444f02273abaf40e298"
|
|
51
51
|
}
|
package/registry.js
CHANGED
|
@@ -6,7 +6,7 @@ const fetcher_1 = require("./fetcher");
|
|
|
6
6
|
class ChainRegistryClient extends fetcher_1.ChainRegistryFetcher {
|
|
7
7
|
_options = {
|
|
8
8
|
chainNames: [],
|
|
9
|
-
baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/
|
|
9
|
+
baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/camel'
|
|
10
10
|
};
|
|
11
11
|
constructor(options) {
|
|
12
12
|
const { chainNames, assetListNames, ibcNamePairs, baseUrl, ...restOptions } = options;
|