Skip to content

Commit

Permalink
refactor: add creators and compressed to collection mints. finish min…
Browse files Browse the repository at this point in the history
…t to collection and retry mint minus creating a purchase record and emitting mint webhook events.
  • Loading branch information
kespinola committed Jul 13, 2023
1 parent 6f3a929 commit 10a67a6
Show file tree
Hide file tree
Showing 20 changed files with 533 additions and 515 deletions.
15 changes: 4 additions & 11 deletions api/src/blockchains/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,15 @@ impl Polygon {
#[must_use]
pub fn event(
&self,
) -> impl DropEvent<
CreateEditionTransaction,
MintEditionTransaction,
UpdateEdtionTransaction,
> + TransferEvent<TransferPolygonAsset> {
) -> impl DropEvent<CreateEditionTransaction, MintEditionTransaction, UpdateEdtionTransaction>
+ TransferEvent<TransferPolygonAsset> {
self.clone()
}
}

#[async_trait::async_trait]
impl
DropEvent<
CreateEditionTransaction,
MintEditionTransaction,
UpdateEdtionTransaction,
> for Polygon
impl DropEvent<CreateEditionTransaction, MintEditionTransaction, UpdateEdtionTransaction>
for Polygon
{
async fn create_drop(&self, key: NftEventKey, payload: CreateEditionTransaction) -> Result<()> {
let event = NftEvents {
Expand Down
2 changes: 1 addition & 1 deletion api/src/blockchains/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Solana {
MintMetaplexEditionTransaction,
MetaplexMasterEditionTransaction,
> + TransferEvent<TransferMetaplexAssetTransaction>
+ CollectionEvent<
+ CollectionEvent<
MetaplexCertifiedCollectionTransaction,
MetaplexCertifiedCollectionTransaction,
MintMetaplexMetadataTransaction,
Expand Down
6 changes: 3 additions & 3 deletions api/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::{
collection_creators::ActiveModel as CollectionCreatorActiveModel,
collections::{ActiveModel, Model},
},
objects::CollectionCreator,
objects::Creator,
};

#[derive(Debug, Clone)]
pub struct Collection {
collection: ActiveModel,
creators: Option<Vec<CollectionCreator>>,
creators: Option<Vec<Creator>>,
}

impl Collection {
Expand All @@ -25,7 +25,7 @@ impl Collection {
}
}

pub fn creators(&mut self, creators: Vec<CollectionCreator>) -> &Collection {
pub fn creators(&mut self, creators: Vec<Creator>) -> &Collection {
self.creators = Some(creators);

self
Expand Down
21 changes: 19 additions & 2 deletions api/src/entities/collection_mints.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.0

use async_graphql::{ComplexObject, Context, Error, Result, SimpleObject};
use sea_orm::entity::prelude::*;
use sea_orm::{entity::prelude::*, JoinType, QuerySelect, SelectTwo};

use super::sea_orm_active_enums::{Blockchain, CreationStatus};
use super::{
collections,
sea_orm_active_enums::{Blockchain, CreationStatus},
};
use crate::{
objects::{Collection, MetadataJson},
AppContext,
Expand All @@ -27,6 +30,7 @@ pub struct Model {
pub edition: i64,
pub seller_fee_basis_points: i16,
pub credits_deduction_id: Option<Uuid>,
pub compressed: bool,
}

/// Represents a single NFT minted from a collection.
Expand Down Expand Up @@ -57,6 +61,8 @@ pub struct CollectionMint {
pub seller_fee_basis_points: i16,
/// credits deduction id
pub credits_deduction_id: Option<Uuid>,
/// Indicates if the NFT is compressed. Compression is only supported on Solana.
pub compressed: bool,
}

#[ComplexObject]
Expand Down Expand Up @@ -104,6 +110,7 @@ impl From<Model> for CollectionMint {
edition,
seller_fee_basis_points,
credits_deduction_id,
compressed,
}: Model,
) -> Self {
Self {
Expand All @@ -118,6 +125,7 @@ impl From<Model> for CollectionMint {
edition,
seller_fee_basis_points,
credits_deduction_id,
compressed,
}
}
}
Expand Down Expand Up @@ -149,3 +157,12 @@ impl Related<super::purchases::Entity> for Entity {
}

impl ActiveModelBehavior for ActiveModel {}

impl Entity {
pub fn find_by_id_with_collection(id: Uuid) -> SelectTwo<Self, collections::Entity> {
Self::find()
.join(JoinType::InnerJoin, Relation::Collections.def())
.select_also(collections::Entity)
.filter(Column::Id.eq(id))
}
}
1 change: 1 addition & 0 deletions api/src/entities/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Model {
#[sea_orm(nullable)]
pub signature: Option<String>,
pub seller_fee_basis_points: i16,
// TODO: add to collections and backfill from the drops
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
60 changes: 60 additions & 0 deletions api/src/entities/mint_creators.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.5

use async_graphql::SimpleObject;
use sea_orm::entity::prelude::*;

use crate::proto;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, SimpleObject)]
#[sea_orm(table_name = "mint_creators")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub collection_mint_id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub address: String,
pub verified: bool,
pub share: i32,
}

impl From<Model> for proto::Creator {
fn from(
Model {
address,
verified,
share,
..
}: Model,
) -> Self {
Self {
address,
verified,
share,
}
}
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::collection_mints::Entity",
from = "Column::CollectionMintId",
to = "super::collection_mints::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
CollectionMints,
}

impl Related<super::collection_mints::Entity> for Entity {
fn to() -> RelationDef {
Relation::CollectionMints.def()
}
}

impl ActiveModelBehavior for ActiveModel {}

impl Entity {
pub fn find_by_collection_mint_id(collection_mint_id: Uuid) -> Select<Self> {
Self::find().filter(Column::CollectionMintId.eq(collection_mint_id))
}
}
1 change: 1 addition & 0 deletions api/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod drops;
pub mod metadata_json_attributes;
pub mod metadata_json_files;
pub mod metadata_jsons;
pub mod mint_creators;
pub mod nft_transfers;
pub mod project_wallets;
pub mod purchases;
Expand Down
5 changes: 3 additions & 2 deletions api/src/entities/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use super::{
collections::Entity as Collections, customer_wallets::Entity as CustomerWallets,
drops::Entity as Drops, metadata_json_attributes::Entity as MetadataJsonAttributes,
metadata_json_files::Entity as MetadataJsonFiles, metadata_jsons::Entity as MetadataJsons,
nft_transfers::Entity as NftTransfers, project_wallets::Entity as ProjectWallets,
purchases::Entity as Purchases, transfer_charges::Entity as TransferCharges,
mint_creators::Entity as MintCreators, nft_transfers::Entity as NftTransfers,
project_wallets::Entity as ProjectWallets, purchases::Entity as Purchases,
transfer_charges::Entity as TransferCharges,
};
8 changes: 4 additions & 4 deletions api/src/metadata_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use crate::{
};
#[derive(Clone, Debug)]
pub struct MetadataJson {
metadata_json: MetadataJsonInput,
uri: Option<String>,
identifier: Option<String>,
pub metadata_json: MetadataJsonInput,
pub uri: Option<String>,
pub identifier: Option<String>,
}

impl MetadataJson {
Expand Down Expand Up @@ -46,7 +46,7 @@ impl MetadataJson {
.await?
.first()
.map(ToOwned::to_owned)
.ok_or_else(|| anyhow!("no metadata_json entry found in db"))?;
.ok_or(anyhow!("no metadata_json entry found in db"))?;

let files = metadata_json_files::Entity::find()
.filter(metadata_json_files::Column::MetadataJsonId.eq(id))
Expand Down
Loading

0 comments on commit 10a67a6

Please sign in to comment.