Skip to content

Commit

Permalink
Merge pull request #154 from holaplex/main
Browse files Browse the repository at this point in the history
Release 07/27
  • Loading branch information
kespinola authored Jul 27, 2023
2 parents 86afe89 + dda0525 commit 1abb102
Show file tree
Hide file tree
Showing 38 changed files with 2,394 additions and 348 deletions.
8 changes: 4 additions & 4 deletions api/proto.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ sha512 = "d75800df0d4744c6b0f4d9a9952d3bfd0bb6b24a8babd19104cc11b54a525f85551b3c

[[schemas]]
subject = "nfts"
version = 19
sha512 = "94be29cc87e02f9622ba880302349b275262bc30546e6a6daacea541a6c1c740df9a185d0e18de782eda77ebf9c51c0e46c295d89abb9f7fb725b0ce9cfaf6f1"
version = 22
sha512 = "c9920f6a5792b067396c88e40b9bd2adfcb55b582734aff924a67a9d5841a5e2839fc734c1bbff66f402f9a9d8852ca5fef1339aaaa3d5b05aa7868ddfa375c1"

[[schemas]]
subject = "organization"
Expand All @@ -20,8 +20,8 @@ sha512 = "c5ddf43d2958ec690ee2261d0ff9808b67ce810d2fc4b6077f96f561929a920f03509f

[[schemas]]
subject = "solana_nfts"
version = 4
sha512 = "272f1aed7d792a5fe5750cdca659091ca1a4a8dd4f36b35f5066ea6bb09cf4f1e905e7e5817dfa6c68d7ea3a8644192b4ff82e7ffcd85b2d9a58e48112a4a8bc"
version = 7
sha512 = "73570b9e58f91a06901ba6455986ce1a0d3675e33860d2447160d711a8cebcfb78cfc714fb08644ad83495dc8612b0b123203561af6d93d29ffb0256725047ba"

[[schemas]]
subject = "timestamp"
Expand Down
4 changes: 2 additions & 2 deletions api/proto.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ endpoint = "https://schemas.holaplex.tools"

[schemas]
organization = 5
nfts = 19
nfts = 22
customer = 2
treasury = 17
solana_nfts = 4
solana_nfts = 7
polygon_nfts = 6
timestamp = 1
51 changes: 17 additions & 34 deletions api/src/blockchains/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod polygon;
pub mod solana;

use hub_core::{anyhow::Result, uuid::Uuid};
use hub_core::anyhow::Result;

use crate::proto::NftEventKey;

Expand All @@ -15,42 +15,25 @@ pub struct TransactionResponse {
pub signed_message_signatures: Vec<String>,
}

/// A trait that defines the fundamental operations that can be performed
/// on a given blockchain for a specific edition of an NFT.
#[async_trait::async_trait]
pub trait Edition<A, B, C, D, E, M> {
/// Creates a new NFT on the blockchain. The specifics of the creation
/// process, such as the parameters it takes and the values it returns,
/// are dependent on the implementation of this method for the specific blockchain.
async fn create(&self, payload: A) -> Result<(M, TransactionResponse)>;

/// Mints a new instance of the NFT on the blockchain. The specifics of the minting
/// process, such as the parameters it takes and the values it returns,
/// are dependent on the implementation of this method for the specific blockchain.
async fn mint(&self, payload: B) -> Result<(M, TransactionResponse)>;

/// Updates an existing collection on the blockchain. The specifics of the update
/// process, such as the parameters it takes and the values it returns,
/// are dependent on the implementation of this method for the specific blockchain.
async fn update(&self, payload: C) -> Result<(M, TransactionResponse)>;

/// Transfers an NFT from one account to another on the blockchain. The specifics of the transfer
/// process, such as the parameters it takes and the values it returns,
/// are dependent on the implementation of this method for the specific blockchain.
async fn transfer(&self, payload: D) -> Result<(Uuid, TransactionResponse)>;

/// Retries a failed drop of an NFT on the blockchain. The specifics of the retry drop
/// process, such as the parameters it takes and the values it returns,
/// are dependent on the implementation of this method for the specific blockchain.
async fn retry_drop(&self, payload: E) -> Result<(M, TransactionResponse)>;
}

#[async_trait::async_trait]
pub trait Event<A, B, C, D> {
pub trait DropEvent<A, B, C> {
async fn create_drop(&self, key: NftEventKey, payload: A) -> Result<()>;
async fn retry_create_drop(&self, key: NftEventKey, payload: A) -> Result<()>;
async fn update_drop(&self, key: NftEventKey, payload: D) -> Result<()>;
async fn update_drop(&self, key: NftEventKey, payload: C) -> Result<()>;
async fn mint_drop(&self, key: NftEventKey, payload: B) -> Result<()>;
async fn retry_mint_drop(&self, key: NftEventKey, payload: B) -> Result<()>;
async fn transfer_asset(&self, key: NftEventKey, payload: C) -> Result<()>;
}

#[async_trait::async_trait]
pub trait CollectionEvent<A, B, C> {
async fn create_collection(&self, key: NftEventKey, payload: A) -> Result<()>;
async fn retry_create_collection(&self, key: NftEventKey, payload: A) -> Result<()>;
async fn update_collection(&self, key: NftEventKey, payload: B) -> Result<()>;
async fn mint_to_collection(&self, key: NftEventKey, payload: C) -> Result<()>;
async fn retry_mint_to_collection(&self, key: NftEventKey, payload: C) -> Result<()>;
}

#[async_trait::async_trait]
pub trait TransferEvent<A> {
async fn transfer_asset(&self, key: NftEventKey, payload: A) -> Result<()>;
}
23 changes: 9 additions & 14 deletions api/src/blockchains/polygon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hub_core::{anyhow::Result, producer::Producer};

use super::Event;
use super::{DropEvent, TransferEvent};
use crate::proto::{
nft_events::Event::{
PolygonCreateDrop, PolygonMintDrop, PolygonRetryDrop, PolygonRetryMintDrop,
Expand All @@ -24,24 +24,15 @@ impl Polygon {
#[must_use]
pub fn event(
&self,
) -> impl Event<
CreateEditionTransaction,
MintEditionTransaction,
TransferPolygonAsset,
UpdateEdtionTransaction,
> {
) -> impl DropEvent<CreateEditionTransaction, MintEditionTransaction, UpdateEdtionTransaction>
+ TransferEvent<TransferPolygonAsset> {
self.clone()
}
}

#[async_trait::async_trait]
impl
Event<
CreateEditionTransaction,
MintEditionTransaction,
TransferPolygonAsset,
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 Expand Up @@ -100,13 +91,17 @@ impl

Ok(())
}
}

#[async_trait::async_trait]
impl TransferEvent<TransferPolygonAsset> for Polygon {
async fn transfer_asset(&self, key: NftEventKey, payload: TransferPolygonAsset) -> Result<()> {
let event = NftEvents {
event: Some(PolygonTransferAsset(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;

Ok(())
}
}
106 changes: 96 additions & 10 deletions api/src/blockchains/solana.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use hub_core::{anyhow::Result, producer::Producer};

use super::Event;
use super::{CollectionEvent, DropEvent, TransferEvent};
use crate::proto::{
nft_events::Event::{
SolanaCreateDrop, SolanaMintDrop, SolanaRetryDrop, SolanaRetryMintDrop,
SolanaTransferAsset, SolanaUpdateDrop,
SolanaCreateCollection, SolanaCreateDrop, SolanaMintDrop, SolanaMintToCollection,
SolanaRetryCreateCollection, SolanaRetryDrop, SolanaRetryMintDrop,
SolanaRetryMintToCollection, SolanaTransferAsset, SolanaUpdateCollection, SolanaUpdateDrop,
},
MetaplexMasterEditionTransaction, MintMetaplexEditionTransaction, NftEventKey, NftEvents,
TransferMetaplexAssetTransaction,
MetaplexMasterEditionTransaction, MintMetaplexEditionTransaction,
MintMetaplexMetadataTransaction, NftEventKey, NftEvents, TransferMetaplexAssetTransaction,
};

#[derive(Clone)]
Expand All @@ -24,22 +25,25 @@ impl Solana {
#[must_use]
pub fn event(
&self,
) -> impl Event<
) -> impl DropEvent<
MetaplexMasterEditionTransaction,
MintMetaplexEditionTransaction,
TransferMetaplexAssetTransaction,
MetaplexMasterEditionTransaction,
> + TransferEvent<TransferMetaplexAssetTransaction>
+ CollectionEvent<
MetaplexMasterEditionTransaction,
MetaplexMasterEditionTransaction,
MintMetaplexMetadataTransaction,
> {
self.clone()
}
}

#[async_trait::async_trait]
impl
Event<
DropEvent<
MetaplexMasterEditionTransaction,
MintMetaplexEditionTransaction,
TransferMetaplexAssetTransaction,
MetaplexMasterEditionTransaction,
> for Solana
{
Expand Down Expand Up @@ -112,13 +116,16 @@ impl

Ok(())
}
}

#[async_trait::async_trait]
impl TransferEvent<TransferMetaplexAssetTransaction> for Solana {
async fn transfer_asset(
&self,
key: NftEventKey,
payload: TransferMetaplexAssetTransaction,
) -> Result<()> {
let event: NftEvents = NftEvents {
let event = NftEvents {
event: Some(SolanaTransferAsset(payload)),
};

Expand All @@ -127,3 +134,82 @@ impl
Ok(())
}
}

#[async_trait::async_trait]
impl
CollectionEvent<
MetaplexMasterEditionTransaction,
MetaplexMasterEditionTransaction,
MintMetaplexMetadataTransaction,
> for Solana
{
async fn create_collection(
&self,
key: NftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaCreateCollection(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;

Ok(())
}

async fn retry_create_collection(
&self,
key: NftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaRetryCreateCollection(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;

Ok(())
}

async fn update_collection(
&self,
key: NftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaUpdateCollection(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;

Ok(())
}

async fn mint_to_collection(
&self,
key: NftEventKey,
payload: MintMetaplexMetadataTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaMintToCollection(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;

Ok(())
}

async fn retry_mint_to_collection(
&self,
key: NftEventKey,
payload: MintMetaplexMetadataTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaRetryMintToCollection(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;

Ok(())
}
}
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
54 changes: 54 additions & 0 deletions api/src/dataloaders/collection_drop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::collections::HashMap;

use async_graphql::{dataloader::Loader as DataLoader, FieldError, Result};
use poem::async_trait;
use sea_orm::{prelude::*, JoinType, QuerySelect};

use crate::{
db::Connection,
entities::{collections, drops},
objects::Drop,
};

#[derive(Debug, Clone)]
pub struct Loader {
pub db: Connection,
}

impl Loader {
#[must_use]
pub fn new(db: Connection) -> Self {
Self { db }
}
}

#[async_trait]
impl DataLoader<Uuid> for Loader {
type Error = FieldError;
type Value = Drop;

async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> {
let drops = drops::Entity::find()
.join(JoinType::InnerJoin, drops::Relation::Collections.def())
.select_also(collections::Entity)
.filter(drops::Column::CollectionId.is_in(keys.iter().map(ToOwned::to_owned)))
.all(self.db.get())
.await?;

drops
.into_iter()
.map(|(drop, collection)| {
Ok((
drop.collection_id,
Drop::new(
drop.clone(),
collection.ok_or(FieldError::new(format!(
"no collection for the drop {}",
drop.id
)))?,
),
))
})
.collect::<Result<HashMap<Uuid, Self::Value>>>()
}
}
Loading

0 comments on commit 1abb102

Please sign in to comment.