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 skip confirm logic #7085

Merged
merged 9 commits into from
Aug 21, 2020
2 changes: 1 addition & 1 deletion client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
}

if !clientCtx.SkipConfirm {
out, err := clientCtx.JSONMarshaler.MarshalJSON(tx)
out, err := clientCtx.TxConfig.TxJSONEncoder()(tx.GetTx())
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions std/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var _ types.PublicKeyCodec = DefaultPublicKeyCodec{}

// Decode implements the PublicKeyCodec.Decode method
func (cdc DefaultPublicKeyCodec) Decode(key *types.PublicKey) (crypto.PubKey, error) {
if key == nil {
return nil, nil
}
Comment on lines +24 to +26
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the pubkey is nil, error makes sense. Is there a reason to handle nil separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nil is a valid pubkey, so it shouldn't error

Copy link
Contributor

@amaury1093 amaury1093 Aug 19, 2020

Choose a reason for hiding this comment

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

I thought PublicKey was a sum. Can you explain how nil is a valid pubkey?

Edit: we're migrating to Any, but imo it should still not be 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.

I don't have full context, @aaronc can explain better

Copy link
Member

@aaronc aaronc Aug 19, 2020

Choose a reason for hiding this comment

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

All fields in proto are optional by default but pubkey is definitely optional. nil is correct here. I can't think of any other good way to handle this. Let's add an explanatory comment.

Copy link
Member

Choose a reason for hiding this comment

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

We should also add a case for key.Sum being nil.

switch key := key.Sum.(type) {
case *types.PublicKey_Secp256K1:
n := len(key.Secp256K1)
Expand Down Expand Up @@ -68,6 +71,9 @@ func (cdc DefaultPublicKeyCodec) Decode(key *types.PublicKey) (crypto.PubKey, er

// Encode implements the PublicKeyCodec.Encode method
func (cdc DefaultPublicKeyCodec) Encode(key crypto.PubKey) (*types.PublicKey, error) {
if key == nil {
return &types.PublicKey{}, nil
}
switch key := key.(type) {
case secp256k1.PubKey:
return &types.PublicKey{Sum: &types.PublicKey_Secp256K1{Secp256K1: key}}, nil
Expand Down
2 changes: 2 additions & 0 deletions std/pubkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func roundTripTest(t *testing.T, pubKey crypto.PubKey) {
}

func TestDefaultPublicKeyCodec(t *testing.T) {
roundTripTest(t, nil)

pubKeySecp256k1 := secp256k1.GenPrivKey().PubKey()
roundTripTest(t, pubKeySecp256k1)

Expand Down