Skip to content

Commit

Permalink
feat: add mcc submitted and failure event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kespinola committed Jul 21, 2023
1 parent 9782689 commit dcfd7e6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/proto.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ sha512 = "c5ddf43d2958ec690ee2261d0ff9808b67ce810d2fc4b6077f96f561929a920f03509f

[[schemas]]
subject = "solana_nfts"
version = 4
sha512 = "272f1aed7d792a5fe5750cdca659091ca1a4a8dd4f36b35f5066ea6bb09cf4f1e905e7e5817dfa6c68d7ea3a8644192b4ff82e7ffcd85b2d9a58e48112a4a8bc"
version = 5
sha512 = "bdc812d4bdbb0d8ac22e6458b53fbd0420daeeb5bb2c4305639d3890741752507ce67bcb7fa40d119806eb578401bcbe1af90c4ef418539d46adba0645746507"

[[schemas]]
subject = "timestamp"
Expand Down
2 changes: 1 addition & 1 deletion api/proto.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ organization = 5
nfts = 20
customer = 2
treasury = 17
solana_nfts = 4
solana_nfts = 5
polygon_nfts = 6
timestamp = 1
71 changes: 65 additions & 6 deletions api/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ impl Processor {
self.drop_created(id, MintResult::Success(payload.into()))
.await
},
Some(
SolanaNftsEvent::CreateCollectionSubmitted(payload)
| SolanaNftsEvent::RetryCreateCollectionSubmitted(payload),
) => {
self.collection_created(id, MintResult::Success(payload.into()))
.await
},
Some(
SolanaNftsEvent::MintDropSubmitted(payload)
| SolanaNftsEvent::RetryMintDropSubmitted(payload),
Expand All @@ -116,9 +123,14 @@ impl Processor {
self.mint_transferred(id, TransferResult::Success(signature))
.await
},
Some(SolanaNftsEvent::CreateDropFailed(_)) => {
self.drop_created(id, MintResult::Failure).await
},
Some(
SolanaNftsEvent::CreateDropFailed(_)
| SolanaNftsEvent::RetryCreateDropFailed(_),
) => self.drop_created(id, MintResult::Failure).await,
Some(
SolanaNftsEvent::CreateCollectionFailed(_)
| SolanaNftsEvent::RetryCreateCollectionFailed(_),
) => self.collection_created(id, MintResult::Failure).await,
Some(SolanaNftsEvent::MintDropFailed(_)) => {
self.drop_minted(id, MintResult::Failure).await
},
Expand All @@ -128,9 +140,6 @@ impl Processor {
Some(SolanaNftsEvent::RetryMintDropFailed(_)) => {
self.drop_minted(id, MintResult::Failure).await
},
Some(SolanaNftsEvent::RetryCreateDropFailed(_)) => {
self.drop_created(id, MintResult::Failure).await
},
Some(SolanaNftsEvent::UpdateMintOwner(e)) => self.update_mint_owner(id, e).await,
None | Some(_) => Ok(()),
},
Expand Down Expand Up @@ -320,6 +329,56 @@ impl Processor {
Ok(())
}

async fn collection_created(&self, id: String, payload: MintResult) -> Result<()> {
let conn = self.db.get();
let collection_id = Uuid::from_str(&id)?;

let collection_model = collections::Entity::find_by_id(collection_id)
.one(conn)
.await
.context("failed to load collection from db")?
.context("collection not found in db")?;

let mut collection_active_model: collections::ActiveModel = collection_model.clone().into();
let mut creation_status = NftCreationStatus::Completed;

if let MintResult::Success(MintTransaction { signature, address }) = payload {
collection_active_model.signature = Set(Some(signature));
collection_active_model.address = Set(Some(address));
collection_active_model.creation_status = Set(CreationStatus::Created);

let deduction_id = collection_model
.credits_deduction_id
.context("drop has no deduction id")?;
self.credits
.confirm_deduction(TransactionId(deduction_id))
.await?;
} else {
collection_active_model.creation_status = Set(CreationStatus::Failed);
creation_status = NftCreationStatus::Failed;
}

// TODO: add unique event for collection created
self.producer
.send(
Some(&NftEvents {
event: Some(NftEvent::DropCreated(DropCreation {
status: creation_status as i32,
})),
}),
Some(&NftEventKey {
id: collection_model.id.to_string(),
project_id: collection_model.project_id.to_string(),
user_id: collection_model.created_by.to_string(),
}),
)
.await?;

collection_active_model.update(conn).await?;

Ok(())
}

async fn drop_minted(&self, id: String, payload: MintResult) -> Result<()> {
let conn = self.db.get();
let collection_mint_id = Uuid::from_str(&id)?;
Expand Down

0 comments on commit dcfd7e6

Please sign in to comment.