Skip to content

Commit

Permalink
Emit signer event for all transactions (sei-protocol#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen authored May 10, 2024
1 parent b36bfe4 commit 3cd4736
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion x/evm/ante/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (p *EVMPreprocessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
derived := msg.Derived
seiAddr := derived.SenderSeiAddr
evmAddr := derived.SenderEVMAddr
ctx.EventManager().EmitEvent(sdk.NewEvent(evmtypes.EventTypeSigner,
sdk.NewAttribute(evmtypes.AttributeKeyEvmAddress, evmAddr.Hex()),
sdk.NewAttribute(evmtypes.AttributeKeySeiAddress, seiAddr.String())))
pubkey := derived.PubKey
isAssociateTx := derived.IsAssociate
_, isAssociated := p.evmKeeper.GetEVMAddress(ctx, seiAddr)
Expand Down Expand Up @@ -353,7 +356,10 @@ func (p *EVMAddressDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
}
signers := sigTx.GetSigners()
for _, signer := range signers {
if _, associated := p.evmKeeper.GetEVMAddress(ctx, signer); associated {
if evmAddr, associated := p.evmKeeper.GetEVMAddress(ctx, signer); associated {
ctx.EventManager().EmitEvent(sdk.NewEvent(evmtypes.EventTypeSigner,
sdk.NewAttribute(evmtypes.AttributeKeyEvmAddress, evmAddr.Hex()),
sdk.NewAttribute(evmtypes.AttributeKeySeiAddress, signer.String())))
continue
}
acc := p.accountKeeper.GetAccount(ctx, signer)
Expand All @@ -371,6 +377,9 @@ func (p *EVMAddressDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo
ctx.Logger().Error(fmt.Sprintf("failed to get EVM address from pubkey due to %s", err))
continue
}
ctx.EventManager().EmitEvent(sdk.NewEvent(evmtypes.EventTypeSigner,
sdk.NewAttribute(evmtypes.AttributeKeyEvmAddress, evmAddr.Hex()),
sdk.NewAttribute(evmtypes.AttributeKeySeiAddress, signer.String())))
p.evmKeeper.SetAddressMapping(ctx, signer, evmAddr)
if err := migrateBalance(ctx, p.evmKeeper, evmAddr, signer); err != nil {
ctx.Logger().Error(fmt.Sprintf("failed to migrate EVM address balance (%s) %s", evmAddr.Hex(), err))
Expand Down
1 change: 1 addition & 0 deletions x/evm/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
const (
EventTypeAddressAssociated = "address_associated"
EventTypePointerRegistered = "pointer_registered"
EventTypeSigner = "signer"

AttributeKeySeiAddress = "sei_addr"
AttributeKeyEvmAddress = "evm_addr"
Expand Down

0 comments on commit 3cd4736

Please sign in to comment.