@xchainjs/xchain-thorchain 0.21.0 → 0.21.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 +11 -0
- package/lib/index.esm.js +18 -5
- package/lib/index.js +17 -4
- package/lib/util.d.ts +13 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -198,6 +198,19 @@ var getPrefix = function (network) {
|
|
|
198
198
|
return 'tthor';
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
|
+
var ChainId;
|
|
202
|
+
(function (ChainId) {
|
|
203
|
+
ChainId["Mainnet"] = "thorchain";
|
|
204
|
+
ChainId["Stagenet"] = "thorchain-stagenet";
|
|
205
|
+
ChainId["Testnet"] = "thorchain-v1";
|
|
206
|
+
})(ChainId || (ChainId = {}));
|
|
207
|
+
/**
|
|
208
|
+
* Type guard to check whether string is a valid `ChainId`
|
|
209
|
+
*
|
|
210
|
+
* @param {string} id Chain id.
|
|
211
|
+
* @returns {boolean} `true` or `false`
|
|
212
|
+
*/
|
|
213
|
+
var isChainId = function (id) { return Object.values(ChainId).includes(id); };
|
|
201
214
|
/**
|
|
202
215
|
* Get the chain id.
|
|
203
216
|
*
|
|
@@ -208,11 +221,11 @@ var getPrefix = function (network) {
|
|
|
208
221
|
var getChainId = function (network) {
|
|
209
222
|
switch (network) {
|
|
210
223
|
case Network.Mainnet:
|
|
211
|
-
return
|
|
224
|
+
return ChainId.Mainnet;
|
|
212
225
|
case Network.Stagenet:
|
|
213
|
-
return
|
|
226
|
+
return ChainId.Stagenet;
|
|
214
227
|
case Network.Testnet:
|
|
215
|
-
return
|
|
228
|
+
return ChainId.Testnet;
|
|
216
229
|
}
|
|
217
230
|
};
|
|
218
231
|
/**
|
|
@@ -306,7 +319,7 @@ var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0,
|
|
|
306
319
|
case 1:
|
|
307
320
|
data = (_c.sent()).data;
|
|
308
321
|
chainId = data.default_node_info.network;
|
|
309
|
-
if (!chainId || !(chainId
|
|
322
|
+
if (!chainId || !isChainId(chainId))
|
|
310
323
|
throw new Error('invalid network');
|
|
311
324
|
return [4 /*yield*/, axios.post(nodeUrl + "/thorchain/deposit", {
|
|
312
325
|
coins: msgNativeTx.coins,
|
|
@@ -1011,4 +1024,4 @@ var Client = /** @class */ (function () {
|
|
|
1011
1024
|
return Client;
|
|
1012
1025
|
}());
|
|
1013
1026
|
|
|
1014
|
-
export { Client, DECIMAL, DEFAULT_GAS_VALUE, DEPOSIT_GAS_VALUE, MAX_TX_COUNT, MsgNativeTx, assetFromDenom, buildDepositTx, getBalance, getChainId, getDefaultClientUrl, getDefaultExplorerUrls, getDefaultFees, getDenom, getDepositTxDataFromLogs, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getTxType, isAssetRuneNative, isBroadcastSuccess, isMsgMultiSend, isMsgSend, msgNativeTxFromJson, registerCodecs };
|
|
1027
|
+
export { ChainId, Client, DECIMAL, DEFAULT_GAS_VALUE, DEPOSIT_GAS_VALUE, MAX_TX_COUNT, MsgNativeTx, assetFromDenom, buildDepositTx, getBalance, getChainId, getDefaultClientUrl, getDefaultExplorerUrls, getDefaultFees, getDenom, getDepositTxDataFromLogs, getExplorerAddressUrl, getExplorerTxUrl, getExplorerUrl, getPrefix, getTxType, isAssetRuneNative, isBroadcastSuccess, isChainId, isMsgMultiSend, isMsgSend, msgNativeTxFromJson, registerCodecs };
|
package/lib/index.js
CHANGED
|
@@ -206,6 +206,18 @@ var getPrefix = function (network) {
|
|
|
206
206
|
return 'tthor';
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
|
+
(function (ChainId) {
|
|
210
|
+
ChainId["Mainnet"] = "thorchain";
|
|
211
|
+
ChainId["Stagenet"] = "thorchain-stagenet";
|
|
212
|
+
ChainId["Testnet"] = "thorchain-v1";
|
|
213
|
+
})(exports.ChainId || (exports.ChainId = {}));
|
|
214
|
+
/**
|
|
215
|
+
* Type guard to check whether string is a valid `ChainId`
|
|
216
|
+
*
|
|
217
|
+
* @param {string} id Chain id.
|
|
218
|
+
* @returns {boolean} `true` or `false`
|
|
219
|
+
*/
|
|
220
|
+
var isChainId = function (id) { return Object.values(exports.ChainId).includes(id); };
|
|
209
221
|
/**
|
|
210
222
|
* Get the chain id.
|
|
211
223
|
*
|
|
@@ -216,11 +228,11 @@ var getPrefix = function (network) {
|
|
|
216
228
|
var getChainId = function (network) {
|
|
217
229
|
switch (network) {
|
|
218
230
|
case xchainClient.Network.Mainnet:
|
|
219
|
-
return
|
|
231
|
+
return exports.ChainId.Mainnet;
|
|
220
232
|
case xchainClient.Network.Stagenet:
|
|
221
|
-
return
|
|
233
|
+
return exports.ChainId.Stagenet;
|
|
222
234
|
case xchainClient.Network.Testnet:
|
|
223
|
-
return
|
|
235
|
+
return exports.ChainId.Testnet;
|
|
224
236
|
}
|
|
225
237
|
};
|
|
226
238
|
/**
|
|
@@ -314,7 +326,7 @@ var buildDepositTx = function (msgNativeTx, nodeUrl) { return __awaiter(void 0,
|
|
|
314
326
|
case 1:
|
|
315
327
|
data = (_c.sent()).data;
|
|
316
328
|
chainId = data.default_node_info.network;
|
|
317
|
-
if (!chainId || !(chainId
|
|
329
|
+
if (!chainId || !isChainId(chainId))
|
|
318
330
|
throw new Error('invalid network');
|
|
319
331
|
return [4 /*yield*/, axios__default['default'].post(nodeUrl + "/thorchain/deposit", {
|
|
320
332
|
coins: msgNativeTx.coins,
|
|
@@ -1041,6 +1053,7 @@ exports.getPrefix = getPrefix;
|
|
|
1041
1053
|
exports.getTxType = getTxType;
|
|
1042
1054
|
exports.isAssetRuneNative = isAssetRuneNative;
|
|
1043
1055
|
exports.isBroadcastSuccess = isBroadcastSuccess;
|
|
1056
|
+
exports.isChainId = isChainId;
|
|
1044
1057
|
exports.isMsgMultiSend = isMsgMultiSend;
|
|
1045
1058
|
exports.isMsgSend = isMsgSend;
|
|
1046
1059
|
exports.msgNativeTxFromJson = msgNativeTxFromJson;
|
package/lib/util.d.ts
CHANGED
|
@@ -60,6 +60,18 @@ export declare const isBroadcastSuccess: (response: unknown) => boolean;
|
|
|
60
60
|
*
|
|
61
61
|
**/
|
|
62
62
|
export declare const getPrefix: (network: Network) => "thor" | "sthor" | "tthor";
|
|
63
|
+
export declare enum ChainId {
|
|
64
|
+
Mainnet = "thorchain",
|
|
65
|
+
Stagenet = "thorchain-stagenet",
|
|
66
|
+
Testnet = "thorchain-v1"
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Type guard to check whether string is a valid `ChainId`
|
|
70
|
+
*
|
|
71
|
+
* @param {string} id Chain id.
|
|
72
|
+
* @returns {boolean} `true` or `false`
|
|
73
|
+
*/
|
|
74
|
+
export declare const isChainId: (id: string) => id is ChainId;
|
|
63
75
|
/**
|
|
64
76
|
* Get the chain id.
|
|
65
77
|
*
|
|
@@ -67,7 +79,7 @@ export declare const getPrefix: (network: Network) => "thor" | "sthor" | "tthor"
|
|
|
67
79
|
* @returns {string} The chain id based on the network.
|
|
68
80
|
*
|
|
69
81
|
*/
|
|
70
|
-
export declare const getChainId: (network: Network) =>
|
|
82
|
+
export declare const getChainId: (network: Network) => ChainId;
|
|
71
83
|
/**
|
|
72
84
|
* Register Codecs based on the prefix.
|
|
73
85
|
*
|