|
1 | | -// import { TypeormDatabase } from "@subsquid/typeorm-store"; |
2 | | -// import { Inscription } from "./model"; |
3 | | -// import { processor } from "./processor"; |
4 | | -import assert from "assert"; |
5 | 1 | import { Inscription } from "../types"; |
6 | 2 | import { isValidDataUri, hexToUTF8 } from "./utils"; |
7 | 3 | import { EthereumTransaction } from "@subql/types-ethereum"; |
8 | 4 |
|
9 | 5 | export async function handleTransaction( |
10 | 6 | tx: EthereumTransaction |
11 | 7 | ): Promise<void> { |
12 | | - logger.warn(tx.hash); |
13 | | - const knownInscriptionsArray: Inscription[] | undefined = |
14 | | - await Inscription.getByIsEsip6(false); |
15 | | - assert(knownInscriptionsArray); |
16 | | - const knownInscriptions: Map<string, Inscription> = new Map( |
17 | | - knownInscriptionsArray.map((c) => [c.data, c]) |
18 | | - ); |
19 | | - const newUniqueInscriptions: Map<string, Inscription> = new Map(); |
20 | | - const inscriptions: Inscription[] = []; |
21 | 8 | if (tx.to) { |
22 | | - //is unique or has rule=esip6 |
23 | | - |
| 9 | + if (!tx.input) { |
| 10 | + return; |
| 11 | + } |
| 12 | + let inscription: Inscription; |
24 | 13 | const decodedData = hexToUTF8(tx.input); |
25 | | - //console.log(decodedData); |
26 | 14 | if (isValidDataUri(decodedData)) { |
27 | | - if (decodedData.includes("rule=esip6")) { |
28 | | - inscriptions.push( |
29 | | - Inscription.create({ |
30 | | - id: tx.hash, |
31 | | - data: decodedData, |
32 | | - block: tx.blockNumber, |
33 | | - creator: tx.from, |
34 | | - isEsip6: true, |
35 | | - }) |
36 | | - ); |
37 | | - } else if ( |
38 | | - !knownInscriptions.has(decodedData) && |
39 | | - !newUniqueInscriptions.has(decodedData) |
40 | | - ) { |
41 | | - //console.log("new"); |
42 | | - newUniqueInscriptions.set( |
43 | | - decodedData, |
44 | | - Inscription.create({ |
45 | | - id: tx.hash, |
46 | | - data: decodedData, |
47 | | - block: tx.blockNumber, |
48 | | - creator: tx.from, |
49 | | - isEsip6: false, |
50 | | - }) |
51 | | - ); |
52 | | - } |
53 | | - //checkuniquesness |
| 15 | + inscription = Inscription.create({ |
| 16 | + id: tx.hash, |
| 17 | + data: decodedData, |
| 18 | + block: tx.blockNumber, |
| 19 | + creator: tx.from, |
| 20 | + }); |
| 21 | + inscription.save(); |
54 | 22 | } |
55 | 23 | } |
56 | | - inscriptions.map(async (inscription) => await inscription.save()); |
57 | | - if (newUniqueInscriptions.size > 0) { |
58 | | - newUniqueInscriptions.forEach(async (value, key) => { |
59 | | - await value.save(); |
60 | | - }); |
61 | | - } |
62 | 24 | } |
0 commit comments