laconicd/x/evm/keeper/msg_server.go
yihuang 116de54617
evm: remove tx logs and block bloom from chain state (#556)
Closes #452

fix unit tests

changelog and fix lint

fix unit test

Update ethereum/rpc/backend/backend.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

Update ethereum/rpc/backend/utils.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

changelog

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
2021-09-15 09:45:03 +00:00

81 lines
2.3 KiB
Go

package keeper
import (
"context"
"fmt"
"github.com/palantir/stacktrace"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmtypes "github.com/tendermint/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tharsis/ethermint/x/evm/types"
)
var _ types.MsgServer = &Keeper{}
// EthereumTx implements the gRPC MsgServer interface. It receives a transaction which is then
// executed (i.e applied) against the go-ethereum EVM. The provided SDK Context is set to the Keeper
// so that it can implements and call the StateDB methods without receiving it as a function
// parameter.
func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
k.WithContext(ctx)
sender := msg.From
tx := msg.AsTransaction()
response, err := k.ApplyTransaction(tx)
if err != nil {
return nil, stacktrace.Propagate(err, "failed to apply transaction")
}
attrs := []sdk.Attribute{
sdk.NewAttribute(sdk.AttributeKeyAmount, tx.Value().String()),
// add event for ethereum transaction hash format
sdk.NewAttribute(types.AttributeKeyEthereumTxHash, response.Hash),
}
if len(ctx.TxBytes()) > 0 {
// add event for tendermint transaction hash format
hash := tmbytes.HexBytes(tmtypes.Tx(ctx.TxBytes()).Hash())
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyTxHash, hash.String()))
}
if tx.To() != nil {
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyRecipient, tx.To().Hex()))
}
if response.Failed() {
attrs = append(attrs, sdk.NewAttribute(types.AttributeKeyEthereumTxFailed, response.VmError))
}
txLogAttrs := make([]sdk.Attribute, 0)
for _, log := range response.Logs {
bz := k.cdc.MustMarshal(log)
txLogAttrs = append(txLogAttrs, sdk.NewAttribute(types.AttributeKeyTxLog, string(bz)))
}
// 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
}