Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ICS chains in ts-client generation #3444

Merged
merged 11 commits into from
Apr 7, 2023
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changes

- [#3444](https://github.com/ignite/cli/pull/3444) Add support for ICS chains in ts-client generation
jeronimoalbi marked this conversation as resolved.
Show resolved Hide resolved

## [`v0.26.1`](https://github.com/ignite/cli/releases/tag/v0.26.1)

### Features
Expand Down
16 changes: 11 additions & 5 deletions ignite/pkg/cosmosgen/generate_typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type tsGenerator struct {
}

type generatePayload struct {
Modules []module.Module
PackageNS string
Modules []module.Module
PackageNS string
IsConsumerChain bool
}

func newTSGenerator(g *generator) *tsGenerator {
Expand All @@ -45,8 +46,9 @@ func (g *generator) generateTS() error {

appModulePath := gomodulepath.ExtractAppPath(chainPath.RawPath)
data := generatePayload{
Modules: g.appModules,
PackageNS: strings.ReplaceAll(appModulePath, "/", "-"),
Modules: g.appModules,
PackageNS: strings.ReplaceAll(appModulePath, "/", "-"),
IsConsumerChain: false,
}

// Third party modules are always required to generate the root
Expand All @@ -55,8 +57,12 @@ func (g *generator) generateTS() error {
// modules when the root templates are re-generated.
for _, modules := range g.thirdModules {
data.Modules = append(data.Modules, modules...)
for _, m := range modules {
if strings.HasPrefix(m.Pkg.Name, "interchain_security.ccv.consumer") {
data.IsConsumerChain = true
}
}
}

// Make sure the modules are always sorted to keep the import
// and module registration order consistent so the generated
// files are not changed.
Expand Down
23 changes: 13 additions & 10 deletions ignite/pkg/cosmosgen/templates/root/client.ts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,22 @@ export class IgniteClient extends EventEmitter {
const queryClient = (
await import("./cosmos.base.tendermint.v1beta1/module")
).queryClient;
const stakingQueryClient = (
await import("./cosmos.staking.v1beta1/module")
).queryClient;
const bankQueryClient = (await import("./cosmos.bank.v1beta1/module"))
.queryClient;

{{ if eq .IsConsumerChain false }}
const stakingQueryClient = (await import("./cosmos.staking.v1beta1/module")).queryClient;
const stakingqc = stakingQueryClient({ addr: this.env.apiURL });
const staking = await (await stakingqc.queryParams()).data;
{{ end }}
const qc = queryClient({ addr: this.env.apiURL });
const node_info = await (await qc.serviceGetNodeInfo()).data;
const chainId = node_info.default_node_info?.network ?? "";
const chainName = chainId?.toUpperCase() + " Network";
const staking = await (await stakingqc.queryParams()).data;
const bankqc = bankQueryClient({ addr: this.env.apiURL });
const tokens = await (await bankqc.queryTotalSupply()).data;
const addrPrefix = this.env.prefix ?? "cosmos";
const rpc = this.env.rpcURL;
const rest = this.env.apiURL;
let stakeCurrency = {
coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "",
coinMinimalDenom: staking.params?.bond_denom ?? "",
coinDecimals: 0,
};

let bip44 = {
coinType: 118,
Expand All @@ -123,6 +117,15 @@ export class IgniteClient extends EventEmitter {
return y;
}) ?? [];

{{ if eq .IsConsumerChain true -}}
let stakeCurrency = currencies.find((x) => !x.coinDenom.startsWith("ibc/"));
{{ else }}
let stakeCurrency = {
coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "",
coinMinimalDenom: staking.params?.bond_denom ?? "",
coinDecimals: 0,
};
{{ end }}
let feeCurrencies =
tokens.supply?.map((x) => {
const y = {
Expand Down