Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: data race issue #135

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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