修复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 () => {
while (true) {
log.info(++count + '-------------------------------------------------------------');
log.info('pendingConfirmOwnerHash.size:' +
Object.keys(this.pendingConfirmOwnerHash).length);
allInstances.forEach((item) => {
log.info(utils.jsonEncode(item));
});

View File

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