Skip to content

Commit

Permalink
Migrate {x/auth, x/gov, x/staking} missing CLI queries to proto (#6994)
Browse files Browse the repository at this point in the history
* Fix error code

* Fix decoder

* Fix typo

* Fix decode

* refactor

* Migrate SearchTxsResult to proto

* fix MarkEventsToIndex

* lint++

* Fix output

* Add QueryTxCmd cli test

* Add fmt

* Put txBuilder in types/tx

* Add GetAnyTx in TxBuilder

* Add new IsAnyTx

* Rename to IntoAny

* Fix bug

* fmt

Co-authored-by: Marie <marie.gauthier63@gmail.com>

* Fix ibc CLI to use proto

* Fix any MarshalJSON

* Fix test

* Make tx.Tx implement sdk.Tx

* Register sdk.Tx

* Fix lint

* Allow DefaultJSONTxEncoder to take tx.Tx

* refactor

* Rename variable

* remove fmt

Co-authored-by: Anil Kumar Kammari <anil@vitwit.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Marie <marie.gauthier63@gmail.com>
  • Loading branch information
6 people authored Sep 10, 2020
1 parent d84296a commit b234818
Show file tree
Hide file tree
Showing 26 changed files with 758 additions and 258 deletions.
9 changes: 8 additions & 1 deletion client/grpc/simulate/simulate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/simulate"
"github.com/cosmos/cosmos-sdk/client/tx"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -98,9 +100,14 @@ func (s IntegrationTestSuite) TestSimulateService() {
)
txBuilder.SetSignatures(sigV2)

any, ok := txBuilder.(codectypes.IntoAny)
s.Require().True(ok)
cached := any.AsAny().GetCachedValue()
txTx, ok := cached.(*txtypes.Tx)
s.Require().True(ok)
res, err := s.queryClient.Simulate(
context.Background(),
&simulate.SimulateRequest{Tx: txBuilder.GetProtoTx()},
&simulate.SimulateRequest{Tx: txTx},
)
s.Require().NoError(err)

Expand Down
1 change: 0 additions & 1 deletion client/tx/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

// ConvertTxToStdTx converts a transaction to the legacy StdTx format
func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (types.StdTx, error) {

if stdTx, ok := tx.(types.StdTx); ok {
return stdTx, nil
}
Expand Down
19 changes: 7 additions & 12 deletions client/tx/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@ package tx_test
import (
"testing"

"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/simapp/params"

"github.com/cosmos/cosmos-sdk/x/auth/signing"

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/client"
tx2 "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
types3 "github.com/cosmos/cosmos-sdk/x/auth/types"

signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types"
signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
types3 "github.com/cosmos/cosmos-sdk/x/auth/types"
types2 "github.com/cosmos/cosmos-sdk/x/bank/types"
)

Expand Down
14 changes: 13 additions & 1 deletion client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
sim "github.com/cosmos/cosmos-sdk/client/grpc/simulate"
"github.com/cosmos/cosmos-sdk/client/input"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
)
Expand Down Expand Up @@ -265,7 +267,17 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) {
return nil, err
}

simReq := sim.SimulateRequest{Tx: txb.GetProtoTx()}
any, ok := txb.(codectypes.IntoAny)
if !ok {
return nil, fmt.Errorf("cannot simulate tx that cannot be wrapped into any")
}
cached := any.AsAny().GetCachedValue()
protoTx, ok := cached.(*tx.Tx)
if !ok {
return nil, fmt.Errorf("cannot simulate amino tx")
}

simReq := sim.SimulateRequest{Tx: protoTx}

return simReq.Marshal()
}
Expand Down
5 changes: 2 additions & 3 deletions client/tx/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)

func NewTestTxConfig() client.TxConfig {
_, cdc := simapp.MakeCodecs()
return types.StdTxConfig{Cdc: cdc}
cfg := simapp.MakeEncodingConfig()
return cfg.TxConfig
}

func TestCalculateGas(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions client/tx_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package client

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx"
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)
Expand Down Expand Up @@ -36,8 +35,6 @@ type (
// also know how to encode itself.
TxBuilder interface {
GetTx() signing.Tx
// GetProtoTx returns the tx as a proto.Message.
GetProtoTx() *tx.Tx

SetMsgs(msgs ...sdk.Msg) error
SetSignatures(signatures ...signingtypes.SignatureV2) error
Expand Down
7 changes: 6 additions & 1 deletion codec/types/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (any *Any) Pack(x proto.Message) error {
func UnsafePackAny(x interface{}) *Any {
if msg, ok := x.(proto.Message); ok {
any, err := NewAnyWithValue(msg)
if err != nil {
if err == nil {
return any
}
}
Expand All @@ -107,3 +107,8 @@ func (any *Any) GetCachedValue() interface{} {
func (any *Any) ClearCachedValue() {
any.cachedValue = nil
}

// IntoAny represents a type that can be wrapped into an Any.
type IntoAny interface {
AsAny() *Any
}
2 changes: 1 addition & 1 deletion codec/types/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (any *Any) UnmarshalAmino(bz []byte) error {
return nil
}

func (any Any) MarshalJSON() ([]byte, error) {
func (any *Any) MarshalJSON() ([]byte, error) {
ac := any.compat
if ac == nil {
return nil, anyCompatError("JSON marshal", any)
Expand Down
27 changes: 27 additions & 0 deletions proto/cosmos/base/abci/v1beta1/abci.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,30 @@ message TxMsgData {

repeated MsgData data = 1;
}

// SearchTxsResult defines a structure for querying txs pageable
message SearchTxsResult {
option (gogoproto.stringer) = true;

// Count of all txs
uint64 total_count = 1 [
(gogoproto.moretags) = "yaml:\"total_count\"",
(gogoproto.jsontag) = "total_count"
];
// Count of txs in current page
uint64 count = 2;
// Index of current page, start from 1
uint64 page_number = 3 [
(gogoproto.moretags) = "yaml:\"page_number\"",
(gogoproto.jsontag) = "page_number"
];
// Count of total pages
uint64 page_total = 4 [
(gogoproto.moretags) = "yaml:\"page_total\"",
(gogoproto.jsontag) = "page_total"
];
// Max count txs per page
uint64 limit = 5;
// List of txs in current page
repeated TxResponse txs = 6;
}
2 changes: 2 additions & 0 deletions std/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

Expand All @@ -17,5 +18,6 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
// RegisterInterfaces registers Interfaces from sdk/types and vesting
func RegisterInterfaces(interfaceRegistry types.InterfaceRegistry) {
sdk.RegisterInterfaces(interfaceRegistry)
txtypes.RegisterInterfaces(interfaceRegistry)
vesting.RegisterInterfaces(interfaceRegistry)
}
Loading

0 comments on commit b234818

Please sign in to comment.