forked from Drago-Labs/golden-raccoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_memory.py
More file actions
33 lines (27 loc) · 1.28 KB
/
Copy pathpatch_memory.py
File metadata and controls
33 lines (27 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import re
with open('frontend/src/server/storage/adapters/memory.ts', 'r') as f:
content = f.read()
# Add WatchlistEntry to import
content = content.replace('X402PaymentReceipt,\n StorageHealth,', 'X402PaymentReceipt,\n StorageHealth,\n WatchlistEntry,')
memory_vars = """
__goldenRaccoonWatchlistEntries?: WatchlistEntry[];
"""
content = content.replace('__goldenRaccoonX402PaymentReceipts?: X402PaymentReceipt[];', '__goldenRaccoonX402PaymentReceipts?: X402PaymentReceipt[];' + memory_vars)
methods = """
async addWatchlistEntriesBulk(entries: WatchlistEntry[]): Promise<{ added: WatchlistEntry[] }> {
memoryStore.__goldenRaccoonWatchlistEntries ??= [];
const store = memoryStore.__goldenRaccoonWatchlistEntries;
const added: WatchlistEntry[] = [];
for (const entry of entries) {
const existing = store.find(e => e.walletAddress === entry.walletAddress && e.identityKey === entry.identityKey);
if (!existing) {
store.unshift(entry);
added.push(entry);
}
}
return { added };
}
"""
content = content.replace('async performHealthProbe(): Promise<HealthProbeResult> {', methods + '\n async performHealthProbe(): Promise<HealthProbeResult> {')
with open('frontend/src/server/storage/adapters/memory.ts', 'w') as f:
f.write(content)