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

Fix omit empty for amino #569

Merged
merged 29 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f9ae22c
feat: partially add support for amino
rasoulMrz Dec 26, 2023
1c4296c
feat: add emit default and fix timestamp
rasoulMrz Dec 27, 2023
9595e4b
fix: amino from-amino null handling
rasoulMrz Dec 28, 2023
fdcae94
fix: pubkey from amino functions
rasoulMrz Dec 28, 2023
94608ed
feat: add return type to arrow-functions
rasoulMrz Dec 28, 2023
757380c
feat: merge main
rasoulMrz Dec 28, 2023
3a8e76b
feat: fix omit empty handling
rasoulMrz Jan 1, 2024
331f35d
feat: handle decimal paddings
rasoulMrz Jan 1, 2024
36f37c3
fix: decimal handling in amino
rasoulMrz Jan 1, 2024
0afc37b
fix: amino enum handling
rasoulMrz Jan 2, 2024
d38a5c8
fix: amino omit empty
rasoulMrz Jan 2, 2024
f7206f0
fix: object empty check
rasoulMrz Jan 2, 2024
efc0dc7
fix: optional field default value
rasoulMrz Jan 2, 2024
1590b18
fix: optional field default value
rasoulMrz Jan 2, 2024
45a6160
fix: array fields
rasoulMrz Jan 3, 2024
ced5e43
feat: re-run tests and update snapshots
rasoulMrz Jan 3, 2024
5da1cad
Merge branch 'main' into fix-amino
Zetazzz Jan 10, 2024
536618f
add tests and gen code
Zetazzz Jan 11, 2024
3c5016f
Merge branch 'main' into fix-amino
Zetazzz Jan 16, 2024
9117a0c
Merge branch 'main' into fix-amino
Zetazzz Feb 26, 2024
dc7fd8d
Merge branch 'main' into fix-amino
Zetazzz Mar 4, 2024
f5a6e12
added shouldOmitEmpty and tests
Zetazzz Mar 12, 2024
24421b9
fixed to amino omit empty logic
Zetazzz Mar 17, 2024
5fd9703
flag for amino legacy null handling
Zetazzz Mar 17, 2024
75db4d2
add flag for amino legacy null handling
Zetazzz Mar 17, 2024
87ace40
flags for amino legacy omitempty and handling null
Zetazzz Mar 17, 2024
6fb77a3
add amino legacy flag for null handling
Zetazzz Mar 17, 2024
00079bb
README
Zetazzz Mar 18, 2024
8cc9e20
update snap
Zetazzz Mar 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
Loading