Skip to content

Commit

Permalink
Update owner and delegate in asset table when collection or creator v…
Browse files Browse the repository at this point in the history
…erification occurs
  • Loading branch information
danenbm committed May 24, 2023
1 parent ff389cc commit 9299d79
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ use blockbuster::{
use digital_asset_types::dao::{asset, asset_grouping};
use sea_orm::{entity::*, query::*, sea_query::OnConflict, DbBackend, Set, Unchanged};

use crate::{
error::IngesterError,
};
use super::{update_asset, save_changelog_event};
use super::{save_changelog_event, update_asset};
use crate::error::IngesterError;
pub async fn process<'c, T>(
parsing_result: &BubblegumInstruction,
bundle: &InstructionBundle<'c>,
Expand All @@ -23,13 +21,25 @@ where
// updates below?
let seq = save_changelog_event(cl, bundle.slot, txn).await?;
match le.schema {
LeafSchema::V1 { id, .. } => {
LeafSchema::V1 {
id,
delegate,
owner,
..
} => {
let id_bytes = id.to_bytes().to_vec();

let delegate = if owner == delegate {
None
} else {
Some(delegate.to_bytes().to_vec())
};
let owner_bytes = owner.to_bytes().to_vec();
let asset_to_update = asset::ActiveModel {
id: Unchanged(id_bytes.clone()),
leaf: Set(Some(le.leaf_hash.to_vec())),
seq: Set(seq as i64),
delegate: Set(delegate),
owner: Set(Some(owner_bytes)),
seq: Set(seq as i64), // gummyroll seq
..Default::default()
};
update_asset(txn, id_bytes.clone(), Some(seq), asset_to_update).await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use digital_asset_types::dao::{asset, asset_creators};
use sea_orm::{ConnectionTrait, Set, TransactionTrait, Unchanged};

use crate::{
program_transformers::bubblegum::{update_asset, update_creator},
error::IngesterError,
program_transformers::bubblegum::{update_asset, update_creator},
};

use super::save_changelog_event;
Expand Down Expand Up @@ -37,15 +37,27 @@ where

let seq = save_changelog_event(cl, bundle.slot, txn).await?;
let asset_id_bytes = match le.schema {
LeafSchema::V1 { id, .. } => {
LeafSchema::V1 {
id,
delegate,
owner,
..
} => {
let id_bytes = id.to_bytes().to_vec();
let delegate = if owner == delegate {
None
} else {
Some(delegate.to_bytes().to_vec())
};
let owner_bytes = owner.to_bytes().to_vec();
let asset_to_update = asset::ActiveModel {
id: Unchanged(id_bytes.clone()),
leaf: Set(Some(le.leaf_hash.to_vec())),
seq: Set(seq as i64),
delegate: Set(delegate),
owner: Set(Some(owner_bytes)),
seq: Set(seq as i64), // gummyroll seq
..Default::default()
};

update_asset(txn, id_bytes.clone(), Some(seq), asset_to_update).await?;
id_bytes
}
Expand Down
5 changes: 1 addition & 4 deletions nft_ingester/src/program_transformers/bubblegum/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
program_transformers::bubblegum::{update_asset},
error::IngesterError,
};
use crate::{error::IngesterError, program_transformers::bubblegum::update_asset};

use super::save_changelog_event;
use blockbuster::{
Expand Down

0 comments on commit 9299d79

Please sign in to comment.