-
Notifications
You must be signed in to change notification settings - Fork 0
/
filler.py
executable file
·2247 lines (1944 loc) · 83.9 KB
/
filler.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import datetime
import itertools
import logging
import os
import re
import time
import _thread
from flask import Flask, json, request
from oto.adaptors.flask import flaskify
from oto import response as oto_response
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.exc import SQLAlchemyError
import funcs
from app_runner import run_loader
from config import PostgresFillerConfig
from flask_executor import Executor
import requests
import random
app = Flask(__name__)
app.config.from_object(PostgresFillerConfig if os.getenv('env') != 'dev' else PostgresFillerConfig)
db = SQLAlchemy(app, session_options={'autocommit': False})
db_auto = SQLAlchemy(app, session_options={'autocommit': True})
executor = Executor(app)
isLoading = False
isLoadingChronicleTx = False
isLoadingUSD = False
isVacuuming = False
isUpdatingAtomicAssets = False
isUpdatingAssetsData = False
isLoadingPFPAttributes = False
isUpdatingRWAXAssets = False
isUpdatingRecentlySold = False
isUpdatingFloorPrices = False
isUpdatingTemplateStats = False
isUpdatingBigVolumes = False
isUpdatingSmallVolumes = False
isUpdatingDrops = False
isUpdatingCollectionUserStats = False
isUpdatingSmallViews = False
action_measure_god = {
'total_time': 0,
'total_count': 0,
'commit_time': 0,
'update_last_time': 0,
'update_time': 0,
'parse_time': 0,
'transaction_time': 0
}
isStopped = True
isForked = True
last_wax_stash_sync = 0
hyperions = [
{
'url': 'https://wax.hivebp.io',
'status': 200,
'blocks_behind': 0,
'limit': 1000,
}
]
apis = [
{
'url': 'https://api.hivebp.io',
'status': 200,
'blocks_behind': 0,
'limit': 1000,
},
{
'url': 'https://api2.hivebp.io',
'status': 200,
'blocks_behind': 0,
'limit': 1000,
},
{
'url': 'https://api3.hivebp.io',
'status': 200,
'blocks_behind': 0,
'limit': 1000,
}
]
def log_error(err):
funcs.log_error(err)
def create_session():
return db.session
def get_hyperions():
global hyperions
urls = []
for hyperion in hyperions:
urls.append(hyperion['url'])
random.shuffle(urls)
return urls
def get_url(pos):
urls = get_hyperions()
url = urls[pos]
return url
def load_wax_usd_rate(session, action):
try:
median = action['median']
timestamp = datetime.datetime.strptime(re.sub(r'\.\d+Z', 'Z', action['timestamp']),
'%Y-%m-%dT%H:%M:%S.%f')
usd = float(median)/10000.0
session.execute('INSERT INTO usd_prices VALUES (:timestamp, :usd)', {
'timestamp': timestamp, 'usd': usd
})
except SQLAlchemyError as e:
log_error('load_wax_usd_rate: {}'.format(e))
raise e
except Exception as err:
log_error('load_wax_usd_rate: {}'.format(err))
raise err
@app.route('/loader/vacuum')
def vacuum():
global isVacuuming
if isVacuuming:
return flaskify(oto_response.Response('Already processing request', status=102))
isVacuuming = True
session = create_session()
total_start_time = time.time()
try:
session.connection().connection.set_isolation_level(0)
start_time = time.time()
session.execute('VACUUM listing_prices_new_mv')
end_time = time.time()
print('VACUUM VIEW 1: {}'.format(end_time - start_time))
start_time = time.time()
session.execute('VACUUM cheapest_new_mv')
end_time = time.time()
print('VACUUM VIEW 2: {}'.format(end_time - start_time))
start_time = time.time()
session.execute('VACUUM collection_users_mw')
end_time = time.time()
print('VACUUM VIEW 5: {}'.format(end_time - start_time))
start_time = time.time()
session.execute('VACUUM users_mv')
end_time = time.time()
print('VACUUM VIEW 6: {}'.format(end_time - start_time))
start_time = time.time()
session.execute('VACUUM price_limits_mv')
end_time = time.time()
print('VACUUM VIEW 7: {}'.format(end_time - start_time))
session.connection().connection.set_isolation_level(1)
except SQLAlchemyError as err:
session.rollback()
log_error('refresh_cheapest: {}'.format(err))
except Exception as err:
log_error('refresh_cheapest: {}'.format(err))
finally:
isVacuuming = False
session.remove()
total_end_time = time.time()
return flaskify(oto_response.Response('Refreshed Cheapest {}'.format(total_end_time - total_start_time)))
@app.route('/loader/reboot-database')
def reboot_database():
return "Dangerous, enable only when you intend to erase all data and reset the tables"
start_time = time.time()
session = create_session()
try:
block_num_tables = session.execute(
'SELECT t1.table_name '
'FROM tables_with_block_num t1 '
)
for tables in block_num_tables:
print(
'TRUNCATE {table_name}'.format(
table_name=tables['table_name']
)
)
session.execute(
'TRUNCATE {table_name}'.format(
table_name=tables['table_name']
)
)
session.execute(
'TRUNCATE transfers'
)
session.execute(
'TRUNCATE simpleassets_offers'
)
session.execute(
'TRUNCATE simpleassets_updates'
)
session.execute(
'TRUNCATE simpleassets_burns'
)
session.execute(
'TRUNCATE collections'
)
session.execute(
'TRUNCATE schemas'
)
session.execute(
'TRUNCATE templates'
)
session.execute(
'TRUNCATE assets'
)
session.execute(
'TRUNCATE attributes'
)
session.execute(
'ALTER SEQUENCE attributes_attribute_id_seq RESTART WITH 1'
)
session.execute(
'TRUNCATE data'
)
session.execute(
'ALTER SEQUENCE data_data_id_seq RESTART WITH 1'
)
session.execute(
'TRUNCATE images'
)
session.execute(
'ALTER SEQUENCE listings_sale_id_seq RESTART WITH 1'
)
session.execute(
'ALTER SEQUENCE images_image_id_seq RESTART WITH 1'
)
session.execute(
'TRUNCATE videos'
)
session.execute(
'ALTER SEQUENCE videos_video_id_seq RESTART WITH 1'
)
session.execute(
'TRUNCATE names'
)
session.execute(
'ALTER SEQUENCE names_name_id_seq RESTART WITH 1'
)
session.execute(
'TRUNCATE transactions'
)
session.execute(
'ALTER SEQUENCE transactions_id_seq RESTART WITH 1'
)
session.execute(
'INSERT INTO handle_fork VALUES (false, 0)'
)
session.commit()
except SQLAlchemyError as err:
log_error('insert_atomic_template {}'.format(err))
session.rollback()
except Exception as err:
raise err
end_time = time.time()
return flaskify(oto_response.Response({'total_time': end_time - start_time}))
def verify_account(session, account):
session.execute(
'UPDATE collections SET verified = TRUE WHERE collection = :collection', {'collection': account}
)
def verify_accounts(session, accounts):
res = session.execute('SELECT distinct collection FROM collections WHERE verified')
already_verified = []
for collection in res:
already_verified.append(collection['collection'])
to_verify = [i for i in accounts if i not in already_verified]
for account in to_verify:
if account not in already_verified:
verify_account(session, account)
def unverify_account(session, account):
session.execute(
'UPDATE collections SET verified = FALSE WHERE collection = :collection', {'collection': account}
)
def unverify_accounts(session, accounts):
res = session.execute('SELECT distinct collection FROM collections WHERE NOT verified')
already_unverified = []
for collection in res:
already_unverified.append(collection['collection'])
to_unverify = [i for i in accounts if i not in already_unverified]
for account in to_unverify:
if account not in already_unverified:
unverify_account(session, account)
def blacklist_account(session, account):
session.execute('INSERT INTO blacklisted_collections VALUES (:collection)', {'collection': account})
session.execute('UPDATE collections SET blacklisted = TRUE WHERE collection = :collection', {'collection': account})
def blacklist_accounts(session, accounts):
res = session.execute('SELECT distinct collection FROM blacklisted_collections')
already_blacklisted = []
for collection in res:
already_blacklisted.append(collection['collection'])
for account in accounts:
if account not in already_blacklisted:
blacklist_account(session, account)
session.commit()
def unblacklist_account(session, account):
session.execute('DELETE FROM blacklisted_collections WHERE collection = :collection', {'collection': account})
session.execute(
'UPDATE collections SET blacklisted = FALSE WHERE collection = :collection', {'collection': account}
)
def all_combinations(array):
# Convert each row of the 2D array into a list, if not already
rows = [row for row in array]
# Use itertools.product to generate all possible combinations
# *rows unpacks the list of rows into separate arguments for product
return list(itertools.product(*rows))
@app.route('/loader/add-sets')
def add_sets():
attribute_names = request.args.get('attribute_names', '')
collection = request.args.get('collection', '')
schema = request.args.get('schema', '')
use_name = request.args.get('use_name', 'false') == 'true'
session = create_session()
attribute_ids = []
for attribute_name in attribute_names.split(','):
res = session.execute(
'SELECT attribute_id '
'FROM attributes '
'WHERE collection = :collection '
'AND schema = :schema '
'AND attribute_name = :attribute_name ',
{'collection': collection, 'schema': schema, 'attribute_name': attribute_name}
)
ids = []
for attribute in res:
ids.append(int(attribute['attribute_id']))
attribute_ids.append(ids)
combinations = all_combinations(attribute_ids)
cnt = 0
if use_name:
names = session.execute(
'SELECT DISTINCT name_id FROM assets WHERE collection = :collection AND schema = :schema',
{'collection': collection, 'schema': schema}
)
for name in names:
for combination in combinations:
res = session.execute(
'INSERT INTO sets '
'SELECT :collection, :schema, :attribute_ids, NULL, :name_id '
'WHERE EXISTS ('
' SELECT asset_id FROM assets WHERE collection = :collection AND schema = :schema '
' AND name_id = :name_id AND :attribute_ids <@ attribute_ids'
') AND NOT EXISTS ('
' SELECT set_id '
' FROM sets '
' WHERE attribute_ids = :attribute_ids '
' AND name_id = :name_id '
' AND collection = :collection '
' AND schema = :schema'
')',
{
'collection': collection,
'schema': schema,
'attribute_ids': list(combination),
'name_id': name['name_id']
}
)
cnt += res.rowcount
session.commit()
else:
for combination in combinations:
res = session.execute(
'INSERT INTO sets '
'SELECT :collection, :schema, :attribute_ids '
'WHERE EXISTS ('
' SELECT asset_id '
' FROM assets '
' WHERE collection = :collection '
' AND schema = :schema '
' AND :attribute_ids <@ attribute_ids'
') AND NOT EXISTS ('
' SELECT set_id '
' FROM sets '
' WHERE attribute_ids = :attribute_ids '
' AND name_id IS NULL '
' AND collection = :collection '
' AND schema = :schema'
')',
{'collection': collection, 'schema': schema, 'attribute_ids': list(combination)}
)
cnt += res.rowcount
session.commit()
return flaskify(oto_response.Response('Added {} Sets'.format(cnt)))
@app.route('/loader/update-rwax-assets')
def update_rwax_assets():
global isUpdatingRWAXAssets
if isUpdatingRWAXAssets:
return flaskify(oto_response.Response('Already processing request', status=102))
isUpdatingRWAXAssets = True
session = create_session()
try:
session.execute(
'INSERT INTO rwax_assets '
'SELECT asset_id, collection, schema, template_id '
'FROM rwax_templates '
'LEFT JOIN assets a USING (collection, template_id) '
'WHERE NOT EXISTS ('
' SELECT asset_id FROM rwax_assets WHERE asset_id = a.asset_id'
')'
)
session.execute(
'DELETE FROM rwax_assets '
'WHERE asset_id IN (SELECT asset_id FROM rwax_assets ra LEFT JOIN assets a USING (asset_id) '
'WHERE a.template_id NOT IN (SELECT template_id FROM rwax_templates WHERE template_id = a.template_id))'
)
session.commit()
return flaskify(oto_response.Response('Updated RWAX Assets'))
except SQLAlchemyError as err:
log_error('update_rwax_assets: {}'.format(err))
session.rollback()
return flaskify(oto_response.Response('An unexpected Error occured', errors=err, status=500))
except Exception as err:
log_error('update_rwax_assets: {}'.format(err))
return flaskify(oto_response.Response('An unexpected Error occured', errors=err, status=500))
finally:
session.remove()
isUpdatingRWAXAssets = False
@app.route('/loader/update-pfp-attributes')
def update_pfp_attributes():
global isLoadingPFPAttributes
if isLoadingPFPAttributes:
return flaskify(oto_response.Response('Already processing request', status=102))
isLoadingPFPAttributes = True
session = create_session()
try:
session.commit()
session.execute(
'INSERT INTO pfp_templates '
'SELECT collection, schema, template_id '
'FROM ('
' SELECT unnest(templates_to_mint) AS template_id '
' FROM drops WHERE (drop_id, contract) IN (SELECT drop_id, contract FROM pfp_drop_data )'
') a '
'INNER JOIN templates t USING (template_id) '
'WHERE NOT EXISTS ('
' SELECT collection, schema, template_id FROM pfp_templates '
' WHERE collection = t.collection AND schema = t.schema AND template_id = t.template_id '
') '
'GROUP BY 1, 2, 3'
)
session.commit()
session.execute(
'INSERT INTO pfp_schemas '
'SELECT collection, schema '
'FROM pfp_templates '
'WHERE (collection, schema) NOT IN (SELECT collection, schema FROM pfp_schemas)'
)
session.commit()
session.execute(
'INSERT INTO pfp_assets '
'SELECT a.asset_id, a.collection, a.schema, a.template_id, array_agg(attribute_id) '
'FROM ('
' SELECT asset_id, t.collection, t.schema, template_id, a.attribute_ids '
' FROM templates t '
' INNER JOIN assets a USING(template_id) '
' WHERE (t.collection, t.schema) IN (SELECT collection, schema FROM pfp_schemas) '
' AND NOT EXISTS (SELECT asset_id FROM pfp_assets WHERE asset_id = a.asset_id)) a '
'LEFT JOIN attributes att ON att.attribute_id = ANY(a.attribute_ids) '
'WHERE NOT EXISTS ('
' SELECT attribute_name FROM pfp_attribute_blacklist WHERE attribute_name = att.attribute_name'
') GROUP BY 1, 2, 3, 4 '
)
session.commit()
collections = session.execute('SELECT DISTINCT collection FROM pfp_schemas')
for collection in collections:
session.execute(
'UPDATE pfp_assets a SET num_traits = ('
' SELECT COUNT(attribute_id) '
' FROM ('
' SELECT attribute_id '
' FROM pfp_assets '
' LEFT JOIN attributes ON attribute_id = ANY(attribute_ids) '
' WHERE attribute_name != \'num_traits\' AND string_value NOT IN (\'none\', \'None\') '
' AND asset_id = a.asset_id'
' ) a'
') '
'WHERE num_traits IS NULL AND attribute_ids IS NOT NULL AND a.collection = :collection ',
{'collection': collection['collection']}
)
session.execute(
'DELETE FROM pfp_assets WHERE asset_id IN ('
' SELECT asset_id '
' FROM pfp_assets p '
' INNER JOIN assets a USING(asset_id) '
' WHERE p.collection = :collection '
' AND (a.collection, a.schema) NOT IN ('
' SELECT collection, schema FROM pfp_schemas'
' )'
')', {'collection': collection['collection']}
)
session.commit()
session.execute(
'INSERT INTO attribute_stats '
'SELECT collection, schema, attribute_id '
'FROM attributes a '
'WHERE EXISTS ('
' SELECT collection, schema '
' FROM pfp_schemas '
' WHERE collection = a.collection '
' AND schema = a.schema'
') '
'AND EXISTS ('
' SELECT asset_id '
' FROM pfp_assets '
' WHERE collection = a.collection AND schema = a.schema '
' AND attribute_id = ANY(attribute_ids) '
')'
'AND NOT EXISTS (SELECT attribute_id FROM attribute_stats WHERE attribute_id = a.attribute_id)'
)
session.commit()
session.execute(
'WITH attribute_totals AS ('
' SELECT attribute_id, COUNT(1) AS total '
' FROM attributes '
' LEFT JOIN pfp_assets aa ON attribute_id = ANY(attribute_ids) '
' LEFT JOIN assets a USING(asset_id) '
' WHERE NOT burned GROUP BY 1'
') '
'UPDATE attribute_stats atu SET total = att.total FROM attribute_totals att WHERE att.attribute_id = '
'atu.attribute_id '
)
session.execute(
'WITH template_totals AS ('
' SELECT a.collection, a.schema, COUNT(1) AS total_schema '
' FROM pfp_assets a '
' LEFT JOIN assets USING(asset_id) '
' WHERE NOT burned GROUP BY 1, 2'
') '
'UPDATE attribute_stats asu SET total_schema = tt.total_schema '
'FROM template_totals tt WHERE asu.collection = tt.collection AND asu.schema = tt.schema '
)
session.execute(
'UPDATE attribute_stats SET rarity_score = 1 / (total / CAST(total_schema AS float)) '
'WHERE total IS NOT NULL AND total_schema > 0'
)
session.commit()
collections = session.execute(
'SELECT DISTINCT collection FROM pfp_schemas'
)
session.remove()
session = create_session()
for collection in collections:
session.execute(
'UPDATE pfp_assets aa SET rarity_score = asu.rarity_score FROM ('
' SELECT aa.asset_id, SUM(asu.rarity_score) AS rarity_score '
' FROM attribute_stats asu '
' LEFT JOIN pfp_assets aa ON asu.attribute_id = ANY(attribute_ids) '
' AND asu.collection = aa.collection '
' AND asu.schema = aa.schema '
' INNER JOIN assets a USING (asset_id) '
' WHERE asu.collection = :collection AND NOT burned '
' GROUP BY 1'
') asu WHERE asu.asset_id = aa.asset_id ', {'collection': collection['collection']}
)
session.execute(
'UPDATE pfp_assets asu SET rank = NULL, rarity_score = NULL '
'FROM assets a '
'WHERE asu.asset_id = a.asset_id AND a.burned AND rank IS NOT NULL AND rarity_score IS NOT NULL '
'AND asu.collection = :collection', {'collection': collection['collection']}
)
session.execute(
'UPDATE pfp_assets asu SET rank = ats.rank FROM ('
' SELECT asset_id, '
' RANK() OVER(PARTITION BY asu.collection, asu.schema ORDER BY rarity_score DESC NULLS LAST) AS rank,'
' burned FROM pfp_assets asu INNER JOIN assets USING (asset_id) '
' WHERE NOT burned AND asu.collection = :collection'
') ats '
'WHERE ats.asset_id = asu.asset_id AND NOT ats.burned', {'collection': collection['collection']}
)
session.execute(
'UPDATE attribute_stats atu SET floor_wax = tp.floor_wax '
'FROM attribute_floors_mv tp '
'WHERE tp.attribute_id = atu.attribute_id AND collection = :collection',
{'collection': collection['collection']}
)
session.commit()
return flaskify(oto_response.Response('Updated PFP Attributes'))
except SQLAlchemyError as err:
log_error('load_pfp_attributes: {}'.format(err))
session.rollback()
return flaskify(oto_response.Response('An unexpected Error occured', errors=err, status=500))
except Exception as err:
log_error('load_pfp_attributes: {}'.format(err))
return flaskify(oto_response.Response('An unexpected Error occured', errors=err, status=500))
finally:
session.remove()
isLoadingPFPAttributes = False
@app.route('/loader/sync-new-collection-verifications')
def sync_new_collection_verifications():
url = 'https://config.api.atomichub.io/v1/atomichub-config?chains=wax-mainnet'
response = requests.request("GET", url)
if response.status_code != 200:
log_error('sync_new_collection_verifications {}: {}'.format(response.status_code, response.content))
return flaskify(oto_response.Response(
'An unexpected Error occured', errors=response.content, status=response.status_code))
collections = json.loads(response.content)
whitelist = []
blacklist = []
verified = []
unverified = []
nsfw = []
badges = {}
for collection in collections['data']['collections']:
if collection['state'] == 'whitelisted':
whitelist.append(collection['id'])
elif collection['state'] == 'verified':
verified.append(collection['id'])
elif collection['state'] == 'blacklisted':
blacklist.append(collection['id'])
elif collection['state'] == 'no_status':
unverified.append(collection['id'])
if 'flags' in collection and collection['flags'] and 'nsfw' in collection['flags']:
nsfw.append(collection['id'])
if 'badges' in collection:
for badge in collection['badges']:
if collection['id'] not in badges:
badges[collection['id']] = {}
badges[collection['id']][badge['name']] = badge
session = create_session()
old_badges = session.execute( 'SELECT * FROM badges')
for old_badge in old_badges:
if old_badge['collection'] not in badges:
session.execute(
'DELETE FROM badges WHERE collection = :collection',
{'collection': old_badge['collection']}
)
elif old_badge['name'] not in badges[old_badge['collection']]:
session.execute(
'DELETE FROM badges WHERE collection = :collection AND name = :name',
{'collection': old_badge['collection'], 'name': old_badge['name']}
)
else:
badges[old_badge['collection']][old_badge['name']]['update'] = True
for collection in badges:
for name in badges[collection]:
badge = badges[collection][name]
if 'update' in badge:
session.execute(
'UPDATE badges SET value = :value, level = :level, timestamp = :timestamp '
'WHERE collection = :collection AND name = :name',
{
'value': badge['value'],
'level': badge['level'],
'timestamp': datetime.datetime.fromtimestamp(int(badge['created_at']) / 1000),
'name': badge['name'],
'collection': collection
}
)
else:
session.execute(
'INSERT INTO badges SELECT :collection, :name, :level, :value, :timestamp '
'WHERE NOT EXISTS ('
' SELECT collection, name FROM badges WHERE collection = :collection AND name = :name'
')', {
'value': badge['value'],
'level': badge['level'],
'timestamp': datetime.datetime.fromtimestamp(int(badge['created_at']) / 1000),
'name': badge['name'],
'collection': collection
}
)
blacklisted_collections = session.execute('SELECT distinct collection FROM blacklisted_collections')
whitelist_overwrite = session.execute('SELECT collection FROM whitelist_overwrite')
for collection in whitelist_overwrite:
if collection['collection'] in unverified:
unverified.remove(collection['collection'])
unverify_overwrite = session.execute(
'SELECT collection FROM unverify_overwrite'
)
for collection in unverify_overwrite:
if collection['collection'] in verified:
verified.remove(collection['collection'])
unblacklist = []
for collection in blacklisted_collections:
if collection['collection'] not in blacklist:
unblacklist.append(collection['collection'])
blacklist_overwrite = session.execute(
'SELECT collection FROM blacklist_overwrite'
)
for collection in blacklist_overwrite:
if collection['collection'] in unblacklist:
unblacklist.remove(collection['collection'])
verify_accounts(session, verified)
verify_accounts(session, whitelist)
unverify_accounts(session, unverified)
blacklist_accounts(session, blacklist)
for collection in unblacklist:
unblacklist_account(session, collection)
session.commit()
session.remove()
return flaskify(oto_response.Response('Collections Synced'))
def parse_action(session, action):
global action_measure_god
act = action['act'] if action and 'act' in action.keys() else None
name = act['name'] if act and 'name' in act.keys() else None
account = act['account'] if act and 'account' in act.keys() else None
if account not in action_measure_god:
action_measure_god[account] = {}
start_time = time.time()
try:
if account in ['atomicdropsx', 'neftyblocksd', 'nfthivedrops', 'twitchreward']:
if name == 'lognewdrop':
funcs.load_drop(session, action, account)
elif name == 'setdropdata':
funcs.load_drop_update(session, action, account)
elif name == 'setdroplimit':
funcs.load_drop_limit_update(session, action, account)
elif name == 'setdropmax':
funcs.load_drop_max_update(session, action, account)
elif name == 'setdropprice':
funcs.load_drop_price_update(session, action, account)
elif name == 'setdprices':
funcs.load_drop_prices_update(session, action, account)
elif name == 'setfeerate':
funcs.load_drop_fee_rate(session, action, account)
elif name == 'setdropauth':
funcs.load_drop_drop_auth(session, action, account)
elif name == 'setdrophiddn':
funcs.load_drop_hidden(session, action, account)
elif name == 'setdroptimes':
funcs.load_drop_times_update(session, action, account)
elif name == 'claimdrop' or name == 'claimdropkey' or name == 'claimdropwl' or name == 'claimwproof':
funcs.load_claim_drop(session, action, account)
elif name == 'erasedrop':
funcs.load_erase_drop(session, action, account)
elif name == 'addconftoken' and account == 'nfthivedrops':
funcs.load_addconftoken(session, action)
elif name == 'remconftoken' and account == 'nfthivedrops':
funcs.load_remconftoken(session, action)
elif name == 'addpfpresult' and account == 'nfthivedrops':
funcs.add_pfp_result(session, action)
elif name == 'lognewpfp':
funcs.load_drop(session, action, account)
elif name == 'setpfpdata':
funcs.load_drop_update(session, action, account)
elif name == 'setpfplimit':
funcs.load_drop_limit_update(session, action, account)
elif name == 'setpfpmax':
funcs.load_drop_max_update(session, action, account)
elif name == 'setpfpprice':
funcs.load_drop_prices_update(session, action, account)
elif name == 'setpfpprices':
funcs.load_drop_prices_update(session, action, account)
elif name == 'setpfpfee':
funcs.load_drop_fee_rate(session, action, account)
elif name == 'setpfpauth':
funcs.load_drop_drop_auth(session, action, account)
elif name == 'setdroptimes':
funcs.load_drop_times_update(session, action, account)
elif name == 'setdroptimes':
funcs.load_drop_times_update(session, action, account)
elif name == 'claimpfpdrop' or name == 'claimpfpwl' or name == 'claimpfproof':
funcs.load_claim_drop(session, action, account)
elif name == 'erasepfp':
funcs.load_erase_drop(session, action, account)
elif name == 'addreward':
funcs.load_add_reward(session, action)
elif name == 'mintpfp':
funcs.load_mint_pfp(session, action)
elif name == 'swappfp':
funcs.add_swap_pfp(session, action)
elif name == 'remintpfp':
funcs.load_remint_pfp(session, action)
elif name == 'logprices' and account == 'nfthivedrops':
funcs.load_logprices(session, action, account)
elif account == 'atomicmarket':
if name == 'purchasesale':
funcs.load_atomic_market_buy(session, action)
elif name == 'cancelsale':
funcs.load_atomic_market_cancel(session, action)
elif name == 'lognewsale':
funcs.load_atomic_market_sale(session, action)
elif name == 'cancelauct':
funcs.load_atomic_market_cancel_auct(session, action)
elif name == 'auctionbid':
funcs.load_atomic_market_auct_bid(session, action)
elif name == 'lognewauct':
funcs.load_atomic_market_auct(session, action)
elif name == 'auctclaimbuy':
funcs.load_atomic_market_claim_auct(session, action)
elif name == 'cancelbuyo':
funcs.load_atomic_market_cancel_buy_offer(session, action)
elif name == 'acceptbuyo':
funcs.load_atomic_market_accept_buy_offer(session, action)
elif name == 'declinebuyo':
funcs.load_atomic_market_decline_buy_offer(session, action)
elif name == 'lognewbuyo':
funcs.load_atomic_market_log_new_buy_offer(session, action)
elif name == 'logsalestart':
funcs.load_atomic_market_sale_start(session, action)
elif name == 'canceltbuyo':
funcs.load_atomic_market_cancel_template_buyo(session, action)
elif name == 'fulfilltbuyo':
funcs.load_atomic_market_fulfill_template_buyo(session, action)
elif name == 'lognewtbuyo':
funcs.load_atomic_market_lognew_template_buyo(session, action)
elif account == 'atomicassets':
if name == 'logmint':
funcs.insert_atomic_asset(session, action)
elif name == 'logbackasset':
funcs.insert_back_action(session, action)
elif name == 'logtransfer':
funcs.load_atomic_transfer(session, action)
elif name == 'burnasset':
funcs.load_atomic_burn(session, action)
elif name == 'lognewoffer':
funcs.load_atomic_offer(session, action)
elif name == 'acceptoffer':
funcs.load_accept_offer(session, action)
elif name == 'canceloffer':
funcs.load_cancel_offer(session, action)
elif name == 'declineoffer':
funcs.load_decline_offer(session, action)
elif name == 'setassetdata':
funcs.load_atomic_update(session, action)
elif name == 'setcoldata':
funcs.load_collection_update(session, action)
elif name == 'setmarketfee':
funcs.load_collection_fee_update(session, action)
elif name == 'addcolauth':
funcs.add_collection_author(session, action)
elif name == 'remcolauth':
funcs.remove_collection_author(session, action)
elif name == 'lognewtempl':
funcs.insert_atomic_template(session, action)
elif name == 'createschema':
funcs.insert_schema(session, action)
elif name == 'createcol':
funcs.insert_collection(session, action)
elif account == 'nft.hive':
if name == 'lognewsale':
funcs.load_nft_hive_ft_lists(session, action)
elif name == 'logbuy':
funcs.load_nft_hive_ft_buys(session, action)
elif name == 'cancelsale':
funcs.load_nft_hive_ft_cancels(session, action)
elif name == 'execute':
funcs.load_nft_hive_execute(session, action)
elif account == 'simpleassets':
if name == 'createlog':
funcs.load_asset(session, action)
elif name == 'transfer':
funcs.load_transaction(session, action)
elif name == 'offer':
funcs.load_offer(session, action)
elif name == 'claim':
funcs.load_claim(session, action)
elif name == 'burn':
funcs.load_asset_burn(session, action)
elif name == 'update':
funcs.load_asset_update(session, action)
elif account == 'waxplorercom':
if name == 'logbuy':
funcs.load_waxplorercom_buy(session, action)
elif name == 'lognewsale':
funcs.load_waxplorercom_list(session, action)
elif name == 'cancelsale':
funcs.load_waxplorercom_unlist(session, action)
elif account == 'market.myth':
if name == 'logsale':
funcs.load_market_myth_buy(session, action)
elif account == 'simplemarket':
if name == 'updateprice':
funcs.load_simplemarket_update(session, action)
elif name == 'buylog':
funcs.load_simplemarket_buy(session, action)
elif name == 'cancel':
funcs.load_simplemarket_cancel(session, action)
elif account == 'wax.gg':
if name == 'updatephoto':
funcs.load_user_picture(session, action)
elif account == 'neftyblocksp':
if name == 'createpack':
funcs.load_createpack(session, action, 'neftyblocksp')
elif name == 'createspack':
funcs.load_createpack(session, action, 'neftyblocksp')
elif name == 'lognewpack':
funcs.load_neftyblocksp_lognewpack(session, action)
elif name == 'setpackdata':