修复nft confirm问题

This commit is contained in:
aozhiwei 2022-04-23 08:34:16 +08:00
parent 91172bf7dd
commit d22eaf9376
2 changed files with 25 additions and 8 deletions

View File

@ -93,6 +93,8 @@ class EventCenter extends BaseService {
const outputLog = async () => { const outputLog = async () => {
while (true) { while (true) {
log.info(++count + '-------------------------------------------------------------'); log.info(++count + '-------------------------------------------------------------');
log.info('pendingConfirmOwnerHash.size:' +
Object.keys(this.pendingConfirmOwnerHash).length);
allInstances.forEach((item) => { allInstances.forEach((item) => {
log.info(utils.jsonEncode(item)); log.info(utils.jsonEncode(item));
}); });

View File

@ -19,7 +19,7 @@ class ExecConfirmOwner {
this.addTryCount(); this.addTryCount();
await this.doConfirm(); await this.doConfirm();
} catch (err) { } catch (err) {
console.log(err); log.error('ExecConfirmOwner:' + this.tokenId + ' err:' + err);
} finally { } finally {
this.destory(); this.destory();
} }
@ -39,7 +39,7 @@ class ExecConfirmOwner {
const oldTryCount = this.tryCount; const oldTryCount = this.tryCount;
const oldBlockNumber = bc.getCurrBlockNumber(); const oldBlockNumber = bc.getCurrBlockNumber();
let oldOwner = await this.getOwner(); let oldOwner = await this.getOwner();
while (oldBlockNumber + 8 < bc.getCurrBlockNumber()) { while (oldBlockNumber + 8 > bc.getCurrBlockNumber()) {
await utils.sleep(1000 + utils.randRange(0, 500)); await utils.sleep(1000 + utils.randRange(0, 500));
} }
@ -48,8 +48,8 @@ class ExecConfirmOwner {
let newOwner = await this.getOwner(); let newOwner = await this.getOwner();
if (oldOwner == newOwner) { if (oldOwner == newOwner) {
await this.updateConfirmed(newOwner, oldBlockNumber); const ok = await this.updateConfirmed(newOwner, oldBlockNumber);
if (oldTryCount == this.tryCount) { if (ok && oldTryCount == this.tryCount) {
break; break;
} }
} }
@ -101,7 +101,9 @@ class ExecConfirmOwner {
async getOwner() { async getOwner() {
const instanceName = this.getInstanceName(); const instanceName = this.getInstanceName();
log.info('getOwner:' + instanceName + ' tryCount:' + this.tryCount); log.info('getOwner:' + instanceName +
' tryCount:' + this.tryCount +
' token_id:' + this.tokenId);
while (true) { while (true) {
await bc.lockQuery(); await bc.lockQuery();
try { try {
@ -123,7 +125,8 @@ class ExecConfirmOwner {
async updateConfirmed(newOwner, blockNumber) { async updateConfirmed(newOwner, blockNumber) {
const {err, conn} = await app.getDbConn('MarketDb0'); const {err, conn} = await app.getDbConn('MarketDb0');
if (err) { if (err) {
return; log.error('updateConfirmed:' + this.tokenId + ' err:' + err);
return false;
} }
try { try {
{ {
@ -134,19 +137,31 @@ class ExecConfirmOwner {
], ],
[ [
['owner_address', bcutils.toNormalAddress(newOwner)], ['owner_address', bcutils.toNormalAddress(newOwner)],
['confirm_count', this.nftDb['confirm_count'] + 1],
['confirm_block_number', blockNumber] ['confirm_block_number', blockNumber]
]); ]);
if (err) {
log.error('updateConfirmed:' + this.tokenId + ' err:' + err);
return false;
}
} }
{ {
await conn.execScript( const {err} = await conn.execScript(
'UPDATE t_nft_transfer SET `owner_confirmed` = 1 WHERE block_number < ?', 'UPDATE t_nft_transfer SET `owner_confirmed`=1 ' +
'WHERE token_id=? AND block_number < ?',
[ [
this.tokenId,
blockNumber blockNumber
]); ]);
if (err) {
log.error('updateConfirmed:' + this.tokenId + ' err:' + err);
return false;
}
} }
} finally { } finally {
conn.release() conn.release()
} }
return true;
} }
} }