mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
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
|
|
}
|
|
arguments := abi.Arguments{event.Inputs[1], event.Inputs[2]}
|
|
b, err := arguments.Pack(signer.PkG1, signer.PkG2)
|
|
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
|
|
}
|
|
arguments := abi.Arguments{event.Inputs[1]}
|
|
b, err := arguments.Pack(socket)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
stateDB.AddLog(&types.Log{
|
|
Address: d.Address(),
|
|
Topics: topics[0],
|
|
Data: b,
|
|
BlockNumber: uint64(ctx.BlockHeight()),
|
|
})
|
|
return nil
|
|
}
|