From 66e5392b138718f686b2048362f9fedbef1d4312 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 24 Jul 2024 11:34:21 +0800 Subject: [PATCH] 1 --- server/light_backtask/service/nftutils.go | 39 +++++++++++++++ server/light_backtask/task/chain_activity.go | 4 +- server/light_backtask/task/repair_nft.go | 52 ++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/server/light_backtask/service/nftutils.go b/server/light_backtask/service/nftutils.go index 579e9d6f..cd76c36e 100644 --- a/server/light_backtask/service/nftutils.go +++ b/server/light_backtask/service/nftutils.go @@ -45,6 +45,45 @@ func GetItemIdHeroQuality(netId int32, contractAddress string, tokenId string, }) } +func GetNftItemIdQuality(netId int32, contractAddress string, tokenId string, + itemId *int32, quality *int32) { + f5.GetGoStyleDb().OrmSelectOne( + constant.BCNFT_DB, + "t_nft", + [][]string { + {"net_id", q5.ToString(netId)}, + {"contract_address", contractAddress}, + {"token_id", tokenId}, + }, + func (err error, ds *f5.DataSet) { + if err != nil { + return + } + if ds.Next() { + *itemId = q5.ToInt32(ds.GetByName("item_id")) + *quality = q5.ToInt32(ds.GetByName("quality")) + tokenType := q5.ToInt32(ds.GetByName("token_type")) + if tokenType == jccommon.NFT_TYPE_CFHERO || + tokenType == jccommon.NFT_TYPE_CFHERO_NORMAL { + f5.GetGoStyleDb().OrmSelectOne( + constant.GAME_DB, + "t_hero", + [][]string { + {"token_id", tokenId}, + }, + func (err error, ds *f5.DataSet) { + if err != nil { + return + } + if ds.Next() { + *quality = q5.ToInt32(ds.GetByName("quality")) + } + }) + } + } + }) +} + func GetHeroByTokenId(tokenId string, itemId *int32, heroQuality *int32) bool { result := false f5.GetGoStyleDb().OrmSelectOne( diff --git a/server/light_backtask/task/chain_activity.go b/server/light_backtask/task/chain_activity.go index e1c8d1e8..2b19a68b 100644 --- a/server/light_backtask/task/chain_activity.go +++ b/server/light_backtask/task/chain_activity.go @@ -98,10 +98,10 @@ func (this* chainActivity) saveToDb(ds *f5.DataSet) bool { {"token_id", tokenId}, } } - genInsertKv := func (nftAddress ,tokenId ,sender, to string, isMint int32) [][]string { + genInsertKv := func (nftAddress, tokenId, sender, to string, isMint int32) [][]string { var itemId int32 var quality int32 - service.GetItemIdHeroQuality(q5.ToInt32(netId), contractAddress, tokenId, &itemId, &quality) + service.GetNftItemIdQuality(q5.ToInt32(netId), contractAddress, tokenId, &itemId, &quality) return [][]string{ {"txhash", txhash}, {"log_index", logIndex}, diff --git a/server/light_backtask/task/repair_nft.go b/server/light_backtask/task/repair_nft.go index e35dfde2..082726d6 100644 --- a/server/light_backtask/task/repair_nft.go +++ b/server/light_backtask/task/repair_nft.go @@ -18,6 +18,7 @@ func (this* repairNft) init() { go this.processNft() go this.processOrder() go this.processSale() + go this.processChainActivity() } func (this* repairNft) unInit() { @@ -102,6 +103,32 @@ SELECT * FROM t_sale WHERE idx > %d AND item_id = 0 LIMIT 1000`, this.repairSale) } +func (this* repairNft) processChainActivity() { + f5.GetGoStyleDb().LoopLoad( + constant.BCEVENT_DB, + "repairNft.chainActivity", + "t_chain_activity", + func () int64 { + return 60 + q5.ToInt64(rand.Intn(2)) + }, + func (lastIdx int64) string { + sql := fmt.Sprintf(` +SELECT * FROM t_chain_activity WHERE idx > %d AND item_id = 0 AND quality = 0 LIMIT 100`, + lastIdx, + ) + return sql + }, + []string{ + }, + func () int64 { + return 10 + }, + func () int64 { + return 60 * 5 + }, + this.repairChainActivity) +} + func (this* repairNft) repairNft(ds *f5.DataSet) bool { netId := q5.ToInt32(ds.GetByName("net_id")) contractAddress := ds.GetByName("contract_address") @@ -233,3 +260,28 @@ func (this* repairNft) updateSale(netId int32, contractAddress string, tokenId s func (err error, lastInsertId int64, rowsAffected int64) { }) } + +func (this* repairNft) repairChainActivity(ds *f5.DataSet) bool { + netId := q5.ToInt32(ds.GetByName("net_id")) + contractAddress := ds.GetByName("contract_address") + tokenId := ds.GetByName("token_id") + switch q5.ToInt32(ds.GetByName("token_type")) { + case jccommon.NFT_TYPE_CFHERO: + case jccommon.NFT_TYPE_CFHERO_NORMAL: + { + var itemId int32 + var quality int32 + if service.GetHeroByTokenId(tokenId, &itemId, &quality) { + this.updateSale(netId, contractAddress, tokenId, itemId, quality) + } + } + case jccommon.NFT_TYPE_GOLD_BULLION: + { + var itemId int32 + if service.GetGoldBullionByNetIdTokenId(netId, tokenId, &itemId) { + this.updateSale(netId, contractAddress, tokenId, itemId, 0) + } + } + } + return true +}