Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Problem: tx log attribtue value not parsable by some client
Browse files Browse the repository at this point in the history
Closes: #614

Solution:
- encode the value to json string rather than bytes

Apply suggestions from code review
  • Loading branch information
yihuang committed Oct 3, 2021
1 parent 34c2593 commit c53ebc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion rpc/ethereum/backend/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package backend

import (
"bytes"
"encoding/json"
"errors"
"math/big"

Expand Down Expand Up @@ -147,7 +148,9 @@ func TxLogsFromEvents(codec codec.Codec, events []abci.Event) []*ethtypes.Log {
}

var log evmtypes.Log
codec.MustUnmarshal(attr.Value, &log)
if err := json.Unmarshal(attr.Value, &log); err != nil {
panic(err)
}
logs = append(logs, &log)
}
}
Expand Down
8 changes: 6 additions & 2 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"encoding/json"
"fmt"

"github.com/palantir/stacktrace"
Expand Down Expand Up @@ -54,8 +55,11 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t

txLogAttrs := make([]sdk.Attribute, 0)
for _, log := range response.Logs {
bz := k.cdc.MustMarshal(log)
txLogAttrs = append(txLogAttrs, sdk.NewAttribute(types.AttributeKeyTxLog, string(bz)))
value, err := json.Marshal(log)
if err != nil {
return nil, stacktrace.Propagate(err, "failed to encode log")
}
txLogAttrs = append(txLogAttrs, sdk.NewAttribute(types.AttributeKeyTxLog, string(value)))
}

// emit events
Expand Down

0 comments on commit c53ebc8

Please sign in to comment.