Add raw_message field
This commit is contained in:
parent
9684e9bf2c
commit
fc6baff634
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE messages
|
||||
DROP COLUMN raw_message;
|
||||
ALTER TABLE erc_to_native_messages
|
||||
DROP COLUMN raw_message;
|
|
@ -0,0 +1,62 @@
|
|||
ALTER TABLE messages
|
||||
ADD COLUMN raw_message BYTEA;
|
||||
ALTER TABLE erc_to_native_messages
|
||||
ADD COLUMN raw_message BYTEA;
|
||||
|
||||
UPDATE messages m
|
||||
SET raw_message = l.transaction_hash || substr(l.data, 65, get_byte(l.data, 62) * 256 + get_byte(l.data, 63))
|
||||
FROM sent_messages sm
|
||||
JOIN logs l
|
||||
ON l.id = sm.log_id
|
||||
WHERE m.bridge_id = sm.bridge_id
|
||||
AND m.msg_hash = sm.msg_hash
|
||||
AND l.topic0 IN (
|
||||
E'\\x9df71e9d2175354c68d0e882702c9eb5d63e036345c53639b8c63be4e8764741',
|
||||
E'\\x733b62005ae93e850dd2b37234e1c7eb634d3b7de068bc0f7f32b7233191a48c'
|
||||
);
|
||||
|
||||
UPDATE messages m
|
||||
SET raw_message = substr(l.data, 65, get_byte(l.data, 62) * 256 + get_byte(l.data, 63))
|
||||
FROM sent_messages sm
|
||||
JOIN logs l
|
||||
ON l.id = sm.log_id
|
||||
WHERE m.bridge_id = sm.bridge_id
|
||||
AND m.msg_hash = sm.msg_hash
|
||||
AND l.topic0 IN (
|
||||
E'\\x482515ce3d9494a37ce83f18b72b363449458435fafdd7a53ddea7460fe01b58',
|
||||
E'\\x520d2afde79cbd5db58755ac9480f81bc658e5c517fcae7365a3d832590b0183'
|
||||
);
|
||||
|
||||
UPDATE erc_to_native_messages m
|
||||
SET raw_message = substr(l.data, 13) || l.transaction_hash || E'\\x4aa42145Aa6Ebf72e164C9bBC74fbD3788045016'
|
||||
FROM sent_messages sm
|
||||
JOIN logs l
|
||||
ON l.id = sm.log_id
|
||||
WHERE m.bridge_id = sm.bridge_id
|
||||
AND m.msg_hash = sm.msg_hash
|
||||
AND m.direction::direction_enum = 'home_to_foreign';
|
||||
|
||||
UPDATE erc_to_native_messages m
|
||||
SET raw_message = substr(l.data, 13) || l.transaction_hash
|
||||
FROM sent_messages sm
|
||||
JOIN logs l
|
||||
ON l.id = sm.log_id
|
||||
WHERE m.bridge_id = sm.bridge_id
|
||||
AND m.msg_hash = sm.msg_hash
|
||||
AND m.direction::direction_enum = 'foreign_to_home'
|
||||
AND l.topic0 = E'\\x1d491a427d1f8cc0d447496f300fac39f7306122481d8e663451eb268274146b';
|
||||
|
||||
UPDATE erc_to_native_messages m
|
||||
SET raw_message = substr(l.topic1, 13) || l.data || l.transaction_hash
|
||||
FROM sent_messages sm
|
||||
JOIN logs l
|
||||
ON l.id = sm.log_id
|
||||
WHERE m.bridge_id = sm.bridge_id
|
||||
AND m.msg_hash = sm.msg_hash
|
||||
AND m.direction::direction_enum = 'foreign_to_home'
|
||||
AND l.topic0 = E'\\xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
||||
|
||||
ALTER TABLE messages
|
||||
ALTER COLUMN raw_message TYPE BLOB;
|
||||
ALTER TABLE erc_to_native_messages
|
||||
ALTER COLUMN raw_message TYPE BLOB;
|
|
@ -15,6 +15,7 @@ type ErcToNativeMessage struct {
|
|||
Sender common.Address `db:"sender"`
|
||||
Receiver common.Address `db:"receiver"`
|
||||
Value string `db:"value"`
|
||||
RawMessage []byte `db:"raw_message"`
|
||||
CreatedAt *time.Time `db:"created_at"`
|
||||
UpdatedAt *time.Time `db:"updated_at"`
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@ type LogsFilter struct {
|
|||
FromBlock *uint
|
||||
ToBlock *uint
|
||||
TxHash *common.Hash
|
||||
Topic0 *common.Hash
|
||||
Topic1 *common.Hash
|
||||
Topic2 *common.Hash
|
||||
Topic3 *common.Hash
|
||||
Topic0 []common.Hash
|
||||
Topic1 []common.Hash
|
||||
Topic2 []common.Hash
|
||||
Topic3 []common.Hash
|
||||
DataLength *uint
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ type Message struct {
|
|||
Data []byte `db:"data"`
|
||||
DataType uint `db:"data_type"`
|
||||
GasLimit uint `db:"gas_limit"`
|
||||
RawMessage []byte `db:"raw_message"`
|
||||
CreatedAt *time.Time `db:"created_at"`
|
||||
UpdatedAt *time.Time `db:"updated_at"`
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ type SignedMessage struct {
|
|||
type SignedMessagesRepo interface {
|
||||
Ensure(ctx context.Context, msg *SignedMessage) error
|
||||
GetByLogID(ctx context.Context, logID uint) (*SignedMessage, error)
|
||||
FindByMsgHash(ctx context.Context, bridgeID string, msgHash common.Hash) ([]*SignedMessage, error)
|
||||
FindByMsgHash(ctx context.Context, bridgeID string, msgHash []common.Hash) ([]*SignedMessage, error)
|
||||
GetLatest(ctx context.Context, bridgeID, chainID string, signer common.Address) (*SignedMessage, error)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ func unmarshalMessage(bridgeID string, direction entity.Direction, encodedData [
|
|||
GasLimit: uint(binary.BigEndian.Uint32(encodedData[104:108])),
|
||||
DataType: uint(encodedData[108]),
|
||||
Data: encodedData[108:],
|
||||
RawMessage: encodedData,
|
||||
}
|
||||
}
|
||||
if bytes.Equal(messageID[0:4], []byte{0, 5, 0, 0}) {
|
||||
|
@ -36,6 +37,7 @@ func unmarshalMessage(bridgeID string, direction entity.Direction, encodedData [
|
|||
GasLimit: uint(binary.BigEndian.Uint32(encodedData[72:76])),
|
||||
DataType: uint(encodedData[78]),
|
||||
Data: encodedData[79+encodedData[76]+encodedData[77]:],
|
||||
RawMessage: encodedData,
|
||||
}
|
||||
}
|
||||
panic("unsupported message version prefix")
|
||||
|
@ -57,6 +59,7 @@ func unmarshalLegacyMessage(bridgeID string, direction entity.Direction, encoded
|
|||
GasLimit: uint(binary.BigEndian.Uint32(encodedData[100:104])),
|
||||
DataType: 0,
|
||||
Data: encodedData[105:],
|
||||
RawMessage: encodedData,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ func (p *BridgeEventHandler) HandleErcToNativeTransfer(ctx context.Context, log
|
|||
FromBlock: &log.BlockNumber,
|
||||
ToBlock: &log.BlockNumber,
|
||||
TxHash: &log.TransactionHash,
|
||||
Topic0: &bridgeabi.ErcToNativeUserRequestForAffirmationEventSignature,
|
||||
Topic0: []common.Hash{bridgeabi.ErcToNativeUserRequestForAffirmationEventSignature},
|
||||
}
|
||||
logs, err := p.repo.Logs.Find(ctx, filter)
|
||||
if err != nil {
|
||||
|
@ -118,6 +118,7 @@ func (p *BridgeEventHandler) HandleErcToNativeTransfer(ctx context.Context, log
|
|||
Sender: from,
|
||||
Receiver: from,
|
||||
Value: value.String(),
|
||||
RawMessage: msg,
|
||||
}
|
||||
err = p.repo.ErcToNativeMessages.Ensure(ctx, message)
|
||||
if err != nil {
|
||||
|
@ -152,8 +153,8 @@ func (p *BridgeEventHandler) HandleErcToNativeUserRequestForAffirmation(ctx cont
|
|||
FromBlock: &log.BlockNumber,
|
||||
ToBlock: &log.BlockNumber,
|
||||
TxHash: &log.TransactionHash,
|
||||
Topic0: &bridgeabi.ErcToNativeTransferEventSignature,
|
||||
Topic2: hashPtr(p.cfg.Foreign.Address.Hash()),
|
||||
Topic0: []common.Hash{bridgeabi.ErcToNativeTransferEventSignature},
|
||||
Topic2: []common.Hash{p.cfg.Foreign.Address.Hash()},
|
||||
DataLength: uintPtr(32),
|
||||
}
|
||||
logs, err := p.repo.Logs.Find(ctx, filter)
|
||||
|
@ -175,6 +176,7 @@ func (p *BridgeEventHandler) HandleErcToNativeUserRequestForAffirmation(ctx cont
|
|||
Sender: sender,
|
||||
Receiver: recipient,
|
||||
Value: value.String(),
|
||||
RawMessage: msg,
|
||||
}
|
||||
err = p.repo.ErcToNativeMessages.Ensure(ctx, message)
|
||||
if err != nil {
|
||||
|
@ -258,6 +260,7 @@ func (p *BridgeEventHandler) HandleErcToNativeUserRequestForSignature(ctx contex
|
|||
Sender: sender,
|
||||
Receiver: recipient,
|
||||
Value: value.String(),
|
||||
RawMessage: msg,
|
||||
}
|
||||
err = p.repo.ErcToNativeMessages.Ensure(ctx, message)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
package monitor
|
||||
|
||||
import "github.com/ethereum/go-ethereum/common"
|
||||
|
||||
func uintPtr(v uint) *uint {
|
||||
return &v
|
||||
}
|
||||
|
||||
func hashPtr(v common.Hash) *common.Hash {
|
||||
return &v
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ func NewErcToNativeMessagesRepo(table string, db *db.DB) entity.ErcToNativeMessa
|
|||
|
||||
func (r *ercToNativeMessagesRepo) Ensure(ctx context.Context, msg *entity.ErcToNativeMessage) error {
|
||||
q, args, err := sq.Insert(r.table).
|
||||
Columns("bridge_id", "msg_hash", "direction", "sender", "receiver", "value").
|
||||
Values(msg.BridgeID, msg.MsgHash, msg.Direction, msg.Sender, msg.Receiver, msg.Value).
|
||||
Columns("bridge_id", "msg_hash", "direction", "sender", "receiver", "value", "raw_message").
|
||||
Values(msg.BridgeID, msg.MsgHash, msg.Direction, msg.Sender, msg.Receiver, msg.Value, msg.RawMessage).
|
||||
Suffix("ON CONFLICT (bridge_id, msg_hash) DO UPDATE SET sender = EXCLUDED.sender, updated_at = NOW()").
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
ToSql()
|
||||
|
|
|
@ -82,17 +82,17 @@ func (r *logsRepo) Find(ctx context.Context, filter entity.LogsFilter) ([]*entit
|
|||
if filter.TxHash != nil {
|
||||
cond = append(cond, sq.Eq{"transaction_hash": *filter.TxHash})
|
||||
}
|
||||
if filter.Topic0 != nil {
|
||||
cond = append(cond, sq.Eq{"topic0": *filter.Topic0})
|
||||
if len(filter.Topic0) > 0 {
|
||||
cond = append(cond, sq.Eq{"topic0": filter.Topic0})
|
||||
}
|
||||
if filter.Topic1 != nil {
|
||||
cond = append(cond, sq.Eq{"topic1": *filter.Topic1})
|
||||
if len(filter.Topic1) > 0 {
|
||||
cond = append(cond, sq.Eq{"topic1": filter.Topic1})
|
||||
}
|
||||
if filter.Topic2 != nil {
|
||||
cond = append(cond, sq.Eq{"topic2": *filter.Topic2})
|
||||
if len(filter.Topic2) > 0 {
|
||||
cond = append(cond, sq.Eq{"topic2": filter.Topic2})
|
||||
}
|
||||
if filter.Topic3 != nil {
|
||||
cond = append(cond, sq.Eq{"topic3": *filter.Topic3})
|
||||
if len(filter.Topic3) > 0 {
|
||||
cond = append(cond, sq.Eq{"topic3": filter.Topic3})
|
||||
}
|
||||
if filter.DataLength != nil {
|
||||
cond = append(cond, sq.Eq{"length(data)": *filter.DataLength})
|
||||
|
|
|
@ -19,8 +19,8 @@ func NewMessagesRepo(table string, db *db.DB) entity.MessagesRepo {
|
|||
|
||||
func (r *messagesRepo) Ensure(ctx context.Context, msg *entity.Message) error {
|
||||
q, args, err := sq.Insert(r.table).
|
||||
Columns("bridge_id", "msg_hash", "message_id", "direction", "sender", "executor", "data", "data_type", "gas_limit").
|
||||
Values(msg.BridgeID, msg.MsgHash, msg.MessageID, msg.Direction, msg.Sender, msg.Executor, msg.Data, msg.DataType, msg.GasLimit).
|
||||
Columns("bridge_id", "msg_hash", "message_id", "direction", "sender", "executor", "data", "data_type", "gas_limit", "raw_message").
|
||||
Values(msg.BridgeID, msg.MsgHash, msg.MessageID, msg.Direction, msg.Sender, msg.Executor, msg.Data, msg.DataType, msg.GasLimit, msg.RawMessage).
|
||||
Suffix("ON CONFLICT (bridge_id, msg_hash) DO UPDATE SET updated_at = NOW()").
|
||||
PlaceholderFormat(sq.Dollar).
|
||||
ToSql()
|
||||
|
|
|
@ -51,7 +51,7 @@ func (r *signedMessagesRepo) GetByLogID(ctx context.Context, logID uint) (*entit
|
|||
return msg, nil
|
||||
}
|
||||
|
||||
func (r *signedMessagesRepo) FindByMsgHash(ctx context.Context, bridgeID string, msgHash common.Hash) ([]*entity.SignedMessage, error) {
|
||||
func (r *signedMessagesRepo) FindByMsgHash(ctx context.Context, bridgeID string, msgHash []common.Hash) ([]*entity.SignedMessage, error) {
|
||||
q, args, err := sq.Select("*").
|
||||
From(r.table).
|
||||
Where(sq.Eq{"bridge_id": bridgeID, "msg_hash": msgHash}).
|
||||
|
|
Loading…
Reference in New Issue