Skip to content

Commit

Permalink
remove x/tx breakage
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Mar 24, 2024
1 parent 7528257 commit 52f4031
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ replace (
cosmossdk.io/x/auth => ./x/auth
cosmossdk.io/x/bank => ./x/bank
cosmossdk.io/x/staking => ./x/staking
cosmossdk.io/x/tx => ./x/tx
)

replace github.com/cosmos/iavl => github.com/cosmos/iavl v1.0.1 // TODO remove
Expand Down
1 change: 0 additions & 1 deletion x/auth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,4 @@ replace (
cosmossdk.io/x/accounts => ../accounts
cosmossdk.io/x/bank => ../bank
cosmossdk.io/x/staking => ../staking
cosmossdk.io/x/tx => ../tx
)
2 changes: 1 addition & 1 deletion x/auth/tx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func newBuilderFromDecodedTx(addrCodec address.Codec, decoder *decode.Decoder, c
addressCodec: addrCodec,
decoder: decoder,
codec: codec,
msgs: decoded.msgsV1,
msgs: decoded.msgs,
timeoutHeight: decoded.GetTimeoutHeight(),
granter: decoded.FeeGranter(),
payer: payer,
Expand Down
37 changes: 23 additions & 14 deletions x/auth/tx/gogotx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

func newWrapperFromDecodedTx(addrCodec address.Codec, cdc codec.BinaryCodec, decodedTx *decode.DecodedTx) (w *gogoTxWrapper, err error) {
// set msgsv1
msgv1, err := decodeMsgsV1(cdc, decodedTx.Tx.Body.Messages)
msgs, err := decodeMsgsV1(cdc, decodedTx.Tx.Body.Messages)
if err != nil {
return nil, fmt.Errorf("unable to convert messagev2 to messagev1: %w", err)
}
Expand Down Expand Up @@ -73,13 +73,21 @@ func newWrapperFromDecodedTx(addrCodec address.Codec, cdc codec.BinaryCodec, dec
return nil, err
}
}

// reflectMsgs
reflectMsgs := make([]protoreflect.Message, len(msgs))
for i, msg := range decodedTx.Messages {
reflectMsgs[i] = msg.ProtoReflect()
}

return &gogoTxWrapper{
cdc: cdc,
decodedTx: decodedTx,
msgsV1: msgv1,
fees: fees,
feePayer: feePayer,
feeGranter: feeGranter,
cdc: cdc,
decodedTx: decodedTx,
reflectMsgs: reflectMsgs,
msgs: msgs,
fees: fees,
feePayer: feePayer,
feeGranter: feeGranter,
}, nil
}

Expand All @@ -89,10 +97,11 @@ type gogoTxWrapper struct {
decodedTx *decode.DecodedTx
cdc codec.BinaryCodec

msgsV1 []proto.Message
fees sdk.Coins
feePayer []byte
feeGranter []byte
msgs []proto.Message
reflectMsgs []protoreflect.Message
fees sdk.Coins
feePayer []byte
feeGranter []byte
}

func (w *gogoTxWrapper) String() string { return w.decodedTx.Tx.String() }
Expand All @@ -111,14 +120,14 @@ type ExtensionOptionsTxBuilder interface {
}

func (w *gogoTxWrapper) GetMsgs() []sdk.Msg {
if w.msgsV1 == nil {
if w.msgs == nil {
panic("fill in msgs")
}
return w.msgsV1
return w.msgs
}

func (w *gogoTxWrapper) GetReflectMessages() ([]protoreflect.Message, error) {
return w.decodedTx.Messages, nil
return w.reflectMsgs, nil
}

func (w *gogoTxWrapper) ValidateBasic() error {
Expand Down
8 changes: 3 additions & 5 deletions x/tx/decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import (

"github.com/cosmos/cosmos-proto/anyutil"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
errorsmod "cosmossdk.io/errors"

"cosmossdk.io/x/tx/signing"
)

// DecodedTx contains the decoded transaction, its signers, and other flags.
type DecodedTx struct {
Messages []protoreflect.Message
Messages []proto.Message
Tx *v1beta1.Tx
TxRaw *v1beta1.TxRaw
Signers [][]byte
Expand Down Expand Up @@ -98,14 +96,14 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) {
}

var signers [][]byte
var msgs []protoreflect.Message
var msgs []proto.Message
seenSigners := map[string]struct{}{}
for _, anyMsg := range body.Messages {
msg, signerErr := anyutil.Unpack(anyMsg, fileResolver, d.signingCtx.TypeResolver())
if signerErr != nil {
return nil, errorsmod.Wrap(ErrTxDecode, signerErr.Error())
}
msgs = append(msgs, msg.ProtoReflect())
msgs = append(msgs, msg)
ss, signerErr := d.signingCtx.GetSigners(msg)
if signerErr != nil {
return nil, errorsmod.Wrap(ErrTxDecode, signerErr.Error())
Expand Down

0 comments on commit 52f4031

Please sign in to comment.