Skip to content

Commit

Permalink
partial revert typed ethereumTx
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jan 10, 2023
1 parent 287d3ae commit 314bb28
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,52 +89,56 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t
}
}()

eventEthereumTx := &types.EventEthereumTx{
Amount: tx.Value().String(),
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyAmount, tx.Value().String()),
// add event for ethereum transaction hash format
EthHash: response.Hash,
sdk.NewAttribute(types.AttributeKeyEthereumTxHash, response.Hash),
// add event for index of valid ethereum tx
Index: strconv.FormatUint(txIndex, 10),
sdk.NewAttribute(types.AttributeKeyTxIndex, strconv.FormatUint(txIndex, 10)),
// add event for eth tx gas used, we can't get it from cosmos tx result when it contains multiple eth tx msgs.
GasUsed: strconv.FormatUint(response.GasUsed, 10),
sdk.NewAttribute(types.AttributeKeyTxGasUsed, strconv.FormatUint(response.GasUsed, 10)),
}

if len(ctx.TxBytes()) > 0 {
// add event for tendermint transaction hash format
hash := tmbytes.HexBytes(tmtypes.Tx(ctx.TxBytes()).Hash())
eventEthereumTx.Hash = hash.String()
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyTxHash, hash.String()))
}

if to := tx.To(); to != nil {
eventEthereumTx.Recipient = to.Hex()
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyRecipient, to.Hex()))
}

if response.Failed() {
eventEthereumTx.EthTxFailed = response.VmError
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyEthereumTxFailed, response.VmError))
}

eventTxLogs := &types.EventTxLog{TxLogs: make([]string, len(response.Logs))}
txLogAttrs := make([]sdk.Attribute, len(response.Logs))
for i, log := range response.Logs {
value, err := json.Marshal(log)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to encode log")
}
eventTxLogs.TxLogs[i] = string(value)
txLogAttrs[i] = sdk.NewAttribute(types.AttributeKeyTxLog, string(value))
}

err = ctx.EventManager().EmitTypedEvents(
eventEthereumTx,
eventTxLogs,
&types.EventMessage{
Module: types.AttributeValueCategory,
Sender: sender,
TxType: fmt.Sprintf("%d", tx.Type()),
},
)

if err != nil {
k.Logger(ctx).Error(err.Error())
}
// emit events
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeEthereumTx,
attrs...,
),
sdk.NewEvent(
types.EventTypeTxLog,
txLogAttrs...,
),
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, sender),
sdk.NewAttribute(types.AttributeKeyTxType, fmt.Sprintf("%d", tx.Type())),
),
})

return response, nil
}
Expand Down

0 comments on commit 314bb28

Please sign in to comment.