carbon-js-sdk 0.7.0-beta.1 → 0.7.0
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/lib/CarbonSDK.js
CHANGED
|
@@ -153,12 +153,23 @@ class CarbonSDK {
|
|
|
153
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
154
|
const network = (_a = opts.network) !== null && _a !== void 0 ? _a : constant_1.DEFAULT_NETWORK;
|
|
155
155
|
const configOverride = (_b = opts.config) !== null && _b !== void 0 ? _b : {};
|
|
156
|
-
const networkConfig = util_1.GenericUtils.overrideConfig(constant_1.NetworkConfigs[network], configOverride);
|
|
157
|
-
const batchQueryClient = new clients.BatchQueryClient(networkConfig.tmRpcUrl);
|
|
158
|
-
const tmClient = (_c = opts.tmClient) !== null && _c !== void 0 ? _c : util_1.GenericUtils.modifyTmClient(yield tendermint_rpc_1.Tendermint34Client.create(batchQueryClient));
|
|
159
156
|
const defaultTimeoutBlocks = opts.defaultTimeoutBlocks;
|
|
160
|
-
const
|
|
157
|
+
const networkConfig = util_1.GenericUtils.overrideConfig(constant_1.NetworkConfigs[network], configOverride);
|
|
158
|
+
const tmClient = (_c = opts.tmClient) !== null && _c !== void 0 ? _c : new tendermint_rpc_1.Tendermint34Client(new clients.BatchQueryClient(networkConfig.tmRpcUrl)); // fallback tmClient
|
|
159
|
+
let chainId = networkConfig.chainId; // fallback chain ID
|
|
160
|
+
let normalInit = true;
|
|
161
|
+
try {
|
|
162
|
+
chainId = (_d = (yield tmClient.status())) === null || _d === void 0 ? void 0 : _d.nodeInfo.network;
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.warn("tm client init failed");
|
|
166
|
+
console.error(error);
|
|
167
|
+
normalInit = false;
|
|
168
|
+
}
|
|
169
|
+
console.log("normal init", normalInit);
|
|
161
170
|
const sdk = new CarbonSDK({ network, config: configOverride, tmClient, defaultTimeoutBlocks, chainId, useTmAbciQuery: opts.useTmAbciQuery });
|
|
171
|
+
if (!normalInit)
|
|
172
|
+
return sdk;
|
|
162
173
|
if (opts.wallet) {
|
|
163
174
|
yield sdk.connect(opts.wallet);
|
|
164
175
|
}
|
|
@@ -105,8 +105,6 @@ declare class CarbonQueryClient {
|
|
|
105
105
|
evmmerge: EvmMergeQueryClient;
|
|
106
106
|
evmbank: EvmBankQueryClient;
|
|
107
107
|
erc20: ERC20QueryClient;
|
|
108
|
-
private readonly baseClient;
|
|
109
|
-
private readonly tmClient;
|
|
110
108
|
constructor(opts: CarbonQueryClientOpts);
|
|
111
109
|
}
|
|
112
110
|
export default CarbonQueryClient;
|
|
@@ -55,8 +55,6 @@ class CarbonQueryClient {
|
|
|
55
55
|
constructor(opts) {
|
|
56
56
|
var _a;
|
|
57
57
|
const rpcClient = (_a = opts.grpcClient) !== null && _a !== void 0 ? _a : stargate_1.createProtobufRpcClient(new stargate_1.QueryClient(opts.tmClient));
|
|
58
|
-
this.tmClient = opts.tmClient;
|
|
59
|
-
this.baseClient = rpcClient;
|
|
60
58
|
this.chain = BlockchainClient_1.default.connectWithTm(opts.tmClient);
|
|
61
59
|
this.adl = new query_1.QueryClientImpl(rpcClient);
|
|
62
60
|
this.alliance = new query_44.QueryClientImpl(rpcClient);
|
package/lib/constant/network.js
CHANGED
|
@@ -25,6 +25,7 @@ exports.DEFAULT_NETWORK = Network.MainNet;
|
|
|
25
25
|
exports.NetworkConfigs = {
|
|
26
26
|
[Network.MainNet]: {
|
|
27
27
|
network: Network.MainNet,
|
|
28
|
+
chainId: "carbon-1",
|
|
28
29
|
tmRpcUrl: "https://tm-api.carbon.network/",
|
|
29
30
|
tmWsUrl: "wss://tm-api.carbon.network/",
|
|
30
31
|
restUrl: "https://api.carbon.network",
|
|
@@ -100,6 +101,7 @@ exports.NetworkConfigs = {
|
|
|
100
101
|
},
|
|
101
102
|
[Network.TestNet]: {
|
|
102
103
|
network: Network.TestNet,
|
|
104
|
+
chainId: "carbon-testnet-42069",
|
|
103
105
|
tmRpcUrl: "https://test-tm-api.carbon.network",
|
|
104
106
|
tmWsUrl: "wss://test-tm-api.carbon.network",
|
|
105
107
|
restUrl: "https://test-api.carbon.network",
|
|
@@ -175,6 +177,7 @@ exports.NetworkConfigs = {
|
|
|
175
177
|
},
|
|
176
178
|
[Network.DevNet]: {
|
|
177
179
|
network: Network.DevNet,
|
|
180
|
+
chainId: "carbon-devnet-39911",
|
|
178
181
|
tmRpcUrl: "https://dev-tm-api.carbon.network",
|
|
179
182
|
tmWsUrl: "wss://dev-tm-api.carbon.network",
|
|
180
183
|
restUrl: "https://dev-api.carbon.network",
|
|
@@ -250,6 +253,7 @@ exports.NetworkConfigs = {
|
|
|
250
253
|
},
|
|
251
254
|
[Network.LocalHost]: {
|
|
252
255
|
network: Network.LocalHost,
|
|
256
|
+
chainId: "carbon-localhost",
|
|
253
257
|
tmRpcUrl: "http://localhost:26657",
|
|
254
258
|
tmWsUrl: "ws://localhost:26657",
|
|
255
259
|
restUrl: "http://localhost:1317",
|
|
@@ -49,7 +49,9 @@ class RootStore {
|
|
|
49
49
|
})();
|
|
50
50
|
function suggestChainFromWindow(keplr, chainInfo) {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const info = Object.assign(Object.assign(
|
|
52
|
+
const info = Object.assign(Object.assign(Object.assign({}, chainInfo), chainInfo.stakeCurrency && ({
|
|
53
|
+
stakeCurrency: Object.assign(Object.assign({}, chainInfo.stakeCurrency), { coinImageUrl: chainInfo.stakeCurrency.coinImageUrl ? window.origin + chainInfo.stakeCurrency.coinImageUrl : undefined }),
|
|
54
|
+
})), { currencies: chainInfo.currencies.map((currency) => (Object.assign(Object.assign({}, currency), { coinImageUrl: currency.coinImageUrl ? window.origin + currency.coinImageUrl : undefined }))), feeCurrencies: chainInfo.feeCurrencies.map((currency) => (Object.assign(Object.assign({}, currency), { coinImageUrl: currency.coinImageUrl ? window.origin + currency.coinImageUrl : undefined }))) });
|
|
53
55
|
yield keplr.experimentalSuggestChain(info);
|
|
54
56
|
});
|
|
55
57
|
}
|