Skip to content

Commit

Permalink
fix[tidb]:updated at from systime to blocktimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
fishTsai20 committed Jan 24, 2024
1 parent c064f67 commit e90b232
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
3 changes: 2 additions & 1 deletion handlers/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ func handleProtocols(inscription *model.Inscription) error {
var protoData map[string]string
err := json.Unmarshal([]byte(content), &protoData)
if err != nil {
logger.Info("json parse error: ", err, ", at ", inscription.Number)
return nil
//logger.Info("json parse error: ", err, ", at ", inscription.Number)
} else {
value, ok := protoData["p"]
if ok && strings.TrimSpace(value) != "" {
Expand Down
34 changes: 17 additions & 17 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func LoadTransactionData(fname string) ([]*model.Transaction, error) {
return nil, err
}

if block < maxBlockNumber {
if block <= maxBlockNumber {
continue
}

Expand Down Expand Up @@ -280,21 +280,21 @@ func ConvertTokensToTokenInfos(tokens map[string]*model.Token) []*model.TokenInf
var tokenInfos []*model.TokenInfo
for _, token := range tokens {
tokenInfo := &model.TokenInfo{
BlockTimestamp: time.Unix(int64(token.CreatedAt), 0),
BlockNumber: token.CreatedBlockNumber,
ID: strconv.FormatUint(token.Number, 10),
TxIndex: token.TxIndex,
TxHash: token.TxHash,
Tick: token.Tick,
MaxSupply: token.Max,
Lim: token.Limit,
Wlim: nil,
Dec: token.Precision,
Creator: token.Creator,
Minted: token.Minted,
Holders: token.Holders,
Txs: token.Trxs,
UpdatedAt: time.Unix(int64(token.UpdatedAt), 0),
BlockTimestamp: time.Unix(int64(token.CreatedAt), 0),
BlockNumber: token.CreatedBlockNumber,
ID: strconv.FormatUint(token.Number, 10),
TxIndex: token.TxIndex,
TxHash: token.TxHash,
Tick: token.Tick,
MaxSupply: token.Max,
Lim: token.Limit,
Wlim: nil,
Dec: token.Precision,
Creator: token.Creator,
Minted: token.Minted,
Holders: token.Holders,
Txs: token.Trxs,
UpdatedTimeStamp: time.Unix(int64(token.UpdatedAt), 0),
}
if token.CompletedAt != 0 {
t := time.Unix(int64(token.CompletedAt), 0)
Expand Down Expand Up @@ -379,7 +379,7 @@ func LoadTokenInfo(db *gorm.DB) ([]*model.Token, error) {
Holders: tokenInfo.Holders,
Trxs: tokenInfo.Txs,
CreatedAt: uint64(tokenInfo.BlockTimestamp.Unix()),
UpdatedAt: uint64(tokenInfo.UpdatedAt.Unix()),
UpdatedAt: uint64(tokenInfo.UpdatedTimeStamp.Unix()),
CompletedAt: completedAt,
Hash: utils.Keccak256(strings.ToLower(tokenInfo.Tick)),
TxHash: tokenInfo.TxHash,
Expand Down
36 changes: 19 additions & 17 deletions model/token_info.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package model

import "time"
import (
"time"
)

type TokenInfo struct {
BlockTimestamp time.Time `gorm:"column:block_timestamp"`
BlockNumber uint64 `gorm:"column:block_number"`
TxIndex uint32 `gorm:"column:tx_index"`
TxHash string `gorm:"column:tx_hash"`
Tick string `gorm:"column:tick;primaryKey"`
MaxSupply *DDecimal `gorm:"column:max_supply"`
Lim *DDecimal `gorm:"column:lim"`
Wlim *DDecimal `gorm:"column:wlim"`
Dec int `gorm:"column:dec"`
Creator string `gorm:"column:creator"`
Minted *DDecimal `gorm:"column:minted"`
Holders int32 `gorm:"column:holders"`
Txs int32 `gorm:"column:txs"`
UpdatedAt time.Time `gorm:"column:updated_timestamp"`
CompletedAt *time.Time `gorm:"column:completed_timestamp"`
ID string `gorm:"column:id"`
BlockTimestamp time.Time `gorm:"column:block_timestamp"`
BlockNumber uint64 `gorm:"column:block_number"`
TxIndex uint32 `gorm:"column:tx_index"`
TxHash string `gorm:"column:tx_hash"`
Tick string `gorm:"column:tick;primaryKey"`
MaxSupply *DDecimal `gorm:"column:max_supply"`
Lim *DDecimal `gorm:"column:lim"`
Wlim *DDecimal `gorm:"column:wlim"`
Dec int `gorm:"column:dec"`
Creator string `gorm:"column:creator"`
Minted *DDecimal `gorm:"column:minted"`
Holders int32 `gorm:"column:holders"`
Txs int32 `gorm:"column:txs"`
UpdatedTimeStamp time.Time `gorm:"column:updated_timestamp"`
CompletedAt *time.Time `gorm:"column:completed_timestamp"`
ID string `gorm:"column:id"`
}

func (TokenInfo) TableName() string {
Expand Down

0 comments on commit e90b232

Please sign in to comment.