Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed Dec 19, 2023
1 parent 504b038 commit 3c57c6e
Showing 1 changed file with 58 additions and 50 deletions.
108 changes: 58 additions & 50 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,12 @@ <h5 class="mt-3">Troubleshooting</h5>
if (!devMode) {
await this.syncApprovalEvents(provider, latestBlockNumber);
}
if (!devMode) {
await this.syncNames(provider);
}
if (!devMode) {
await this.syncBlockTimestamps();
}
// if (!devMode) {
await this.syncAccounts(provider);
// }
// if (devMode) {
await this.processData(provider);
// }
Expand All @@ -775,7 +775,6 @@ <h5 class="mt-3">Troubleshooting</h5>
},

async syncApprovalEvents(provider, latestBlockNumber) {
console.log(moment().format("HH:mm:ss") + " syncApprovalEvents BEGIN");
// ERC-20 Approval (index_topic_1 address owner, index_topic_2 address spender, uint256 value)
// 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925
// ERC-721 Approval (index_topic_1 address owner, index_topic_2 address approved, index_topic_3 uint256 tokenId)
Expand All @@ -784,6 +783,10 @@ <h5 class="mt-3">Troubleshooting</h5>
// 0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31
// ERC-1155 ApprovalForAll (index_topic_1 address account, index_topic_2 address operator, bool approved)
// 0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31
console.log(moment().format("HH:mm:ss") + " syncApprovalEvents BEGIN");
this.sync.completed = 0;
this.sync.total = 0;
this.sync.section = 'Approval Events';
const accounts = [this.coinbase];
const accountsAs32Bytes = accounts.map(e => '0x000000000000000000000000' + e.substring(2, 42).toLowerCase());
const approvalLogs = await provider.getLogs({
Expand All @@ -798,6 +801,7 @@ <h5 class="mt-3">Troubleshooting</h5>
null
],
});
this.sync.completed = approvalLogs.length;
const events = [];
for (const log of approvalLogs) {
const topic0 = log.topics[0];
Expand Down Expand Up @@ -826,8 +830,50 @@ <h5 class="mt-3">Troubleshooting</h5>
console.log(moment().format("HH:mm:ss") + " syncApprovalEvents BEGIN");
},

async syncNames(provider) {
console.log(moment().format("HH:mm:ss") + " syncNames BEGIN");
async syncBlockTimestamps() {
console.log(moment().format("HH:mm:ss") + " syncBlockTimestamps BEGIN");
const blockNumbersMap = {};
for (const event of this.events) {
if (!(event.blockNumber in blockNumbersMap)) {
blockNumbersMap[event.blockNumber] = true;
}
}
const blockNumbers = Object.keys(blockNumbersMap);
this.sync.completed = 0;
this.sync.total = blockNumbers.length;
this.sync.section = 'Block Timestamps';
const BATCHSIZE = 1000;
const blockTimestamps = {};
for (let i = 0; i < blockNumbers.length; i += BATCHSIZE) {
const batch = blockNumbers.slice(i, parseInt(i) + BATCHSIZE);
const data = await fetch(BLOCKTIMESTAMPSUBGRAPHURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: BLOCKTIMESTAMPINQUERY,
variables: { blockNumbers: batch.map(e => parseInt(e)) },
})
}).then(response => response.json())
.catch(function(e) {
console.log("error: " + e);
});
const timestamps = data.data && data.data.blocks || [];
for (const timestampItem of timestamps) {
blockTimestamps[timestampItem.number] = parseInt(timestampItem.timestamp);
}
this.sync.completed += timestamps.length;
console.log(moment().format("HH:mm:ss") + " syncBlockTimestamps " + this.sync.completed + " of " + blockNumbers.length);
}
localStorage.approvalBlockTimestamps = JSON.stringify(blockTimestamps);
Vue.set(this, 'blockTimestamps', blockTimestamps);
console.log(moment().format("HH:mm:ss") + " syncBlockTimestamps END");
},

async syncAccounts(provider) {
console.log(moment().format("HH:mm:ss") + " syncAccounts BEGIN");
const ownersMap = {};
const contractsMap = {};
const spendersMap = {};
Expand Down Expand Up @@ -861,6 +907,9 @@ <h5 class="mt-3">Troubleshooting</h5>
}
const erc721Helper = new ethers.Contract(ERC721HELPERADDRESS, ERC721HELPERABI, provider);
const accountsToCheck = [...owners, ...contracts, ...spenders];
this.sync.completed = 0;
this.sync.total = accountsToCheck.length;
this.sync.section = 'Addresses';
for (const account of accountsToCheck) {
if (account in CUSTOMNAMES) {
accounts[account].type = CUSTOMNAMES[account][0];
Expand Down Expand Up @@ -908,14 +957,15 @@ <h5 class="mt-3">Troubleshooting</h5>
}
}
} catch (e) {
console.log("syncNames erc721Helper - ERROR: " + account + ", message: " + e.message);
console.log("syncAccounts erc721Helper - ERROR: " + account + ", message: " + e.message);
accounts[account].type = "unknown0";
}
}
this.sync.completed++;
}
localStorage.approvalAccounts = JSON.stringify(accounts);
Vue.set(this, 'accounts', accounts);
console.log(moment().format("HH:mm:ss") + " syncNames END");
console.log(moment().format("HH:mm:ss") + " syncAccounts END");
},

// // TODO: Refresh sync
Expand Down Expand Up @@ -981,48 +1031,6 @@ <h5 class="mt-3">Troubleshooting</h5>
// console.log(moment().format("HH:mm:ss") + " syncENSNames END");
// },

async syncBlockTimestamps() {
console.log(moment().format("HH:mm:ss") + " syncBlockTimestamps BEGIN");
const blockNumbersMap = {};
for (const event of this.events) {
if (!(event.blockNumber in blockNumbersMap)) {
blockNumbersMap[event.blockNumber] = true;
}
}
const blockNumbers = Object.keys(blockNumbersMap);
this.sync.completed = 0;
this.sync.total = blockNumbers.length;
this.sync.section = 'Block Timestamps';
const BATCHSIZE = 1000;
const blockTimestamps = {};
for (let i = 0; i < blockNumbers.length; i += BATCHSIZE) {
const batch = blockNumbers.slice(i, parseInt(i) + BATCHSIZE);
const data = await fetch(BLOCKTIMESTAMPSUBGRAPHURL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: BLOCKTIMESTAMPINQUERY,
variables: { blockNumbers: batch.map(e => parseInt(e)) },
})
}).then(response => response.json())
.catch(function(e) {
console.log("error: " + e);
});
const timestamps = data.data && data.data.blocks || [];
for (const timestampItem of timestamps) {
blockTimestamps[timestampItem.number] = parseInt(timestampItem.timestamp);
}
this.sync.completed += timestamps.length;
console.log(moment().format("HH:mm:ss") + " syncBlockTimestamps " + this.sync.completed + " of " + blockNumbers.length);
}
localStorage.approvalBlockTimestamps = JSON.stringify(blockTimestamps);
Vue.set(this, 'blockTimestamps', blockTimestamps);
console.log(moment().format("HH:mm:ss") + " syncBlockTimestamps END");
},

async processData(provider) {
console.log(moment().format("HH:mm:ss") + " processData BEGIN");
const accounts = this.accounts;
Expand Down

0 comments on commit 3c57c6e

Please sign in to comment.