Skip to content

Commit

Permalink
Merge pull request #41 from holaplex/main
Browse files Browse the repository at this point in the history
8/3 Release
  • Loading branch information
kespinola committed Aug 3, 2023
2 parents 5b6aa73 + fa0716b commit 46872e1
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 160 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion consumer/src/asset_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct Asset {
pub struct AssetSupply {
pub print_max_supply: u32,
pub print_current_supply: u32,
pub edition_nonce: u64,
pub edition_nonce: Option<u64>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
Expand Down
13 changes: 9 additions & 4 deletions consumer/src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use holaplex_hub_nfts_solana_core::proto::{
MetaplexMasterEditionTransaction, SolanaPendingTransaction, TransferMetaplexAssetTransaction,
};
use holaplex_hub_nfts_solana_entity::{collection_mints, collections};
use holaplex_hub_nfts_solana_entity::collections;
use hub_core::prelude::*;
use solana_program::pubkey::Pubkey;

Expand Down Expand Up @@ -43,6 +43,11 @@ pub struct MintCompressedMintV1Addresses {
pub leaf_owner: Pubkey,
}

pub struct TransferCompressedMintV1Addresses {
pub owner: Pubkey,
pub recipient: Pubkey,
}

#[derive(Clone)]
pub struct UpdateMasterEditionAddresses {
pub metadata: Pubkey,
Expand Down Expand Up @@ -103,10 +108,10 @@ pub trait MintBackend<T, R> {
}

#[async_trait]
pub trait TransferBackend {
pub trait TransferBackend<M, R> {
async fn transfer(
&self,
collection_mint: &collection_mints::Model,
collection_mint: &M,
txn: TransferMetaplexAssetTransaction,
) -> Result<TransactionResponse<TransferAssetAddresses>>;
) -> Result<TransactionResponse<R>>;
}
97 changes: 59 additions & 38 deletions consumer/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use holaplex_hub_nfts_solana_core::{
SolanaFailedTransaction, SolanaNftEventKey, SolanaNftEvents, SolanaPendingTransaction,
SolanaTransactionFailureReason, TransferMetaplexAssetTransaction,
},
sea_orm::{DbErr, Set},
sea_orm::{DatabaseConnection, DbErr, Set},
Collection, CollectionMint, CompressionLeaf, Services,
};
use holaplex_hub_nfts_solana_entity::{collection_mints, collections, compression_leafs};
Expand Down Expand Up @@ -117,7 +117,7 @@ impl EventKind {
Self::CreateDrop => "drop creation",
Self::MintDrop => "drop mint",
Self::UpdateDrop => "drop update",
Self::TransferAsset => "drop asset transfer",
Self::TransferAsset => "asset transfer",
Self::RetryCreateDrop => "drop creation retry",
Self::RetryMintDrop => "drop mint retry",
Self::CreateCollection => "collection creation",
Expand Down Expand Up @@ -150,7 +150,7 @@ impl EventKind {

async fn into_success(
self,
db: &db::Connection,
conn: &DatabaseConnection,
solana: &Solana,
key: &SolanaNftEventKey,
signature: String,
Expand All @@ -160,7 +160,7 @@ impl EventKind {
Ok(match self {
Self::CreateDrop => {
let id = id()?;
let collection = Collection::find_by_id(db, id)
let collection = Collection::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -172,7 +172,7 @@ impl EventKind {
Self::CreateCollection => {
let id = id()?;

let collection = Collection::find_by_id(db, id)
let collection = Collection::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -184,7 +184,7 @@ impl EventKind {
Self::RetryCreateCollection => {
let id = id()?;

let collection = Collection::find_by_id(db, id)
let collection = Collection::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -200,9 +200,9 @@ impl EventKind {
},
Self::MintToCollection => {
let id = id()?;
let collection_mint = CollectionMint::find_by_id(db, id).await?;
let collection_mint = CollectionMint::find_by_id(conn, id).await?;

let compression_leafs = CompressionLeaf::find_by_id(db, id).await?;
let compression_leafs = CompressionLeaf::find_by_id(conn, id).await?;

let address = if let Some(compression_leaf) = compression_leafs {
let signature = Signature::from_str(&signature)?;
Expand All @@ -220,7 +220,7 @@ impl EventKind {

compression_leaf.asset_id = Set(Some(asset_id.clone()));

CompressionLeaf::update(db, compression_leaf).await?;
CompressionLeaf::update(conn, compression_leaf).await?;

asset_id
} else {
Expand All @@ -236,7 +236,7 @@ impl EventKind {
},
Self::MintDrop => {
let id = id()?;
let collection_mint = CollectionMint::find_by_id(db, id)
let collection_mint = CollectionMint::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -255,7 +255,7 @@ impl EventKind {
},
Self::RetryCreateDrop => {
let id = id()?;
let collection = Collection::find_by_id(db, id)
let collection = Collection::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -266,7 +266,7 @@ impl EventKind {
},
Self::RetryMintDrop => {
let id = id()?;
let collection_mint = CollectionMint::find_by_id(db, id)
let collection_mint = CollectionMint::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -277,7 +277,7 @@ impl EventKind {
},
Self::RetryMintToCollection => {
let id = id()?;
let collection_mint = CollectionMint::find_by_id(db, id)
let collection_mint = CollectionMint::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand Down Expand Up @@ -387,7 +387,7 @@ impl Processor {
self.process_nft(
EventKind::TransferAsset,
&key,
self.transfer_asset(&UncompressedRef(self.solana()), &key, payload),
self.transfer_asset(&key, payload),
)
.await
},
Expand Down Expand Up @@ -562,10 +562,11 @@ impl Processor {
key: &SolanaNftEventKey,
sig: String,
) -> ProcessResult<()> {
let conn = self.db.get();
self.producer
.send(
Some(&SolanaNftEvents {
event: Some(kind.into_success(&self.db, self.solana(), key, sig).await?),
event: Some(kind.into_success(conn, self.solana(), key, sig).await?),
}),
Some(key),
)
Expand Down Expand Up @@ -598,6 +599,7 @@ impl Processor {
key: &SolanaNftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let tx = backend
.create(payload.clone())
.map_err(ProcessorErrorKind::Solana)?;
Expand All @@ -623,7 +625,7 @@ impl Processor {
created_at: Utc::now().naive_utc(),
};

Collection::create(&self.db, collection.into()).await?;
Collection::create(conn, collection.into()).await?;

Ok(tx.into())
}
Expand All @@ -633,9 +635,10 @@ impl Processor {
key: &SolanaNftEventKey,
payload: MintMetaplexMetadataTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let id = Uuid::parse_str(&key.id.clone())?;
let collection_id = Uuid::parse_str(&payload.collection_id)?;
let collection = Collection::find_by_id(&self.db, collection_id)
let collection = Collection::find_by_id(conn, collection_id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -657,7 +660,7 @@ impl Processor {
..Default::default()
};

CompressionLeaf::create(&self.db, compression_leaf).await?;
CompressionLeaf::create(conn, compression_leaf).await?;

return Ok(tx.into());
}
Expand All @@ -677,7 +680,7 @@ impl Processor {
associated_token_account: tx.addresses.associated_token_account.to_string(),
};

CollectionMint::create(&self.db, collection_mint).await?;
CollectionMint::create(conn, collection_mint).await?;

Ok(tx.into())
}
Expand All @@ -688,9 +691,10 @@ impl Processor {
key: &SolanaNftEventKey,
payload: MintMetaplexEditionTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let id = Uuid::parse_str(&key.id.clone())?;
let collection_id = Uuid::parse_str(&payload.collection_id)?;
let collection = Collection::find_by_id(&self.db, collection_id)
let collection = Collection::find_by_id(conn, collection_id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -707,7 +711,7 @@ impl Processor {
created_at: Utc::now().naive_utc(),
};

CollectionMint::create(&self.db, collection_mint).await?;
CollectionMint::create(conn, collection_mint).await?;

Ok(tx.into())
}
Expand All @@ -718,8 +722,9 @@ impl Processor {
key: &SolanaNftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let collection_id = Uuid::parse_str(&key.id.clone())?;
let collection = Collection::find_by_id(&self.db, collection_id)
let collection = Collection::find_by_id(conn, collection_id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -730,19 +735,34 @@ impl Processor {
Ok(tx.into())
}

async fn transfer_asset<B: TransferBackend>(
async fn transfer_asset(
&self,
backend: &B,
_key: &SolanaNftEventKey,
payload: TransferMetaplexAssetTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let collection_mint_id = Uuid::parse_str(&payload.collection_mint_id.clone())?;
let collection_mint = CollectionMint::find_by_id(&self.db, collection_mint_id)
let collection_mint = CollectionMint::find_by_id(conn, collection_mint_id).await?;

if let Some(collection_mint) = collection_mint {
let backend = &UncompressedRef(self.solana());

let tx = backend
.transfer(&collection_mint, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

return Ok(tx.into());
}

let compression_leaf = CompressionLeaf::find_by_id(conn, collection_mint_id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

let backend = &CompressedRef(self.solana());

let tx = backend
.transfer(&collection_mint, payload)
.transfer(&compression_leaf, payload)
.await
.map_err(ProcessorErrorKind::Solana)?;

Expand All @@ -755,6 +775,7 @@ impl Processor {
key: &SolanaNftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let tx = backend
.create(payload.clone())
.map_err(ProcessorErrorKind::Solana)?;
Expand All @@ -769,7 +790,7 @@ impl Processor {
} = tx.addresses;

let collection_id = Uuid::parse_str(&key.id.clone())?;
let collection = Collection::find_by_id(&self.db, collection_id)
let collection = Collection::find_by_id(conn, collection_id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -782,7 +803,7 @@ impl Processor {
collection.update_authority = Set(update_authority.to_string());
collection.owner = Set(owner.to_string());

Collection::update(&self.db, collection).await?;
Collection::update(conn, collection).await?;

Ok(tx.into())
}
Expand All @@ -795,12 +816,12 @@ impl Processor {
key: &SolanaNftEventKey,
payload: MintMetaplexEditionTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let id = Uuid::parse_str(&key.id.clone())?;

let (collection_mint, collection) =
CollectionMint::find_by_id_with_collection(&self.db, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;
let (collection_mint, collection) = CollectionMint::find_by_id_with_collection(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

let collection = collection.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -821,7 +842,7 @@ impl Processor {
collection_mint.owner = Set(recipient.to_string());
collection_mint.associated_token_account = Set(associated_token_account.to_string());

CollectionMint::update(&self.db, collection_mint).await?;
CollectionMint::update(conn, collection_mint).await?;

Ok(tx.into())
}
Expand All @@ -834,12 +855,12 @@ impl Processor {
key: &SolanaNftEventKey,
payload: MintMetaplexMetadataTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
let conn = self.db.get();
let id = Uuid::parse_str(&key.id.clone())?;

let (collection_mint, collection) =
CollectionMint::find_by_id_with_collection(&self.db, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;
let (collection_mint, collection) = CollectionMint::find_by_id_with_collection(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

let collection = collection.ok_or(ProcessorErrorKind::RecordNotFound)?;

Expand All @@ -860,7 +881,7 @@ impl Processor {
collection_mint.owner = Set(recipient.to_string());
collection_mint.associated_token_account = Set(associated_token_account.to_string());

CollectionMint::update(&self.db, collection_mint).await?;
CollectionMint::update(conn, collection_mint).await?;

Ok(tx.into())
}
Expand Down
Loading

0 comments on commit 46872e1

Please sign in to comment.