Cosmos-sdk: Delete BechValidator by bechsifying the validator pubKey on MarshalJSON

Created on 10 Sep 2018  ·  5Comments  ·  Source: cosmos/cosmos-sdk

Summary

Get rid of the BechValidator struct by bechsifying the validator public key when marshaled to JSON

Problem Definition

Currently the only attribute that Validator and BechValidator differ when marshaled to JSON is the pub_key. Here's an example output for the Validator Pubkey:

“pub_key”: {
     “type”: “tendermint/PubKeyEd25519”,
     “value”: “AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE=”
},

what we would like is to return a string with the cosmosconspub prefix by using the sdk.Bech32ifyConsPub(pub crypto.PubKey) function

Proposal

As @sunnya97 said, the Validator.Operator (sdk.ValAddress) is converted to string with the bech32 encoding when marshaled to JSON. We'd have to implement the same logic for the PubKey.

cc: @Liamsi who said he could implement this


For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
UX good first issue staking

All 5 comments

This is a really simple change. Wasn't there a reason though for having both a bechified and a non-bechified version in the first place? It doesn't look like it makes much sense but maybe there is some reason for this design-decision? cc @zmanian @ValarDragon

This seems like a good idea to me. The only point of confusion may be that output from tendermint and date in state won't know about bech32. I think thats fine, if your parsing through tm state its reasonable to expect awareness of how pubkeys and addresses are encoded. (Now that were using default bech32, there should be libraries in basically every language to ease this)

All for this and DRY-ing up the code.

OK, the simples to implement this is to have a non-public helper struct and implement amino's MarshalJSON and UnmarshalJSON for the original Validator struct. Then we can remove all occurrences BechValidator. Will push sth. shortly.

This is probably a legacy of the original idea that we should have a way of getting raw hex encoded values for machine readable interfaces

Was this page helpful?
0 / 5 - 0 ratings