Skip to content

Commit

Permalink
fix: remove legacy REST endpoints for broadcast & encode (v0.44.x) (c…
Browse files Browse the repository at this point in the history
…osmos#10041)

* fix: remove legacy REST endpoints for broadcast & encode

* add changelog

* update changelog

* fix amino tx marshaling test

* try to fix x/auth/client/rest tests

* changing tx broadcast request type

* remove auth client/rest_test.go

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
  • Loading branch information
2 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 5ebc2b8 commit fcf5e34
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 11 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes
* (client/tx) [\#9421](https://github.com/cosmos/cosmos-sdk/pull/9421/) `BuildUnsignedTx`, `BuildSimTx`, `PrintUnsignedStdTx` functions are moved to
the Tx Factory as methods.


### Client Breaking Changes
* [\#10041](https://github.com/cosmos/cosmos-sdk/pull/10041) Remove broadcast & encode legacy REST endpoints. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/master/migrations/rest.html) to migrate to the new REST endpoints.

## [v0.43.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.43.0) - 2021-08-10

### Features
Expand Down
24 changes: 24 additions & 0 deletions codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)

func createTestCodec() *codec.LegacyAmino {
Expand Down Expand Up @@ -112,3 +114,25 @@ func TestAminoCodecUnpackAnyFails(t *testing.T) {
require.Error(t, err)
require.Equal(t, err, errors.New("AminoCodec can't handle unpack protobuf Any's"))
}

func TestAminoCodecFullDecodeAndEncode(t *testing.T) {
// This tx comes from https://github.com/cosmos/cosmos-sdk/issues/8117.
txSigned := `{"type":"cosmos-sdk/StdTx","value":{"msg":[{"type":"cosmos-sdk/MsgCreateValidator","value":{"description":{"moniker":"fulltest","identity":"satoshi","website":"example.com","details":"example inc"},"commission":{"rate":"0.500000000000000000","max_rate":"1.000000000000000000","max_change_rate":"0.200000000000000000"},"min_self_delegation":"1000000","delegator_address":"cosmos14pt0q5cwf38zt08uu0n6yrstf3rndzr5057jys","validator_address":"cosmosvaloper14pt0q5cwf38zt08uu0n6yrstf3rndzr52q28gr","pubkey":{"type":"tendermint/PubKeyEd25519","value":"CYrOiM3HtS7uv1B1OAkknZnFYSRpQYSYII8AtMMtev0="},"value":{"denom":"umuon","amount":"700000000"}}}],"fee":{"amount":[{"denom":"umuon","amount":"6000"}],"gas":"160000"},"signatures":[{"pub_key":{"type":"tendermint/PubKeySecp256k1","value":"AwAOXeWgNf1FjMaayrSnrOOKz+Fivr6DiI/i0x0sZCHw"},"signature":"RcnfS/u2yl7uIShTrSUlDWvsXo2p2dYu6WJC8VDVHMBLEQZWc8bsINSCjOnlsIVkUNNe1q/WCA9n3Gy1+0zhYA=="}],"memo":"","timeout_height":"0"}}`
var legacyCdc = simapp.MakeTestEncodingConfig().Amino
var tx legacytx.StdTx
err := legacyCdc.UnmarshalJSON([]byte(txSigned), &tx)
require.NoError(t, err)

// Marshalling/unmarshalling the tx should work.
marshaledTx, err := legacyCdc.MarshalJSON(tx)
require.NoError(t, err)
require.Equal(t, string(marshaledTx), txSigned)

// Marshalling/unmarshalling the tx wrapped in a struct should work.
txRequest := &cli.BroadcastReq{
Mode: "block",
Tx: tx,
}
_, err = legacyCdc.MarshalJSON(txRequest)
require.NoError(t, err)
}
59 changes: 52 additions & 7 deletions x/auth/client/cli/tx_multisign.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ import (
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)

// GetMultiSignCommand returns the multi-sign command
// BroadcastReq defines a tx broadcasting request.
type BroadcastReq struct {
Tx legacytx.StdTx `json:"tx" yaml:"tx"`
Mode string `json:"mode" yaml:"mode"`
}

// GetSignCommand returns the sign command
func GetMultiSignCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "multi-sign <file> <name> [<signature>...]",
Expand Down Expand Up @@ -198,9 +205,31 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {
sigOnly, _ := cmd.Flags().GetBool(flagSigOnly)

var json []byte
json, err = marshalSignatureJSON(txCfg, txBuilder.GetTx(), sigOnly)
if err != nil {
return err

if aminoJSON {
stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx())
if err != nil {
return err
}

req := BroadcastReq{
Tx: stdTx,
Mode: "block|sync|async",
}

json, _ = clientCtx.LegacyAmino.MarshalJSON(req)

} else {
json, err = marshalSignatureJSON(txCfg, txBuilder, sigOnly)
if err != nil {
return err
}
}

outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
if outputDoc == "" {
cmd.Printf("%s\n", json)
return
}

closeFunc, err := setOutputFile(cmd)
Expand Down Expand Up @@ -375,9 +404,25 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error {

sigOnly, _ := cmd.Flags().GetBool(flagSigOnly)
var json []byte
json, err = marshalSignatureJSON(txCfg, txBuilder.GetTx(), sigOnly)
if err != nil {
return err

if aminoJSON {
stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBldr.GetTx())
if err != nil {
return err
}

req := BroadcastReq{
Tx: stdTx,
Mode: "block|sync|async",
}

json, _ = clientCtx.LegacyAmino.MarshalJSON(req)

} else {
json, err = marshalSignatureJSON(txCfg, txBldr, sigOnly)
if err != nil {
return err
}
}

err = clientCtx.PrintString(fmt.Sprintf("%s\n", json))
Expand Down
23 changes: 20 additions & 3 deletions x/auth/client/cli/tx_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)

const (
Expand Down Expand Up @@ -449,8 +448,26 @@ func signTx(cmd *cobra.Command, clientCtx client.Context, txFactory tx.Factory,
if err != nil {
return err
}
if !isSigner {
return errors.New("signing key is not a part of multisig key")

var json []byte
if aminoJSON {
stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx())
if err != nil {
return err
}
req := BroadcastReq{
Tx: stdTx,
Mode: "block|sync|async",
}
json, err = clientCtx.LegacyAmino.MarshalJSON(req)
if err != nil {
return err
}
} else {
json, err = marshalSignatureJSON(txCfg, txBuilder, printSignatureOnly)
if err != nil {
return err
}
}

err = authclient.SignTxWithSignerAddress(
Expand Down

0 comments on commit fcf5e34

Please sign in to comment.