From 8bb298261805fe710dea6c4a570dac9e50b41b81 Mon Sep 17 00:00:00 2001 From: Kyle Espinola Date: Wed, 19 Jul 2023 15:20:51 +0200 Subject: [PATCH] refactor: use master edition transaction message for mcc --- api/src/blockchains/solana.rs | 21 +++-- api/src/mutations/collection.rs | 138 ++++++++++++++++++-------------- 2 files changed, 89 insertions(+), 70 deletions(-) diff --git a/api/src/blockchains/solana.rs b/api/src/blockchains/solana.rs index adcf20f..b2041a6 100644 --- a/api/src/blockchains/solana.rs +++ b/api/src/blockchains/solana.rs @@ -7,9 +7,8 @@ use crate::proto::{ SolanaRetryCreateCollection, SolanaRetryDrop, SolanaRetryMintDrop, SolanaRetryMintToCollection, SolanaTransferAsset, SolanaUpdateCollection, SolanaUpdateDrop, }, - MetaplexCertifiedCollectionTransaction, MetaplexMasterEditionTransaction, - MintMetaplexEditionTransaction, MintMetaplexMetadataTransaction, NftEventKey, NftEvents, - TransferMetaplexAssetTransaction, + MetaplexMasterEditionTransaction, MintMetaplexEditionTransaction, + MintMetaplexMetadataTransaction, NftEventKey, NftEvents, TransferMetaplexAssetTransaction, }; #[derive(Clone)] @@ -31,9 +30,9 @@ impl Solana { MintMetaplexEditionTransaction, MetaplexMasterEditionTransaction, > + TransferEvent - + CollectionEvent< - MetaplexCertifiedCollectionTransaction, - MetaplexCertifiedCollectionTransaction, + + CollectionEvent< + MetaplexMasterEditionTransaction, + MetaplexMasterEditionTransaction, MintMetaplexMetadataTransaction, > { self.clone() @@ -139,15 +138,15 @@ impl TransferEvent for Solana { #[async_trait::async_trait] impl CollectionEvent< - MetaplexCertifiedCollectionTransaction, - MetaplexCertifiedCollectionTransaction, + MetaplexMasterEditionTransaction, + MetaplexMasterEditionTransaction, MintMetaplexMetadataTransaction, > for Solana { async fn create_collection( &self, key: NftEventKey, - payload: MetaplexCertifiedCollectionTransaction, + payload: MetaplexMasterEditionTransaction, ) -> Result<()> { let event = NftEvents { event: Some(SolanaCreateCollection(payload)), @@ -161,7 +160,7 @@ impl async fn retry_create_collection( &self, key: NftEventKey, - payload: MetaplexCertifiedCollectionTransaction, + payload: MetaplexMasterEditionTransaction, ) -> Result<()> { let event = NftEvents { event: Some(SolanaRetryCreateCollection(payload)), @@ -175,7 +174,7 @@ impl async fn update_collection( &self, key: NftEventKey, - payload: MetaplexCertifiedCollectionTransaction, + payload: MetaplexMasterEditionTransaction, ) -> Result<()> { let event = NftEvents { event: Some(SolanaUpdateCollection(payload)), diff --git a/api/src/mutations/collection.rs b/api/src/mutations/collection.rs index 6bfffdd..17227d1 100644 --- a/api/src/mutations/collection.rs +++ b/api/src/mutations/collection.rs @@ -21,8 +21,8 @@ use crate::{ objects::{Collection as CollectionObject, Creator, MetadataJsonInput}, proto::{ nft_events::Event as NftEvent, CreationStatus as NftCreationStatus, - Creator as ProtoCreator, DropCreation, MetaplexCertifiedCollectionTransaction, - MetaplexMetadata, NftEventKey, NftEvents, + Creator as ProtoCreator, DropCreation, MasterEdition, MetaplexMasterEditionTransaction, + NftEventKey, NftEvents, }, Actions, AppContext, NftStorageClient, OrganizationId, UserID, }; @@ -101,20 +101,24 @@ impl Mutation { BlockchainEnum::Solana => { solana .event() - .create_collection(event_key, MetaplexCertifiedCollectionTransaction { - metadata: Some(MetaplexMetadata { - owner_address, - name: metadata_json.name, - symbol: metadata_json.symbol, - metadata_uri: metadata_json.uri, - seller_fee_basis_points: 0, - creators: input - .creators - .into_iter() - .map(TryFrom::try_from) - .collect::>()?, - }), - }) + .create_collection( + event_key, + MetaplexMasterEditionTransaction { + master_edition: Some(MasterEdition { + owner_address, + supply: Some(0), + name: metadata_json.name, + symbol: metadata_json.symbol, + metadata_uri: metadata_json.uri, + seller_fee_basis_points: 0, + creators: input + .creators + .into_iter() + .map(TryFrom::try_from) + .collect::>()?, + }), + }, + ) .await?; }, BlockchainEnum::Ethereum | BlockchainEnum::Polygon => { @@ -122,14 +126,18 @@ impl Mutation { }, }; - submit_pending_deduction(credits, db, DeductionParams { - user_id, - org_id, - balance, - collection: collection.id, - blockchain: input.blockchain, - action: Actions::CreateDrop, - }) + submit_pending_deduction( + credits, + db, + DeductionParams { + user_id, + org_id, + balance, + collection: collection.id, + blockchain: input.blockchain, + action: Actions::CreateDrop, + }, + ) .await?; // TODO: separate event for collection creation @@ -214,23 +222,27 @@ impl Mutation { BlockchainEnum::Solana => { solana .event() - .retry_create_collection(event_key, MetaplexCertifiedCollectionTransaction { - metadata: Some(MetaplexMetadata { - owner_address, - name: metadata_json.name, - symbol: metadata_json.symbol, - metadata_uri: metadata_json.uri, - seller_fee_basis_points: 0, - creators: creators - .into_iter() - .map(|c| ProtoCreator { - address: c.address, - verified: c.verified, - share: c.share, - }) - .collect(), - }), - }) + .retry_create_collection( + event_key, + MetaplexMasterEditionTransaction { + master_edition: Some(MasterEdition { + owner_address, + name: metadata_json.name, + symbol: metadata_json.symbol, + metadata_uri: metadata_json.uri, + seller_fee_basis_points: 0, + supply: Some(0), + creators: creators + .into_iter() + .map(|c| ProtoCreator { + address: c.address, + verified: c.verified, + share: c.share, + }) + .collect(), + }), + }, + ) .await?; }, BlockchainEnum::Polygon | BlockchainEnum::Ethereum => { @@ -238,14 +250,18 @@ impl Mutation { }, }; - submit_pending_deduction(credits, db, DeductionParams { - balance, - user_id, - org_id, - collection: collection.id, - blockchain: collection.blockchain, - action: Actions::RetryDrop, - }) + submit_pending_deduction( + credits, + db, + DeductionParams { + balance, + user_id, + org_id, + collection: collection.id, + blockchain: collection.blockchain, + action: Actions::RetryDrop, + }, + ) .await?; Ok(CreateCollectionPayload { @@ -367,16 +383,20 @@ impl Mutation { solana .event() - .update_collection(event_key, MetaplexCertifiedCollectionTransaction { - metadata: Some(MetaplexMetadata { - owner_address, - name: metadata_json_model.name, - symbol: metadata_json_model.symbol, - metadata_uri: metadata_json_model.uri, - seller_fee_basis_points: 0, - creators, - }), - }) + .update_collection( + event_key, + MetaplexMasterEditionTransaction { + master_edition: Some(MasterEdition { + owner_address, + supply: Some(0), + name: metadata_json_model.name, + symbol: metadata_json_model.symbol, + metadata_uri: metadata_json_model.uri, + seller_fee_basis_points: 0, + creators, + }), + }, + ) .await?; }, BlockchainEnum::Polygon | BlockchainEnum::Ethereum => {