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

Add Amino converters from Telescope #68

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to

## [Unreleased]

- Upgrade to Telescope 0.97.0
- Enable Amino converters

## [0.8.0] - 2023-05-24

- Upgrade Cosmos SDK types to 0.47.2 including new modules like group and NFT.
Expand Down
1,099 changes: 644 additions & 455 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"protobufjs": "~6.11.2"
},
"devDependencies": {
"@osmonauts/telescope": "^0.94.1",
"@osmonauts/telescope": "^0.97.0",
"@types/long": "^4.0.1",
"@types/node": "^15.6.2",
"prettier": "^2.8.8",
Expand Down
6 changes: 6 additions & 0 deletions scripts/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ telescope({
],
outPath: outPath,
options: {
aminoEncoding: {
enabled: true,
useRecursiveV2encoding: true,
},
Comment on lines +18 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option also appears at the end of the options in this file as aminoEncoding: { enabled: false } - not sure if the later one is having any impact.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, indeed, that is a bug. Thank you!

logLevel: 0,
useSDKTypes: false,
tsDisable: {
Expand Down Expand Up @@ -59,6 +63,8 @@ telescope({
// See https://github.com/cosmos/cosmjs/pull/1329
fromJSON: true,
toJSON: true,
fromAmino: true,
toAmino: true,
},
typingsFormat: {
useDeepPartial: true,
Expand Down
74 changes: 74 additions & 0 deletions src/cosmos/app/runtime/v1alpha1/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,59 @@ export const Module = {
message.overrideStoreKeys = object.overrideStoreKeys?.map((e) => StoreKeyConfig.fromPartial(e)) || [];
return message;
},
fromAmino(object: ModuleAmino): Module {
return {
appName: object.app_name,
beginBlockers: Array.isArray(object?.begin_blockers) ? object.begin_blockers.map((e: any) => e) : [],
endBlockers: Array.isArray(object?.end_blockers) ? object.end_blockers.map((e: any) => e) : [],
initGenesis: Array.isArray(object?.init_genesis) ? object.init_genesis.map((e: any) => e) : [],
exportGenesis: Array.isArray(object?.export_genesis) ? object.export_genesis.map((e: any) => e) : [],
overrideStoreKeys: Array.isArray(object?.override_store_keys)
? object.override_store_keys.map((e: any) => StoreKeyConfig.fromAmino(e))
: [],
};
},
toAmino(message: Module): ModuleAmino {
const obj: any = {};
obj.app_name = message.appName;
if (message.beginBlockers) {
obj.begin_blockers = message.beginBlockers.map((e) => e);
} else {
obj.begin_blockers = [];
}
if (message.endBlockers) {
obj.end_blockers = message.endBlockers.map((e) => e);
} else {
obj.end_blockers = [];
}
if (message.initGenesis) {
obj.init_genesis = message.initGenesis.map((e) => e);
} else {
obj.init_genesis = [];
}
if (message.exportGenesis) {
obj.export_genesis = message.exportGenesis.map((e) => e);
} else {
obj.export_genesis = [];
}
if (message.overrideStoreKeys) {
obj.override_store_keys = message.overrideStoreKeys.map((e) =>
e ? StoreKeyConfig.toAmino(e) : undefined,
);
} else {
obj.override_store_keys = [];
}
return obj;
},
fromAminoMsg(object: ModuleAminoMsg): Module {
return Module.fromAmino(object.value);
},
toAminoMsg(message: Module): ModuleAminoMsg {
return {
type: "cosmos-sdk/Module",
value: Module.toAmino(message),
};
},
};
function createBaseStoreKeyConfig(): StoreKeyConfig {
return {
Expand Down Expand Up @@ -223,4 +276,25 @@ export const StoreKeyConfig = {
message.kvStoreKey = object.kvStoreKey ?? "";
return message;
},
fromAmino(object: StoreKeyConfigAmino): StoreKeyConfig {
return {
moduleName: object.module_name,
kvStoreKey: object.kv_store_key,
};
},
toAmino(message: StoreKeyConfig): StoreKeyConfigAmino {
const obj: any = {};
obj.module_name = message.moduleName;
obj.kv_store_key = message.kvStoreKey;
return obj;
},
fromAminoMsg(object: StoreKeyConfigAminoMsg): StoreKeyConfig {
return StoreKeyConfig.fromAmino(object.value);
},
toAminoMsg(message: StoreKeyConfig): StoreKeyConfigAminoMsg {
return {
type: "cosmos-sdk/StoreKeyConfig",
value: StoreKeyConfig.toAmino(message),
};
},
};
83 changes: 83 additions & 0 deletions src/cosmos/app/v1alpha1/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,39 @@ export const Config = {
message.golangBindings = object.golangBindings?.map((e) => GolangBinding.fromPartial(e)) || [];
return message;
},
fromAmino(object: ConfigAmino): Config {
return {
modules: Array.isArray(object?.modules)
? object.modules.map((e: any) => ModuleConfig.fromAmino(e))
: [],
golangBindings: Array.isArray(object?.golang_bindings)
? object.golang_bindings.map((e: any) => GolangBinding.fromAmino(e))
: [],
};
},
toAmino(message: Config): ConfigAmino {
const obj: any = {};
if (message.modules) {
obj.modules = message.modules.map((e) => (e ? ModuleConfig.toAmino(e) : undefined));
} else {
obj.modules = [];
}
if (message.golangBindings) {
obj.golang_bindings = message.golangBindings.map((e) => (e ? GolangBinding.toAmino(e) : undefined));
} else {
obj.golang_bindings = [];
}
return obj;
},
fromAminoMsg(object: ConfigAminoMsg): Config {
return Config.fromAmino(object.value);
},
toAminoMsg(message: Config): ConfigAminoMsg {
return {
type: "cosmos-sdk/Config",
value: Config.toAmino(message),
};
},
};
function createBaseModuleConfig(): ModuleConfig {
return {
Expand Down Expand Up @@ -192,6 +225,35 @@ export const ModuleConfig = {
message.golangBindings = object.golangBindings?.map((e) => GolangBinding.fromPartial(e)) || [];
return message;
},
fromAmino(object: ModuleConfigAmino): ModuleConfig {
return {
name: object.name,
config: object?.config ? Any.fromAmino(object.config) : undefined,
golangBindings: Array.isArray(object?.golang_bindings)
? object.golang_bindings.map((e: any) => GolangBinding.fromAmino(e))
: [],
};
},
toAmino(message: ModuleConfig): ModuleConfigAmino {
const obj: any = {};
obj.name = message.name;
obj.config = message.config ? Any.toAmino(message.config) : undefined;
if (message.golangBindings) {
obj.golang_bindings = message.golangBindings.map((e) => (e ? GolangBinding.toAmino(e) : undefined));
} else {
obj.golang_bindings = [];
}
return obj;
},
fromAminoMsg(object: ModuleConfigAminoMsg): ModuleConfig {
return ModuleConfig.fromAmino(object.value);
},
toAminoMsg(message: ModuleConfig): ModuleConfigAminoMsg {
return {
type: "cosmos-sdk/ModuleConfig",
value: ModuleConfig.toAmino(message),
};
},
};
function createBaseGolangBinding(): GolangBinding {
return {
Expand Down Expand Up @@ -247,4 +309,25 @@ export const GolangBinding = {
message.implementation = object.implementation ?? "";
return message;
},
fromAmino(object: GolangBindingAmino): GolangBinding {
return {
interfaceType: object.interface_type,
implementation: object.implementation,
};
},
toAmino(message: GolangBinding): GolangBindingAmino {
const obj: any = {};
obj.interface_type = message.interfaceType;
obj.implementation = message.implementation;
return obj;
},
fromAminoMsg(object: GolangBindingAminoMsg): GolangBinding {
return GolangBinding.fromAmino(object.value);
},
toAminoMsg(message: GolangBinding): GolangBindingAminoMsg {
return {
type: "cosmos-sdk/GolangBinding",
value: GolangBinding.toAmino(message),
};
},
};
75 changes: 75 additions & 0 deletions src/cosmos/app/v1alpha1/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,41 @@ export const ModuleDescriptor = {
message.canMigrateFrom = object.canMigrateFrom?.map((e) => MigrateFromInfo.fromPartial(e)) || [];
return message;
},
fromAmino(object: ModuleDescriptorAmino): ModuleDescriptor {
return {
goImport: object.go_import,
usePackage: Array.isArray(object?.use_package)
? object.use_package.map((e: any) => PackageReference.fromAmino(e))
: [],
canMigrateFrom: Array.isArray(object?.can_migrate_from)
? object.can_migrate_from.map((e: any) => MigrateFromInfo.fromAmino(e))
: [],
};
},
toAmino(message: ModuleDescriptor): ModuleDescriptorAmino {
const obj: any = {};
obj.go_import = message.goImport;
if (message.usePackage) {
obj.use_package = message.usePackage.map((e) => (e ? PackageReference.toAmino(e) : undefined));
} else {
obj.use_package = [];
}
if (message.canMigrateFrom) {
obj.can_migrate_from = message.canMigrateFrom.map((e) => (e ? MigrateFromInfo.toAmino(e) : undefined));
} else {
obj.can_migrate_from = [];
}
return obj;
},
fromAminoMsg(object: ModuleDescriptorAminoMsg): ModuleDescriptor {
return ModuleDescriptor.fromAmino(object.value);
},
toAminoMsg(message: ModuleDescriptor): ModuleDescriptorAminoMsg {
return {
type: "cosmos-sdk/ModuleDescriptor",
value: ModuleDescriptor.toAmino(message),
};
},
};
function createBasePackageReference(): PackageReference {
return {
Expand Down Expand Up @@ -213,6 +248,27 @@ export const PackageReference = {
message.revision = object.revision ?? 0;
return message;
},
fromAmino(object: PackageReferenceAmino): PackageReference {
return {
name: object.name,
revision: object.revision,
};
},
toAmino(message: PackageReference): PackageReferenceAmino {
const obj: any = {};
obj.name = message.name;
obj.revision = message.revision;
return obj;
},
fromAminoMsg(object: PackageReferenceAminoMsg): PackageReference {
return PackageReference.fromAmino(object.value);
},
toAminoMsg(message: PackageReference): PackageReferenceAminoMsg {
return {
type: "cosmos-sdk/PackageReference",
value: PackageReference.toAmino(message),
};
},
};
function createBaseMigrateFromInfo(): MigrateFromInfo {
return {
Expand Down Expand Up @@ -258,4 +314,23 @@ export const MigrateFromInfo = {
message.module = object.module ?? "";
return message;
},
fromAmino(object: MigrateFromInfoAmino): MigrateFromInfo {
return {
module: object.module,
};
},
toAmino(message: MigrateFromInfo): MigrateFromInfoAmino {
const obj: any = {};
obj.module = message.module;
return obj;
},
fromAminoMsg(object: MigrateFromInfoAminoMsg): MigrateFromInfo {
return MigrateFromInfo.fromAmino(object.value);
},
toAminoMsg(message: MigrateFromInfo): MigrateFromInfoAminoMsg {
return {
type: "cosmos-sdk/MigrateFromInfo",
value: MigrateFromInfo.toAmino(message),
};
},
};
35 changes: 35 additions & 0 deletions src/cosmos/app/v1alpha1/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ export const QueryConfigRequest = {
const message = createBaseQueryConfigRequest();
return message;
},
fromAmino(_: QueryConfigRequestAmino): QueryConfigRequest {
return {};
},
toAmino(_: QueryConfigRequest): QueryConfigRequestAmino {
const obj: any = {};
return obj;
},
fromAminoMsg(object: QueryConfigRequestAminoMsg): QueryConfigRequest {
return QueryConfigRequest.fromAmino(object.value);
},
toAminoMsg(message: QueryConfigRequest): QueryConfigRequestAminoMsg {
return {
type: "cosmos-sdk/QueryConfigRequest",
value: QueryConfigRequest.toAmino(message),
};
},
};
function createBaseQueryConfigResponse(): QueryConfigResponse {
return {
Expand Down Expand Up @@ -88,6 +104,25 @@ export const QueryConfigResponse = {
object.config !== undefined && object.config !== null ? Config.fromPartial(object.config) : undefined;
return message;
},
fromAmino(object: QueryConfigResponseAmino): QueryConfigResponse {
return {
config: object?.config ? Config.fromAmino(object.config) : undefined,
};
},
toAmino(message: QueryConfigResponse): QueryConfigResponseAmino {
const obj: any = {};
obj.config = message.config ? Config.toAmino(message.config) : undefined;
return obj;
},
fromAminoMsg(object: QueryConfigResponseAminoMsg): QueryConfigResponse {
return QueryConfigResponse.fromAmino(object.value);
},
toAminoMsg(message: QueryConfigResponse): QueryConfigResponseAminoMsg {
return {
type: "cosmos-sdk/QueryConfigResponse",
value: QueryConfigResponse.toAmino(message),
};
},
};
/** Query is the app module query service. */
export interface Query {
Expand Down