Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add msg_index in nft_event
Browse files Browse the repository at this point in the history
williamchong committed Oct 3, 2024

Verified

This commit was signed with the committer’s verified signature.
williamchong William Chong
1 parent 2ac7992 commit f6f7671
Showing 5 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions db/extract.go
Original file line number Diff line number Diff line change
@@ -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 {
6 changes: 3 additions & 3 deletions db/nft.go
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions db/schema/v020.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE nft_event
ADD COLUMN msg_index INT DEFAULT 0 NOT NULL
;
1 change: 1 addition & 0 deletions db/types.go
Original file line number Diff line number Diff line change
@@ -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"`
1 change: 1 addition & 0 deletions extractor/nft.go
Original file line number Diff line number Diff line change
@@ -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 {

0 comments on commit f6f7671

Please sign in to comment.