tokenbridge-monitor/monitor/handlers.go

545 lines
18 KiB
Go
Raw Normal View History

2021-06-07 02:08:23 -07:00
package monitor
import (
2021-09-19 14:38:56 -07:00
"context"
"fmt"
"math/big"
2021-09-19 14:38:56 -07:00
2021-06-07 02:08:23 -07:00
"github.com/ethereum/go-ethereum/common"
2022-04-02 04:49:18 -07:00
"github.com/ethereum/go-ethereum/crypto"
2022-05-22 04:29:01 -07:00
2022-08-28 04:31:28 -07:00
"github.com/omni/tokenbridge-monitor/config"
"github.com/omni/tokenbridge-monitor/contract/bridgeabi"
"github.com/omni/tokenbridge-monitor/db"
"github.com/omni/tokenbridge-monitor/entity"
"github.com/omni/tokenbridge-monitor/ethclient"
"github.com/omni/tokenbridge-monitor/repository"
2021-06-07 02:08:23 -07:00
)
2021-09-19 14:38:56 -07:00
type EventHandler func(ctx context.Context, log *entity.Log, data map[string]interface{}) error
2021-06-07 02:08:23 -07:00
2021-09-19 14:38:56 -07:00
type BridgeEventHandler struct {
2022-05-12 16:24:55 -07:00
repo *repository.Repo
bridgeID string
2022-05-21 04:26:28 -07:00
homeClient ethclient.Client
2022-05-12 16:24:55 -07:00
cfg *config.BridgeConfig
2021-06-07 02:08:23 -07:00
}
2022-05-21 04:26:28 -07:00
func NewBridgeEventHandler(repo *repository.Repo, cfg *config.BridgeConfig, homeClient ethclient.Client) *BridgeEventHandler {
2021-09-19 14:38:56 -07:00
return &BridgeEventHandler{
2022-05-12 16:24:55 -07:00
repo: repo,
bridgeID: cfg.ID,
homeClient: homeClient,
cfg: cfg,
2021-06-07 02:08:23 -07:00
}
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleUserRequestForAffirmation(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
encodedData, ok := data["encodedData"].([]byte)
if !ok {
return fmt.Errorf("encodedData type %T is invalid: %w", data["encodedData"], ErrWrongArgumentType)
}
2021-09-19 14:38:56 -07:00
message := unmarshalMessage(p.bridgeID, entity.DirectionForeignToHome, encodedData)
err := p.repo.Messages.Ensure(ctx, message)
if err != nil {
return err
}
return p.repo.SentMessages.Ensure(ctx, &entity.SentMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: message.MsgHash,
})
2021-06-07 02:08:23 -07:00
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleLegacyUserRequestForAffirmation(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
encodedData, ok := data["encodedData"].([]byte)
if !ok {
return fmt.Errorf("encodedData type %T is invalid: %w", data["encodedData"], ErrWrongArgumentType)
}
2021-09-19 14:38:56 -07:00
encodedData = append(log.TransactionHash[:], encodedData...)
message := unmarshalLegacyMessage(p.bridgeID, entity.DirectionForeignToHome, encodedData)
err := p.repo.Messages.Ensure(ctx, message)
if err != nil {
return err
}
return p.repo.SentMessages.Ensure(ctx, &entity.SentMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: message.MsgHash,
})
2021-06-07 02:08:23 -07:00
}
2022-04-02 04:49:18 -07:00
func (p *BridgeEventHandler) HandleErcToNativeTransfer(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
from, ok := data["from"].(common.Address)
if !ok {
return fmt.Errorf("from type %T is invalid: %w", data["from"], ErrWrongArgumentType)
}
value, ok := data["value"].(*big.Int)
if !ok {
return fmt.Errorf("value type %T is invalid: %w", data["value"], ErrWrongArgumentType)
}
2022-04-02 04:49:18 -07:00
2022-05-22 02:12:30 -07:00
for _, token := range p.cfg.Foreign.ErcToNativeTokens {
if token.Address == log.Address {
for _, addr := range token.BlacklistedSenders {
if from == addr {
return nil
}
}
break
2022-04-02 04:49:18 -07:00
}
}
2022-05-25 11:00:21 -07:00
filter := entity.LogsFilter{
ChainID: &log.ChainID,
Addresses: []common.Address{p.cfg.Foreign.Address},
FromBlock: &log.BlockNumber,
ToBlock: &log.BlockNumber,
TxHash: &log.TransactionHash,
2022-06-22 08:42:23 -07:00
Topic0: []common.Hash{bridgeabi.ErcToNativeUserRequestForAffirmationEventSignature},
2022-05-25 11:00:21 -07:00
}
logs, err := p.repo.Logs.Find(ctx, filter)
2022-04-02 04:49:18 -07:00
if err != nil {
2022-04-13 05:47:28 -07:00
return fmt.Errorf("failed to get transaction logs for %s: %w", log.TransactionHash, err)
2022-04-02 04:49:18 -07:00
}
2022-05-25 13:47:41 -07:00
if len(logs) > 0 {
return nil
2022-04-02 04:49:18 -07:00
}
valueBytes := common.BigToHash(value)
msg := from[:]
msg = append(msg, valueBytes[:]...)
msg = append(msg, log.TransactionHash[:]...)
msgHash := crypto.Keccak256Hash(msg)
message := &entity.ErcToNativeMessage{
2022-06-22 08:42:23 -07:00
BridgeID: p.bridgeID,
Direction: entity.DirectionForeignToHome,
MsgHash: msgHash,
Sender: from,
Receiver: from,
Value: value.String(),
RawMessage: msg,
2022-04-02 04:49:18 -07:00
}
err = p.repo.ErcToNativeMessages.Ensure(ctx, message)
if err != nil {
return err
}
return p.repo.SentMessages.Ensure(ctx, &entity.SentMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: msgHash,
})
}
func (p *BridgeEventHandler) HandleErcToNativeUserRequestForAffirmation(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
recipient, ok := data["recipient"].(common.Address)
if !ok {
return fmt.Errorf("recipient type %T is invalid: %w", data["recipient"], ErrWrongArgumentType)
}
value, ok := data["value"].(*big.Int)
if !ok {
return fmt.Errorf("value type %T is invalid: %w", data["value"], ErrWrongArgumentType)
}
2022-04-02 04:49:18 -07:00
valueBytes := common.BigToHash(value)
msg := recipient[:]
msg = append(msg, valueBytes[:]...)
msg = append(msg, log.TransactionHash[:]...)
msgHash := crypto.Keccak256Hash(msg)
2022-05-25 11:00:21 -07:00
filter := entity.LogsFilter{
ChainID: &log.ChainID,
Addresses: p.cfg.Foreign.ErcToNativeTokenAddresses(log.BlockNumber, log.BlockNumber),
FromBlock: &log.BlockNumber,
ToBlock: &log.BlockNumber,
TxHash: &log.TransactionHash,
2022-06-22 08:42:23 -07:00
Topic0: []common.Hash{bridgeabi.ErcToNativeTransferEventSignature},
Topic2: []common.Hash{p.cfg.Foreign.Address.Hash()},
2022-05-25 11:00:21 -07:00
DataLength: uintPtr(32),
}
logs, err := p.repo.Logs.Find(ctx, filter)
2022-04-13 05:47:28 -07:00
if err != nil {
return fmt.Errorf("failed to get transaction logs for %s: %w", log.TransactionHash, err)
}
2022-05-25 11:00:21 -07:00
sender := recipient
2022-05-23 08:11:24 -07:00
for _, txLog := range logs {
2022-05-25 11:00:21 -07:00
transferValue := new(big.Int).SetBytes(txLog.Data)
if value.Cmp(transferValue) == 0 {
sender = common.BytesToAddress(txLog.Topic1[:])
2022-04-13 05:47:28 -07:00
}
}
2022-04-02 04:49:18 -07:00
message := &entity.ErcToNativeMessage{
2022-06-22 08:42:23 -07:00
BridgeID: p.bridgeID,
Direction: entity.DirectionForeignToHome,
MsgHash: msgHash,
Sender: sender,
Receiver: recipient,
Value: value.String(),
RawMessage: msg,
2022-04-02 04:49:18 -07:00
}
2022-04-13 05:47:28 -07:00
err = p.repo.ErcToNativeMessages.Ensure(ctx, message)
2022-04-02 04:49:18 -07:00
if err != nil {
return err
}
return p.repo.SentMessages.Ensure(ctx, &entity.SentMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: msgHash,
})
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleUserRequestForSignature(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
encodedData, ok := data["encodedData"].([]byte)
if !ok {
return fmt.Errorf("encodedData type %T is invalid: %w", data["encodedData"], ErrWrongArgumentType)
}
2021-09-19 14:38:56 -07:00
message := unmarshalMessage(p.bridgeID, entity.DirectionHomeToForeign, encodedData)
err := p.repo.Messages.Ensure(ctx, message)
if err != nil {
return err
}
return p.repo.SentMessages.Ensure(ctx, &entity.SentMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: message.MsgHash,
})
2021-06-07 02:08:23 -07:00
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleLegacyUserRequestForSignature(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
encodedData, ok := data["encodedData"].([]byte)
if !ok {
return fmt.Errorf("encodedData type %T is invalid: %w", data["encodedData"], ErrWrongArgumentType)
}
2021-09-19 14:38:56 -07:00
encodedData = append(log.TransactionHash[:], encodedData...)
message := unmarshalLegacyMessage(p.bridgeID, entity.DirectionHomeToForeign, encodedData)
err := p.repo.Messages.Ensure(ctx, message)
if err != nil {
return err
}
return p.repo.SentMessages.Ensure(ctx, &entity.SentMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: message.MsgHash,
})
2021-06-07 02:08:23 -07:00
}
2022-04-02 04:49:18 -07:00
func (p *BridgeEventHandler) HandleErcToNativeUserRequestForSignature(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
recipient, ok := data["recipient"].(common.Address)
if !ok {
return fmt.Errorf("recipient type %T is invalid: %w", data["recipient"], ErrWrongArgumentType)
}
value, ok := data["value"].(*big.Int)
if !ok {
return fmt.Errorf("value type %T is invalid: %w", data["value"], ErrWrongArgumentType)
}
2022-04-02 04:49:18 -07:00
valueBytes := common.BigToHash(value)
msg := recipient[:]
msg = append(msg, valueBytes[:]...)
msg = append(msg, log.TransactionHash[:]...)
msg = append(msg, p.cfg.Foreign.Address[:]...)
msgHash := crypto.Keccak256Hash(msg)
2022-04-13 05:47:28 -07:00
sender := recipient
tx, err := p.homeClient.TransactionByHash(ctx, log.TransactionHash)
if err != nil {
return err
}
if tx.Value().Cmp(value) == 0 {
sender, err = p.homeClient.TransactionSender(tx)
if err != nil {
return fmt.Errorf("failed to extract transaction sender: %w", err)
}
}
2022-04-02 04:49:18 -07:00
message := &entity.ErcToNativeMessage{
2022-06-22 08:42:23 -07:00
BridgeID: p.bridgeID,
Direction: entity.DirectionHomeToForeign,
MsgHash: msgHash,
Sender: sender,
Receiver: recipient,
Value: value.String(),
RawMessage: msg,
2022-04-02 04:49:18 -07:00
}
2022-04-13 05:47:28 -07:00
err = p.repo.ErcToNativeMessages.Ensure(ctx, message)
2022-04-02 04:49:18 -07:00
if err != nil {
return err
}
return p.repo.SentMessages.Ensure(ctx, &entity.SentMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: msgHash,
})
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleSignedForUserRequest(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
msgHash, ok := data["messageHash"].([32]byte)
if !ok {
return fmt.Errorf("messageHash type %T is invalid: %w", data["messageHash"], ErrWrongArgumentType)
}
validator, ok := data["signer"].(common.Address)
if !ok {
return fmt.Errorf("signer type %T is invalid: %w", data["signer"], ErrWrongArgumentType)
}
2021-09-19 14:38:56 -07:00
return p.repo.SignedMessages.Ensure(ctx, &entity.SignedMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: msgHash,
Signer: validator,
2021-09-19 14:38:56 -07:00
})
2021-06-07 02:08:23 -07:00
}
2022-04-02 04:49:18 -07:00
func (p *BridgeEventHandler) HandleErcToNativeSignedForAffirmation(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
validator, ok := data["signer"].(common.Address)
if !ok {
return fmt.Errorf("signer type %T is invalid: %w", data["signer"], ErrWrongArgumentType)
}
2021-09-19 14:38:56 -07:00
2022-04-02 04:49:18 -07:00
tx, err := p.homeClient.TransactionByHash(ctx, log.TransactionHash)
if err != nil {
return fmt.Errorf("failed to get transaction by hash %s: %w", log.TransactionHash, err)
}
msg := tx.Data()[16:]
2021-09-19 14:38:56 -07:00
return p.repo.SignedMessages.Ensure(ctx, &entity.SignedMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
2022-04-02 04:49:18 -07:00
MsgHash: crypto.Keccak256Hash(msg),
Signer: validator,
2021-09-19 14:38:56 -07:00
})
2021-06-07 02:08:23 -07:00
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleRelayedMessage(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
messageID, ok := data["messageId"].([32]byte)
if !ok {
return fmt.Errorf("messageId type %T is invalid: %w", data["messageId"], ErrWrongArgumentType)
}
status, ok := data["status"].(bool)
if !ok {
return fmt.Errorf("status type %T is invalid: %w", data["status"], ErrWrongArgumentType)
}
2021-06-07 02:08:23 -07:00
2021-09-19 14:38:56 -07:00
return p.repo.ExecutedMessages.Ensure(ctx, &entity.ExecutedMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MessageID: messageID,
2021-06-07 02:08:23 -07:00
Status: status,
2021-09-19 14:38:56 -07:00
})
2021-06-07 02:08:23 -07:00
}
2022-04-02 04:49:18 -07:00
func (p *BridgeEventHandler) HandleErcToNativeRelayedMessage(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
recipient, ok := data["recipient"].(common.Address)
if !ok {
return fmt.Errorf("recipient type %T is invalid: %w", data["recipient"], ErrWrongArgumentType)
}
value, ok := data["value"].(*big.Int)
if !ok {
return fmt.Errorf("value type %T is invalid: %w", data["value"], ErrWrongArgumentType)
}
transactionHash, ok := data["transactionHash"].([32]byte)
if !ok {
return fmt.Errorf("transactionHash type %T is invalid: %w", data["transactionHash"], ErrWrongArgumentType)
}
2022-04-02 04:49:18 -07:00
valueBytes := common.BigToHash(value)
msg := recipient[:]
msg = append(msg, valueBytes[:]...)
msg = append(msg, transactionHash[:]...)
msg = append(msg, log.Address[:]...)
return p.repo.ExecutedMessages.Ensure(ctx, &entity.ExecutedMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MessageID: crypto.Keccak256Hash(msg),
Status: true,
})
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleAffirmationCompleted(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
messageID, ok := data["messageId"].([32]byte)
if !ok {
return fmt.Errorf("messageId type %T is invalid: %w", data["messageId"], ErrWrongArgumentType)
}
status, ok := data["status"].(bool)
if !ok {
return fmt.Errorf("status type %T is invalid: %w", data["status"], ErrWrongArgumentType)
}
2021-06-07 02:08:23 -07:00
2021-09-19 14:38:56 -07:00
return p.repo.ExecutedMessages.Ensure(ctx, &entity.ExecutedMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MessageID: messageID,
2021-06-07 02:08:23 -07:00
Status: status,
2021-09-19 14:38:56 -07:00
})
}
2022-04-02 04:49:18 -07:00
func (p *BridgeEventHandler) HandleErcToNativeAffirmationCompleted(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
recipient, ok := data["recipient"].(common.Address)
if !ok {
return fmt.Errorf("recipient type %T is invalid: %w", data["recipient"], ErrWrongArgumentType)
}
value, ok := data["value"].(*big.Int)
if !ok {
return fmt.Errorf("value type %T is invalid: %w", data["value"], ErrWrongArgumentType)
}
transactionHash, ok := data["transactionHash"].([32]byte)
if !ok {
return fmt.Errorf("transactionHash type %T is invalid: %w", data["transactionHash"], ErrWrongArgumentType)
}
2022-04-02 04:49:18 -07:00
valueBytes := common.BigToHash(value)
msg := recipient[:]
msg = append(msg, valueBytes[:]...)
msg = append(msg, transactionHash[:]...)
return p.repo.ExecutedMessages.Ensure(ctx, &entity.ExecutedMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MessageID: crypto.Keccak256Hash(msg),
Status: true,
})
}
2021-09-19 14:38:56 -07:00
func (p *BridgeEventHandler) HandleCollectedSignatures(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
msgHash, ok := data["messageHash"].([32]byte)
if !ok {
return fmt.Errorf("messageHash type %T is invalid: %w", data["messageHash"], ErrWrongArgumentType)
}
relayer, ok := data["authorityResponsibleForRelay"].(common.Address)
if !ok {
return fmt.Errorf("authorityResponsibleForRelay type %T is invalid: %w", data["authorityResponsibleForRelay"], ErrWrongArgumentType)
}
numSignatures, ok := data["NumberOfCollectedSignatures"].(*big.Int)
if !ok {
return fmt.Errorf("NumberOfCollectedSignatures type %T is invalid: %w", data["NumberOfCollectedSignatures"], ErrWrongArgumentType)
}
return p.repo.CollectedMessages.Ensure(ctx, &entity.CollectedMessage{
LogID: log.ID,
BridgeID: p.bridgeID,
MsgHash: msgHash,
ResponsibleSigner: relayer,
NumSignatures: uint(numSignatures.Uint64()),
})
2021-06-07 02:08:23 -07:00
}
func (p *BridgeEventHandler) HandleUserRequestForInformation(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
messageID, ok := data["messageId"].([32]byte)
if !ok {
return fmt.Errorf("messageId type %T is invalid: %w", data["messageId"], ErrWrongArgumentType)
}
requestSelector, ok := data["requestSelector"].([32]byte)
if !ok {
return fmt.Errorf("requestSelector type %T is invalid: %w", data["requestSelector"], ErrWrongArgumentType)
}
sender, ok := data["sender"].(common.Address)
if !ok {
return fmt.Errorf("sender type %T is invalid: %w", data["sender"], ErrWrongArgumentType)
}
requestData, ok := data["data"].([]byte)
if !ok {
return fmt.Errorf("data type %T is invalid: %w", data["data"], ErrWrongArgumentType)
}
err := p.repo.InformationRequests.Ensure(ctx, &entity.InformationRequest{
BridgeID: p.bridgeID,
MessageID: messageID,
Direction: entity.DirectionHomeToForeign,
RequestSelector: requestSelector,
Sender: sender,
Executor: sender,
Data: requestData,
})
if err != nil {
return err
}
return p.repo.SentInformationRequests.Ensure(ctx, &entity.SentInformationRequest{
LogID: log.ID,
BridgeID: p.bridgeID,
MessageID: messageID,
})
}
func (p *BridgeEventHandler) HandleSignedForInformation(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
messageID, ok := data["messageId"].([32]byte)
if !ok {
return fmt.Errorf("messageId type %T is invalid: %w", data["messageId"], ErrWrongArgumentType)
}
validator, ok := data["signer"].(common.Address)
if !ok {
return fmt.Errorf("signer type %T is invalid: %w", data["signer"], ErrWrongArgumentType)
}
tx, err := p.homeClient.TransactionByHash(ctx, log.TransactionHash)
if err != nil {
return fmt.Errorf("failed to get transaction by hash %s: %w", log.TransactionHash, err)
}
return p.repo.SignedInformationRequests.Ensure(ctx, &entity.SignedInformationRequest{
LogID: log.ID,
BridgeID: p.bridgeID,
MessageID: messageID,
Data: unmarshalConfirmInformationResult(tx.Data()),
Signer: validator,
})
}
func (p *BridgeEventHandler) HandleInformationRetrieved(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
messageID, ok := data["messageId"].([32]byte)
if !ok {
return fmt.Errorf("messageId type %T is invalid: %w", data["messageId"], ErrWrongArgumentType)
}
status, ok := data["status"].(bool)
if !ok {
return fmt.Errorf("status type %T is invalid: %w", data["status"], ErrWrongArgumentType)
}
callbackStatus, ok := data["callbackStatus"].(bool)
if !ok {
return fmt.Errorf("callbackStatus type %T is invalid: %w", data["callbackStatus"], ErrWrongArgumentType)
}
tx, err := p.homeClient.TransactionByHash(ctx, log.TransactionHash)
if err != nil {
return fmt.Errorf("failed to get transaction by hash %s: %w", log.TransactionHash, err)
}
return p.repo.ExecutedInformationRequests.Ensure(ctx, &entity.ExecutedInformationRequest{
LogID: log.ID,
BridgeID: p.bridgeID,
MessageID: messageID,
Status: status,
CallbackStatus: callbackStatus,
Data: unmarshalConfirmInformationResult(tx.Data()),
})
}
2022-03-14 02:43:14 -07:00
func (p *BridgeEventHandler) HandleValidatorAdded(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
validator, ok := data["validator"].(common.Address)
if !ok {
return fmt.Errorf("validator type %T is invalid: %w", data["validator"], ErrWrongArgumentType)
}
2022-03-14 02:43:14 -07:00
return p.repo.BridgeValidators.Ensure(ctx, &entity.BridgeValidator{
LogID: log.ID,
BridgeID: p.bridgeID,
ChainID: log.ChainID,
Address: validator,
})
}
func (p *BridgeEventHandler) HandleValidatorRemoved(ctx context.Context, log *entity.Log, data map[string]interface{}) error {
2022-05-22 04:40:12 -07:00
validator, ok := data["validator"].(common.Address)
if !ok {
return fmt.Errorf("validator type %T is invalid: %w", data["validator"], ErrWrongArgumentType)
}
2022-06-01 11:26:57 -07:00
val, err := p.repo.BridgeValidators.GetActiveValidator(ctx, p.bridgeID, log.ChainID, validator)
2022-03-14 02:43:14 -07:00
if err != nil {
2022-06-01 11:26:57 -07:00
return db.IgnoreErrNotFound(err)
2022-03-14 02:43:14 -07:00
}
val.RemovedLogID = &log.ID
return p.repo.BridgeValidators.Ensure(ctx, val)
}