event-log-harvester
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,20 +0,20 @@ | ||
async function F(i, t, r, s, c) { | ||
async function F(i, r, t, s, c) { | ||
const d = {}; | ||
let o = /* @__PURE__ */ new Set(); | ||
const e = /* @__PURE__ */ new Set(); | ||
let e = /* @__PURE__ */ new Set(); | ||
const o = /* @__PURE__ */ new Set(); | ||
let k = !1; | ||
for (const f in t) | ||
d[f] = [], t[f].forEach((h) => { | ||
!h.addresses || h.addresses.length === 0 ? k = !0 : h.addresses.forEach((n) => o.add(n)), h.topics.forEach((n) => e.add(n)); | ||
for (const f in r) | ||
d[f] = [], r[f].forEach((h) => { | ||
!h.addresses || h.addresses.length === 0 ? k = !0 : h.addresses.forEach((n) => e.add(n)), h.topics.forEach((n) => o.add(n)); | ||
}); | ||
k && (o = void 0); | ||
k && (e = void 0); | ||
const a = (await i({ | ||
fromBlock: r, | ||
fromBlock: t, | ||
toBlock: s, | ||
addresses: o ? Array.from(o) : void 0, | ||
topics: e.size > 0 ? Array.from(e) : void 0 | ||
addresses: e ? Array.from(e) : void 0, | ||
topics: o.size > 0 ? Array.from(o) : void 0 | ||
})).map(async (f) => { | ||
for (const m in t) | ||
for (const m in r) | ||
await E( | ||
t, | ||
r, | ||
m, | ||
@@ -28,17 +28,17 @@ f, | ||
} | ||
async function E(i, t, r, s, c) { | ||
const o = i[t].find( | ||
(e) => (!e.addresses || e.addresses.length === 0 || e.addresses.includes(r.address)) && e.topics[0] === r.topics[0] && r.blockNumber >= e.fromBlock && r.blockNumber <= e.toBlock | ||
async function E(i, r, t, s, c) { | ||
const e = i[r].find( | ||
(o) => (!o.addresses || o.addresses.length === 0 || o.addresses.includes(t.address)) && o.topics[0] === t.topics[0] && t.blockNumber >= o.fromBlock && t.blockNumber <= o.toBlock | ||
); | ||
if (o) | ||
if (e) | ||
try { | ||
r.data = r.data === "0x" ? "0x0000000000000000000000000000000000000000000000000000000000000000" : r.data; | ||
const e = await o.decodeLog(r); | ||
s[t] || (s[t] = []), s[t].push(e); | ||
} catch (e) { | ||
t.data = t.data === "0x" ? "0x0000000000000000000000000000000000000000000000000000000000000000" : t.data; | ||
const o = await e.decodeLog(t); | ||
s[r] || (s[r] = []), s[r].push(o); | ||
} catch (o) { | ||
if (console.error( | ||
`Error decoding log for key ${t.toString()}:`, | ||
e, | ||
r, | ||
o | ||
`Error decoding log for key ${r.toString()}:`, | ||
o, | ||
t, | ||
e | ||
), c) | ||
@@ -48,27 +48,27 @@ throw new Error("Decoding error occurred"); | ||
} | ||
async function A(i, t, r, s, c, d) { | ||
let o = 0; | ||
for (; c === -1 || o < c; ) | ||
async function A(i, r, t, s, c, d) { | ||
let e = 0; | ||
for (; c === -1 || e < c; ) | ||
try { | ||
return await F( | ||
i, | ||
r, | ||
t, | ||
r, | ||
s, | ||
d | ||
); | ||
} catch (e) { | ||
if (o += 1, console.error(`Attempt ${o} failed: ${e.message}`), c !== -1 && o >= c) | ||
} catch (o) { | ||
if (e += 1, console.error(`Attempt ${e} failed: ${o.message}`), c !== -1 && e >= c) | ||
throw new Error(`Failed to fetch logs after ${c} retries`); | ||
await new Promise((k) => setTimeout(k, 1e3 * o)); | ||
await new Promise((k) => setTimeout(k, 1e3 * e)); | ||
} | ||
throw new Error("Failed to fetch logs"); | ||
} | ||
function L(i, t, r) { | ||
function L(i, r, t) { | ||
const s = {}; | ||
for (const c in i) { | ||
const o = i[c].filter( | ||
(e) => e.fromBlock <= r && e.toBlock >= t | ||
const e = i[c].filter( | ||
(o) => o.fromBlock <= t && o.toBlock >= r | ||
); | ||
o.length > 0 && (s[c] = o); | ||
e.length > 0 && (s[c] = e); | ||
} | ||
@@ -79,9 +79,9 @@ return s; | ||
const { | ||
batchSize: t = 1e3, | ||
maxRetries: r = 0, | ||
batchSize: r = 1e3, | ||
maxRetries: t = 0, | ||
eventFilters: s, | ||
getLogs: c, | ||
failOnDecodeError: d = !1, | ||
failOnCallbackError: o = !1 | ||
} = i, e = {}, k = Math.min( | ||
failOnCallbackError: e = !1 | ||
} = i, o = {}, k = Math.min( | ||
...Object.values(s).flat().map((a) => a.fromBlock) | ||
@@ -91,4 +91,4 @@ ), b = Math.max( | ||
); | ||
for (let a = k; a <= b; a += t) { | ||
const f = Math.min(a + t - 1, b), m = L( | ||
for (let a = k; a <= b; a += r) { | ||
const f = Math.min(a + r - 1, b), m = L( | ||
s, | ||
@@ -104,31 +104,30 @@ a, | ||
f, | ||
r, | ||
t, | ||
d | ||
); | ||
for (const n in h) { | ||
e[n] || (e[n] = []); | ||
o[n] || (o[n] = []); | ||
const w = h[n]; | ||
e[n].push(...w); | ||
const y = m[n].map((l) => { | ||
o[n].push(...w); | ||
const p = m[n].map((l) => { | ||
if (l.callback) { | ||
const p = w.filter((u) => { | ||
const y = w.filter((u) => { | ||
const g = !l.addresses || l.addresses.includes(u.address), v = l.topics[0] === u.topics[0], B = u.blockNumber >= l.fromBlock && u.blockNumber <= l.toBlock; | ||
return g && v && B; | ||
}); | ||
if (p.length > 0) | ||
try { | ||
return l.callback(p, { | ||
startBlock: a, | ||
endBlock: f | ||
}); | ||
} catch (u) { | ||
if (console.error(`Error in callback for filter ${n}:`, u), o) | ||
throw u; | ||
} | ||
try { | ||
return l.callback(y, { | ||
startBlock: a, | ||
endBlock: f | ||
}); | ||
} catch (u) { | ||
if (console.error(`Error in callback for filter ${n}:`, u), e) | ||
throw u; | ||
} | ||
} | ||
}); | ||
try { | ||
await Promise.all(y); | ||
await Promise.all(p); | ||
} catch (l) { | ||
if (console.error(`Error in callback for filter ${n}:`, l), o) | ||
if (console.error(`Error in callback for filter ${n}:`, l), e) | ||
throw l; | ||
@@ -139,3 +138,3 @@ } | ||
} | ||
return e; | ||
return o; | ||
} | ||
@@ -142,0 +141,0 @@ export { |
{ | ||
"name": "event-log-harvester", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13911
218