@keplr-wallet/background 0.9.7 → 0.9.9
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/build/updater/service.d.ts +3 -1
- package/build/updater/service.js +67 -93
- package/build/updater/service.js.map +1 -1
- package/package.json +7 -7
- package/src/updater/service.ts +83 -127
|
@@ -7,7 +7,7 @@ export declare class ChainUpdaterService {
|
|
|
7
7
|
constructor(kvStore: KVStore, chainsService: ChainsService);
|
|
8
8
|
putUpdatedPropertyToChainInfo(chainInfo: ChainInfo): Promise<ChainInfo>;
|
|
9
9
|
clearUpdatedProperty(chainId: string): Promise<void>;
|
|
10
|
-
tryUpdateChain(chainId: string): Promise<
|
|
10
|
+
tryUpdateChain(chainId: string): Promise<void>;
|
|
11
11
|
private getUpdatedChainProperty;
|
|
12
12
|
private saveChainProperty;
|
|
13
13
|
private loadChainProperty;
|
|
@@ -19,5 +19,7 @@ export declare class ChainUpdaterService {
|
|
|
19
19
|
static checkChainUpdate(chainInfo: Readonly<ChainInfo>): Promise<{
|
|
20
20
|
explicit: boolean;
|
|
21
21
|
slient: boolean;
|
|
22
|
+
chainId?: string;
|
|
23
|
+
features?: string[];
|
|
22
24
|
}>;
|
|
23
25
|
}
|
package/build/updater/service.js
CHANGED
|
@@ -23,6 +23,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
23
23
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
|
+
var ChainUpdaterService_1;
|
|
26
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
28
|
exports.ChainUpdaterService = void 0;
|
|
28
29
|
const tsyringe_1 = require("tsyringe");
|
|
@@ -30,7 +31,7 @@ const types_1 = require("../types");
|
|
|
30
31
|
const axios_1 = __importDefault(require("axios"));
|
|
31
32
|
const cosmos_1 = require("@keplr-wallet/cosmos");
|
|
32
33
|
const chains_1 = require("../chains");
|
|
33
|
-
let ChainUpdaterService = class ChainUpdaterService {
|
|
34
|
+
let ChainUpdaterService = ChainUpdaterService_1 = class ChainUpdaterService {
|
|
34
35
|
constructor(kvStore, chainsService) {
|
|
35
36
|
this.kvStore = kvStore;
|
|
36
37
|
this.chainsService = chainsService;
|
|
@@ -64,97 +65,40 @@ let ChainUpdaterService = class ChainUpdaterService {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
tryUpdateChain(chainId) {
|
|
67
|
-
var _a
|
|
68
|
+
var _a;
|
|
68
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
70
|
const chainInfo = yield this.chainsService.getChainInfo(chainId);
|
|
70
71
|
// If chain id is not fomatted as {chainID}-{version},
|
|
71
72
|
// there is no way to deal with the updated chain id.
|
|
72
73
|
if (!cosmos_1.ChainIdHelper.hasChainVersion(chainInfo.chainId)) {
|
|
73
|
-
return
|
|
74
|
+
return;
|
|
74
75
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (currentVersion.identifier === fetchedVersion.identifier &&
|
|
84
|
-
currentVersion.version < fetchedVersion.version) {
|
|
85
|
-
yield this.saveChainProperty(currentVersion.identifier, {
|
|
86
|
-
chainId: fetchedChainId,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
let staragteUpdate = false;
|
|
90
|
-
try {
|
|
91
|
-
if (!chainInfo.features || !chainInfo.features.includes("stargate")) {
|
|
92
|
-
const restInstance = axios_1.default.create({
|
|
93
|
-
baseURL: chainInfo.rest,
|
|
94
|
-
});
|
|
95
|
-
// If the chain doesn't have the stargate feature,
|
|
96
|
-
// but it can use the GRPC HTTP Gateway,
|
|
97
|
-
// assume that it can support the stargate and try to update the features.
|
|
98
|
-
yield restInstance.get("/cosmos/base/tendermint/v1beta1/node_info");
|
|
99
|
-
const savedChainProperty = yield this.getUpdatedChainProperty(chainInfo.chainId);
|
|
100
|
-
yield this.saveChainProperty(currentVersion.identifier, {
|
|
101
|
-
features: ((_a = savedChainProperty.features) !== null && _a !== void 0 ? _a : []).concat(["stargate"]),
|
|
102
|
-
});
|
|
103
|
-
staragteUpdate = true;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (_d) { }
|
|
107
|
-
try {
|
|
108
|
-
if ((!chainInfo.features || !chainInfo.features.includes("ibc-transfer")) &&
|
|
109
|
-
(staragteUpdate ||
|
|
110
|
-
(chainInfo.features && chainInfo.features.includes("stargate")))) {
|
|
111
|
-
const restInstance = axios_1.default.create({
|
|
112
|
-
baseURL: chainInfo.rest,
|
|
113
|
-
});
|
|
114
|
-
// If the chain doesn't have the ibc transfer feature,
|
|
115
|
-
// try to fetch the params of ibc transfer module.
|
|
116
|
-
// assume that it can support the ibc transfer if the params return true, and try to update the features.
|
|
117
|
-
const result = yield restInstance.get("/ibc/applications/transfer/v1beta1/params");
|
|
118
|
-
if (result.data.params.receive_enabled &&
|
|
119
|
-
result.data.params.send_enabled) {
|
|
120
|
-
const savedChainProperty = yield this.getUpdatedChainProperty(chainInfo.chainId);
|
|
76
|
+
const updates = yield ChainUpdaterService_1.checkChainUpdate(chainInfo);
|
|
77
|
+
if (updates.explicit || updates.slient) {
|
|
78
|
+
const currentVersion = cosmos_1.ChainIdHelper.parse(chainInfo.chainId);
|
|
79
|
+
if (updates.chainId) {
|
|
80
|
+
const fetchedChainId = updates.chainId;
|
|
81
|
+
const fetchedVersion = cosmos_1.ChainIdHelper.parse(fetchedChainId);
|
|
82
|
+
if (currentVersion.identifier === fetchedVersion.identifier &&
|
|
83
|
+
currentVersion.version < fetchedVersion.version) {
|
|
121
84
|
yield this.saveChainProperty(currentVersion.identifier, {
|
|
122
|
-
|
|
123
|
-
"ibc-transfer",
|
|
124
|
-
]),
|
|
85
|
+
chainId: fetchedChainId,
|
|
125
86
|
});
|
|
126
87
|
}
|
|
127
88
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const restInstance = axios_1.default.create({
|
|
136
|
-
baseURL: chainInfo.rest,
|
|
137
|
-
});
|
|
138
|
-
// The chain with above cosmos-sdk@v0.44.0 can't send the legacy stdTx,
|
|
139
|
-
// Assume that it can't send the legacy stdTx if the POST /txs responses "not implemented".
|
|
140
|
-
const result = yield restInstance.post("/txs", undefined, {
|
|
141
|
-
validateStatus: (status) => {
|
|
142
|
-
return (status >= 200 && status < 300) || status === 501;
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
if (result.status === 501 &&
|
|
146
|
-
result.data.code === 12 &&
|
|
147
|
-
result.data.message === "Not Implemented") {
|
|
148
|
-
const savedChainProperty = yield this.getUpdatedChainProperty(chainInfo.chainId);
|
|
149
|
-
yield this.saveChainProperty(currentVersion.identifier, {
|
|
150
|
-
features: ((_c = savedChainProperty.features) !== null && _c !== void 0 ? _c : []).concat([
|
|
151
|
-
"no-legacy-stdTx",
|
|
152
|
-
]),
|
|
153
|
-
});
|
|
89
|
+
if (updates.features && updates.features.length > 0) {
|
|
90
|
+
const savedChainProperty = yield this.getUpdatedChainProperty(chainInfo.chainId);
|
|
91
|
+
const updateFeatures = (_a = savedChainProperty.features) !== null && _a !== void 0 ? _a : [];
|
|
92
|
+
for (const feature of updates.features) {
|
|
93
|
+
if (!updateFeatures.includes(feature)) {
|
|
94
|
+
updateFeatures.push(feature);
|
|
95
|
+
}
|
|
154
96
|
}
|
|
97
|
+
yield this.saveChainProperty(currentVersion.identifier, {
|
|
98
|
+
features: updateFeatures,
|
|
99
|
+
});
|
|
155
100
|
}
|
|
156
101
|
}
|
|
157
|
-
catch (_f) { }
|
|
158
102
|
});
|
|
159
103
|
}
|
|
160
104
|
getUpdatedChainProperty(chainId) {
|
|
@@ -209,12 +153,12 @@ let ChainUpdaterService = class ChainUpdaterService {
|
|
|
209
153
|
slient: false,
|
|
210
154
|
};
|
|
211
155
|
}
|
|
156
|
+
const restInstance = axios_1.default.create({
|
|
157
|
+
baseURL: chainInfo.rest,
|
|
158
|
+
});
|
|
212
159
|
let staragteUpdate = false;
|
|
213
160
|
try {
|
|
214
161
|
if (!chainInfo.features || !chainInfo.features.includes("stargate")) {
|
|
215
|
-
const restInstance = axios_1.default.create({
|
|
216
|
-
baseURL: chainInfo.rest,
|
|
217
|
-
});
|
|
218
162
|
// If the chain doesn't have the stargate feature,
|
|
219
163
|
// but it can use the GRPC HTTP Gateway,
|
|
220
164
|
// assume that it can support the stargate and try to update the features.
|
|
@@ -223,34 +167,46 @@ let ChainUpdaterService = class ChainUpdaterService {
|
|
|
223
167
|
}
|
|
224
168
|
}
|
|
225
169
|
catch (_a) { }
|
|
170
|
+
let ibcGoUpdates = false;
|
|
171
|
+
try {
|
|
172
|
+
if ((!chainInfo.features || !chainInfo.features.includes("ibc-go")) &&
|
|
173
|
+
(staragteUpdate ||
|
|
174
|
+
(chainInfo.features && chainInfo.features.includes("stargate")))) {
|
|
175
|
+
// If the chain uses the ibc-go module separated from the cosmos-sdk,
|
|
176
|
+
// we need to check it because the REST API is different.
|
|
177
|
+
const result = yield restInstance.get("/ibc/apps/transfer/v1/params");
|
|
178
|
+
if (result.status === 200) {
|
|
179
|
+
ibcGoUpdates = true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (_b) { }
|
|
226
184
|
let ibcTransferUpdate = false;
|
|
227
185
|
try {
|
|
228
186
|
if ((!chainInfo.features || !chainInfo.features.includes("ibc-transfer")) &&
|
|
229
187
|
(staragteUpdate ||
|
|
230
188
|
(chainInfo.features && chainInfo.features.includes("stargate")))) {
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
});
|
|
189
|
+
const isIBCGo = ibcGoUpdates ||
|
|
190
|
+
(chainInfo.features && chainInfo.features.includes("ibc-go"));
|
|
234
191
|
// If the chain doesn't have the ibc transfer feature,
|
|
235
192
|
// try to fetch the params of ibc transfer module.
|
|
236
193
|
// assume that it can support the ibc transfer if the params return true, and try to update the features.
|
|
237
|
-
const result = yield restInstance.get(
|
|
194
|
+
const result = yield restInstance.get(isIBCGo
|
|
195
|
+
? "/ibc/apps/transfer/v1/params"
|
|
196
|
+
: "/ibc/applications/transfer/v1beta1/params");
|
|
238
197
|
if (result.data.params.receive_enabled &&
|
|
239
198
|
result.data.params.send_enabled) {
|
|
240
199
|
ibcTransferUpdate = true;
|
|
241
200
|
}
|
|
242
201
|
}
|
|
243
202
|
}
|
|
244
|
-
catch (
|
|
203
|
+
catch (_c) { }
|
|
245
204
|
let noLegacyStdTxUpdate = false;
|
|
246
205
|
try {
|
|
247
206
|
if ((!chainInfo.features ||
|
|
248
207
|
!chainInfo.features.includes("no-legacy-stdTx")) &&
|
|
249
208
|
(staragteUpdate ||
|
|
250
209
|
(chainInfo.features && chainInfo.features.includes("stargate")))) {
|
|
251
|
-
const restInstance = axios_1.default.create({
|
|
252
|
-
baseURL: chainInfo.rest,
|
|
253
|
-
});
|
|
254
210
|
// The chain with above cosmos-sdk@v0.44.0 can't send the legacy stdTx,
|
|
255
211
|
// Assume that it can't send the legacy stdTx if the POST /txs responses "not implemented".
|
|
256
212
|
const result = yield restInstance.post("/txs", undefined, {
|
|
@@ -265,15 +221,33 @@ let ChainUpdaterService = class ChainUpdaterService {
|
|
|
265
221
|
}
|
|
266
222
|
}
|
|
267
223
|
}
|
|
268
|
-
catch (
|
|
224
|
+
catch (_d) { }
|
|
225
|
+
const features = [];
|
|
226
|
+
if (staragteUpdate) {
|
|
227
|
+
features.push("stargate");
|
|
228
|
+
}
|
|
229
|
+
if (ibcGoUpdates) {
|
|
230
|
+
features.push("ibc-go");
|
|
231
|
+
}
|
|
232
|
+
if (ibcTransferUpdate) {
|
|
233
|
+
features.push("ibc-transfer");
|
|
234
|
+
}
|
|
235
|
+
if (noLegacyStdTxUpdate) {
|
|
236
|
+
features.push("no-legacy-stdTx");
|
|
237
|
+
}
|
|
269
238
|
return {
|
|
270
239
|
explicit: version.version < fetchedVersion.version,
|
|
271
|
-
slient: staragteUpdate ||
|
|
240
|
+
slient: staragteUpdate ||
|
|
241
|
+
ibcGoUpdates ||
|
|
242
|
+
ibcTransferUpdate ||
|
|
243
|
+
noLegacyStdTxUpdate,
|
|
244
|
+
chainId: resultChainId,
|
|
245
|
+
features,
|
|
272
246
|
};
|
|
273
247
|
});
|
|
274
248
|
}
|
|
275
249
|
};
|
|
276
|
-
ChainUpdaterService = __decorate([
|
|
250
|
+
ChainUpdaterService = ChainUpdaterService_1 = __decorate([
|
|
277
251
|
tsyringe_1.singleton(),
|
|
278
252
|
__param(0, tsyringe_1.inject(types_1.TYPES.UpdaterStore)),
|
|
279
253
|
__param(1, tsyringe_1.inject(tsyringe_1.delay(() => chains_1.ChainsService))),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/updater/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/updater/service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAoD;AACpD,oCAAiC;AAGjC,kDAA0B;AAE1B,iDAAqD;AACrD,sCAA0C;AAG1C,IAAa,mBAAmB,2BAAhC,MAAa,mBAAmB;IAC9B,YACiD,OAAgB,EAE5C,aAA4B;QAFA,YAAO,GAAP,OAAO,CAAS;QAE5C,kBAAa,GAAb,aAAa,CAAe;IAC9C,CAAC;IAEE,6BAA6B,CACjC,SAAoB;;;YAEpB,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,uBAAuB,CACxD,SAAS,CAAC,OAAO,CAClB,CAAC;YAEF,MAAM,OAAO,GAAG,sBAAa,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACvD,MAAM,cAAc,GAAG,sBAAa,CAAC,KAAK,CACxC,eAAe,CAAC,OAAO,IAAI,SA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,MAAM,QAAQ,GAAa,EAAE,CAAC;YAC9B,IAAI,cAAc,EAAE;gBAClB,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAC3B;YACD,IAAI,YAAY,EAAE;gBAChB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aACzB;YACD,IAAI,iBAAiB,EAAE;gBACrB,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;aAC/B;YACD,IAAI,mBAAmB,EAAE;gBACvB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;aAClC;YAED,OAAO;gBACL,QAAQ,EAAE,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,OAAO;gBAClD,MAAM,EACJ,cAAc;oBACd,YAAY;oBACZ,iBAAiB;oBACjB,mBAAmB;gBAErB,OAAO,EAAE,aAAa;gBACtB,QAAQ;aACT,CAAC;QACJ,CAAC;KAAA;CACF,CAAA;AA/SY,mBAAmB;IAD/B,oBAAS,EAAE;IAGP,WAAA,iBAAM,CAAC,aAAK,CAAC,YAAY,CAAC,CAAA;IAC1B,WAAA,iBAAM,CAAC,gBAAK,CAAC,GAAG,EAAE,CAAC,sBAAa,CAAC,CAAC,CAAA;6CACD,sBAAa;GAJtC,mBAAmB,CA+S/B;AA/SY,kDAAmB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keplr-wallet/background",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.9",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"author": "chainapsis",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@cosmjs/launchpad": "^0.24.0-alpha.25",
|
|
28
28
|
"@cosmjs/proto-signing": "^0.24.0-alpha.25",
|
|
29
|
-
"@keplr-wallet/common": "^0.9.
|
|
30
|
-
"@keplr-wallet/cosmos": "^0.9.
|
|
31
|
-
"@keplr-wallet/crypto": "^0.9.
|
|
29
|
+
"@keplr-wallet/common": "^0.9.9",
|
|
30
|
+
"@keplr-wallet/cosmos": "^0.9.9",
|
|
31
|
+
"@keplr-wallet/crypto": "^0.9.9",
|
|
32
32
|
"@keplr-wallet/popup": "^0.9.6",
|
|
33
33
|
"@keplr-wallet/router": "^0.9.6",
|
|
34
|
-
"@keplr-wallet/types": "^0.9.
|
|
35
|
-
"@keplr-wallet/unit": "^0.9.
|
|
34
|
+
"@keplr-wallet/types": "^0.9.9",
|
|
35
|
+
"@keplr-wallet/unit": "^0.9.9",
|
|
36
36
|
"@ledgerhq/hw-transport": "^6.3.0",
|
|
37
37
|
"@ledgerhq/hw-transport-webhid": "^6.3.0",
|
|
38
38
|
"@ledgerhq/hw-transport-webusb": "^6.3.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"secretjs": "^0.17.0",
|
|
52
52
|
"tsyringe": "^4.4.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "ead06cf2f414219770f0e27a8ab69d166a392b27"
|
|
55
55
|
}
|
package/src/updater/service.ts
CHANGED
|
@@ -60,136 +60,46 @@ export class ChainUpdaterService {
|
|
|
60
60
|
// If chain id is not fomatted as {chainID}-{version},
|
|
61
61
|
// there is no way to deal with the updated chain id.
|
|
62
62
|
if (!ChainIdHelper.hasChainVersion(chainInfo.chainId)) {
|
|
63
|
-
return
|
|
63
|
+
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const
|
|
67
|
-
baseURL: chainInfo.rpc,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// Get the status to get the chain id.
|
|
71
|
-
const result = await instance.get<{
|
|
72
|
-
result: {
|
|
73
|
-
node_info: {
|
|
74
|
-
network: string;
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
}>("/status");
|
|
78
|
-
|
|
79
|
-
const currentVersion = ChainIdHelper.parse(chainInfo.chainId);
|
|
80
|
-
const fetchedChainId = result.data.result.node_info.network;
|
|
81
|
-
const fetchedVersion = ChainIdHelper.parse(fetchedChainId);
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
currentVersion.identifier === fetchedVersion.identifier &&
|
|
85
|
-
currentVersion.version < fetchedVersion.version
|
|
86
|
-
) {
|
|
87
|
-
await this.saveChainProperty(currentVersion.identifier, {
|
|
88
|
-
chainId: fetchedChainId,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let staragteUpdate = false;
|
|
93
|
-
try {
|
|
94
|
-
if (!chainInfo.features || !chainInfo.features.includes("stargate")) {
|
|
95
|
-
const restInstance = Axios.create({
|
|
96
|
-
baseURL: chainInfo.rest,
|
|
97
|
-
});
|
|
66
|
+
const updates = await ChainUpdaterService.checkChainUpdate(chainInfo);
|
|
98
67
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// assume that it can support the stargate and try to update the features.
|
|
102
|
-
await restInstance.get("/cosmos/base/tendermint/v1beta1/node_info");
|
|
68
|
+
if (updates.explicit || updates.slient) {
|
|
69
|
+
const currentVersion = ChainIdHelper.parse(chainInfo.chainId);
|
|
103
70
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
71
|
+
if (updates.chainId) {
|
|
72
|
+
const fetchedChainId = updates.chainId;
|
|
73
|
+
const fetchedVersion = ChainIdHelper.parse(fetchedChainId);
|
|
107
74
|
|
|
108
|
-
await this.saveChainProperty(currentVersion.identifier, {
|
|
109
|
-
features: (savedChainProperty.features ?? []).concat(["stargate"]),
|
|
110
|
-
});
|
|
111
|
-
staragteUpdate = true;
|
|
112
|
-
}
|
|
113
|
-
} catch {}
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
if (
|
|
117
|
-
(!chainInfo.features || !chainInfo.features.includes("ibc-transfer")) &&
|
|
118
|
-
(staragteUpdate ||
|
|
119
|
-
(chainInfo.features && chainInfo.features.includes("stargate")))
|
|
120
|
-
) {
|
|
121
|
-
const restInstance = Axios.create({
|
|
122
|
-
baseURL: chainInfo.rest,
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
// If the chain doesn't have the ibc transfer feature,
|
|
126
|
-
// try to fetch the params of ibc transfer module.
|
|
127
|
-
// assume that it can support the ibc transfer if the params return true, and try to update the features.
|
|
128
|
-
const result = await restInstance.get<{
|
|
129
|
-
params: {
|
|
130
|
-
receive_enabled: boolean;
|
|
131
|
-
send_enabled: boolean;
|
|
132
|
-
};
|
|
133
|
-
}>("/ibc/applications/transfer/v1beta1/params");
|
|
134
75
|
if (
|
|
135
|
-
|
|
136
|
-
|
|
76
|
+
currentVersion.identifier === fetchedVersion.identifier &&
|
|
77
|
+
currentVersion.version < fetchedVersion.version
|
|
137
78
|
) {
|
|
138
|
-
const savedChainProperty = await this.getUpdatedChainProperty(
|
|
139
|
-
chainInfo.chainId
|
|
140
|
-
);
|
|
141
|
-
|
|
142
79
|
await this.saveChainProperty(currentVersion.identifier, {
|
|
143
|
-
|
|
144
|
-
"ibc-transfer",
|
|
145
|
-
]),
|
|
80
|
+
chainId: fetchedChainId,
|
|
146
81
|
});
|
|
147
82
|
}
|
|
148
83
|
}
|
|
149
|
-
} catch {}
|
|
150
84
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
(staragteUpdate ||
|
|
156
|
-
(chainInfo.features && chainInfo.features.includes("stargate")))
|
|
157
|
-
) {
|
|
158
|
-
const restInstance = Axios.create({
|
|
159
|
-
baseURL: chainInfo.rest,
|
|
160
|
-
});
|
|
85
|
+
if (updates.features && updates.features.length > 0) {
|
|
86
|
+
const savedChainProperty = await this.getUpdatedChainProperty(
|
|
87
|
+
chainInfo.chainId
|
|
88
|
+
);
|
|
161
89
|
|
|
162
|
-
|
|
163
|
-
// Assume that it can't send the legacy stdTx if the POST /txs responses "not implemented".
|
|
164
|
-
const result = await restInstance.post<
|
|
165
|
-
| {
|
|
166
|
-
code: 12;
|
|
167
|
-
message: "Not Implemented";
|
|
168
|
-
details: [];
|
|
169
|
-
}
|
|
170
|
-
| any
|
|
171
|
-
>("/txs", undefined, {
|
|
172
|
-
validateStatus: (status) => {
|
|
173
|
-
return (status >= 200 && status < 300) || status === 501;
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
if (
|
|
177
|
-
result.status === 501 &&
|
|
178
|
-
result.data.code === 12 &&
|
|
179
|
-
result.data.message === "Not Implemented"
|
|
180
|
-
) {
|
|
181
|
-
const savedChainProperty = await this.getUpdatedChainProperty(
|
|
182
|
-
chainInfo.chainId
|
|
183
|
-
);
|
|
90
|
+
const updateFeatures = savedChainProperty.features ?? [];
|
|
184
91
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
});
|
|
92
|
+
for (const feature of updates.features) {
|
|
93
|
+
if (!updateFeatures.includes(feature)) {
|
|
94
|
+
updateFeatures.push(feature);
|
|
95
|
+
}
|
|
190
96
|
}
|
|
97
|
+
|
|
98
|
+
await this.saveChainProperty(currentVersion.identifier, {
|
|
99
|
+
features: updateFeatures,
|
|
100
|
+
});
|
|
191
101
|
}
|
|
192
|
-
}
|
|
102
|
+
}
|
|
193
103
|
}
|
|
194
104
|
|
|
195
105
|
private async getUpdatedChainProperty(
|
|
@@ -232,6 +142,9 @@ export class ChainUpdaterService {
|
|
|
232
142
|
): Promise<{
|
|
233
143
|
explicit: boolean;
|
|
234
144
|
slient: boolean;
|
|
145
|
+
|
|
146
|
+
chainId?: string;
|
|
147
|
+
features?: string[];
|
|
235
148
|
}> {
|
|
236
149
|
const chainId = chainInfo.chainId;
|
|
237
150
|
|
|
@@ -270,13 +183,13 @@ export class ChainUpdaterService {
|
|
|
270
183
|
};
|
|
271
184
|
}
|
|
272
185
|
|
|
186
|
+
const restInstance = Axios.create({
|
|
187
|
+
baseURL: chainInfo.rest,
|
|
188
|
+
});
|
|
189
|
+
|
|
273
190
|
let staragteUpdate = false;
|
|
274
191
|
try {
|
|
275
192
|
if (!chainInfo.features || !chainInfo.features.includes("stargate")) {
|
|
276
|
-
const restInstance = Axios.create({
|
|
277
|
-
baseURL: chainInfo.rest,
|
|
278
|
-
});
|
|
279
|
-
|
|
280
193
|
// If the chain doesn't have the stargate feature,
|
|
281
194
|
// but it can use the GRPC HTTP Gateway,
|
|
282
195
|
// assume that it can support the stargate and try to update the features.
|
|
@@ -285,6 +198,28 @@ export class ChainUpdaterService {
|
|
|
285
198
|
}
|
|
286
199
|
} catch {}
|
|
287
200
|
|
|
201
|
+
let ibcGoUpdates = false;
|
|
202
|
+
try {
|
|
203
|
+
if (
|
|
204
|
+
(!chainInfo.features || !chainInfo.features.includes("ibc-go")) &&
|
|
205
|
+
(staragteUpdate ||
|
|
206
|
+
(chainInfo.features && chainInfo.features.includes("stargate")))
|
|
207
|
+
) {
|
|
208
|
+
// If the chain uses the ibc-go module separated from the cosmos-sdk,
|
|
209
|
+
// we need to check it because the REST API is different.
|
|
210
|
+
const result = await restInstance.get<{
|
|
211
|
+
params: {
|
|
212
|
+
receive_enabled: boolean;
|
|
213
|
+
send_enabled: boolean;
|
|
214
|
+
};
|
|
215
|
+
}>("/ibc/apps/transfer/v1/params");
|
|
216
|
+
|
|
217
|
+
if (result.status === 200) {
|
|
218
|
+
ibcGoUpdates = true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
} catch {}
|
|
222
|
+
|
|
288
223
|
let ibcTransferUpdate = false;
|
|
289
224
|
try {
|
|
290
225
|
if (
|
|
@@ -292,9 +227,9 @@ export class ChainUpdaterService {
|
|
|
292
227
|
(staragteUpdate ||
|
|
293
228
|
(chainInfo.features && chainInfo.features.includes("stargate")))
|
|
294
229
|
) {
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
230
|
+
const isIBCGo =
|
|
231
|
+
ibcGoUpdates ||
|
|
232
|
+
(chainInfo.features && chainInfo.features.includes("ibc-go"));
|
|
298
233
|
|
|
299
234
|
// If the chain doesn't have the ibc transfer feature,
|
|
300
235
|
// try to fetch the params of ibc transfer module.
|
|
@@ -304,7 +239,11 @@ export class ChainUpdaterService {
|
|
|
304
239
|
receive_enabled: boolean;
|
|
305
240
|
send_enabled: boolean;
|
|
306
241
|
};
|
|
307
|
-
}>(
|
|
242
|
+
}>(
|
|
243
|
+
isIBCGo
|
|
244
|
+
? "/ibc/apps/transfer/v1/params"
|
|
245
|
+
: "/ibc/applications/transfer/v1beta1/params"
|
|
246
|
+
);
|
|
308
247
|
if (
|
|
309
248
|
result.data.params.receive_enabled &&
|
|
310
249
|
result.data.params.send_enabled
|
|
@@ -322,10 +261,6 @@ export class ChainUpdaterService {
|
|
|
322
261
|
(staragteUpdate ||
|
|
323
262
|
(chainInfo.features && chainInfo.features.includes("stargate")))
|
|
324
263
|
) {
|
|
325
|
-
const restInstance = Axios.create({
|
|
326
|
-
baseURL: chainInfo.rest,
|
|
327
|
-
});
|
|
328
|
-
|
|
329
264
|
// The chain with above cosmos-sdk@v0.44.0 can't send the legacy stdTx,
|
|
330
265
|
// Assume that it can't send the legacy stdTx if the POST /txs responses "not implemented".
|
|
331
266
|
const result = await restInstance.post<
|
|
@@ -350,9 +285,30 @@ export class ChainUpdaterService {
|
|
|
350
285
|
}
|
|
351
286
|
} catch {}
|
|
352
287
|
|
|
288
|
+
const features: string[] = [];
|
|
289
|
+
if (staragteUpdate) {
|
|
290
|
+
features.push("stargate");
|
|
291
|
+
}
|
|
292
|
+
if (ibcGoUpdates) {
|
|
293
|
+
features.push("ibc-go");
|
|
294
|
+
}
|
|
295
|
+
if (ibcTransferUpdate) {
|
|
296
|
+
features.push("ibc-transfer");
|
|
297
|
+
}
|
|
298
|
+
if (noLegacyStdTxUpdate) {
|
|
299
|
+
features.push("no-legacy-stdTx");
|
|
300
|
+
}
|
|
301
|
+
|
|
353
302
|
return {
|
|
354
303
|
explicit: version.version < fetchedVersion.version,
|
|
355
|
-
slient:
|
|
304
|
+
slient:
|
|
305
|
+
staragteUpdate ||
|
|
306
|
+
ibcGoUpdates ||
|
|
307
|
+
ibcTransferUpdate ||
|
|
308
|
+
noLegacyStdTxUpdate,
|
|
309
|
+
|
|
310
|
+
chainId: resultChainId,
|
|
311
|
+
features,
|
|
356
312
|
};
|
|
357
313
|
}
|
|
358
314
|
}
|