Skip to content

Commit

Permalink
fix: data race issue (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 authored Mar 16, 2023
1 parent 2af4458 commit ab4c7d5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions x/auth/tx/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ import (
"github.com/gogo/protobuf/jsonpb"
)

var MsgCodec = jsonpb.Marshaler{
EmitDefaults: true,
OrigName: true,
}

var domain = apitypes.TypedDataDomain{
var domain = &apitypes.TypedDataDomain{
Name: "Greenfield Tx",
Version: "1.0.0",
VerifyingContract: "greenfield",
Expand Down Expand Up @@ -164,8 +159,13 @@ func WrapTxToTypedData(
signDoc *types.SignDocEip712,
msgTypes apitypes.Types,
) (apitypes.TypedData, error) {
msgCodec := jsonpb.Marshaler{
EmitDefaults: true,
OrigName: true,
}
bz, err := msgCodec.MarshalToString(signDoc)

var txData map[string]interface{}
bz, err := MsgCodec.MarshalToString(signDoc)
if err != nil {
return apitypes.TypedData{}, errors.Wrap(err, "failed to JSON marshal data")
}
Expand All @@ -180,11 +180,12 @@ func WrapTxToTypedData(
// filling nil value
cleanTypesAndMsgValue(msgTypes, "Msg", txData["msg"].(map[string]interface{}))

domain.ChainId = math.NewHexOrDecimal256(int64(chainID))
domainTemp := *domain
domainTemp.ChainId = math.NewHexOrDecimal256(int64(chainID))
typedData := apitypes.TypedData{
Types: msgTypes,
PrimaryType: "Tx",
Domain: domain,
Domain: domainTemp,
Message: txData,
}

Expand Down

0 comments on commit ab4c7d5

Please sign in to comment.