Skip to content

Commit

Permalink
Reorganization of client style option with all, sdk-module, custom
Browse files Browse the repository at this point in the history
  • Loading branch information
NorOldBurden committed Dec 10, 2024
1 parent 3e99536 commit c44c022
Show file tree
Hide file tree
Showing 22 changed files with 913 additions and 136 deletions.
67 changes: 33 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,11 @@ See [LCD Clients](#lcd-clients) for more info.
| `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] |
| `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` |
| `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` |
`rpcClients.combinedClient.name` | assign the client name like `{name}AminoConverters`, `get{name}SigningClient` etc | `undefined`
| `rpcClients.combinedClient.fileName` | assign the file name of generated client in root directory | `undefined`
| `rpcClients.combinedClient.include.patterns` | determine which proto files will be imported for the current client such as `cosmos.gov.v1beta1.**` | `undefined`
`rpcClients.clientStyle.useUpdatedClientStyle` | The default value is `false`, which sets the generated client to use the legacy style. Setting it to `true` applies the updated style and activates the remaining options in clientStyle. | `false`
| `rpcClients.clientStyle.type` | A string array containing possible values: `all-client`, `sdk-module-client`, and `custom-client`. The value `all-client` generates an all-module-client file. The value `sdk-module-client` generates a client for the module specified by the `sdkModuleClientOption`. The value `custom-client` generates a customized client as specified by `customClientOption` | `undefined`
`rpcClients.clientStyle.customClientOption.name` | assign the client name like `{name}AminoConverters`, `get{name}SigningClient` etc | `undefined`
| `rpcClients.clientStyle.customClientOption.fileName` | assign the file name of generated client in root directory | `undefined`
| `rpcClients.clientStyle.customClientOption.include.patterns` | determine which proto files will be imported for the current client such as `cosmos.gov.v1beta1.**` | `undefined`

See [RPC Clients](#rpc-clients) for more info.

Expand Down Expand Up @@ -1063,44 +1065,41 @@ export class CosmosAuthAccount {
}
```

## Combined Clients Methods
## Client Style Methods

Using combined option to generate multiple module clients
Use client style to define the client file generated according to the config

For example, for this config:
```js
{
combinedClient: [
{
name: "CosmosIbc",
fileName: "cosmos-ibc-client.ts",
include: {
patterns: [
"cosmos.gov.v1beta1*",
"cosmos.gov.v1*",
"ibc.core.channel.*",
],
},
},
{
name: "AkashCosmos",
fileName: "akash-cosmos-client.ts",
include: {
patterns: [
"cosmos.group.v1*",
"cosmos.nft.v1beta1*",
"akash.**.v1beta2",
"akash.audit.v1beta1*",
],
clientStyle: {
useUpdatedClientStyle: true,
type: ['all-client', 'sdk-module-client', 'custom-client'],
customClientOption: [
{
name: "custom",
fileName: "custom-client.ts",
include: {
patterns: [
"cosmos.gov.v1beta1*",
"cosmos.gov.v1*",
"ibc.core.channel.*",
],
},
},
},
],
}
],
sdkModuleClientOption: [
'akash',
'osmosis',
'cosmos',
],
},
```

There'll be client files (`cosmos-ibc-client.ts`, `akash-cosmos-client.ts`) generated in the root folder according to fileName in the setting.
The combined client will import proto files accroding to include.patterns. (The protos can come from different modules)
For example the cosmos-ibc-client.ts will be like:
There'll be client files (`all-module-client.ts`, `akash-sdk-module-client.ts`, `osmosis-sdk-module-client.ts`, `cosmos-sdk-module-client.ts`, `custom-client.ts`) generated in the root directory according to the setting.<br>
The `all-module-client.ts` file consolidates all proto imports into one file and exports them as a single client.<br>
All sdk module client files will be identical to the legacy `client.ts` files generated in each module directory, except they will be located in the root directory. <br>
The custom client imports proto files based on `include.patterns`, allowing protos to originate from different modules.<br>
For example the custom-client.ts will be like:
```ts
export const cosmosIbcAminoConverters = {
...cosmosGovV1TxAmino.AminoConverter,
Expand Down
81 changes: 81 additions & 0 deletions __fixtures__/v-next/outputinstantrpc/akash-sdk-module-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { GeneratedType, Registry, OfflineSigner } from "@cosmjs/proto-signing";
import { defaultRegistryTypes, AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
import { HttpEndpoint } from "@cosmjs/tendermint-rpc";
import { createRpcClient } from "./extern";
import { DeliverTxResponse, EncodeObject, StdFee, TxRpc, SigningClientParams } from "./types";
import * as akashAuditV1beta1AuditRegistry from "./akash/audit/v1beta1/audit.registry";
import * as akashAuditV1beta2AuditRegistry from "./akash/audit/v1beta2/audit.registry";
import * as akashCertV1beta2CertRegistry from "./akash/cert/v1beta2/cert.registry";
import * as akashDeploymentV1beta2ServiceRegistry from "./akash/deployment/v1beta2/service.registry";
import * as akashMarketV1beta2ServiceRegistry from "./akash/market/v1beta2/service.registry";
import * as akashProviderV1beta1ProviderRegistry from "./akash/provider/v1beta1/provider.registry";
import * as akashProviderV1beta2ProviderRegistry from "./akash/provider/v1beta2/provider.registry";
import * as akashAuditV1beta1AuditAmino from "./akash/audit/v1beta1/audit.amino";
import * as akashAuditV1beta2AuditAmino from "./akash/audit/v1beta2/audit.amino";
import * as akashCertV1beta2CertAmino from "./akash/cert/v1beta2/cert.amino";
import * as akashDeploymentV1beta2ServiceAmino from "./akash/deployment/v1beta2/service.amino";
import * as akashMarketV1beta2ServiceAmino from "./akash/market/v1beta2/service.amino";
import * as akashProviderV1beta1ProviderAmino from "./akash/provider/v1beta1/provider.amino";
import * as akashProviderV1beta2ProviderAmino from "./akash/provider/v1beta2/provider.amino";
export const akashAminoConverters = {
...akashAuditV1beta1AuditAmino.AminoConverter,
...akashAuditV1beta2AuditAmino.AminoConverter,
...akashCertV1beta2CertAmino.AminoConverter,
...akashDeploymentV1beta2ServiceAmino.AminoConverter,
...akashMarketV1beta2ServiceAmino.AminoConverter,
...akashProviderV1beta1ProviderAmino.AminoConverter,
...akashProviderV1beta2ProviderAmino.AminoConverter
};
export const akashProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [...akashAuditV1beta1AuditRegistry.registry, ...akashAuditV1beta2AuditRegistry.registry, ...akashCertV1beta2CertRegistry.registry, ...akashDeploymentV1beta2ServiceRegistry.registry, ...akashMarketV1beta2ServiceRegistry.registry, ...akashProviderV1beta1ProviderRegistry.registry, ...akashProviderV1beta2ProviderRegistry.registry];
export const getSigningAkashClientOptions = ({
defaultTypes = defaultRegistryTypes
}: {
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
} = {}): {
registry: Registry;
aminoTypes: AminoTypes;
} => {
const registry = new Registry([...defaultTypes, ...akashProtoRegistry]);
const aminoTypes = new AminoTypes({
...akashAminoConverters
});
return {
registry,
aminoTypes
};
};
export const getSigningAkashClient = async ({
rpcEndpoint,
signer,
defaultTypes = defaultRegistryTypes
}: {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
}) => {
const {
registry,
aminoTypes
} = getSigningAkashClientOptions({
defaultTypes
});
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry: (registry as any),
aminoTypes
});
return client;
};
export const getSigningAkashTxRpc = async ({
rpcEndpoint,
signer
}: SigningClientParams) => {
let txRpc = (await createRpcClient(rpcEndpoint) as TxRpc);
const signingClient = await getSigningAkashClient({
rpcEndpoint,
signer
});
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
168 changes: 168 additions & 0 deletions __fixtures__/v-next/outputinstantrpc/all-module-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { GeneratedType, Registry, OfflineSigner } from "@cosmjs/proto-signing";
import { defaultRegistryTypes, AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
import { HttpEndpoint } from "@cosmjs/tendermint-rpc";
import { createRpcClient } from "./extern";
import { DeliverTxResponse, EncodeObject, StdFee, TxRpc, SigningClientParams } from "./types";
import * as akashAuditV1beta1AuditRegistry from "./akash/audit/v1beta1/audit.registry";
import * as akashAuditV1beta2AuditRegistry from "./akash/audit/v1beta2/audit.registry";
import * as akashCertV1beta2CertRegistry from "./akash/cert/v1beta2/cert.registry";
import * as akashDeploymentV1beta2ServiceRegistry from "./akash/deployment/v1beta2/service.registry";
import * as akashMarketV1beta2ServiceRegistry from "./akash/market/v1beta2/service.registry";
import * as akashProviderV1beta1ProviderRegistry from "./akash/provider/v1beta1/provider.registry";
import * as akashProviderV1beta2ProviderRegistry from "./akash/provider/v1beta2/provider.registry";
import * as cosmosAuthzV1beta1TxRegistry from "./cosmos/authz/v1beta1/tx.registry";
import * as cosmosBankV1beta1TxRegistry from "./cosmos/bank/v1beta1/tx.registry";
import * as cosmosCrisisV1beta1TxRegistry from "./cosmos/crisis/v1beta1/tx.registry";
import * as cosmosDistributionV1beta1TxRegistry from "./cosmos/distribution/v1beta1/tx.registry";
import * as cosmosEvidenceV1beta1TxRegistry from "./cosmos/evidence/v1beta1/tx.registry";
import * as cosmosFeegrantV1beta1TxRegistry from "./cosmos/feegrant/v1beta1/tx.registry";
import * as cosmosGovV1TxRegistry from "./cosmos/gov/v1/tx.registry";
import * as cosmosGovV1beta1TxRegistry from "./cosmos/gov/v1beta1/tx.registry";
import * as cosmosGroupV1TxRegistry from "./cosmos/group/v1/tx.registry";
import * as cosmosNftV1beta1TxRegistry from "./cosmos/nft/v1beta1/tx.registry";
import * as cosmosSlashingV1beta1TxRegistry from "./cosmos/slashing/v1beta1/tx.registry";
import * as cosmosStakingV1beta1TxRegistry from "./cosmos/staking/v1beta1/tx.registry";
import * as cosmosUpgradeV1beta1TxRegistry from "./cosmos/upgrade/v1beta1/tx.registry";
import * as cosmosVestingV1beta1TxRegistry from "./cosmos/vesting/v1beta1/tx.registry";
import * as cosmwasmWasmV1TxRegistry from "./cosmwasm/wasm/v1/tx.registry";
import * as evmosErc20V1TxRegistry from "./evmos/erc20/v1/tx.registry";
import * as evmosFeesV1TxRegistry from "./evmos/fees/v1/tx.registry";
import * as evmosVestingV1TxRegistry from "./evmos/vesting/v1/tx.registry";
import * as ibcApplicationsTransferV1TxRegistry from "./ibc/applications/transfer/v1/tx.registry";
import * as ibcCoreChannelV1TxRegistry from "./ibc/core/channel/v1/tx.registry";
import * as ibcCoreClientV1TxRegistry from "./ibc/core/client/v1/tx.registry";
import * as ibcCoreConnectionV1TxRegistry from "./ibc/core/connection/v1/tx.registry";
import * as osmosisGammPoolmodelsBalancerTxTxRegistry from "./osmosis/gamm/pool-models/balancer/tx/tx.registry";
import * as osmosisGammPoolmodelsStableswapTxRegistry from "./osmosis/gamm/pool-models/stableswap/tx.registry";
import * as osmosisGammV1beta1TxRegistry from "./osmosis/gamm/v1beta1/tx.registry";
import * as osmosisIncentivesTxRegistry from "./osmosis/incentives/tx.registry";
import * as osmosisLockupTxRegistry from "./osmosis/lockup/tx.registry";
import * as osmosisSuperfluidTxRegistry from "./osmosis/superfluid/tx.registry";
import * as osmosisTokenfactoryV1beta1TxRegistry from "./osmosis/tokenfactory/v1beta1/tx.registry";
import * as akashAuditV1beta1AuditAmino from "./akash/audit/v1beta1/audit.amino";
import * as akashAuditV1beta2AuditAmino from "./akash/audit/v1beta2/audit.amino";
import * as akashCertV1beta2CertAmino from "./akash/cert/v1beta2/cert.amino";
import * as akashDeploymentV1beta2ServiceAmino from "./akash/deployment/v1beta2/service.amino";
import * as akashMarketV1beta2ServiceAmino from "./akash/market/v1beta2/service.amino";
import * as akashProviderV1beta1ProviderAmino from "./akash/provider/v1beta1/provider.amino";
import * as akashProviderV1beta2ProviderAmino from "./akash/provider/v1beta2/provider.amino";
import * as cosmosAuthzV1beta1TxAmino from "./cosmos/authz/v1beta1/tx.amino";
import * as cosmosBankV1beta1TxAmino from "./cosmos/bank/v1beta1/tx.amino";
import * as cosmosCrisisV1beta1TxAmino from "./cosmos/crisis/v1beta1/tx.amino";
import * as cosmosDistributionV1beta1TxAmino from "./cosmos/distribution/v1beta1/tx.amino";
import * as cosmosEvidenceV1beta1TxAmino from "./cosmos/evidence/v1beta1/tx.amino";
import * as cosmosFeegrantV1beta1TxAmino from "./cosmos/feegrant/v1beta1/tx.amino";
import * as cosmosGovV1TxAmino from "./cosmos/gov/v1/tx.amino";
import * as cosmosGovV1beta1TxAmino from "./cosmos/gov/v1beta1/tx.amino";
import * as cosmosGroupV1TxAmino from "./cosmos/group/v1/tx.amino";
import * as cosmosNftV1beta1TxAmino from "./cosmos/nft/v1beta1/tx.amino";
import * as cosmosSlashingV1beta1TxAmino from "./cosmos/slashing/v1beta1/tx.amino";
import * as cosmosStakingV1beta1TxAmino from "./cosmos/staking/v1beta1/tx.amino";
import * as cosmosUpgradeV1beta1TxAmino from "./cosmos/upgrade/v1beta1/tx.amino";
import * as cosmosVestingV1beta1TxAmino from "./cosmos/vesting/v1beta1/tx.amino";
import * as cosmwasmWasmV1TxAmino from "./cosmwasm/wasm/v1/tx.amino";
import * as evmosErc20V1TxAmino from "./evmos/erc20/v1/tx.amino";
import * as evmosFeesV1TxAmino from "./evmos/fees/v1/tx.amino";
import * as evmosVestingV1TxAmino from "./evmos/vesting/v1/tx.amino";
import * as ibcApplicationsTransferV1TxAmino from "./ibc/applications/transfer/v1/tx.amino";
import * as ibcCoreChannelV1TxAmino from "./ibc/core/channel/v1/tx.amino";
import * as ibcCoreClientV1TxAmino from "./ibc/core/client/v1/tx.amino";
import * as ibcCoreConnectionV1TxAmino from "./ibc/core/connection/v1/tx.amino";
import * as osmosisGammPoolmodelsBalancerTxTxAmino from "./osmosis/gamm/pool-models/balancer/tx/tx.amino";
import * as osmosisGammPoolmodelsStableswapTxAmino from "./osmosis/gamm/pool-models/stableswap/tx.amino";
import * as osmosisGammV1beta1TxAmino from "./osmosis/gamm/v1beta1/tx.amino";
import * as osmosisIncentivesTxAmino from "./osmosis/incentives/tx.amino";
import * as osmosisLockupTxAmino from "./osmosis/lockup/tx.amino";
import * as osmosisSuperfluidTxAmino from "./osmosis/superfluid/tx.amino";
import * as osmosisTokenfactoryV1beta1TxAmino from "./osmosis/tokenfactory/v1beta1/tx.amino";
export const allAminoConverters = {
...akashAuditV1beta1AuditAmino.AminoConverter,
...akashAuditV1beta2AuditAmino.AminoConverter,
...akashCertV1beta2CertAmino.AminoConverter,
...akashDeploymentV1beta2ServiceAmino.AminoConverter,
...akashMarketV1beta2ServiceAmino.AminoConverter,
...akashProviderV1beta1ProviderAmino.AminoConverter,
...akashProviderV1beta2ProviderAmino.AminoConverter,
...cosmosAuthzV1beta1TxAmino.AminoConverter,
...cosmosBankV1beta1TxAmino.AminoConverter,
...cosmosCrisisV1beta1TxAmino.AminoConverter,
...cosmosDistributionV1beta1TxAmino.AminoConverter,
...cosmosEvidenceV1beta1TxAmino.AminoConverter,
...cosmosFeegrantV1beta1TxAmino.AminoConverter,
...cosmosGovV1TxAmino.AminoConverter,
...cosmosGovV1beta1TxAmino.AminoConverter,
...cosmosGroupV1TxAmino.AminoConverter,
...cosmosNftV1beta1TxAmino.AminoConverter,
...cosmosSlashingV1beta1TxAmino.AminoConverter,
...cosmosStakingV1beta1TxAmino.AminoConverter,
...cosmosUpgradeV1beta1TxAmino.AminoConverter,
...cosmosVestingV1beta1TxAmino.AminoConverter,
...cosmwasmWasmV1TxAmino.AminoConverter,
...evmosErc20V1TxAmino.AminoConverter,
...evmosFeesV1TxAmino.AminoConverter,
...evmosVestingV1TxAmino.AminoConverter,
...ibcApplicationsTransferV1TxAmino.AminoConverter,
...ibcCoreChannelV1TxAmino.AminoConverter,
...ibcCoreClientV1TxAmino.AminoConverter,
...ibcCoreConnectionV1TxAmino.AminoConverter,
...osmosisGammPoolmodelsBalancerTxTxAmino.AminoConverter,
...osmosisGammPoolmodelsStableswapTxAmino.AminoConverter,
...osmosisGammV1beta1TxAmino.AminoConverter,
...osmosisIncentivesTxAmino.AminoConverter,
...osmosisLockupTxAmino.AminoConverter,
...osmosisSuperfluidTxAmino.AminoConverter,
...osmosisTokenfactoryV1beta1TxAmino.AminoConverter
};
export const allProtoRegistry: ReadonlyArray<[string, GeneratedType]> = [...akashAuditV1beta1AuditRegistry.registry, ...akashAuditV1beta2AuditRegistry.registry, ...akashCertV1beta2CertRegistry.registry, ...akashDeploymentV1beta2ServiceRegistry.registry, ...akashMarketV1beta2ServiceRegistry.registry, ...akashProviderV1beta1ProviderRegistry.registry, ...akashProviderV1beta2ProviderRegistry.registry, ...cosmosAuthzV1beta1TxRegistry.registry, ...cosmosBankV1beta1TxRegistry.registry, ...cosmosCrisisV1beta1TxRegistry.registry, ...cosmosDistributionV1beta1TxRegistry.registry, ...cosmosEvidenceV1beta1TxRegistry.registry, ...cosmosFeegrantV1beta1TxRegistry.registry, ...cosmosGovV1TxRegistry.registry, ...cosmosGovV1beta1TxRegistry.registry, ...cosmosGroupV1TxRegistry.registry, ...cosmosNftV1beta1TxRegistry.registry, ...cosmosSlashingV1beta1TxRegistry.registry, ...cosmosStakingV1beta1TxRegistry.registry, ...cosmosUpgradeV1beta1TxRegistry.registry, ...cosmosVestingV1beta1TxRegistry.registry, ...cosmwasmWasmV1TxRegistry.registry, ...evmosErc20V1TxRegistry.registry, ...evmosFeesV1TxRegistry.registry, ...evmosVestingV1TxRegistry.registry, ...ibcApplicationsTransferV1TxRegistry.registry, ...ibcCoreChannelV1TxRegistry.registry, ...ibcCoreClientV1TxRegistry.registry, ...ibcCoreConnectionV1TxRegistry.registry, ...osmosisGammPoolmodelsBalancerTxTxRegistry.registry, ...osmosisGammPoolmodelsStableswapTxRegistry.registry, ...osmosisGammV1beta1TxRegistry.registry, ...osmosisIncentivesTxRegistry.registry, ...osmosisLockupTxRegistry.registry, ...osmosisSuperfluidTxRegistry.registry, ...osmosisTokenfactoryV1beta1TxRegistry.registry];
export const getAllSigningClientOptions = ({
defaultTypes = defaultRegistryTypes
}: {
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
} = {}): {
registry: Registry;
aminoTypes: AminoTypes;
} => {
const registry = new Registry([...defaultTypes, ...allProtoRegistry]);
const aminoTypes = new AminoTypes({
...allAminoConverters
});
return {
registry,
aminoTypes
};
};
export const getAllSigningClient = async ({
rpcEndpoint,
signer,
defaultTypes = defaultRegistryTypes
}: {
rpcEndpoint: string | HttpEndpoint;
signer: OfflineSigner;
defaultTypes?: ReadonlyArray<[string, GeneratedType]>;
}) => {
const {
registry,
aminoTypes
} = getAllSigningClientOptions({
defaultTypes
});
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry: (registry as any),
aminoTypes
});
return client;
};
export const getAllSigningTxRpc = async ({
rpcEndpoint,
signer
}: SigningClientParams) => {
let txRpc = (await createRpcClient(rpcEndpoint) as TxRpc);
const signingClient = await getAllSigningClient({
rpcEndpoint,
signer
});
txRpc.signAndBroadcast = (signerAddress: string, messages: EncodeObject[], fee: number | StdFee | "auto", memo?: string) => {
return (signingClient.signAndBroadcast(signerAddress, messages, fee, memo) as Promise<DeliverTxResponse>);
};
return txRpc;
};
Loading

0 comments on commit c44c022

Please sign in to comment.