Skip to content

Commit

Permalink
revert decode.go changes
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed May 31, 2024
1 parent cd12f3b commit c8adf60
Showing 1 changed file with 0 additions and 63 deletions.
63 changes: 0 additions & 63 deletions x/tx/decode/decode.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit c8adf60

Please sign in to comment.