Skip to content

Commit

Permalink
(fix) Updated eip712_cosmos module. Solved all pre-commit issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
aarmoa committed May 31, 2024
1 parent b9ca0af commit 020aa4b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
7 changes: 4 additions & 3 deletions client/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chain

import (
"context"
sdkmath "cosmossdk.io/math"
"encoding/base64"
"encoding/hex"
"encoding/json"
Expand All @@ -14,6 +13,8 @@ import (
"sync/atomic"
"time"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"

distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -832,7 +833,7 @@ func (c *chainClient) SyncBroadcastSignedTx(txBytes []byte) (*txtypes.BroadcastT
case <-t.C:
resultTx, err := c.ctx.Client.Tx(awaitCtx, txHash, false)
if err != nil {
if errRes := client.CheckTendermintError(err, txBytes); errRes != nil {
if errRes := client.CheckCometError(err, txBytes); errRes != nil {
return &txtypes.BroadcastTxResponse{TxResponse: errRes}, err
}

Expand Down Expand Up @@ -903,7 +904,7 @@ func (c *chainClient) broadcastTx(
case <-t.C:
resultTx, err := clientCtx.Client.Tx(awaitCtx, txHash, false)
if err != nil {
if errRes := client.CheckTendermintError(err, txBytes); errRes != nil {
if errRes := client.CheckCometError(err, txBytes); errRes != nil {
return &txtypes.BroadcastTxResponse{TxResponse: errRes}, err
}

Expand Down
3 changes: 2 additions & 1 deletion client/chain/chain_test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package chain

import (
"context"
sdkmath "cosmossdk.io/math"
"errors"
"time"

sdkmath "cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
"google.golang.org/grpc"

Expand Down
3 changes: 2 additions & 1 deletion client/core/market_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package core

import (
sdkmath "cosmossdk.io/math"
"testing"

sdkmath "cosmossdk.io/math"

"github.com/huandu/go-assert"
"github.com/shopspring/decimal"
)
Expand Down
17 changes: 8 additions & 9 deletions eip712_cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
"strings"
"time"

sdkmath "cosmossdk.io/math"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cosmtypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
ethmath "github.com/ethereum/go-ethereum/common/math"
"github.com/pkg/errors"

"github.com/InjectiveLabs/sdk-go/typeddata"
Expand Down Expand Up @@ -53,7 +53,6 @@ func WrapTxToEIP712(
timeoutHeight,
feeInfo,
msgs, memo,
nil,
)

txData := make(map[string]interface{})
Expand All @@ -65,7 +64,7 @@ func WrapTxToEIP712(
domain := typeddata.TypedDataDomain{
Name: "Injective Web3",
Version: "1.0.0",
ChainId: math.NewHexOrDecimal256(int64(chainID)),
ChainId: ethmath.NewHexOrDecimal256(int64(chainID)),
VerifyingContract: "cosmos",
Salt: "0",
}
Expand Down Expand Up @@ -291,7 +290,7 @@ func traverseFields(

fieldPrefix := fmt.Sprintf("%s.%s", prefix, fieldName)
ethTyp := typToEth(fieldType)
if len(ethTyp) > 0 {
if ethTyp != "" {
if isCollection {
ethTyp += "[]"
}
Expand Down Expand Up @@ -380,7 +379,7 @@ var (
hashType = reflect.TypeOf(common.Hash{})
addressType = reflect.TypeOf(common.Address{})
bigIntType = reflect.TypeOf(big.Int{})
cosmIntType = reflect.TypeOf(sdkmath.Int{})
cosmIntType = reflect.TypeOf(math.Int{})
cosmosAnyType = reflect.TypeOf(&codectypes.Any{})
timeType = reflect.TypeOf(time.Time{})
)
Expand Down Expand Up @@ -415,12 +414,12 @@ func typToEth(typ reflect.Type) string {
return "uint64"
case reflect.Slice:
ethName := typToEth(typ.Elem())
if len(ethName) > 0 {
if ethName != "" {
return ethName + "[]"
}
case reflect.Array:
ethName := typToEth(typ.Elem())
if len(ethName) > 0 {
if ethName != "" {
return ethName + "[]"
}
case reflect.Ptr:
Expand Down Expand Up @@ -501,7 +500,7 @@ func WrapTxToEIP712V2(
domain := typeddata.TypedDataDomain{
Name: "Injective Web3",
Version: "1.0.0",
ChainId: math.NewHexOrDecimal256(int64(chainID)),
ChainId: ethmath.NewHexOrDecimal256(int64(chainID)),
VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
Salt: "0",
}
Expand Down
8 changes: 4 additions & 4 deletions typeddata/typed_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,19 +784,19 @@ func (domain *TypedDataDomain) Map() map[string]interface{} {
dataMap["chainId"] = domain.ChainId
}

if len(domain.Name) > 0 {
if domain.Name != "" {
dataMap["name"] = domain.Name
}

if len(domain.Version) > 0 {
if domain.Version != "" {
dataMap["version"] = domain.Version
}

if len(domain.VerifyingContract) > 0 {
if domain.VerifyingContract != "" {
dataMap["verifyingContract"] = domain.VerifyingContract
}

if len(domain.Salt) > 0 {
if domain.Salt != "" {
dataMap["salt"] = domain.Salt
}
return dataMap
Expand Down

0 comments on commit 020aa4b

Please sign in to comment.