diff --git a/api/src/entities/sea_orm_active_enums.rs b/api/src/entities/sea_orm_active_enums.rs index 824c485..a453bc0 100644 --- a/api/src/entities/sea_orm_active_enums.rs +++ b/api/src/entities/sea_orm_active_enums.rs @@ -55,3 +55,9 @@ pub enum DropType { #[sea_orm(string_value = "open")] Open, } + +impl Default for DropType { + fn default() -> Self { + DropType::Edition + } +} diff --git a/api/src/mutations/drop.rs b/api/src/mutations/drop.rs index 6a8c86d..9e900df 100644 --- a/api/src/mutations/drop.rs +++ b/api/src/mutations/drop.rs @@ -686,7 +686,7 @@ pub struct CreateDropInput { pub blockchain: BlockchainEnum, pub creators: Vec, pub metadata_json: MetadataJsonInput, - #[graphql(name = "type")] + #[graphql(name = "type", default)] pub drop_type: DropType, } diff --git a/api/src/mutations/mint.rs b/api/src/mutations/mint.rs index d85e873..2b33ed3 100644 --- a/api/src/mutations/mint.rs +++ b/api/src/mutations/mint.rs @@ -846,6 +846,9 @@ impl Mutation { }) } + // Add a mint to the queue for a drop. + // The queued mint can be minted by calling `mint_queued` mutation for specific mint + // or `mint_random_queued_to_drop` for random mint. async fn queue_mint_to_drop( &self, ctx: &Context<'_>, @@ -909,6 +912,7 @@ impl Mutation { }) } + /// This mutation mints a specific queued drop mint. async fn mint_queued( &self, ctx: &Context<'_>, @@ -924,6 +928,7 @@ impl Mutation { let credits = ctx.data::>()?; let conn = db.get(); let solana = ctx.data::()?; + let nfts_producer = ctx.data::>()?; let UserID(id) = user_id; let OrganizationId(org) = organization_id; @@ -1011,6 +1016,28 @@ impl Mutation { mint_am.creation_status = Set(CreationStatus::Pending); let mint = mint_am.update(conn).await?; + let drop = drops::Entity::find() + .filter(drops::Column::CollectionId.eq(collection.id)) + .one(conn) + .await? + .ok_or(Error::new("drop not found"))?; + + nfts_producer + .send( + Some(&NftEvents { + event: Some(NftEvent::DropMinted(MintCreation { + drop_id: drop.id.to_string(), + status: NftCreationStatus::InProgress as i32, + })), + }), + Some(&NftEventKey { + id: mint.id.to_string(), + project_id: drop.project_id.to_string(), + user_id: user_id.to_string(), + }), + ) + .await?; + let mint_history_am = mint_histories::ActiveModel { mint_id: Set(mint.id), wallet: Set(input.recipient), @@ -1028,7 +1055,8 @@ impl Mutation { }) } - async fn mint_random_queued( + /// This mutation mints a random queued drop mint. + async fn mint_random_queued_to_drop( &self, ctx: &Context<'_>, input: MintRandomQueuedInput, @@ -1043,6 +1071,7 @@ impl Mutation { let credits = ctx.data::>()?; let conn = db.get(); let solana = ctx.data::()?; + let nfts_producer = ctx.data::>()?; let UserID(id) = user_id; let OrganizationId(org) = organization_id; @@ -1133,6 +1162,34 @@ impl Mutation { mint_am.creation_status = Set(CreationStatus::Pending); let mint = mint_am.update(conn).await?; + let mint_history_am = mint_histories::ActiveModel { + mint_id: Set(mint.id), + wallet: Set(input.recipient), + collection_id: Set(collection.id), + tx_signature: Set(None), + status: Set(CreationStatus::Pending), + created_at: Set(Utc::now().into()), + ..Default::default() + }; + + mint_history_am.insert(conn).await?; + + nfts_producer + .send( + Some(&NftEvents { + event: Some(NftEvent::DropMinted(MintCreation { + drop_id: drop.id.to_string(), + status: NftCreationStatus::InProgress as i32, + })), + }), + Some(&NftEventKey { + id: mint.id.to_string(), + project_id: drop.project_id.to_string(), + user_id: user_id.to_string(), + }), + ) + .await?; + Ok(MintQueuedPayload { collection_mint: mint.into(), })