evm, rpc: fix tx log attribute value is not parsable by some client (#615)
* Problem: tx log attribute value not parsable by some client Closes: #614 Solution: - encode the value to json string rather than bytes Apply suggestions from code review * rm cdc and changelog Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>
This commit is contained in:
co-authored by
Federico Kunze Küllmer
Federico Kunze
parent
d6423f0c3f
commit
cda968bddd
@@ -400,7 +400,8 @@ func (e *EVMBackend) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log, er
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return TxLogsFromEvents(e.clientCtx.Codec, tx.TxResult.Events), nil
|
||||
|
||||
return TxLogsFromEvents(tx.TxResult.Events)
|
||||
}
|
||||
|
||||
// PendingTransactions returns the transactions that are in the transaction pool
|
||||
@@ -433,7 +434,11 @@ func (e *EVMBackend) GetLogsByHeight(height *int64) ([][]*ethtypes.Log, error) {
|
||||
|
||||
blockLogs := [][]*ethtypes.Log{}
|
||||
for _, txResult := range blockRes.TxsResults {
|
||||
logs := TxLogsFromEvents(e.clientCtx.Codec, txResult.Events)
|
||||
logs, err := TxLogsFromEvents(txResult.Events)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blockLogs = append(blockLogs, logs)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ package backend
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -135,21 +135,25 @@ func (e *EVMBackend) getAccountNonce(accAddr common.Address, pending bool, heigh
|
||||
}
|
||||
|
||||
// TxLogsFromEvents parses ethereum logs from cosmos events
|
||||
func TxLogsFromEvents(codec codec.Codec, events []abci.Event) []*ethtypes.Log {
|
||||
func TxLogsFromEvents(events []abci.Event) ([]*ethtypes.Log, error) {
|
||||
logs := make([]*evmtypes.Log, 0)
|
||||
for _, event := range events {
|
||||
if event.Type != evmtypes.EventTypeTxLog {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, attr := range event.Attributes {
|
||||
if !bytes.Equal(attr.Key, []byte(evmtypes.AttributeKeyTxLog)) {
|
||||
continue
|
||||
}
|
||||
|
||||
var log evmtypes.Log
|
||||
codec.MustUnmarshal(attr.Value, &log)
|
||||
if err := json.Unmarshal(attr.Value, &log); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logs = append(logs, &log)
|
||||
}
|
||||
}
|
||||
return evmtypes.LogsToEthereum(logs)
|
||||
return evmtypes.LogsToEthereum(logs), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user