Skip to content

Commit 44144f1

Browse files
authored
Merge pull request #503 from cosmology-tech/feat/tendermint34Client_to_cometClient
feat/use Comet Client
2 parents 25d5b5d + c951142 commit 44144f1

File tree

11 files changed

+215
-18
lines changed

11 files changed

+215
-18
lines changed

packages/ast/src/clients/rpc/scoped/__snapshots__/rpc.test.ts.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ exports[`createScopedRpcFactory 1`] = `
2222
});"
2323
`;
2424

25+
exports[`createScopedRpcFactoryWithComet 1`] = `
26+
"export const createRpcFactorizzleWithComet = async ({
27+
rpc
28+
}: {
29+
rpc: Rpc;
30+
}) => {
31+
return {
32+
cosmos: {
33+
bank: {
34+
v1beta1: (await import("./proto/cosmos/bank/v1beta1/query.lcd")).createClientImpl(rpc)
35+
},
36+
gov: {
37+
v1beta1: (await import("./proto/cosmos/bank/v1beta1/query.lcd")).createClientImpl(rpc)
38+
}
39+
},
40+
osmosis: {
41+
gamm: {
42+
v1beta1: (await import("./proto/cosmos/bank/v1beta1/query.lcd")).createClientImpl(rpc)
43+
}
44+
}
45+
};
46+
};"
47+
`;
48+
2549
exports[`createScopedRpcFactoryWithoutTm 1`] = `
2650
"export const createRpcFactorizzleWithoutTM = async ({
2751
rpc

packages/ast/src/clients/rpc/scoped/rpc.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,25 @@ it('createScopedRpcFactoryWithoutTm', async () => {
7373
'createRpcFactorizzleWithoutTM',
7474
))
7575
});
76+
77+
it('createScopedRpcFactoryWithComet', async () => {
78+
const context = getGenericParseContext();
79+
context.options!.rpcClients!.useConnectComet = true;
80+
expectCode(createScopedRpcTmFactory(context, {
81+
cosmos: {
82+
bank: {
83+
v1beta1: "./proto/cosmos/bank/v1beta1/query.lcd"
84+
},
85+
gov: {
86+
v1beta1: "./proto/cosmos/bank/v1beta1/query.lcd"
87+
},
88+
},
89+
osmosis: {
90+
gamm: {
91+
v1beta1: "./proto/cosmos/bank/v1beta1/query.lcd"
92+
}
93+
}
94+
},
95+
'createRpcFactorizzleWithComet',
96+
))
97+
});

packages/ast/src/clients/rpc/scoped/rpc.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export const createScopedRpcTmFactory = (
191191
obj: object,
192192
identifier: string
193193
) => {
194+
const newClientType = context.pluginValue('rpcClients.useConnectComet');
194195
const extensions = context.pluginValue('rpcClients.extensions');
195196
let functionParams;
196197
const returnStatement = t.returnStatement(
@@ -200,10 +201,34 @@ export const createScopedRpcTmFactory = (
200201
extensions ? 'client' : 'rpc',
201202
)
202203
);
204+
203205
let functionStatements;
206+
let awaitClientCreation;
207+
// TODO: remove tendermint34client and options if not needed
208+
if (newClientType) {
209+
// use connectComet for dynamic client
210+
context.addUtil('connectComet');
211+
awaitClientCreation = t.callExpression(
212+
t.identifier('connectComet'),
213+
[
214+
t.identifier('rpcEndpoint')
215+
]
216+
)
217+
} else {
218+
// use tendermint34 client
219+
context.addUtil('Tendermint34Client');
220+
awaitClientCreation = t.callExpression(
221+
t.memberExpression(
222+
t.identifier('Tendermint34Client'),
223+
t.identifier('connect')
224+
),
225+
[
226+
t.identifier('rpcEndpoint')
227+
]
228+
)
229+
}
204230

205231
if(extensions){
206-
context.addUtil('Tendermint34Client');
207232
context.addUtil('HttpEndpoint');
208233
context.addUtil('QueryClient');
209234

@@ -239,15 +264,7 @@ export const createScopedRpcTmFactory = (
239264
t.variableDeclarator(
240265
t.identifier('tmClient'),
241266
t.awaitExpression(
242-
t.callExpression(
243-
t.memberExpression(
244-
t.identifier('Tendermint34Client'),
245-
t.identifier('connect')
246-
),
247-
[
248-
t.identifier('rpcEndpoint')
249-
]
250-
)
267+
awaitClientCreation
251268
)
252269
)
253270
]),

packages/starship/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@
9797
"typescript": "^5.0.4"
9898
},
9999
"dependencies": {
100-
"@cosmjs/amino": "0.29.3",
101-
"@cosmjs/proto-signing": "0.29.3",
102-
"@cosmjs/stargate": "0.29.3",
103-
"@cosmjs/tendermint-rpc": "^0.29.3",
100+
"@cosmjs/amino": "^0.32.0",
101+
"@cosmjs/proto-signing": "^0.32.0",
102+
"@cosmjs/stargate": "^0.32.0",
103+
"@cosmjs/tendermint-rpc": "^0.32.0",
104104
"@cosmology/core": "1.23.0",
105105
"@cosmology/lcd": "^0.13.3",
106106
"@keplr-wallet/unit": "0.11.56",

packages/telescope/src/helpers/external.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const external = `import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate'
2-
import { Tendermint34Client, HttpEndpoint } from "@cosmjs/tendermint-rpc";
2+
import { connectComet, HttpEndpoint } from "@cosmjs/tendermint-rpc";
33
44
const _rpcClients: Record<string, ProtobufRpcClient> = {};
55
@@ -18,9 +18,9 @@ export const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {
1818
if (_rpcClients.hasOwnProperty(key)) {
1919
return _rpcClients[key];
2020
}
21-
const tmClient = await Tendermint34Client.connect(rpcEndpoint);
21+
const cometClient = await connectComet(rpcEndpoint);
2222
//@ts-ignore
23-
const client = new QueryClient(tmClient);
23+
const client = new QueryClient(cometClient);
2424
const rpc = createProtobufRpcClient(client);
2525
_rpcClients[key] = rpc;
2626
return rpc;

packages/telescope/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const UTILS = {
1919
base64FromBytes: '__helpers__',
2020
bytesFromBase64: '__helpers__',
2121
BrowserHeaders: 'browser-headers',
22+
connectComet: '@cosmjs/tendermint-rpc',
2223
Decimal: '@cosmjs/math',
2324
createProtobufRpcClient: '@cosmjs/stargate',
2425
Pubkey: '@cosmjs/amino',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export declare const external = "import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate'\nimport { Tendermint34Client, HttpEndpoint } from \"@cosmjs/tendermint-rpc\";\n\nconst _rpcClients: Record<string, ProtobufRpcClient> = {};\n\nexport const getRpcEndpointKey = (rpcEndpoint: string | HttpEndpoint) => {\n if (typeof rpcEndpoint === 'string') {\n return rpcEndpoint;\n } else if (!!rpcEndpoint) {\n //@ts-ignore \n return rpcEndpoint.url;\n }\n}\n\nexport const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const key = getRpcEndpointKey(rpcEndpoint);\n if (!key) return;\n if (_rpcClients.hasOwnProperty(key)) {\n return _rpcClients[key];\n }\n const tmClient = await Tendermint34Client.connect(rpcEndpoint);\n //@ts-ignore\n const client = new QueryClient(tmClient);\n const rpc = createProtobufRpcClient(client);\n _rpcClients[key] = rpc;\n return rpc;\n}\n";
1+
export declare const external = "import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate'\nimport { connectComet, HttpEndpoint } from \"@cosmjs/tendermint-rpc\";\n\nconst _rpcClients: Record<string, ProtobufRpcClient> = {};\n\nexport const getRpcEndpointKey = (rpcEndpoint: string | HttpEndpoint) => {\n if (typeof rpcEndpoint === 'string') {\n return rpcEndpoint;\n } else if (!!rpcEndpoint) {\n //@ts-ignore \n return rpcEndpoint.url;\n }\n}\n\nexport const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => {\n const key = getRpcEndpointKey(rpcEndpoint);\n if (!key) return;\n if (_rpcClients.hasOwnProperty(key)) {\n return _rpcClients[key];\n }\n const cometClient = await connectComet(rpcEndpoint);\n //@ts-ignore\n const client = new QueryClient(cometClient);\n const rpc = createProtobufRpcClient(client);\n _rpcClients[key] = rpc;\n return rpc;\n}\n";

packages/telescope/types/utils/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export declare const UTILS: {
1313
base64FromBytes: string;
1414
bytesFromBase64: string;
1515
BrowserHeaders: string;
16+
connectComet: string;
1617
Decimal: string;
1718
createProtobufRpcClient: string;
1819
Pubkey: string;

packages/types/src/telescope.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ interface TelescopeOpts {
219219
};
220220
}
221221
}[];
222+
useConnectComet?: boolean;
222223
};
223224
reactQuery?: {
224225
enabled: boolean;

packages/types/types/telescope.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ interface TelescopeOpts {
176176
};
177177
};
178178
}[];
179+
useConnectComet?: boolean;
179180
};
180181
reactQuery?: {
181182
enabled: boolean;

0 commit comments

Comments
 (0)