This commit is contained in:
aozhiwei 2023-07-12 11:31:22 +08:00
parent ecae00f4b4
commit 7fbcd56bb8
2 changed files with 31 additions and 4 deletions

View File

@ -60,7 +60,11 @@ class BlockChain extends BaseService {
}
async getPastEvents(contractName, eventName, ...args) {
return this.#bc[contractName + 'Instance'].getPastEvents(eventName, ...args);
return await this.#bc[contractName + 'Instance'].getPastEvents(eventName, ...args);
}
async ownerOf721(contractName, tokenId) {
return await this.#bc[contractName + 'Instance'].methods.ownerOf(tokenId).call();
}
}

View File

@ -89,14 +89,14 @@ class Erc721Refresher extends BaseService {
while (true) {
await this.bc.mustBeActive();
const oldBlockNumber = this.bc.getCurrBlockNumber();
let oldOwner = await this.getOwner();
let oldOwner = await this.getOwner(row['token_id']);
while (oldBlockNumber + 8 > this.bc.getCurrBlockNumber()) {
await utils.sleep(1000 + utils.randRange(0, 500));
}
await this.bc.mustBeActive();
const newBlockNumber = this.bc.getCurrBlockNumber();
let newOwner = await this.getOwner();
let newOwner = await this.getOwner(row['token_id']);
if (oldOwner == newOwner) {
const ok = await this.updateConfirmed(newOwner, oldBlockNumber, row);
@ -110,10 +110,33 @@ class Erc721Refresher extends BaseService {
}
}
await utils.sleep(1000 + utils.randRange(500, 1500));
}
}
async getOwner(tokenId) {
while (true) {
await this.bc.lockQuery();
try {
let owner = await this.bc.ownerOf721(this.getContractName(), tokenId);
return owner;
} catch (err) {
const reason = utils.getVal(err, 'reason');
if (reason == 'ERC721: owner query for nonexistent token') {
return '';
}
if (err == 'Error: Returned error: VM Exception while processing transaction: revert ERC721: owner query for nonexistent token' ||
err == 'Error: Returned error: execution reverted: ERC721: owner query for nonexistent token') {
return '';
}
log.error(err);
} finally {
await this.bc.unlockQuery();
}
await utils.sleep(5000 + utils.randRange(1500, 2500));
}
}
async updateConfirmed(newOwner, blockNumber, row) {
const logHead = this.genLogHead('updateConfirmed ');
const tokenId = row['token_id'];