@ping-pub/chain-registry-client
Version:
Cosmos Blockchain Registry Client
62 lines • 2.55 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import fetch from "cross-fetch";
export default class ChainRegistryClient {
constructor(endpoint = 'https://registry.ping.pub') {
this.endpoint = endpoint;
}
getAny(url) {
return __awaiter(this, void 0, void 0, function* () {
return fetch(`${this.endpoint}${url}`).then((res) => res.json());
});
}
get(url) {
return __awaiter(this, void 0, void 0, function* () {
return fetch(`${this.endpoint}${url}`).then((res) => res.json());
});
}
fetchChainNames() {
return __awaiter(this, void 0, void 0, function* () {
const entris = yield this.get('/');
return entris.filter(i => i.type === 'directory' && i.name !== 'testnet' && !i.name.startsWith('_')).map(x => x.name);
});
}
fetchChainInfo(chainName) {
return __awaiter(this, void 0, void 0, function* () {
return this.get(`/${chainName}/chain.json`);
});
}
fetchAssetsList(chainName) {
return __awaiter(this, void 0, void 0, function* () {
return this.get(`/${chainName}/assetlist.json`);
});
}
fetchIBCPaths() {
return __awaiter(this, void 0, void 0, function* () {
const entries = yield this.get('/_IBC/');
const re = /([\w]+)-([\w]+)\.json/;
return entries.map(x => {
const matches = x.name.match(re);
const bridge = {};
bridge.path = x.name;
bridge.from = matches[1];
bridge.to = matches[2];
return bridge;
});
});
}
fetchIBCPathInfo(path) {
return __awaiter(this, void 0, void 0, function* () {
const info = yield this.get(`/_IBC/${path}`);
return info;
});
}
}
//# sourceMappingURL=index.js.map