Skip to content

Commit

Permalink
das-ingester: Add metrics to figure out token account stats (metaplex…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil Acharya authored Jul 4, 2023
1 parent 9b6aef0 commit ba81058
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions nft_ingester/src/program_transformers/token/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{error::IngesterError, tasks::TaskData};
use blockbuster::programs::token_account::TokenProgramAccount;
use digital_asset_types::dao::{asset, token_accounts, tokens};
use cadence_macros::statsd_count;
use digital_asset_types::dao::{asset, asset_data, token_accounts, tokens};
use log::error;
use plerkle_serialization::AccountInfo;
use sea_orm::{
entity::*, query::*, sea_query::OnConflict, ActiveValue::Set, ConnectionTrait,
Expand Down Expand Up @@ -67,18 +69,29 @@ pub async fn handle_token_program_account<'a, 'b, 'c>(
);
db.execute(query).await?;
let txn = db.begin().await?;
let asset_update: Option<asset::Model> = asset::Entity::find_by_id(mint)

let asset_with_data = asset::Entity::find_by_id(mint)
.filter(asset::Column::OwnerType.eq("single"))
.find_also_related(asset_data::Entity)
.one(&txn)
.await?;
if let Some(asset) = asset_update {

if let Some((asset, data)) = asset_with_data {
// will only update owner if token account balance is non-zero
if ta.amount > 0 {
let mut active: asset::ActiveModel = asset.into();
active.owner = Set(Some(owner));
active.delegate = Set(delegate);
active.frozen = Set(frozen);
active.save(&txn).await?;

if let Some(data) = data {
if data.metadata_url.is_empty() {
statsd_count!("token_account.empty_url", 1);
} else {
statsd_count!("token_account.non_empty_url", 1);
}
}
}
}
txn.commit().await?;
Expand Down

0 comments on commit ba81058

Please sign in to comment.