cosmology-tech / telescope

A TypeScript Transpiler for Cosmos Protobufs ⚛️
https://cosmology.zone/products/telescope
Apache License 2.0
145 stars 43 forks source link

allow customization of stargate clients with multiple modules/packages for one client (both amino/proto registries) #382

Open pyramation opened 1 year ago

pyramation commented 1 year ago

should be! with telescope you can pull the registry from the client generated files and make one massive stargate client

we should make a plugin option in telescope to make this easier, since each module currently gets bundled separately to avoid naming collisions (e.g. different version of governance can be in protos, so we had to make a sensible default)

manual work around for now:

to manually do this, you’d find the registry/amino converters in the client of each package you want to combine, say osmosis and wasmd protos:

https://github.com/osmosis-labs/osmojs/blob/ad20842e5183a1182317f70509e66dc913b926be/packages/osmojs/src/codegen/osmosis/client.ts#L32-L48

https://github.com/osmosis-labs/osmojs/blob/main/packages/osmojs/src/codegen/cosmwasm/client.ts#L6-L9

merge the arrays

then

import { GeneratedType, Registry, OfflineSigner } from "@cosmjs/proto-signing";
import { defaultRegistryTypes, AminoTypes, SigningStargateClient } from "@cosmjs/stargate";

 const registry = new Registry([…myCombinedProtoRegistry]);
  const aminoTypes = new AminoTypes({
    …myCombinedAminoConverters
  });

then make your client

const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
    registry: (registry as any),
    aminoTypes
  });

Now you have a single client that has everything you need!

specs for TelescopeOptions

Zetazzz commented 3 weeks ago