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

Misc CLI fixes #812

Merged
merged 6 commits into from
Apr 11, 2018
Merged

Misc CLI fixes #812

merged 6 commits into from
Apr 11, 2018

Conversation

cwgoes
Copy link
Contributor

@cwgoes cwgoes commented Apr 6, 2018

Ref #810

@cwgoes cwgoes requested a review from ebuchman as a code owner April 6, 2018 16:09
@codecov
Copy link

codecov bot commented Apr 6, 2018

Codecov Report

Merging #812 into develop will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop     #812   +/-   ##
========================================
  Coverage    65.18%   65.18%           
========================================
  Files           67       67           
  Lines         3539     3539           
========================================
  Hits          2307     2307           
  Misses        1045     1045           
  Partials       187      187

@cwgoes cwgoes force-pushed the cwgoes/misc-cli-fixes branch 2 times, most recently from ae87ed2 to a13a4d4 Compare April 9, 2018 14:07
@cwgoes
Copy link
Contributor Author

cwgoes commented Apr 9, 2018

Ref #807

@cwgoes cwgoes force-pushed the cwgoes/misc-cli-fixes branch 3 times, most recently from 6155d45 to 4d4a7ee Compare April 9, 2018 19:06
@cwgoes cwgoes changed the title WIP: Misc CLI fixes Misc CLI fixes Apr 9, 2018
@cwgoes
Copy link
Contributor Author

cwgoes commented Apr 9, 2018

Ready for review.

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

Good stuff, few comments herein also we should include tests for NextSequence and AutoSequence

if err == nil {
var doc tmtypes.GenesisDoc
err = json.Unmarshal(bz, &doc)
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Bad practice to nest if statements like this. I understand that we don't return an error in this function so you are nesting the operations but this suggests to me that this nest should be a seperate function which does return an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, updated.


// Automatically set sequence number
func AutoSequence(ctx core.CoreContext) (core.CoreContext, error) {
if !viper.IsSet(client.FlagSequence) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same thing with the nesting here, instead you could check the opposite and just return if it's true:

if viper.IsSet(client.FlagSequence) {
    return ctx nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

}

// Automatically set sequence number
func AutoSequence(ctx core.CoreContext) (core.CoreContext, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function name is slightly misleading because it's not always auto-sequencing it's only sequencing when there isn't a sequence number provided - but I get that you're trying to avoid dup code in all the command functions.. Maybe a more appropriate name would be SetSequence or EnsureSequence

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to EnsureSequence.

@@ -48,3 +52,13 @@ func (c CoreContext) WithClient(client rpcclient.Client) CoreContext {
c.Client = client
return c
}

func (c CoreContext) WithDecoder(decoder sdk.AccountDecoder) CoreContext {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add comment headers - what's dis stuff doing anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes it easier to change context parameters one-at-a-time (the IBC module uses these functions quite a bit, for example).

Comment headers added.

return c
}

func (c CoreContext) WithAccountStore(accountStore string) CoreContext {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add comment headers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Header added.

@@ -137,6 +140,24 @@ func (ctx CoreContext) SignBuildBroadcast(name string, msg sdk.Msg, cdc *wire.Co
return ctx.BroadcastTx(txBytes)
}

func (c CoreContext) NextSequence(address []byte) (int64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Function header comments please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Header added.

Copy link
Contributor

Choose a reason for hiding this comment

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

uh.. not quite hehehe - I just pushed with a comment though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, too many windows open apparently. Thanks!

@cwgoes
Copy link
Contributor Author

cwgoes commented Apr 10, 2018

Also in favor of tests, but not sure how best to implement - we'll need an app with accounts to test sequence retrieval, doesn't make sense to import Basecoin in the context package. Maybe modules wanting to use sequence retrieval should test it with their own AccountDecoders?

All other comments addressed.

@cwgoes cwgoes dismissed rigelrozanski’s stale review April 10, 2018 09:56

Addressed, except tests (see comment).

@rigelrozanski
Copy link
Contributor

cool - let's finalize the sequence testing as a part of this issue when we address #816

return "", err
}
genesisFile := cfg.GenesisFile()
bz, err := ioutil.ReadFile(genesisFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

func (c CoreContext) WithChainID(chainID string) CoreContext {
c.ChainID = chainID
return c
}

// WithHeight - eturn a copy of the context with an updated height
Copy link
Contributor

Choose a reason for hiding this comment

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

return

@rigelrozanski rigelrozanski merged commit 5212ac0 into develop Apr 11, 2018
@rigelrozanski rigelrozanski deleted the cwgoes/misc-cli-fixes branch April 11, 2018 15:42
@rigelrozanski rigelrozanski restored the cwgoes/misc-cli-fixes branch April 11, 2018 15:43
rigelrozanski added a commit that referenced this pull request Apr 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants