From 40d769e55e4a2c40be55898621283d829c700988 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 18 Jun 2024 14:04:58 +0800 Subject: [PATCH] 1 --- server/common/bchelper.js | 5 ++ .../services/events/CFHero/transfer.js | 6 +-- .../services/events/GoldBrick/transfer.js | 6 +-- .../events/common/BaseEventProcess.js | 50 +++++++++++++++++-- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/server/common/bchelper.js b/server/common/bchelper.js index 97b5ab0..c0cd444 100644 --- a/server/common/bchelper.js +++ b/server/common/bchelper.js @@ -63,6 +63,11 @@ function getNftTableName(tokenType) { return 't_chip'; } break; + case bcconst.BC_NFT_GOLD_BULLION: + { + return 't_gold_bullion'; + } + break; default: { return ''; diff --git a/server/web3dbspider/services/events/CFHero/transfer.js b/server/web3dbspider/services/events/CFHero/transfer.js index 002c34c..b2636e3 100644 --- a/server/web3dbspider/services/events/CFHero/transfer.js +++ b/server/web3dbspider/services/events/CFHero/transfer.js @@ -9,8 +9,8 @@ class Transfer extends BaseEventProcess { async start() { const returnValues = this.getReturnValues(); - const from = returnValues['from']; - const to = returnValues['to']; + const from = bcutils.toNormalAddress(returnValues['from']); + const to = bcutils.toNormalAddress(returnValues['to']); const tokenId = returnValues['tokenId']; await this.mustBeMint(to, tokenId, bcconst.BC_NFT_HERO); @@ -25,7 +25,7 @@ class Transfer extends BaseEventProcess { if (airDropMeta) { await this.apiMint(to, tokenId, airDropMeta); } else { - await this.ingameActivate(tokenId, bcconst.BC_NFT_HERO); + await this.ingameActivate(from, to, tokenId, bcconst.BC_NFT_HERO); } } else { await this.add721NftRefresh diff --git a/server/web3dbspider/services/events/GoldBrick/transfer.js b/server/web3dbspider/services/events/GoldBrick/transfer.js index a1be447..09ed843 100644 --- a/server/web3dbspider/services/events/GoldBrick/transfer.js +++ b/server/web3dbspider/services/events/GoldBrick/transfer.js @@ -9,13 +9,13 @@ class Transfer extends BaseEventProcess { async start() { const returnValues = this.getReturnValues(); - const from = returnValues['from']; - const to = returnValues['to']; + const from = bcutils.toNormalAddress(returnValues['from']); + const to = bcutils.toNormalAddress(returnValues['to']); const tokenId = returnValues['tokenId']; await this.mustBeMint(to, tokenId, bcconst.BC_NFT_GOLD_BULLION); if (bcutils.isSysAddress(from)) { - await this.ingameActivate(tokenId, bcconst.BC_NFT_GOLD_BULLION); + await this.ingameActivate(from, to, tokenId, bcconst.BC_NFT_GOLD_BULLION); } else { await this.add721NftRefresh ( diff --git a/server/web3dbspider/services/events/common/BaseEventProcess.js b/server/web3dbspider/services/events/common/BaseEventProcess.js index c3a9026..c72709e 100644 --- a/server/web3dbspider/services/events/common/BaseEventProcess.js +++ b/server/web3dbspider/services/events/common/BaseEventProcess.js @@ -396,7 +396,7 @@ class BaseEventProcess { } } - async ingameActivate(tokenId, tokenType) { + async ingameActivate(from, to, tokenId, tokenType) { const logHead = this.genLogHead(' ingameActivate '); const tblName = bchelper.getNftTableName(tokenType); if (!tblName) { @@ -404,11 +404,13 @@ class BaseEventProcess { return; } if (tokenType == bcconst.BC_NFT_HERO) { - await this.ingameActivateHero(tblName, tokenId, tokenType); + await this.ingameActivateHero(from, to, tblName, tokenId, tokenType); + } else if (tokenType == bcconst.BC_NFT_GOLD_BULLION) { + await this.ingameActivateGoldBullion(from, to, tblName, tokenId, tokenType); } } - async ingameActivateHero(tblName, tokenId, tokenType) { + async ingameActivateHero(from, to, tblName, tokenId, tokenType) { const logHead = this.genLogHead(' ingameActivateHero '); const nowTime = utils.getUtcTime(); { @@ -458,6 +460,48 @@ class BaseEventProcess { } } + async ingameActivateGoldBullion(from, to, tblName, tokenId, tokenType) { + const logHead = this.genLogHead(' ingameActivateGoldBullion '); + const nowTime = utils.getUtcTime(); + const {err, row} = await this.gameDbConn( + 'ormSelectOne', + tblName, + [ + ['token_id', tokenId], + ] + ); + if (err) { + this.throwError(logHead + err); + } + if (!row) { + await this.addLog([ + ['type', 'ingameActivateGoldError'], + ['subtype', 'token_id.notfound'], + ['net_id', this.getNetId()], + ['param1', tokenId], + ['createtime', nowTime], + ['modifytime', nowTime], + ]); + return; + } + if (!row['activated']) { + const {err} = await this.gameDbConn( + 'update', + tblName, + [ + ['token_id', tokenId], + ], + [ + ['activated', 1], + ['activate_time', nowTime], + ] + ); + if (err) { + this.throwError(logHead + err); + } + } + } + async addLog(fieldsKv) { const {err} = await this.bcEventDbConn( 'insert',