0g-chain/precompiles/dasigners/events.go

61 lines
1.6 KiB
Go
Raw Permalink Normal View History

2024-05-09 18:54:47 +00:00
package dasigners
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/evmos/ethermint/x/evm/statedb"
)
const (
NewSignerEvent = "NewSigner"
SocketUpdatedEvent = "SocketUpdated"
)
func (d *DASignersPrecompile) EmitNewSignerEvent(ctx sdk.Context, stateDB *statedb.StateDB, signer IDASignersSignerDetail) error {
event := d.abi.Events[NewSignerEvent]
quries := make([]interface{}, 2)
quries[0] = event.ID
quries[1] = signer.Signer
topics, err := abi.MakeTopics(quries)
if err != nil {
return err
}
2024-05-10 18:41:14 +00:00
arguments := abi.Arguments{event.Inputs[1], event.Inputs[2]}
b, err := arguments.Pack(signer.PkG1, signer.PkG2)
2024-05-09 18:54:47 +00:00
if err != nil {
return err
}
stateDB.AddLog(&types.Log{
Address: d.Address(),
Topics: topics[0],
Data: b,
BlockNumber: uint64(ctx.BlockHeight()),
})
return d.EmitSocketUpdatedEvent(ctx, stateDB, signer.Signer, signer.Socket)
}
func (d *DASignersPrecompile) EmitSocketUpdatedEvent(ctx sdk.Context, stateDB *statedb.StateDB, signer common.Address, socket string) error {
event := d.abi.Events[SocketUpdatedEvent]
quries := make([]interface{}, 2)
quries[0] = event.ID
quries[1] = signer
topics, err := abi.MakeTopics(quries)
if err != nil {
return err
}
2024-05-10 18:41:14 +00:00
arguments := abi.Arguments{event.Inputs[1]}
b, err := arguments.Pack(socket)
2024-05-09 18:54:47 +00:00
if err != nil {
return err
}
stateDB.AddLog(&types.Log{
Address: d.Address(),
Topics: topics[0],
Data: b,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}