From a4573dbec57a8708aa43b7a2fa9b654049d74bc6 Mon Sep 17 00:00:00 2001 From: BokkyPooBah Date: Sat, 17 Aug 2024 17:01:58 +1000 Subject: [PATCH] wip --- docs/index.html | 86 ++++++++++++++++++++++++------------------ docs/parseEventLogs.js | 34 +++++++++++++---- 2 files changed, 77 insertions(+), 43 deletions(-) diff --git a/docs/index.html b/docs/index.html index e46e67c..bcd8042 100644 --- a/docs/index.html +++ b/docs/index.html @@ -102,6 +102,8 @@ + +
Welcome
@@ -337,37 +339,37 @@
Troubleshooting
@@ -809,6 +811,12 @@
Troubleshooting
el: '#app', // --- DATA --- data: { + EVENT_TRANSFER: 0, + EVENT_TRANSFERSINGLE: 1, + EVENT_TRANSFERBATCH: 2, + EVENT_APPROVAL: 3, + EVENT_APPROVALFORALL: 4, + DB_PROCESSING_BATCH_SIZE: 10000, connected: false, @@ -1024,6 +1032,12 @@
Troubleshooting
// --- COMPUTED --- computed: { + // EVENTTYPE() { + // return EVENTTYPE; + // }, + EVENTNAME() { + return EVENTNAME; + }, network() { return NETWORKS[this.chainId] || {}; }, @@ -1083,7 +1097,7 @@
Troubleshooting
for (const item of this.events) { const metadata = tokensMetadata[item.tokenId] || null; let metadatas = null; - if (item.type == "TransferBatch") { + if (item.type == EVENT_TRANSFERBATCH) { metadatas = []; for (const [index, tokenId] of item.tokenIds.entries()) { metadatas.push({ @@ -1097,34 +1111,34 @@
Troubleshooting
} let include = true; if (addressRegex) { - if (item.type == "Transfer") { + if (item.type == EVENT_TRANSFER) { if (!(addressRegex.test(item.from) || addressRegex.test(item.to) || addressRegex.test(item.txHash) || addressRegex.test(item.blockNumber.toString()))) { include = false; } - } else if (item.type == "TransferSingle") { + } else if (item.type == EVENT_TRANSFERSINGLE) { if (!(addressRegex.test(item.from) || addressRegex.test(item.to) || addressRegex.test(item.txHash) || addressRegex.test(item.blockNumber.toString()) || addressRegex.test(item.tokenId.toString()))) { include = false; } - } else if (item.type == "TransferBatch") { + } else if (item.type == EVENT_TRANSFERBATCH) { if (!(addressRegex.test(item.from) || addressRegex.test(item.to) || addressRegex.test(item.txHash) || addressRegex.test(item.blockNumber.toString()))) { include = false; } - } else if (item.type == "Approval") { + } else if (item.type == EVENT_APPROVAL) { if (!(addressRegex.test(item.owner) || addressRegex.test(item.spender) || addressRegex.test(item.txHash) || addressRegex.test(item.blockNumber))) { include = false; } - } else if (item.type == "ApprovalForAll") { + } else if (item.type == EVENT_APPROVALFORALL) { if (!(addressRegex.test(item.owner) || addressRegex.test(item.operator) || addressRegex.test(item.txHash) || addressRegex.test(item.blockNumber))) { include = false; } } } if (include && tokenIdRegex && (this.type == 721 || this.type == 1155)) { - if (this.type == 721 || (this.type == 1155 && item.type == "TransferSingle")) { + if (this.type == 721 || (this.type == 1155 && item.type == EVENT_TRANSFERSINGLE)) { if (!(tokenIdRegex.test(item.tokenId))) { include = false; } - } else if (this.type == 1155 && item.type == "TransferBatch") { + } else if (this.type == 1155 && item.type == EVENT_TRANSFERBATCH) { let found = false; for (const [index, tokenId] of item.tokenIds.entries()) { // console.log(index + " " + tokenId); @@ -1844,7 +1858,7 @@
Troubleshooting
for (const event of records) { // console.log(now() + " INFO loadERC20 - event: " + JSON.stringify(event)); events.push(event); - if (event.type == "Transfer") { + if (event.type == EVENT_TRANSFER) { if (!(event.from in tokensCollator)) { tokensCollator[event.from] = { blockNumber: event.blockNumber, @@ -1878,7 +1892,7 @@
Troubleshooting
tokensCollator[event.to].logIndex = event.logIndex; tokensCollator[event.to].tokens = ethers.BigNumber.from(tokensCollator[event.to].tokens).add(event.tokens).toString(); } - } else if (event.type == "Approval") { + } else if (event.type == EVENT_APPROVAL) { if (!(event.owner in approvalsCollator)) { approvalsCollator[event.owner] = {}; } @@ -1930,7 +1944,7 @@
Troubleshooting
for (const event of records) { // console.log(now() + " INFO loadERC721 - event: " + JSON.stringify(event)); events.push(event); - if (event.type == "Transfer") { + if (event.type == EVENT_TRANSFER) { tokensCollator[event.tokenId] = { blockNumber: event.blockNumber, txIndex: event.txIndex, @@ -1938,7 +1952,7 @@
Troubleshooting
logIndex: event.logIndex, owner: event.to, }; - } else if (event.type == "Approval") { + } else if (event.type == EVENT_APPROVAL) { approvalsCollator[event.tokenId] = { blockNumber: event.blockNumber, txIndex: event.txIndex, @@ -1947,7 +1961,7 @@
Troubleshooting
owner: event.owner, spender: event.spender, }; - } else if (event.type == "ApprovalForAll") { + } else if (event.type == EVENT_APPROVALFORALL) { if (!(event.owner in approvalForAllsCollator)) { approvalForAllsCollator[event.owner] = {}; } @@ -2005,7 +2019,7 @@
Troubleshooting
for (const event of records) { // console.log(now() + " INFO loadERC1155 - event: " + JSON.stringify(event)); events.push(event); - if (event.type == "TransferSingle") { + if (event.type == EVENT_TRANSFERSINGLE) { if (!(event.tokenId in tokensCollator)) { tokensCollator[event.tokenId] = {}; } @@ -2041,7 +2055,7 @@
Troubleshooting
tokensCollator[event.tokenId][event.to].logIndex = event.logIndex; tokensCollator[event.tokenId][event.to].value = ethers.BigNumber.from(tokensCollator[event.tokenId][event.to].value).add(event.value).toString(); } - } else if (event.type == "TransferBatch") { + } else if (event.type == EVENT_TRANSFERBATCH) { for (let i = 0; i < event.tokenIds.length; i++) { if (!(event.tokenIds[i] in tokensCollator)) { tokensCollator[event.tokenIds[i]] = {}; @@ -2065,7 +2079,7 @@
Troubleshooting
} } - } else if (event.type == "ApprovalForAll") { + } else if (event.type == EVENT_APPROVALFORALL) { if (!(event.owner in approvalForAllsCollator)) { approvalForAllsCollator[event.owner] = {}; } @@ -2110,7 +2124,7 @@
Troubleshooting
const tokensCollator = {}; const approvalsCollator = {}; for (const event of this.events) { - if (event.type == "Transfer") { + if (event.type == EVENT_TRANSFER) { if (!(event.from in tokensCollator)) { tokensCollator[event.from] = { blockNumber: event.blockNumber, @@ -2144,7 +2158,7 @@
Troubleshooting
tokensCollator[event.to].logIndex = event.logIndex; tokensCollator[event.to].tokens = ethers.BigNumber.from(tokensCollator[event.to].tokens).add(event.tokens).toString(); } - } else if (event.type == "Approval") { + } else if (event.type == EVENT_APPROVAL) { if (!(event.owner in approvalsCollator)) { approvalsCollator[event.owner] = {}; } @@ -2179,7 +2193,7 @@
Troubleshooting
const approvalForAllsCollator = {}; const approvalsCollator = {}; for (const event of this.events) { - if (event.type == "Transfer") { + if (event.type == EVENT_TRANSFER) { tokensCollator[event.tokenId] = { blockNumber: event.blockNumber, txIndex: event.txIndex, @@ -2187,7 +2201,7 @@
Troubleshooting
logIndex: event.logIndex, owner: event.to, }; - } else if (event.type == "Approval") { + } else if (event.type == EVENT_APPROVAL) { approvalsCollator[event.tokenId] = { blockNumber: event.blockNumber, txIndex: event.txIndex, @@ -2196,7 +2210,7 @@
Troubleshooting
owner: event.owner, spender: event.spender, }; - } else if (event.type == "ApprovalForAll") { + } else if (event.type == EVENT_APPROVALFORALL) { if (!(event.owner in approvalForAllsCollator)) { approvalForAllsCollator[event.owner] = {}; } @@ -2237,7 +2251,7 @@
Troubleshooting
const tokensCollator = {}; const approvalForAllsCollator = {}; for (const event of this.events) { - if (event.type == "TransferSingle") { + if (event.type == EVENT_TRANSFERSINGLE) { if (!(event.tokenId in tokensCollator)) { tokensCollator[event.tokenId] = {}; } @@ -2273,7 +2287,7 @@
Troubleshooting
tokensCollator[event.tokenId][event.to].logIndex = event.logIndex; tokensCollator[event.tokenId][event.to].value = ethers.BigNumber.from(tokensCollator[event.tokenId][event.to].value).add(event.value).toString(); } - } else if (event.type == "TransferBatch") { + } else if (event.type == EVENT_TRANSFERBATCH) { for (let i = 0; i < event.tokenIds.length; i++) { if (!(event.tokenIds[i] in tokensCollator)) { tokensCollator[event.tokenIds[i]] = {}; @@ -2297,7 +2311,7 @@
Troubleshooting
} } - } else if (event.type == "ApprovalForAll") { + } else if (event.type == EVENT_APPROVALFORALL) { if (!(event.owner in approvalForAllsCollator)) { approvalForAllsCollator[event.owner] = {}; } diff --git a/docs/parseEventLogs.js b/docs/parseEventLogs.js index f32ffa2..b14b1c6 100644 --- a/docs/parseEventLogs.js +++ b/docs/parseEventLogs.js @@ -1,3 +1,23 @@ +const EVENT_TRANSFER = 0; +const EVENT_TRANSFERSINGLE = 1; +const EVENT_TRANSFERBATCH = 2; +const EVENT_APPROVAL = 3; +const EVENT_APPROVALFORALL = 4; +// const EVENTTYPE = { +// TRANSFER: 0, +// TRANSFERSINGLE: 1, +// TRANSFERBATCH: 2, +// APPROVAL: 3, +// APPROVALFORALL: 4, +// }; +const EVENTNAME = [ + "Transfer", + "TransferSingle", + "TransferBatch", + "Approval", + "ApprovalForAll", +]; + function parseEventLogs(logs, contractType, chainId, latestBlockNumber) { // console.log(now() + " INFO parseEventLogs - logs: " + JSON.stringify(logs, null, 2)); const erc721Interface = new ethers.utils.Interface(ERC721ABI); @@ -29,9 +49,9 @@ function parseEventLogs(logs, contractType, chainId, latestBlockNumber) { } if (from) { if (log.topics.length == 4) { - eventRecord = { type: "Transfer", from, to, tokenId: tokensOrTokenId /*, contractType: 721*/ }; + eventRecord = { type: EVENT_TRANSFER, from, to, tokenId: tokensOrTokenId /*, contractType: 721*/ }; } else { - eventRecord = { type: "Transfer", from, to, tokens: tokensOrTokenId /*, contractType: 20*/ }; + eventRecord = { type: EVENT_TRANSFER, from, to, tokens: tokensOrTokenId /*, contractType: 20*/ }; } } } else if (log.topics[0] == "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925") { @@ -43,12 +63,12 @@ function parseEventLogs(logs, contractType, chainId, latestBlockNumber) { owner = ethers.utils.getAddress('0x' + log.topics[1].substring(26)); spender = ethers.utils.getAddress('0x' + log.topics[2].substring(26)); tokenId = ethers.BigNumber.from(log.topics[3]).toString(); - eventRecord = { type: "Approval", owner, spender, tokenId /*, contractType: 721*/ }; + eventRecord = { type: EVENT_APPROVAL, owner, spender, tokenId /*, contractType: 721*/ }; } else if (log.topics.length == 3) { owner = ethers.utils.getAddress('0x' + log.topics[1].substring(26)); spender = ethers.utils.getAddress('0x' + log.topics[2].substring(26)); tokens = ethers.BigNumber.from(log.data).toString(); - eventRecord = { type: "Approval", owner, spender, tokens /*, contractType: 20*/ }; + eventRecord = { type: EVENT_APPROVAL, owner, spender, tokens /*, contractType: 20*/ }; } } else if (log.topics[0] == "0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31") { // ERC-721 event ApprovalForAll(address indexed owner, address indexed operator, bool approved); @@ -57,19 +77,19 @@ function parseEventLogs(logs, contractType, chainId, latestBlockNumber) { const operator = ethers.utils.getAddress('0x' + log.topics[2].substring(26)); approved = ethers.BigNumber.from(log.data) > 0; // NOTE: Both erc1155 and erc721 fall in this category, but assigning all to erc721 - eventRecord = { type: "ApprovalForAll", owner, operator, approved /*, contractType: 721*/ }; + eventRecord = { type: EVENT_APPROVALFORALL, owner, operator, approved /*, contractType: 721*/ }; } else if (log.topics[0] == "0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62") { // ERC-1155 TransferSingle (index_topic_1 address operator, index_topic_2 address from, index_topic_3 address to, uint256 id, uint256 value) const logData = erc1155Interface.parseLog(log); const [operator, from, to, id, value] = logData.args; tokenId = ethers.BigNumber.from(id).toString(); - eventRecord = { type: "TransferSingle", operator, from, to, tokenId, value: value.toString() /*, contractType: 1155*/ }; + eventRecord = { type: EVENT_TRANSFERSINGLE, operator, from, to, tokenId, value: value.toString() /*, contractType: 1155*/ }; } else if (log.topics[0] == "0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb") { // ERC-1155 TransferBatch (index_topic_1 address operator, index_topic_2 address from, index_topic_3 address to, uint256[] ids, uint256[] values) const logData = erc1155Interface.parseLog(log); const [operator, from, to, ids, values] = logData.args; const tokenIds = ids.map(e => ethers.BigNumber.from(e).toString()); - eventRecord = { type: "TransferBatch", operator, from, to, tokenIds, values: values.map(e => e.toString()) /*, contractType: 1155*/ }; + eventRecord = { type: EVENT_TRANSFERBATCH, operator, from, to, tokenIds, values: values.map(e => e.toString()) /*, contractType: 1155*/ }; } if (eventRecord) { records.push( {