Skip to content

Commit

Permalink
[Processor] Simplify some logic to reduce unnecessary duplicated work.
Browse files Browse the repository at this point in the history
  • Loading branch information
grao1991 committed Sep 10, 2024
1 parent e7bc40d commit 22a7444
Show file tree
Hide file tree
Showing 26 changed files with 502 additions and 699 deletions.
27 changes: 27 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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
Expand Down
1 change: 1 addition & 0 deletions rust/processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -76,8 +77,7 @@ impl FungibleAssetBalance {
txn_timestamp: chrono::NaiveDateTime,
object_metadatas: &ObjectAggregatedDataMapping,
) -> anyhow::Result<Option<(Self, CurrentFungibleAssetBalance)>> {
if let Some(inner) = &FungibleAssetStore::from_write_resource(write_resource, txn_version)?
{
if let Some(inner) = &FungibleAssetStore::from_write_resource(write_resource)? {
let storage_id = standardize_address(write_resource.address.as_str());
// Need to get the object of the store
if let Some(object_data) = object_metadatas.get(&storage_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
db::common::models::{
coin_models::coin_utils::{CoinInfoType, CoinResource},
object_models::v2_object_utils::ObjectAggregatedDataMapping,
resources::FromWriteResource,
token_v2_models::v2_token_utils::{TokenStandard, V2_STANDARD},
},
schema::{
Expand Down Expand Up @@ -157,8 +158,7 @@ impl FungibleAssetBalance {
txn_timestamp: chrono::NaiveDateTime,
object_metadatas: &ObjectAggregatedDataMapping,
) -> anyhow::Result<Option<(Self, CurrentFungibleAssetBalance)>> {
if let Some(inner) = &FungibleAssetStore::from_write_resource(write_resource, txn_version)?
{
if let Some(inner) = &FungibleAssetStore::from_write_resource(write_resource)? {
let storage_id = standardize_address(write_resource.address.as_str());
// Need to get the object of the store
if let Some(object_data) = object_metadatas.get(&storage_id) {
Expand Down
Loading

0 comments on commit 22a7444

Please sign in to comment.