From 2e1fbaed9c417315c9f140449bcbb93dc2370624 Mon Sep 17 00:00:00 2001 From: SaReN Date: Fri, 21 Aug 2020 21:13:12 +0530 Subject: [PATCH] Fix skip confirm logic (#7085) * Fix skip confirm logic * Fix dry run * Update gh actions * Replace switch with if * revert liveness fix * Add key.Sum validation Co-authored-by: Alessio Treglia --- client/tx/tx.go | 2 +- std/pubkey.go | 10 ++++++++++ std/pubkey_test.go | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client/tx/tx.go b/client/tx/tx.go index 64f8ba2b7e..963be2ba9e 100644 --- a/client/tx/tx.go +++ b/client/tx/tx.go @@ -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 } diff --git a/std/pubkey.go b/std/pubkey.go index ff7a636b78..cac6ef8837 100644 --- a/std/pubkey.go +++ b/std/pubkey.go @@ -20,6 +20,13 @@ var _ types.PublicKeyCodec = DefaultPublicKeyCodec{} // Decode implements the PublicKeyCodec.Decode method func (cdc DefaultPublicKeyCodec) Decode(key *types.PublicKey) (crypto.PubKey, error) { + // key being nil is allowed as all fields in proto are optional + if key == nil { + return nil, nil + } + if key.Sum == nil { + return nil, nil + } switch key := key.Sum.(type) { case *types.PublicKey_Secp256K1: n := len(key.Secp256K1) @@ -68,6 +75,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 diff --git a/std/pubkey_test.go b/std/pubkey_test.go index 22397a4b78..484a5d8990 100644 --- a/std/pubkey_test.go +++ b/std/pubkey_test.go @@ -25,6 +25,10 @@ func roundTripTest(t *testing.T, pubKey crypto.PubKey) { } func TestDefaultPublicKeyCodec(t *testing.T) { + roundTripTest(t, nil) + + roundTripTest(t, crypto.PubKey(nil)) + pubKeySecp256k1 := secp256k1.GenPrivKey().PubKey() roundTripTest(t, pubKeySecp256k1)