From c933a10a9cc1fc3f3683b46710e474a0b6bb2fbf Mon Sep 17 00:00:00 2001 From: cdc-Hitesh Date: Thu, 10 Nov 2022 20:58:38 +0800 Subject: [PATCH 1/3] #316: Bug fix for `MsgCreateValidator` & `MsgEditValidator` --- .../msg/staking/MsgCreateValidator.spec.ts | 38 ++++++++--------- .../msg/staking/MsgEditValidator.spec.ts | 16 ++++---- lib/src/utils/txDecoder.spec.ts | 6 +-- lib/src/utils/txDecoder.ts | 41 ++----------------- package-lock.json | 4 +- 5 files changed, 36 insertions(+), 69 deletions(-) diff --git a/lib/src/transaction/msg/staking/MsgCreateValidator.spec.ts b/lib/src/transaction/msg/staking/MsgCreateValidator.spec.ts index e4a0cb69..b62e251a 100644 --- a/lib/src/transaction/msg/staking/MsgCreateValidator.spec.ts +++ b/lib/src/transaction/msg/staking/MsgCreateValidator.spec.ts @@ -36,9 +36,9 @@ describe('Testing MsgCreateValidator', function () { moniker: 'hiteshTest', }, commission: { - rate: '0.1', - maxRate: '0.2', - maxChangeRate: '0.01', + rate: '10000000000', + maxRate: '20000000000', + maxChangeRate: '10000000000', }, minSelfDelegation: '1', delegatorAddress: 'tcro1j7pej8kplem4wt50p4hfvndhuw5jprxxn5625q', @@ -67,9 +67,9 @@ describe('Testing MsgCreateValidator', function () { securityContact: 'hitesh.goel@crypto.com', }, commission: { - rate: '0.1', - maxRate: '0.2', - maxChangeRate: '0.01', + rate: '10000000000', + maxRate: '20000000000', + maxChangeRate: '10000000000', }, pubkey: 'ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=', minSelfDelegation: '1', @@ -85,9 +85,9 @@ describe('Testing MsgCreateValidator', function () { securityContact: 'hitesh.goel@crypto.com', }, commission: { - rate: '0.1', - maxRate: '0.2', - maxChangeRate: '0.01', + rate: '10000000000', + maxRate: '20000000000', + maxChangeRate: '10000000000', }, pubkey: protoEncodeEd25519PubKey( Bytes.fromBase64String('ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM='), @@ -111,9 +111,9 @@ describe('Testing MsgCreateValidator', function () { securityContact: 'hitesh.goel@crypto.com', }, commission: { - rate: '0.1', - maxRate: '0.2', - maxChangeRate: '0.01', + rate: '10000000000', + maxRate: '20000000000', + maxChangeRate: '10000000000', }, pubkey: 'ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=', minSelfDelegation: '1', @@ -130,9 +130,9 @@ describe('Testing MsgCreateValidator', function () { securityContact: 'hitesh.goel@crypto.com', }, commission: { - rate: '0.1', - maxRate: '0.2', - maxChangeRate: '0.01', + rate: '10000000000', + maxRate: '20000000000', + maxChangeRate: '10000000000', }, pubkey, minSelfDelegation: '1', @@ -160,9 +160,9 @@ describe('Testing MsgCreateValidator', function () { details: '', }, commission: { - rate: '0.1', - maxRate: '0.2', - maxChangeRate: '0.01', + rate: '10000000000', + maxRate: '20000000000', + maxChangeRate: '10000000000', }, pubkey: 'ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=', minSelfDelegation: '1', @@ -183,7 +183,7 @@ describe('Testing MsgCreateValidator', function () { const signedTxHex = signedTx.encode().toHexString(); expect(signedTxHex).to.be.eql( - '0ab4020ab1020a2a2f636f736d6f732e7374616b696e672e763162657461312e4d736743726561746556616c696461746f721282020a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a0012100a03302e311203302e321a04302e30311a0131222b7463726f313635747a63726832796c3833673871657178756567326735677a6775353779336665336b63332a2f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e767232430a1d2f636f736d6f732e63727970746f2e656432353531392e5075624b657912220a20ca4c63b3e731a331e236ea6d5c81c448854a41c8f50f0828eecc0e5ecdc769333a1c0a08626173657463726f12103132303030353030303030303030303012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40f659741d05e997666313a98b545398937b6aa40d884f1f2bf5aed8a281b5118d1123d11e98db388a6cf303a2c41341b6602b685d967aebf4b74af67d767dbd45', + '0acb020ac8020a2a2f636f736d6f732e7374616b696e672e763162657461312e4d736743726561746556616c696461746f721299020a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a0012270a0b3130303030303030303030120b32303030303030303030301a0b31303030303030303030301a0131222b7463726f313635747a63726832796c3833673871657178756567326735677a6775353779336665336b63332a2f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e767232430a1d2f636f736d6f732e63727970746f2e656432353531392e5075624b657912220a20ca4c63b3e731a331e236ea6d5c81c448854a41c8f50f0828eecc0e5ecdc769333a1c0a08626173657463726f12103132303030353030303030303030303012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a404ba43f9ddac81dec3325d20d6b31deb67be19d7d331cc5504009b68bca76d7ff57620f93ebe9f0fed44f0a56f01e812b9b8f6dc97b81c60c2a32a21e4415f34a', ); }); diff --git a/lib/src/transaction/msg/staking/MsgEditValidator.spec.ts b/lib/src/transaction/msg/staking/MsgEditValidator.spec.ts index fd6ff665..bb0502cc 100644 --- a/lib/src/transaction/msg/staking/MsgEditValidator.spec.ts +++ b/lib/src/transaction/msg/staking/MsgEditValidator.spec.ts @@ -62,7 +62,7 @@ describe('Testing MsgEditValidator', function () { details: 'HiteshTest', }, validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx', - commissionRate: '0.100000000000000000', + commissionRate: '100000000000000000', minSelfDelegation: '2', }); @@ -77,7 +77,7 @@ describe('Testing MsgEditValidator', function () { details: 'HiteshTest', }, validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx', - commissionRate: '0.100000000000000000', + commissionRate: '100000000000000000', minSelfDelegation: '2', }, }; @@ -89,7 +89,7 @@ describe('Testing MsgEditValidator', function () { const msgSend = new cro.staking.MsgEditValidator({ description: {}, validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx', - commissionRate: '0.100000000000000000', + commissionRate: '100000000000000000', minSelfDelegation: '2', }); @@ -98,7 +98,7 @@ describe('Testing MsgEditValidator', function () { value: { description: {}, validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3wx', - commissionRate: '0.100000000000000000', + commissionRate: '100000000000000000', minSelfDelegation: '2', }, }; @@ -119,7 +119,7 @@ describe('Testing MsgEditValidator', function () { securityContact: 'hitesh.goel@crypto.com', details: '', }, - commissionRate: '0.100000000000000000', + commissionRate: '100000000000000000', minSelfDelegation: '1.0', validatorAddress: 'tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr', }); @@ -135,7 +135,7 @@ describe('Testing MsgEditValidator', function () { const signedTx = signableTx.setSignature(0, anyKeyPair.sign(signableTx.toSignDocumentHash(0))).toSigned(); const signedTxHex = signedTx.encode().toHexString(); expect(signedTxHex).to.be.eql( - '0aa7010aa4010a282f636f736d6f732e7374616b696e672e763162657461312e4d73674564697456616c696461746f7212780a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a00122f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e76721a14302e3130303030303030303030303030303030302203312e3012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a4087e81b3b9706a35520778ed9099560c86b3ce8aaec3b384cc9720c89d3e044ab2601240a0d83f6a2e683e370c828b27dca8117de53eea269065c034e45e820f3', + '0aa5010aa2010a282f636f736d6f732e7374616b696e672e763162657461312e4d73674564697456616c696461746f7212760a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a00122f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e76721a123130303030303030303030303030303030302203312e3012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40fe79a59e66813e4848d3c807ccf4a8f8b4cb91e0a4db97aa2e61dba4db2b4c9b100e4ebbc20dc7a08015a0bd6b1ef040be4a3e9584edb5f66b843d8c6b389432', ); }); @@ -149,7 +149,7 @@ describe('Testing MsgEditValidator', function () { details: 'HiteshTest', }, validatorAddress: 'tcro1j7pej8kplem4wt50p4hfvndhuw5jprxxn5625q', - commissionRate: '0.100000000000000000', + commissionRate: '100000000000000000', minSelfDelegation: '2', }; @@ -162,7 +162,7 @@ describe('Testing MsgEditValidator', function () { details: 'HiteshTest', }, validatorAddress: 'tcrocncl16mmzexp3zqfpgqtnn927m5ph560qgxrs52a3w', - commissionRate: '0.100000000000000000', + commissionRate: '100000000000000000', minSelfDelegation: '2', }; diff --git a/lib/src/utils/txDecoder.spec.ts b/lib/src/utils/txDecoder.spec.ts index 72fe737b..b2b84c22 100644 --- a/lib/src/utils/txDecoder.spec.ts +++ b/lib/src/utils/txDecoder.spec.ts @@ -127,7 +127,7 @@ describe('TxDecoder', function () { '0ab4020ab1020a2a2f636f736d6f732e7374616b696e672e763162657461312e4d736743726561746556616c696461746f721282020a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a0012100a03302e311203302e321a04302e30311a0131222b7463726f313635747a63726832796c3833673871657178756567326735677a6775353779336665336b63332a2f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e767232430a1d2f636f736d6f732e63727970746f2e656432353531392e5075624b657912220a20ca4c63b3e731a331e236ea6d5c81c448854a41c8f50f0828eecc0e5ecdc769333a1c0a08626173657463726f12103132303030353030303030303030303012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40f659741d05e997666313a98b545398937b6aa40d884f1f2bf5aed8a281b5118d1123d11e98db388a6cf303a2c41341b6602b685d967aebf4b74af67d767dbd45', ) .toCosmosJSON(), - ).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "hitesh.goel@crypto.com", "details": "" }, "commission": { "rate": "0.100000000000000000", "max_rate": "0.200000000000000000", "max_change_rate": "0.010000000000000000" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "memo": "", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] }, "auth_info": { "signer_infos": [{ "public_key": { "@type": "/cosmos.crypto.secp256k1.PubKey", "key": "A/0NVgtsSqHKFnIdA5oZKGfDRX4Z2tVT7bmOe6iLFZwn" }, "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } }, "sequence": "2" }], "fee": { "amount": [], "gas_limit": "200000", "payer": "", "granter": "" } }, "signatures": ["9ll0HQXpl2ZjE6mLVFOYk3tqpA2ITx8r9a7YooG1EY0RI9EemNs4imzzA6LEE0G2YCtoXZZ66/S3SvZ9dn29RQ=="] })); + ).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "hitesh.goel@crypto.com", "details": "" }, "commission": { "rate": "0.1", "max_rate": "0.2", "max_change_rate": "0.01" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "memo": "", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] }, "auth_info": { "signer_infos": [{ "public_key": { "@type": "/cosmos.crypto.secp256k1.PubKey", "key": "A/0NVgtsSqHKFnIdA5oZKGfDRX4Z2tVT7bmOe6iLFZwn" }, "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } }, "sequence": "2" }], "fee": { "amount": [], "gas_limit": "200000", "payer": "", "granter": "" } }, "signatures": ["9ll0HQXpl2ZjE6mLVFOYk3tqpA2ITx8r9a7YooG1EY0RI9EemNs4imzzA6LEE0G2YCtoXZZ66/S3SvZ9dn29RQ=="] })); }); it('should decode `MsgCreateValidator` with no-decimal commission rates', function () { @@ -139,7 +139,7 @@ describe('TxDecoder', function () { , ) .toCosmosJSON(), - ).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest" }, "commission": { "rate": "0.100000000000000000", "max_rate": "0.200000000000000000", "max_change_rate": "0.010000000000000000" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "memo": "", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] }, "auth_info": { "signer_infos": [{ "public_key": { "@type": "/cosmos.crypto.secp256k1.PubKey", "key": "A/0NVgtsSqHKFnIdA5oZKGfDRX4Z2tVT7bmOe6iLFZwn" }, "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } }, "sequence": "2" }], "fee": { "amount": [], "gas_limit": "200000", "payer": "", "granter": "" } }, "signatures": ["qe7YZd/7lau8YzUS8X55k9nlRnjyBbjpBDESKF0ZZcYudd0Kw/UDBao10m0/ouqKSwMC4Eqcvo/emU3xFNpG1Q=="] })); + ).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgCreateValidator", "description": { "moniker": "hiteshTest" }, "commission": { "rate": "100000000000000000", "max_rate": "200000000000000000", "max_change_rate": "10000000000000000" }, "min_self_delegation": "1", "delegator_address": "tcro165tzcrh2yl83g8qeqxueg2g5gzgu57y3fe3kc3", "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "pubkey": { "@type": "/cosmos.crypto.ed25519.PubKey", "key": "ykxjs+cxozHiNuptXIHESIVKQcj1Dwgo7swOXs3HaTM=" }, "value": { "denom": "basetcro", "amount": "1200050000000000" } }], "memo": "", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] }, "auth_info": { "signer_infos": [{ "public_key": { "@type": "/cosmos.crypto.secp256k1.PubKey", "key": "A/0NVgtsSqHKFnIdA5oZKGfDRX4Z2tVT7bmOe6iLFZwn" }, "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } }, "sequence": "2" }], "fee": { "amount": [], "gas_limit": "200000", "payer": "", "granter": "" } }, "signatures": ["qe7YZd/7lau8YzUS8X55k9nlRnjyBbjpBDESKF0ZZcYudd0Kw/UDBao10m0/ouqKSwMC4Eqcvo/emU3xFNpG1Q=="] })); }); }) @@ -162,7 +162,7 @@ describe('TxDecoder', function () { '0aa5010aa2010a282f636f736d6f732e7374616b696e672e763162657461312e4d73674564697456616c696461746f7212760a2a0a0a6869746573685465737412001a0022166869746573682e676f656c4063727970746f2e636f6d2a00122f7463726f636e636c316a3770656a386b706c656d347774353070346866766e64687577356a707278787874656e76721a123130303030303030303030303030303030302203312e3012580a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103fd0d560b6c4aa1ca16721d039a192867c3457e19dad553edb98e7ba88b159c2712040a0208011802120410c09a0c1a40fe79a59e66813e4848d3c807ccf4a8f8b4cb91e0a4db97aa2e61dba4db2b4c9b100e4ebbc20dc7a08015a0bd6b1ef040be4a3e9584edb5f66b843d8c6b389432', ) .toCosmosJSON(), - ).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgEditValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "hitesh.goel@crypto.com", "details": "" }, "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "commission_rate": "0.100000000000000000", "min_self_delegation": "1.0" }], "memo": "", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] }, "auth_info": { "signer_infos": [{ "public_key": { "@type": "/cosmos.crypto.secp256k1.PubKey", "key": "A/0NVgtsSqHKFnIdA5oZKGfDRX4Z2tVT7bmOe6iLFZwn" }, "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } }, "sequence": "2" }], "fee": { "amount": [], "gas_limit": "200000", "payer": "", "granter": "" } }, "signatures": ["/nmlnmaBPkhI08gHzPSo+LTLkeCk25eqLmHbpNsrTJsQDk67wg3HoIAVoL1rHvBAvko+lYTttfZrhD2MaziUMg=="] })); + ).to.deep.equal(JSON.stringify({ "body": { "messages": [{ "@type": "/cosmos.staking.v1beta1.MsgEditValidator", "description": { "moniker": "hiteshTest", "identity": "", "website": "", "security_contact": "hitesh.goel@crypto.com", "details": "" }, "validator_address": "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", "commission_rate": "100000000000000000", "min_self_delegation": "1.0" }], "memo": "", "timeout_height": "0", "extension_options": [], "non_critical_extension_options": [] }, "auth_info": { "signer_infos": [{ "public_key": { "@type": "/cosmos.crypto.secp256k1.PubKey", "key": "A/0NVgtsSqHKFnIdA5oZKGfDRX4Z2tVT7bmOe6iLFZwn" }, "mode_info": { "single": { "mode": "SIGN_MODE_DIRECT" } }, "sequence": "2" }], "fee": { "amount": [], "gas_limit": "200000", "payer": "", "granter": "" } }, "signatures": ["/nmlnmaBPkhI08gHzPSo+LTLkeCk25eqLmHbpNsrTJsQDk67wg3HoIAVoL1rHvBAvko+lYTttfZrhD2MaziUMg=="] })); }); it('should decode `MsgEditValidator` with `null` commissionRate', function () { const txDecoder = new TxDecoder(); diff --git a/lib/src/utils/txDecoder.ts b/lib/src/utils/txDecoder.ts index 527cedeb..a744c4b1 100644 --- a/lib/src/utils/txDecoder.ts +++ b/lib/src/utils/txDecoder.ts @@ -3,7 +3,7 @@ import { toBase64, fromBase64 } from '@cosmjs/encoding'; import { AuthInfo, TxBody, SignerInfo, Tx } from '@cosmjs/proto-signing/build/codec/cosmos/tx/v1beta1/tx'; import * as snakecaseKeys from 'snakecase-keys'; import Long from 'long'; -import Big from 'big.js'; +// import Big from 'big.js'; import { cosmos, ics23, tendermintV2 } from '../cosmos/v1beta1/codec/generated/codecimpl'; import { Bytes } from './bytes/bytes'; import { typeUrlMappings } from '../cosmos/v1beta1/types/typeurls'; @@ -11,7 +11,7 @@ import { COSMOS_MSG_TYPEURL } from '../transaction/common/constants/typeurl'; import { convertSecondsNanosToTZFormat } from './timestamp'; const cosmJSRegistry = new Registry(Object.entries(typeUrlMappings)); -const DISPLAY_DIVISION_STRING = '1000000000000000000'; +// const DISPLAY_DIVISION_STRING = '1000000000000000000'; export class TxDecoder { private libDecodedTxBody!: TxBody; @@ -142,51 +142,18 @@ function handleSpecialParams(decodedParams: any, typeUrl: string) { if (typeUrl === COSMOS_MSG_TYPEURL.MsgCreateValidator) { clonedDecodedParams.pubkey = decodeAnyType(decodedParams.pubkey.type_url, decodedParams.pubkey.value); clonedDecodedParams.pubkey.key = Bytes.fromUint8Array(clonedDecodedParams.pubkey.key).toBase64String(); - - // Check if the `commission` object values are represented already in `float` - /*eslint-disable */ - for (const key in decodedParams.commission) { - const rateString = decodedParams.commission[key]; - const splitRateByDecimal = rateString.split('.'); - - // if `string` has `NO` decimal place - if (splitRateByDecimal.length === 1) { - const rateToBig = new Big(rateString); - clonedDecodedParams.commission[key] = rateToBig.div(new Big(DISPLAY_DIVISION_STRING)).toFixed(18); - } - // If `string` has `ONE` decimal place - else if (splitRateByDecimal.length === 2) { - const rateToBig = new Big(rateString); - clonedDecodedParams.commission[key] = rateToBig.toFixed(18); - } - } } // handle `MsgEditValidator` if (typeUrl === COSMOS_MSG_TYPEURL.MsgEditValidator) { - if (decodedParams.commissionRate === "" || typeof decodedParams.commissionRate === "undefined") { + if (decodedParams.commissionRate === '' || typeof decodedParams.commissionRate === 'undefined') { clonedDecodedParams.commissionRate = null; - } else { - const rateString = decodedParams.commissionRate; - const splitRateByDecimal = rateString.split('.'); - - // if `string` has `NO` decimal place - if (splitRateByDecimal.length === 1) { - const rateToBig = new Big(rateString); - clonedDecodedParams.commissionRate = rateToBig.div(new Big(DISPLAY_DIVISION_STRING)).toFixed(18); - } - // If `string` has `ONE` decimal place - else if (splitRateByDecimal.length === 2) { - const rateToBig = new Big(rateString); - clonedDecodedParams.commissionRate = rateToBig.toFixed(18); - } } // use `null` in case minSelfDelegation is undefined - if (decodedParams.minSelfDelegation === "" || typeof decodedParams.minSelfDelegation === "undefined") { + if (decodedParams.minSelfDelegation === '' || typeof decodedParams.minSelfDelegation === 'undefined') { clonedDecodedParams.minSelfDelegation = null; } - } /* eslint-enable */ diff --git a/package-lock.json b/package-lock.json index ccbf0023..984b45cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@crypto-org-chain/chain-jslib", - "version": "1.0.5", + "version": "1.0.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@crypto-org-chain/chain-jslib", - "version": "1.0.5", + "version": "1.0.7", "license": "Apache-2.0", "dependencies": { "@cosmjs/amino": "0.25.0-alpha.2", From 785d6c96fc7e14c88b71c67aadce8267e21ec181 Mon Sep 17 00:00:00 2001 From: cdc-Hitesh Date: Thu, 10 Nov 2022 21:01:43 +0800 Subject: [PATCH 2/3] Add changelog and increment package version --- CHANGELOG.md | 3 +++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5826921..bdc4b247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. +## v1.0.8 +- Fix decimal formatted tx decoding for `MsgCreateValidator` type of `MsgEditValidator` + ## v1.0.7 - Fix incorrect `proposal_id` type of `MsgDeposit` in Amino format diff --git a/package-lock.json b/package-lock.json index 984b45cc..614e2f61 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@crypto-org-chain/chain-jslib", - "version": "1.0.7", + "version": "1.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@crypto-org-chain/chain-jslib", - "version": "1.0.7", + "version": "1.0.8", "license": "Apache-2.0", "dependencies": { "@cosmjs/amino": "0.25.0-alpha.2", diff --git a/package.json b/package.json index 0badbb9d..1fa7e66a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@crypto-org-chain/chain-jslib", - "version": "1.0.7", + "version": "1.0.8", "description": "Crypto.org Chain JavaScript library", "author": "Crypto.org ", "license": "Apache-2.0", From 2b2c74580055cd39bbf494b99c8510964e81b8a6 Mon Sep 17 00:00:00 2001 From: cdc-Hitesh Date: Thu, 10 Nov 2022 21:05:39 +0800 Subject: [PATCH 3/3] Fix typo and grammar for changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdc4b247..8d856db7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. ## v1.0.8 -- Fix decimal formatted tx decoding for `MsgCreateValidator` type of `MsgEditValidator` +- Fix wrong commission tx decoding for `MsgCreateValidator` and `MsgEditValidator` ## v1.0.7 - Fix incorrect `proposal_id` type of `MsgDeposit` in Amino format