From f6f76710c3e7842b1469d558851aa2955221e6f9 Mon Sep 17 00:00:00 2001 From: William Chong Date: Thu, 3 Oct 2024 17:59:56 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20msg=5Findex=20in=20nft=5Feven?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/extract.go | 6 +++--- db/nft.go | 6 +++--- db/schema/v020.sql | 3 +++ db/types.go | 1 + extractor/nft.go | 1 + 5 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 db/schema/v020.sql diff --git a/db/extract.go b/db/extract.go index ff22694..4b69e5b 100644 --- a/db/extract.go +++ b/db/extract.go @@ -246,11 +246,11 @@ func (batch *Batch) InsertNftEvent(e NftEvent) { sql := ` INSERT INTO nft_event ( action, class_id, nft_id, sender, receiver, - events, tx_hash, timestamp, price, memo, + events, tx_hash, timestamp, price, memo, msg_index, iscn_owner_at_the_time ) VALUES ( - $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, COALESCE( (SELECT i.owner FROM nft_class AS c @@ -266,7 +266,7 @@ func (batch *Batch) InsertNftEvent(e NftEvent) { ON CONFLICT DO NOTHING` batch.Batch.Queue(sql, e.Action, e.ClassId, e.NftId, e.Sender, e.Receiver, - utils.GetEventStrings(e.Events), e.TxHash, e.Timestamp, e.Price, e.Memo, + utils.GetEventStrings(e.Events), e.TxHash, e.Timestamp, e.Price, e.Memo, e.MsgIndex, ) if e.Price > 0 { diff --git a/db/nft.go b/db/nft.go index 3f4eae6..ca0e210 100644 --- a/db/nft.go +++ b/db/nft.go @@ -311,7 +311,7 @@ func GetNftEvents(conn *pgxpool.Conn, q QueryEventsRequest, p PageRequest) (Quer SELECT e.id, e.action, e.class_id, e.nft_id, e.sender, e.receiver, e.timestamp, e.tx_hash, e.events, e.price, - e.memo + e.memo, e.msg_index FROM nft_event as e JOIN nft_class as c ON e.class_id = c.class_id @@ -341,7 +341,7 @@ func GetNftEvents(conn *pgxpool.Conn, q QueryEventsRequest, p PageRequest) (Quer SELECT e.id, e.action, e.class_id, e.nft_id, e.sender, e.receiver, e.timestamp, e.tx_hash, e.events, e.price, - e.memo + e.memo, e.msg_index FROM nft_event as e JOIN nft_class as c ON e.class_id = c.class_id @@ -394,7 +394,7 @@ func GetNftEvents(conn *pgxpool.Conn, q QueryEventsRequest, p PageRequest) (Quer if err = rows.Scan( &res.Pagination.NextKey, &e.Action, &e.ClassId, &e.NftId, &e.Sender, &e.Receiver, &e.Timestamp, &e.TxHash, &eventRaw, &price, - &e.Memo, + &e.Memo, &e.MsgIndex, ); err != nil { logger.L.Errorw("failed to scan nft events", "error", err, "q", q) return QueryEventsResponse{}, fmt.Errorf("query nft events data failed: %w", err) diff --git a/db/schema/v020.sql b/db/schema/v020.sql new file mode 100644 index 0000000..fb79681 --- /dev/null +++ b/db/schema/v020.sql @@ -0,0 +1,3 @@ +ALTER TABLE nft_event + ADD COLUMN msg_index INT DEFAULT 0 NOT NULL +; \ No newline at end of file diff --git a/db/types.go b/db/types.go index 302b8ff..180d335 100644 --- a/db/types.go +++ b/db/types.go @@ -138,6 +138,7 @@ type NftEvent struct { NftId string `json:"nft_id"` Sender string `json:"sender"` Receiver string `json:"receiver"` + MsgIndex int `json:"msg_index,omitempty"` Events types.StringEvents `json:"events,omitempty"` TxHash string `json:"tx_hash"` Timestamp time.Time `json:"timestamp"` diff --git a/extractor/nft.go b/extractor/nft.go index b8b8829..6b8fae8 100644 --- a/extractor/nft.go +++ b/extractor/nft.go @@ -16,6 +16,7 @@ func attachNftEvent(e *db.NftEvent, payload *Payload) { e.Timestamp = payload.Timestamp e.TxHash = payload.TxHash e.Memo = payload.Memo + e.MsgIndex = payload.MsgIndex } type nftClassMessage struct {