From d1ea0a4cb4fce29c8865734162e1e3c983d35853 Mon Sep 17 00:00:00 2001
From: Guoteng Rao <3603304+grao1991@users.noreply.github.com>
Date: Fri, 6 Sep 2024 02:28:28 +0000
Subject: [PATCH] [Processor] Simplify some logic to reduce unnecessary
duplicated work.
---
rust/Cargo.lock | 27 ++
rust/Cargo.toml | 1 +
.../src/models/account_transaction_models.rs | 6 +-
rust/processor/Cargo.toml | 1 +
.../account_transactions.rs | 6 +-
.../common/models/coin_models/coin_utils.rs | 3 +-
.../parquet_v2_fungible_asset_balances.rs | 4 +-
.../v2_fungible_asset_balances.rs | 4 +-
.../v2_fungible_asset_utils.rs | 226 ++-----------
.../v2_fungible_metadata.rs | 5 +-
rust/processor/src/db/common/models/mod.rs | 1 +
.../models/object_models/v2_object_utils.rs | 80 ++---
.../src/db/common/models/resources.rs | 212 ++++++++++++
.../common/models/token_models/token_utils.rs | 10 +-
.../token_v2_models/parquet_v2_token_datas.rs | 3 +-
.../parquet_v2_token_ownerships.rs | 5 +-
.../models/token_v2_models/v2_collections.rs | 26 +-
.../models/token_v2_models/v2_token_datas.rs | 4 +-
.../token_v2_models/v2_token_metadata.rs | 5 +-
.../token_v2_models/v2_token_ownerships.rs | 5 +-
.../models/token_v2_models/v2_token_utils.rs | 309 +++---------------
.../processors/fungible_asset_processor.rs | 83 +++--
.../src/processors/nft_metadata_processor.rs | 5 +-
.../src/processors/objects_processor.rs | 13 +-
...uet_fungible_asset_activities_processor.rs | 83 +++--
.../parquet_fungible_asset_processor.rs | 5 +-
.../parquet_token_v2_processor.rs | 79 ++---
.../src/processors/token_v2_processor.rs | 79 ++---
.../objects_processor/objects_extractor.rs | 13 +-
29 files changed, 551 insertions(+), 752 deletions(-)
create mode 100644 rust/processor/src/db/common/models/resources.rs
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 51f288ca2..e446e52c5 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -882,6 +882,26 @@ dependencies = [
"tiny-keccak",
]
+[[package]]
+name = "const_format"
+version = "0.2.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "50c655d81ff1114fb0dcdea9225ea9f0cc712a6f8d189378e82bdf62a473a64b"
+dependencies = [
+ "const_format_proc_macros",
+]
+
+[[package]]
+name = "const_format_proc_macros"
+version = "0.2.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eff1a44b93f47b1bac19a27932f5c591e43d1ba357ee4f61526c8a25603f0eb1"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
+]
+
[[package]]
name = "cookie"
version = "0.17.0"
@@ -3394,6 +3414,7 @@ dependencies = [
"canonical_json",
"chrono",
"clap",
+ "const_format",
"diesel",
"diesel-async",
"diesel_migrations",
@@ -5311,6 +5332,12 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0"
+[[package]]
+name = "unicode-xid"
+version = "0.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a"
+
[[package]]
name = "untrusted"
version = "0.7.1"
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 40095ec30..6e449d144 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -45,6 +45,7 @@ bigdecimal = { version = "0.4.0", features = ["serde"] }
bitflags = "2.5.0"
chrono = { version = "0.4.19", features = ["clock", "serde"] }
clap = { version = "4.3.5", features = ["derive", "unstable-styles"] }
+const_format = "0.2.33"
# Do NOT enable the postgres feature here, it is conditionally enabled in a feature
# block in the Cargo.toml file for the processor crate.
# https://github.com/aptos-labs/aptos-indexer-processors/pull/325
diff --git a/rust/integration-tests/src/models/account_transaction_models.rs b/rust/integration-tests/src/models/account_transaction_models.rs
index ab1af47cc..d749e3b76 100644
--- a/rust/integration-tests/src/models/account_transaction_models.rs
+++ b/rust/integration-tests/src/models/account_transaction_models.rs
@@ -11,7 +11,7 @@ use diesel::{Identifiable, Insertable, Queryable};
use field_count::FieldCount;
use processor::{
db::common::models::{
- object_models::v2_object_utils::ObjectWithMetadata,
+ object_models::v2_object_utils::ObjectWithMetadata, resources::FromWriteResource,
user_transactions_models::user_transactions::UserTransaction,
},
schema::account_transactions,
@@ -98,9 +98,7 @@ impl AccountTransaction {
// owner as well.
// This handles partial deletes as well.
accounts.insert(standardize_address(res.address.as_str()));
- if let Some(inner) =
- &ObjectWithMetadata::from_write_resource(res, txn_version).unwrap()
- {
+ if let Some(inner) = &ObjectWithMetadata::from_write_resource(res).unwrap() {
accounts.insert(inner.object_core.get_owner_address());
}
},
diff --git a/rust/processor/Cargo.toml b/rust/processor/Cargo.toml
index 32c87ad6a..964e6fb63 100644
--- a/rust/processor/Cargo.toml
+++ b/rust/processor/Cargo.toml
@@ -27,6 +27,7 @@ bitflags = { workspace = true }
canonical_json = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
+const_format = { workspace = true }
diesel = { workspace = true }
diesel-async = { workspace = true }
diesel_migrations = { workspace = true }
diff --git a/rust/processor/src/db/common/models/account_transaction_models/account_transactions.rs b/rust/processor/src/db/common/models/account_transaction_models/account_transactions.rs
index 385d1e010..611e16652 100644
--- a/rust/processor/src/db/common/models/account_transaction_models/account_transactions.rs
+++ b/rust/processor/src/db/common/models/account_transaction_models/account_transactions.rs
@@ -7,7 +7,7 @@
use crate::{
db::common::models::{
- object_models::v2_object_utils::ObjectWithMetadata,
+ object_models::v2_object_utils::ObjectWithMetadata, resources::FromWriteResource,
user_transactions_models::user_transactions::UserTransaction,
},
schema::account_transactions,
@@ -98,9 +98,7 @@ impl AccountTransaction {
// owner as well.
// This handles partial deletes as well.
accounts.insert(standardize_address(res.address.as_str()));
- if let Some(inner) =
- &ObjectWithMetadata::from_write_resource(res, txn_version).unwrap()
- {
+ if let Some(inner) = &ObjectWithMetadata::from_write_resource(res).unwrap() {
accounts.insert(inner.object_core.get_owner_address());
}
},
diff --git a/rust/processor/src/db/common/models/coin_models/coin_utils.rs b/rust/processor/src/db/common/models/coin_models/coin_utils.rs
index aeed74d2d..9cef7322b 100644
--- a/rust/processor/src/db/common/models/coin_models/coin_utils.rs
+++ b/rust/processor/src/db/common/models/coin_models/coin_utils.rs
@@ -5,7 +5,7 @@
#![allow(clippy::extra_unused_lifetimes)]
use crate::{
- db::common::models::default_models::move_resources::MoveResource,
+ db::common::models::{default_models::move_resources::MoveResource, resources::COIN_ADDR},
utils::util::{deserialize_from_string, hash_str, standardize_address, truncate_str},
};
use anyhow::{bail, Context, Result};
@@ -16,7 +16,6 @@ use regex::Regex;
use serde::{Deserialize, Serialize};
use tracing::error;
-pub const COIN_ADDR: &str = "0x0000000000000000000000000000000000000000000000000000000000000001";
const COIN_TYPE_HASH_LENGTH: usize = 5000;
const COIN_TYPE_MAX: usize = 1000;
diff --git a/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs b/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs
index 9fe62d32f..072ea0339 100644
--- a/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs
+++ b/rust/processor/src/db/common/models/fungible_asset_models/parquet_v2_fungible_asset_balances.rs
@@ -17,6 +17,7 @@ use crate::{
v2_fungible_asset_utils::FungibleAssetStore,
},
object_models::v2_object_utils::ObjectAggregatedDataMapping,
+ resources::FromWriteResource,
token_v2_models::v2_token_utils::TokenStandard,
},
utils::util::standardize_address,
@@ -76,8 +77,7 @@ impl FungibleAssetBalance {
txn_timestamp: chrono::NaiveDateTime,
object_metadatas: &ObjectAggregatedDataMapping,
) -> anyhow::Result