@@ -70,10 +70,52 @@ async function fetchFromPingPub(){
70
70
}
71
71
}
72
72
73
+ async function fetchFromCosmosChainRegistry ( ) {
74
+ const res = await fetch (
75
+ 'https://api.github.com/repos/cosmos/chain-registry/git/trees/master?recursive=1'
76
+ ) ;
77
+ const data = await res . json ( ) ;
78
+ const COSMOS_CHAIN_REGISTRY_BASE_URL = data . tree . filter (
79
+ ( folder ) => folder . path === '_IBC'
80
+ ) [ 0 ] ?. url ;
81
+
82
+ if ( ! COSMOS_CHAIN_REGISTRY_BASE_URL ) {
83
+ return fetchFromPingPub ( ) ;
84
+ }
85
+
86
+ const response = await fetch ( COSMOS_CHAIN_REGISTRY_BASE_URL ) ;
87
+ const ibcData = await response . json ( ) ;
88
+ const hrefs = ibcData . tree
89
+ . filter ( ( file ) => file . path )
90
+ . map ( ( file ) => file . path ) ;
91
+
92
+ const ibcSupport = { } ;
93
+
94
+ hrefs . forEach ( ( href ) => {
95
+ const [ src , dest ] = href . slice ( 0 , - 5 ) . split ( '-' ) ;
96
+ if ( ibcSupport [ src ] ) {
97
+ ibcSupport [ src ] [ dest ] = true ;
98
+ } else {
99
+ ibcSupport [ src ] = { [ dest ] : true } ;
100
+ }
101
+ if ( ibcSupport [ dest ] ) {
102
+ ibcSupport [ dest ] [ src ] = true ;
103
+ } else {
104
+ ibcSupport [ dest ] = { [ src ] : true } ;
105
+ }
106
+ } ) ;
107
+
108
+ return {
109
+ baseUrl :
110
+ 'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC' ,
111
+ hrefs,
112
+ ibcSupport,
113
+ } ;
114
+ }
73
115
74
116
const main = async ( ) => {
75
117
try {
76
- const { baseUrl, ibcSupport, hrefs } = await fetchFromPingPub ( )
118
+ const { baseUrl, ibcSupport, hrefs } = await fetchFromCosmosChainRegistry ( )
77
119
const allData = Object . entries ( ibcSupport ) . reduce ( ( acc , [ key , value ] ) => {
78
120
return {
79
121
...acc ,
@@ -108,4 +150,4 @@ const main = async () => {
108
150
}
109
151
} ;
110
152
111
- main ( ) ;
153
+ main ( ) ;
0 commit comments