-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathans_processor.rs
741 lines (695 loc) · 27.5 KB
/
ans_processor.rs
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
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0
use super::{DefaultProcessingResult, ProcessorName, ProcessorTrait};
use crate::{
db::common::models::ans_models::{
ans_lookup::{AnsLookup, AnsPrimaryName, CurrentAnsLookup, CurrentAnsPrimaryName},
ans_lookup_v2::{
AnsLookupV2, AnsPrimaryNameV2, CurrentAnsLookupV2, CurrentAnsPrimaryNameV2,
},
ans_utils::{RenewNameEvent, SubdomainExtV2},
},
gap_detectors::ProcessingResult,
schema,
utils::{
counters::PROCESSOR_UNKNOWN_TYPE_COUNT,
database::{execute_in_chunks, get_config_table_chunk_size, ArcDbPool},
util::standardize_address,
},
worker::TableFlags,
};
use ahash::AHashMap;
use anyhow::bail;
use aptos_protos::transaction::v1::{
transaction::TxnData, write_set_change::Change as WriteSetChange, Transaction,
};
use async_trait::async_trait;
use diesel::{
pg::{upsert::excluded, Pg},
query_builder::QueryFragment,
ExpressionMethods,
};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use tracing::error;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct AnsProcessorConfig {
pub ans_v1_primary_names_table_handle: String,
pub ans_v1_name_records_table_handle: String,
pub ans_v2_contract_address: String,
}
pub struct AnsProcessor {
connection_pool: ArcDbPool,
config: AnsProcessorConfig,
per_table_chunk_sizes: AHashMap<String, usize>,
deprecated_tables: TableFlags,
}
impl AnsProcessor {
pub fn new(
connection_pool: ArcDbPool,
config: AnsProcessorConfig,
per_table_chunk_sizes: AHashMap<String, usize>,
deprecated_tables: TableFlags,
) -> Self {
tracing::info!(
ans_v1_primary_names_table_handle = config.ans_v1_primary_names_table_handle,
ans_v1_name_records_table_handle = config.ans_v1_name_records_table_handle,
ans_v2_contract_address = config.ans_v2_contract_address,
"init AnsProcessor"
);
Self {
connection_pool,
config,
per_table_chunk_sizes,
deprecated_tables,
}
}
}
impl Debug for AnsProcessor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let state = &self.connection_pool.state();
write!(
f,
"AnsProcessor {{ connections: {:?} idle_connections: {:?} }}",
state.connections, state.idle_connections
)
}
}
async fn insert_to_db(
conn: ArcDbPool,
name: &'static str,
start_version: u64,
end_version: u64,
current_ans_lookups: &[CurrentAnsLookup],
ans_lookups: &[AnsLookup],
current_ans_primary_names: &[CurrentAnsPrimaryName],
ans_primary_names: &[AnsPrimaryName],
current_ans_lookups_v2: &[CurrentAnsLookupV2],
ans_lookups_v2: &[AnsLookupV2],
current_ans_primary_names_v2: &[CurrentAnsPrimaryNameV2],
ans_primary_names_v2: &[AnsPrimaryNameV2],
per_table_chunk_sizes: &AHashMap<String, usize>,
) -> Result<(), diesel::result::Error> {
tracing::trace!(
name = name,
start_version = start_version,
end_version = end_version,
"Inserting to db",
);
let cal = execute_in_chunks(
conn.clone(),
insert_current_ans_lookups_query,
current_ans_lookups,
get_config_table_chunk_size::<CurrentAnsLookup>(
"current_ans_lookup",
per_table_chunk_sizes,
),
);
let al = execute_in_chunks(
conn.clone(),
insert_ans_lookups_query,
ans_lookups,
get_config_table_chunk_size::<AnsLookup>("ans_lookup", per_table_chunk_sizes),
);
let capn = execute_in_chunks(
conn.clone(),
insert_current_ans_primary_names_query,
current_ans_primary_names,
get_config_table_chunk_size::<CurrentAnsPrimaryName>(
"current_ans_primary_name",
per_table_chunk_sizes,
),
);
let apn = execute_in_chunks(
conn.clone(),
insert_ans_primary_names_query,
ans_primary_names,
get_config_table_chunk_size::<AnsPrimaryName>("ans_primary_name", per_table_chunk_sizes),
);
let cal_v2 = execute_in_chunks(
conn.clone(),
insert_current_ans_lookups_v2_query,
current_ans_lookups_v2,
get_config_table_chunk_size::<CurrentAnsLookupV2>(
"current_ans_lookup_v2",
per_table_chunk_sizes,
),
);
let al_v2 = execute_in_chunks(
conn.clone(),
insert_ans_lookups_v2_query,
ans_lookups_v2,
get_config_table_chunk_size::<AnsLookupV2>("ans_lookup_v2", per_table_chunk_sizes),
);
let capn_v2 = execute_in_chunks(
conn.clone(),
insert_current_ans_primary_names_v2_query,
current_ans_primary_names_v2,
get_config_table_chunk_size::<CurrentAnsPrimaryNameV2>(
"current_ans_primary_name_v2",
per_table_chunk_sizes,
),
);
let apn_v2 = execute_in_chunks(
conn,
insert_ans_primary_names_v2_query,
ans_primary_names_v2,
get_config_table_chunk_size::<AnsPrimaryNameV2>(
"ans_primary_name_v2",
per_table_chunk_sizes,
),
);
let (cal_res, al_res, capn_res, apn_res, cal_v2_res, al_v2_res, capn_v2_res, apn_v2_res) =
tokio::join!(cal, al, capn, apn, cal_v2, al_v2, capn_v2, apn_v2);
for res in vec![
cal_res,
al_res,
capn_res,
apn_res,
cal_v2_res,
al_v2_res,
capn_v2_res,
apn_v2_res,
] {
res?;
}
Ok(())
}
fn insert_current_ans_lookups_query(
item_to_insert: Vec<CurrentAnsLookup>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::current_ans_lookup::dsl::*;
(
diesel::insert_into(schema::current_ans_lookup::table)
.values(item_to_insert)
.on_conflict((domain, subdomain))
.do_update()
.set((
registered_address.eq(excluded(registered_address)),
expiration_timestamp.eq(excluded(expiration_timestamp)),
last_transaction_version.eq(excluded(last_transaction_version)),
token_name.eq(excluded(token_name)),
is_deleted.eq(excluded(is_deleted)),
inserted_at.eq(excluded(inserted_at)),
)),
Some(" WHERE current_ans_lookup.last_transaction_version <= excluded.last_transaction_version "),
)
}
fn insert_ans_lookups_query(
item_to_insert: Vec<AnsLookup>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::ans_lookup::dsl::*;
(
diesel::insert_into(schema::ans_lookup::table)
.values(item_to_insert)
.on_conflict((transaction_version, write_set_change_index))
.do_nothing(),
None,
)
}
fn insert_current_ans_primary_names_query(
item_to_insert: Vec<CurrentAnsPrimaryName>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::current_ans_primary_name::dsl::*;
(
diesel::insert_into(schema::current_ans_primary_name::table)
.values(item_to_insert)
.on_conflict(registered_address)
.do_update()
.set((
domain.eq(excluded(domain)),
subdomain.eq(excluded(subdomain)),
token_name.eq(excluded(token_name)),
is_deleted.eq(excluded(is_deleted)),
last_transaction_version.eq(excluded(last_transaction_version)),
inserted_at.eq(excluded(inserted_at)),
)),
Some(" WHERE current_ans_primary_name.last_transaction_version <= excluded.last_transaction_version "),
)
}
fn insert_ans_primary_names_query(
item_to_insert: Vec<AnsPrimaryName>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::ans_primary_name::dsl::*;
(
diesel::insert_into(schema::ans_primary_name::table)
.values(item_to_insert)
.on_conflict((transaction_version, write_set_change_index))
.do_nothing(),
None,
)
}
fn insert_current_ans_lookups_v2_query(
item_to_insert: Vec<CurrentAnsLookupV2>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::current_ans_lookup_v2::dsl::*;
(
diesel::insert_into(schema::current_ans_lookup_v2::table)
.values(item_to_insert)
.on_conflict((domain, subdomain, token_standard))
.do_update()
.set((
registered_address.eq(excluded(registered_address)),
expiration_timestamp.eq(excluded(expiration_timestamp)),
last_transaction_version.eq(excluded(last_transaction_version)),
token_name.eq(excluded(token_name)),
is_deleted.eq(excluded(is_deleted)),
inserted_at.eq(excluded(inserted_at)),
subdomain_expiration_policy.eq(excluded(subdomain_expiration_policy)),
)),
Some(" WHERE current_ans_lookup_v2.last_transaction_version <= excluded.last_transaction_version "),
)
}
fn insert_ans_lookups_v2_query(
item_to_insert: Vec<AnsLookupV2>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::ans_lookup_v2::dsl::*;
(
diesel::insert_into(schema::ans_lookup_v2::table)
.values(item_to_insert)
.on_conflict((transaction_version, write_set_change_index))
.do_update()
.set((
inserted_at.eq(excluded(inserted_at)),
subdomain_expiration_policy.eq(excluded(subdomain_expiration_policy)),
)),
None,
)
}
fn insert_current_ans_primary_names_v2_query(
item_to_insert: Vec<CurrentAnsPrimaryNameV2>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::current_ans_primary_name_v2::dsl::*;
(
diesel::insert_into(schema::current_ans_primary_name_v2::table)
.values(item_to_insert)
.on_conflict((registered_address, token_standard))
.do_update()
.set((
domain.eq(excluded(domain)),
subdomain.eq(excluded(subdomain)),
token_name.eq(excluded(token_name)),
is_deleted.eq(excluded(is_deleted)),
last_transaction_version.eq(excluded(last_transaction_version)),
inserted_at.eq(excluded(inserted_at)),
)),
Some(" WHERE current_ans_primary_name_v2.last_transaction_version <= excluded.last_transaction_version "),
)
}
fn insert_ans_primary_names_v2_query(
items_to_insert: Vec<AnsPrimaryNameV2>,
) -> (
impl QueryFragment<Pg> + diesel::query_builder::QueryId + Send,
Option<&'static str>,
) {
use schema::ans_primary_name_v2::dsl::*;
(
diesel::insert_into(schema::ans_primary_name_v2::table)
.values(items_to_insert)
.on_conflict((transaction_version, write_set_change_index))
.do_nothing(),
None,
)
}
#[async_trait]
impl ProcessorTrait for AnsProcessor {
fn name(&self) -> &'static str {
ProcessorName::AnsProcessor.into()
}
async fn process_transactions(
&self,
transactions: Vec<Transaction>,
start_version: u64,
end_version: u64,
_db_chain_id: Option<u64>,
) -> anyhow::Result<ProcessingResult> {
let processing_start = std::time::Instant::now();
let last_transaction_timestamp = transactions.last().unwrap().timestamp.clone();
let (
mut all_current_ans_lookups,
mut all_ans_lookups,
mut all_current_ans_primary_names,
mut all_ans_primary_names,
all_current_ans_lookups_v2,
all_ans_lookups_v2,
all_current_ans_primary_names_v2,
mut all_ans_primary_names_v2,
) = parse_ans(
&transactions,
self.config.ans_v1_primary_names_table_handle.clone(),
self.config.ans_v1_name_records_table_handle.clone(),
self.config.ans_v2_contract_address.clone(),
);
let processing_duration_in_secs = processing_start.elapsed().as_secs_f64();
let db_insertion_start = std::time::Instant::now();
if self
.deprecated_tables
.contains(TableFlags::ANS_PRIMARY_NAME)
{
all_ans_primary_names.clear();
}
if self
.deprecated_tables
.contains(TableFlags::ANS_PRIMARY_NAME_V2)
{
all_ans_primary_names_v2.clear();
}
if self.deprecated_tables.contains(TableFlags::ANS_LOOKUP) {
all_ans_lookups.clear();
}
if self
.deprecated_tables
.contains(TableFlags::CURRENT_ANS_LOOKUP)
{
all_current_ans_lookups.clear();
}
if self
.deprecated_tables
.contains(TableFlags::CURRENT_ANS_PRIMARY_NAME)
{
all_current_ans_primary_names.clear();
}
// Insert values to db
let tx_result = insert_to_db(
self.get_pool(),
self.name(),
start_version,
end_version,
&all_current_ans_lookups,
&all_ans_lookups,
&all_current_ans_primary_names,
&all_ans_primary_names,
&all_current_ans_lookups_v2,
&all_ans_lookups_v2,
&all_current_ans_primary_names_v2,
&all_ans_primary_names_v2,
&self.per_table_chunk_sizes,
)
.await;
let db_insertion_duration_in_secs = db_insertion_start.elapsed().as_secs_f64();
match tx_result {
Ok(_) => Ok(ProcessingResult::DefaultProcessingResult(
DefaultProcessingResult {
start_version,
end_version,
processing_duration_in_secs,
db_insertion_duration_in_secs,
last_transaction_timestamp,
},
)),
Err(e) => {
error!(
start_version = start_version,
end_version = end_version,
processor_name = self.name(),
error = ?e,
"[Parser] Error inserting transactions to db",
);
bail!(e)
},
}
}
fn connection_pool(&self) -> &ArcDbPool {
&self.connection_pool
}
}
fn parse_ans(
transactions: &[Transaction],
ans_v1_primary_names_table_handle: String,
ans_v1_name_records_table_handle: String,
ans_v2_contract_address: String,
) -> (
Vec<CurrentAnsLookup>,
Vec<AnsLookup>,
Vec<CurrentAnsPrimaryName>,
Vec<AnsPrimaryName>,
Vec<CurrentAnsLookupV2>,
Vec<AnsLookupV2>,
Vec<CurrentAnsPrimaryNameV2>,
Vec<AnsPrimaryNameV2>,
) {
let mut all_current_ans_lookups = AHashMap::new();
let mut all_ans_lookups = vec![];
let mut all_current_ans_primary_names = AHashMap::new();
let mut all_ans_primary_names = vec![];
let mut all_current_ans_lookups_v2 = AHashMap::new();
let mut all_ans_lookups_v2 = vec![];
let mut all_current_ans_primary_names_v2 = AHashMap::new();
let mut all_ans_primary_names_v2 = vec![];
for transaction in transactions {
let txn_version = transaction.version as i64;
let txn_data = match transaction.txn_data.as_ref() {
Some(data) => data,
None => {
PROCESSOR_UNKNOWN_TYPE_COUNT
.with_label_values(&["AnsProcessor"])
.inc();
tracing::warn!(
transaction_version = txn_version,
"Transaction data doesn't exist",
);
continue;
},
};
let transaction_info = transaction
.info
.as_ref()
.expect("Transaction info doesn't exist!");
// Extracts from user transactions. Other transactions won't have any ANS changes
if let TxnData::User(user_txn) = txn_data {
// TODO: Use the v2_renew_name_events to preserve metadata once we switch to a single ANS table to store everything
let mut v2_renew_name_events = vec![];
let mut v2_address_to_subdomain_ext = AHashMap::new();
// Parse V2 ANS Events. We only care about the following events:
// 1. RenewNameEvents: helps to fill in metadata for name records with updated expiration time
// 2. SetReverseLookupEvents: parse to get current_ans_primary_names
for (event_index, event) in user_txn.events.iter().enumerate() {
if let Some(renew_name_event) =
RenewNameEvent::from_event(event, &ans_v2_contract_address, txn_version)
.unwrap()
{
v2_renew_name_events.push(renew_name_event);
}
if let Some((current_ans_lookup_v2, ans_lookup_v2)) =
CurrentAnsPrimaryNameV2::parse_v2_primary_name_record_from_event(
event,
txn_version,
event_index as i64,
&ans_v2_contract_address,
)
.unwrap()
{
all_current_ans_primary_names_v2
.insert(current_ans_lookup_v2.pk(), current_ans_lookup_v2);
all_ans_primary_names_v2.push(ans_lookup_v2);
}
}
// Parse V2 ANS subdomain exts
for wsc in transaction_info.changes.iter() {
match wsc.change.as_ref().unwrap() {
WriteSetChange::WriteResource(write_resource) => {
if let Some(subdomain_ext) = SubdomainExtV2::from_write_resource(
write_resource,
&ans_v2_contract_address,
txn_version,
)
.unwrap()
{
// Track resource account -> SubdomainExt to create the full subdomain ANS later
v2_address_to_subdomain_ext.insert(
standardize_address(write_resource.address.as_str()),
subdomain_ext,
);
}
},
_ => continue,
}
}
// Parse V1 ANS write set changes
for (wsc_index, wsc) in transaction_info.changes.iter().enumerate() {
match wsc.change.as_ref().unwrap() {
WriteSetChange::WriteTableItem(table_item) => {
if let Some((current_ans_lookup, ans_lookup)) =
CurrentAnsLookup::parse_name_record_from_write_table_item_v1(
table_item,
&ans_v1_name_records_table_handle,
txn_version,
wsc_index as i64,
)
.unwrap_or_else(|e| {
error!(
error = ?e,
"Error parsing ANS v1 name record from write table item"
);
panic!();
})
{
all_current_ans_lookups
.insert(current_ans_lookup.pk(), current_ans_lookup.clone());
all_ans_lookups.push(ans_lookup.clone());
// Include all v1 lookups in v2 data
let (current_ans_lookup_v2, ans_lookup_v2) =
CurrentAnsLookupV2::get_v2_from_v1(current_ans_lookup, ans_lookup);
all_current_ans_lookups_v2
.insert(current_ans_lookup_v2.pk(), current_ans_lookup_v2);
all_ans_lookups_v2.push(ans_lookup_v2);
}
if let Some((current_primary_name, primary_name)) =
CurrentAnsPrimaryName::parse_primary_name_record_from_write_table_item_v1(
table_item,
&ans_v1_primary_names_table_handle,
txn_version,
wsc_index as i64,
)
.unwrap_or_else(|e| {
error!(
error = ?e,
"Error parsing ANS v1 primary name from write table item"
);
panic!();
})
{
all_current_ans_primary_names
.insert(current_primary_name.pk(), current_primary_name.clone());
all_ans_primary_names.push(primary_name.clone());
// Include all v1 primary names in v2 data
let (current_primary_name_v2, primary_name_v2) =
CurrentAnsPrimaryNameV2::get_v2_from_v1(current_primary_name.clone(), primary_name.clone());
all_current_ans_primary_names_v2
.insert(current_primary_name_v2.pk(), current_primary_name_v2);
all_ans_primary_names_v2.push(primary_name_v2);
}
},
WriteSetChange::DeleteTableItem(table_item) => {
if let Some((current_ans_lookup, ans_lookup)) =
CurrentAnsLookup::parse_name_record_from_delete_table_item_v1(
table_item,
&ans_v1_name_records_table_handle,
txn_version,
wsc_index as i64,
)
.unwrap_or_else(|e| {
error!(
error = ?e,
"Error parsing ANS v1 name record from delete table item"
);
panic!();
})
{
all_current_ans_lookups
.insert(current_ans_lookup.pk(), current_ans_lookup.clone());
all_ans_lookups.push(ans_lookup.clone());
// Include all v1 lookups in v2 data
let (current_ans_lookup_v2, ans_lookup_v2) =
CurrentAnsLookupV2::get_v2_from_v1(current_ans_lookup, ans_lookup);
all_current_ans_lookups_v2
.insert(current_ans_lookup_v2.pk(), current_ans_lookup_v2);
all_ans_lookups_v2.push(ans_lookup_v2);
}
if let Some((current_primary_name, primary_name)) =
CurrentAnsPrimaryName::parse_primary_name_record_from_delete_table_item_v1(
table_item,
&ans_v1_primary_names_table_handle,
txn_version,
wsc_index as i64,
)
.unwrap_or_else(|e| {
error!(
error = ?e,
"Error parsing ANS v1 primary name from delete table item"
);
panic!();
})
{
all_current_ans_primary_names
.insert(current_primary_name.pk(), current_primary_name.clone());
all_ans_primary_names.push(primary_name.clone());
// Include all v1 primary names in v2 data
let (current_primary_name_v2, primary_name_v2) =
CurrentAnsPrimaryNameV2::get_v2_from_v1(current_primary_name, primary_name);
all_current_ans_primary_names_v2
.insert(current_primary_name_v2.pk(), current_primary_name_v2);
all_ans_primary_names_v2.push(primary_name_v2);
}
},
WriteSetChange::WriteResource(write_resource) => {
if let Some((current_ans_lookup_v2, ans_lookup_v2)) =
CurrentAnsLookupV2::parse_name_record_from_write_resource_v2(
write_resource,
&ans_v2_contract_address,
txn_version,
wsc_index as i64,
&v2_address_to_subdomain_ext,
)
.unwrap_or_else(|e| {
error!(
error = ?e,
"Error parsing ANS v2 name record from write resource"
);
panic!();
})
{
all_current_ans_lookups_v2
.insert(current_ans_lookup_v2.pk(), current_ans_lookup_v2);
all_ans_lookups_v2.push(ans_lookup_v2);
}
},
// For ANS V2, there are no delete resource changes
// 1. Unsetting a primary name will show up as a ReverseRecord write resource with empty fields
// 2. Name record v2 tokens are never deleted
_ => continue,
}
}
}
}
// Boilerplate after this for diesel
// Sort ans lookup values for postgres insert
let mut all_current_ans_lookups = all_current_ans_lookups
.into_values()
.collect::<Vec<CurrentAnsLookup>>();
let mut all_current_ans_primary_names = all_current_ans_primary_names
.into_values()
.collect::<Vec<CurrentAnsPrimaryName>>();
let mut all_current_ans_lookups_v2 = all_current_ans_lookups_v2
.into_values()
.collect::<Vec<CurrentAnsLookupV2>>();
let mut all_current_ans_primary_names_v2 = all_current_ans_primary_names_v2
.into_values()
.collect::<Vec<CurrentAnsPrimaryNameV2>>();
all_current_ans_lookups.sort();
all_current_ans_primary_names.sort();
all_current_ans_lookups_v2.sort();
all_current_ans_primary_names_v2.sort();
(
all_current_ans_lookups,
all_ans_lookups,
all_current_ans_primary_names,
all_ans_primary_names,
all_current_ans_lookups_v2,
all_ans_lookups_v2,
all_current_ans_primary_names_v2,
all_ans_primary_names_v2,
)
}