Skip to content

Commit

Permalink
Merge pull request #569 from cosmology-tech/fix-amino
Browse files Browse the repository at this point in the history
Fix omit empty for amino
  • Loading branch information
Zetazzz committed Mar 18, 2024
2 parents 8f6e2f0 + 8cc9e20 commit 24dfd67
Show file tree
Hide file tree
Showing 2,089 changed files with 25,989 additions and 25,684 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ packages/**/main
packages/**/module
launch.json
.vscode/settings.json
.idea/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,15 @@ telescope({
| option | description | defaults |
| ------------------------------ | -------------------------------------------------------------- | ---------- |
| `aminoEncoding.enabled` | generate amino types and amino converters | `true` |
| `aminoEncoding.omitEmptyTags` | An array of strings that determines whether a field should be omitted when serialized to JSON. If the array includes "omitempty", any field with the "omitempty" option in either gogoproto.jsontag or cosmos_proto.json_tag will be omitted. If the array includes "dont_omitempty", the field will be omitted or not based on the value of "(amino.dont_omitempty)": if it's null or false, the field will be omitted; if it's true, the field will not be omitted. | `["omitempty", "dont_omitempty"]` |
| `aminoEncoding.disableMsgTypes` | disable generating AminoMsg types | `false` |
| `aminoEncoding.casingFn` | set the amino-casing function for a project | `snake()` |
| `aminoEncoding.exceptions` | set specific aminoType name exceptions | see code |
| `aminoEncoding.typeUrlToAmino` | create functions for aminoType name exceptions | `undefined`|
| `aminoEncoding.useLegacyInlineEncoding` | @deprecated. To use legacy inline encoding instead of using v2 recursive encoding | `false`|
| `aminoEncoding.useRecursiveV2encoding` | this's been removed. See useLegacyInlineEncoding instead. | |
| `aminoEncoding.legacy.useNullHandling` | handle null case when generating legacy amino converters(those in tx.amino.ts) | |
| `aminoEncoding.legacy.useOmitEmpty` | handle omit empty or not when generating legacy amino converters(those in tx.amino.ts) | |

### Implemented Interface Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface DepositDeploymentAuthorizationAmino {
* SpendLimit is the amount the grantee is authorized to spend from the granter's account for
* the purpose of deployment.
*/
spend_limit?: CoinAmino;
spend_limit: CoinAmino;
}
export interface DepositDeploymentAuthorizationAminoMsg {
type: "/akash.deployment.v1beta1.DepositDeploymentAuthorization";
Expand Down Expand Up @@ -120,7 +120,7 @@ export const DepositDeploymentAuthorization = {
},
toAmino(message: DepositDeploymentAuthorization): DepositDeploymentAuthorizationAmino {
const obj: any = {};
obj.spend_limit = message.spendLimit ? Coin.toAmino(message.spendLimit) : undefined;
obj.spend_limit = message.spendLimit ? Coin.toAmino(message.spendLimit) : Coin.toAmino(Coin.fromPartial({}));
return obj;
},
fromAminoMsg(object: DepositDeploymentAuthorizationAminoMsg): DepositDeploymentAuthorization {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export const GenericAuthorization = {
},
toAmino(message: GenericAuthorization): GenericAuthorizationAmino {
const obj: any = {};
obj.msg = message.msg;
obj.msg = message.msg === "" ? undefined : message.msg;
return obj;
},
fromAminoMsg(object: GenericAuthorizationAminoMsg): GenericAuthorization {
Expand Down Expand Up @@ -482,7 +482,7 @@ export const Grant = {
message.expiration = fromTimestamp(Timestamp.fromAmino(object.expiration));
}
if (object.opt !== undefined && object.opt !== null) {
message.opt = voteOptionFromJSON(object.opt);
message.opt = object.opt;
}
if (object.single_msg !== undefined && object.single_msg !== null) {
message.singleMsg = Any.fromAmino(object.single_msg);
Expand All @@ -494,12 +494,12 @@ export const Grant = {
const obj: any = {};
obj.authorization = message.authorization ? GlobalDecoderRegistry.toAminoMsg(message.authorization) : undefined;
obj.expiration = message.expiration ? Timestamp.toAmino(toTimestamp(message.expiration)) : undefined;
obj.opt = message.opt;
obj.opt = message.opt === 0 ? undefined : message.opt;
obj.single_msg = message.singleMsg ? Any.toAmino(message.singleMsg) : undefined;
if (message.messages) {
obj.messages = message.messages.map(e => e ? Any.toAmino(e) : undefined);
} else {
obj.messages = [];
obj.messages = message.messages;
}
return obj;
},
Expand Down Expand Up @@ -656,8 +656,8 @@ export const GrantAuthorization = {
},
toAmino(message: GrantAuthorization): GrantAuthorizationAmino {
const obj: any = {};
obj.granter = message.granter;
obj.grantee = message.grantee;
obj.granter = message.granter === "" ? undefined : message.granter;
obj.grantee = message.grantee === "" ? undefined : message.grantee;
obj.authorization = message.authorization ? GlobalDecoderRegistry.toAminoMsg(message.authorization) : undefined;
obj.expiration = message.expiration ? Timestamp.toAmino(toTimestamp(message.expiration)) : undefined;
return obj;
Expand Down Expand Up @@ -774,7 +774,7 @@ export const GrantQueueItem = {
if (message.msgTypeUrls) {
obj.msg_type_urls = message.msgTypeUrls.map(e => e);
} else {
obj.msg_type_urls = [];
obj.msg_type_urls = message.msgTypeUrls;
}
return obj;
},
Expand Down Expand Up @@ -890,7 +890,7 @@ export const Grants = {
if (message.authorization) {
obj.authorization = message.authorization.map(e => e ? GlobalDecoderRegistry.toAminoMsg(e) : undefined);
} else {
obj.authorization = [];
obj.authorization = message.authorization;
}
return obj;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ export const MsgGrant = {
},
toAmino(message: MsgGrant): MsgGrantAmino {
const obj: any = {};
obj.granter = message.granter;
obj.grantee = message.grantee;
obj.granter = message.granter === "" ? undefined : message.granter;
obj.grantee = message.grantee === "" ? undefined : message.grantee;
obj.grant = message.grant ? Grant.toAmino(message.grant) : undefined;
return obj;
},
Expand Down Expand Up @@ -405,7 +405,7 @@ export const MsgExecResponse = {
if (message.results) {
obj.results = message.results.map(e => base64FromBytes(e));
} else {
obj.results = [];
obj.results = message.results;
}
return obj;
},
Expand Down Expand Up @@ -534,11 +534,11 @@ export const MsgExec = {
},
toAmino(message: MsgExec): MsgExecAmino {
const obj: any = {};
obj.grantee = message.grantee;
obj.grantee = message.grantee === "" ? undefined : message.grantee;
if (message.msgs) {
obj.msgs = message.msgs.map(e => e ? GlobalDecoderRegistry.toAminoMsg(e) : undefined);
} else {
obj.msgs = [];
obj.msgs = message.msgs;
}
return obj;
},
Expand Down Expand Up @@ -763,9 +763,9 @@ export const MsgRevoke = {
},
toAmino(message: MsgRevoke): MsgRevokeAmino {
const obj: any = {};
obj.granter = message.granter;
obj.grantee = message.grantee;
obj.msg_type_url = message.msgTypeUrl;
obj.granter = message.granter === "" ? undefined : message.granter;
obj.grantee = message.grantee === "" ? undefined : message.grantee;
obj.msg_type_url = message.msgTypeUrl === "" ? undefined : message.msgTypeUrl;
return obj;
},
fromAminoMsg(object: MsgRevokeAminoMsg): MsgRevoke {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const SendAuthorization = {
if (message.spendLimit) {
obj.spend_limit = message.spendLimit.map(e => e ? Coin.toAmino(e) : undefined);
} else {
obj.spend_limit = [];
obj.spend_limit = message.spendLimit;
}
return obj;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,20 @@ export const MsgInstantiateContract2 = {
},
toAmino(message: MsgInstantiateContract2): MsgInstantiateContract2Amino {
const obj: any = {};
obj.code_id = message.codeId ? message.codeId.toString() : undefined;
obj.label = message.label;
obj.code_id = message.codeId !== BigInt(0) ? message.codeId.toString() : undefined;
obj.label = message.label === "" ? undefined : message.label;
if (message.funds) {
obj.funds = message.funds.map(e => e ? Coin.toAmino(e) : undefined);
} else {
obj.funds = [];
obj.funds = message.funds;
}
obj.salt = message.salt ? base64FromBytes(message.salt) : undefined;
obj.fix_msg = message.fixMsg;
obj.fix_msg = message.fixMsg === false ? undefined : message.fixMsg;
obj.dont_omitempty_fix_msg = message.dontOmitemptyFixMsg ?? false;
if (message.aListOfBytes) {
obj.a_list_of_bytes = message.aListOfBytes.map(e => base64FromBytes(e));
} else {
obj.a_list_of_bytes = [];
obj.a_list_of_bytes = message.aListOfBytes;
}
return obj;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export const Coin = {
},
toAmino(message: Coin): CoinAmino {
const obj: any = {};
obj.denom = message.denom;
obj.amount = message.amount;
obj.denom = message.denom === "" ? undefined : message.denom;
obj.amount = message.amount === "" ? undefined : message.amount;
return obj;
},
fromAminoMsg(object: CoinAminoMsg): Coin {
Expand Down Expand Up @@ -336,8 +336,8 @@ export const DecCoin = {
},
toAmino(message: DecCoin): DecCoinAmino {
const obj: any = {};
obj.denom = message.denom;
obj.amount = message.amount;
obj.denom = message.denom === "" ? undefined : message.denom;
obj.amount = message.amount === "" ? undefined : message.amount;
return obj;
},
fromAminoMsg(object: DecCoinAminoMsg): DecCoin {
Expand Down Expand Up @@ -443,7 +443,7 @@ export const IntProto = {
},
toAmino(message: IntProto): IntProtoAmino {
const obj: any = {};
obj.int = message.int;
obj.int = message.int === "" ? undefined : message.int;
return obj;
},
fromAminoMsg(object: IntProtoAminoMsg): IntProto {
Expand Down Expand Up @@ -549,7 +549,7 @@ export const DecProto = {
},
toAmino(message: DecProto): DecProtoAmino {
const obj: any = {};
obj.dec = message.dec;
obj.dec = message.dec === "" ? undefined : message.dec;
return obj;
},
fromAminoMsg(object: DecProtoAminoMsg): DecProto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ export const InterfaceDescriptor = {
},
toAmino(message: InterfaceDescriptor): InterfaceDescriptorAmino {
const obj: any = {};
obj.name = message.name;
obj.description = message.description;
obj.name = message.name === "" ? undefined : message.name;
obj.description = message.description === "" ? undefined : message.description;
return obj;
},
fromAminoMsg(object: InterfaceDescriptorAminoMsg): InterfaceDescriptor {
Expand Down Expand Up @@ -411,17 +411,17 @@ export const ScalarDescriptor = {
if (object.description !== undefined && object.description !== null) {
message.description = object.description;
}
message.fieldType = object.field_type?.map(e => scalarTypeFromJSON(e)) || [];
message.fieldType = object.field_type?.map(e => e) || [];
return message;
},
toAmino(message: ScalarDescriptor): ScalarDescriptorAmino {
const obj: any = {};
obj.name = message.name;
obj.description = message.description;
obj.name = message.name === "" ? undefined : message.name;
obj.description = message.description === "" ? undefined : message.description;
if (message.fieldType) {
obj.field_type = message.fieldType.map(e => e);
} else {
obj.field_type = [];
obj.field_type = message.fieldType;
}
return obj;
},
Expand Down
Loading

0 comments on commit 24dfd67

Please sign in to comment.