From c8adf60d428f66d95e0b52a605951e5d91d5347b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 31 May 2024 14:32:04 +0200 Subject: [PATCH] revert decode.go changes --- x/tx/decode/decode.go | 63 ------------------------------------------- 1 file changed, 63 deletions(-) diff --git a/x/tx/decode/decode.go b/x/tx/decode/decode.go index 45a1c9ce962e..4dafe9549af4 100644 --- a/x/tx/decode/decode.go +++ b/x/tx/decode/decode.go @@ -1,15 +1,12 @@ package decode import ( - "crypto/sha256" "errors" "github.com/cosmos/cosmos-proto/anyutil" "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/protoadapt" v1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" - "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/tx/signing" ) @@ -21,15 +18,8 @@ type DecodedTx struct { TxRaw *v1beta1.TxRaw Signers [][]byte TxBodyHasUnknownNonCriticals bool - - // Cache for hash and full bytes - cachedHash [32]byte - cachedBytes []byte - cachedHashed bool } -var _ transaction.Tx = &DecodedTx{} - // Decoder contains the dependencies required for decoding transactions. type Decoder struct { signingCtx *signing.Context @@ -136,56 +126,3 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { Signers: signers, }, nil } - -// Hash implements the interface for the Tx interface. -func (dtx *DecodedTx) Hash() [32]byte { - if !dtx.cachedHashed { - dtx.computeHashAndBytes() - } - return dtx.cachedHash -} - -func (dtx *DecodedTx) GetGasLimit() (uint64, error) { - if dtx == nil || dtx.Tx == nil || dtx.Tx.AuthInfo == nil || dtx.Tx.AuthInfo.Fee == nil { - return 0, errors.New("gas limit not available or one or more required fields are nil") - } - return dtx.Tx.AuthInfo.Fee.GasLimit, nil -} - -func (dtx *DecodedTx) GetMessages() ([]transaction.Msg, error) { - if dtx == nil || dtx.Messages == nil { - return nil, errors.New("messages not available or are nil") - } - - msgs := make([]transaction.Msg, len(dtx.Messages)) - for i, msg := range dtx.Messages { - msgs[i] = protoadapt.MessageV1Of(msg) - } - - return msgs, nil -} - -func (dtx *DecodedTx) GetSenders() ([][]byte, error) { - if dtx == nil || dtx.Signers == nil { - return nil, errors.New("senders not available or are nil") - } - return dtx.Signers, nil -} - -func (dtx *DecodedTx) Bytes() []byte { - if !dtx.cachedHashed { - dtx.computeHashAndBytes() - } - return dtx.cachedBytes -} - -func (dtx *DecodedTx) computeHashAndBytes() { - bz, err := proto.Marshal(dtx.TxRaw) - if err != nil { - panic(err) - } - - dtx.cachedBytes = bz - dtx.cachedHash = sha256.Sum256(bz) - dtx.cachedHashed = true -}