Skip to content

Commit

Permalink
Merge pull request #221 from holaplex/abdul/open-drop
Browse files Browse the repository at this point in the history
Open Drop API
  • Loading branch information
imabdulbasit authored Sep 14, 2023
2 parents 0106920 + 3ab49bf commit 6d202cb
Show file tree
Hide file tree
Showing 23 changed files with 945 additions and 210 deletions.
12 changes: 6 additions & 6 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 = 28
sha512 = "25960e99e2eb1edeb70b7619918926d877b834640cf44fcc8104da5be6e213c05be18f8f49dba35e649d751bc62e16d9ca428cbafdb432b7c0b7f40a6cef7483"
version = 29
sha512 = "b3b2136bd6c7a136d317da84395661de5fc056e8270510575a3281d78884d99a0d89f444754ed02cb18ad26dcc7cd65300c1df73b9d74d2edc6bcc8d552465d0"

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

[[schemas]]
subject = "solana_nfts"
version = 10
sha512 = "1bcb166ab5dfdf4841d60caa07a4098dcec03d7e3b0e63adb090ed2f5fe990c1e13826867e8df7521ec631027d5a931a08865fd2cf2daa905807c4b7dca40213"
version = 11
sha512 = "967fefde938a0f6ce05194e4fca15673e681caac54d8aeec114c5d38418632b9696dbaf5362345a15114e5abb49de55d0af8b9edcc0f2c91f9ef1ccc4ff55d68"

[[schemas]]
subject = "timestamp"
Expand All @@ -30,5 +30,5 @@ sha512 = "d167e0a143c813073eef8597f0b237e5a8eaf32abbf709724e8071b2dd73ce0438b82f

[[schemas]]
subject = "treasury"
version = 22
sha512 = "bde788b07f818aa52e684dcbd91e1f1e3db82f242f616ec2a42ab6d412df33a1461677c229f2f9bae345938c2f325e6332a95caef2c7e01a47531af53e39bf03"
version = 23
sha512 = "0e4d77999767d5971122e720c1cee7a57c3e47ce69f58a582f1762d8e65e031ea3bd9024cfc21bd7da5db6e38a71657151c58cdfa21d9ff643fb2fc657105cf5"
6 changes: 3 additions & 3 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 = 28
nfts = 29
customer = 2
treasury = 22
solana_nfts = 10
treasury = 23
solana_nfts = 11
polygon_nfts = 6
timestamp = 1
18 changes: 13 additions & 5 deletions api/src/blockchains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ pub mod solana;

use hub_core::anyhow::Result;

use crate::proto::{
NftEventKey, RetryUpdateSolanaMintPayload, SwitchCollectionPayload, UpdateSolanaMintPayload,
use crate::{
entities::sea_orm_active_enums::DropType,
proto::{
NftEventKey, RetryUpdateSolanaMintPayload, SwitchCollectionPayload, UpdateSolanaMintPayload,
},
};

/// Represents a response from a transaction on the blockchain. This struct
Expand All @@ -19,9 +22,14 @@ pub struct TransactionResponse {

#[async_trait::async_trait]
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: C) -> Result<()>;
async fn create_drop(&self, drop_type: DropType, key: NftEventKey, payload: A) -> Result<()>;
async fn retry_create_drop(
&self,
drop_type: DropType,
key: NftEventKey,
payload: A,
) -> Result<()>;
async fn update_drop(&self, drop_type: DropType, 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<()>;
}
Expand Down
85 changes: 57 additions & 28 deletions api/src/blockchains/polygon.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use hub_core::{anyhow::Result, producer::Producer};
use hub_core::{anyhow::Result, prelude::bail, producer::Producer};

use super::{DropEvent, TransferEvent};
use crate::proto::{
nft_events::Event::{
PolygonCreateDrop, PolygonMintDrop, PolygonRetryDrop, PolygonRetryMintDrop,
PolygonTransferAsset, PolygonUpdateDrop,
use crate::{
entities::sea_orm_active_enums::DropType,
proto::{
nft_events::Event::{
PolygonCreateDrop, PolygonMintDrop, PolygonRetryDrop, PolygonRetryMintDrop,
PolygonTransferAsset, PolygonUpdateDrop,
},
CreateEditionTransaction, MintEditionTransaction, NftEventKey, NftEvents,
TransferPolygonAsset, UpdateEdtionTransaction,
},
CreateEditionTransaction, MintEditionTransaction, NftEventKey, NftEvents, TransferPolygonAsset,
UpdateEdtionTransaction,
};

#[derive(Clone)]
Expand All @@ -34,46 +37,69 @@ impl Polygon {
impl DropEvent<CreateEditionTransaction, MintEditionTransaction, UpdateEdtionTransaction>
for Polygon
{
async fn create_drop(&self, key: NftEventKey, payload: CreateEditionTransaction) -> Result<()> {
let event = NftEvents {
event: Some(PolygonCreateDrop(payload)),
async fn create_drop(
&self,
drop_type: DropType,
key: NftEventKey,
payload: CreateEditionTransaction,
) -> Result<()> {
let event = match drop_type {
DropType::Edition => Some(PolygonCreateDrop(payload)),
DropType::Open => bail!("Open drops are not supported on Polygon"),
};

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

Ok(())
}

async fn retry_create_drop(
&self,
drop_type: DropType,
key: NftEventKey,
payload: CreateEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(PolygonRetryDrop(payload)),
let event = match drop_type {
DropType::Edition => Some(PolygonRetryDrop(payload)),
DropType::Open => bail!("Open drops are not supported on Polygon"),
};

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

Ok(())
}

async fn update_drop(&self, key: NftEventKey, payload: UpdateEdtionTransaction) -> Result<()> {
let event = NftEvents {
event: Some(PolygonUpdateDrop(payload)),
async fn update_drop(
&self,
drop_type: DropType,
key: NftEventKey,
payload: UpdateEdtionTransaction,
) -> Result<()> {
let event = match drop_type {
DropType::Edition => Some(PolygonUpdateDrop(payload)),
DropType::Open => bail!("Open drops are not supported on Polygon"),
};

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

Ok(())
}

async fn mint_drop(&self, key: NftEventKey, payload: MintEditionTransaction) -> Result<()> {
let event = NftEvents {
event: Some(PolygonMintDrop(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;
self.producer
.send(
Some(&NftEvents {
event: Some(PolygonMintDrop(payload)),
}),
Some(&key),
)
.await?;

Ok(())
}
Expand All @@ -83,11 +109,14 @@ impl DropEvent<CreateEditionTransaction, MintEditionTransaction, UpdateEdtionTra
key: NftEventKey,
payload: MintEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(PolygonRetryMintDrop(payload)),
};

self.producer.send(Some(&event), Some(&key)).await?;
self.producer
.send(
Some(&NftEvents {
event: Some(PolygonRetryMintDrop(payload)),
}),
Some(&key),
)
.await?;

Ok(())
}
Expand Down
95 changes: 58 additions & 37 deletions api/src/blockchains/solana.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
use hub_core::{anyhow::Result, producer::Producer};

use super::{CollectionEvent, DropEvent, TransferEvent};
use crate::proto::{
nft_events::Event::{
SolanaCreateCollection, SolanaCreateDrop, SolanaMintDrop, SolanaMintToCollection,
SolanaRetryCreateCollection, SolanaRetryDrop, SolanaRetryMintDrop,
SolanaRetryMintToCollection, SolanaRetryUpdatedCollectionMint,
SolanaSwitchMintCollectionRequested, SolanaTransferAsset, SolanaUpdateCollection,
SolanaUpdateDrop, SolanaUpdatedCollectionMint,
use crate::{
entities::sea_orm_active_enums::DropType,
proto::{
nft_events::Event::{
SolanaCreateCollection, SolanaCreateEditionDrop, SolanaCreateOpenDrop,
SolanaMintEditionDrop, SolanaMintOpenDrop, SolanaMintToCollection,
SolanaRetryCreateCollection, SolanaRetryEditionDrop, SolanaRetryMintEditionDrop,
SolanaRetryMintOpenDrop, SolanaRetryMintToCollection, SolanaRetryOpenDrop,
SolanaRetryUpdatedCollectionMint, SolanaSwitchMintCollectionRequested,
SolanaTransferAsset, SolanaUpdateCollection, SolanaUpdateEditionDrop,
SolanaUpdateOpenDrop, SolanaUpdatedCollectionMint,
},
MetaplexMasterEditionTransaction, MintMetaplexEditionTransaction,
MintMetaplexMetadataTransaction, NftEventKey, NftEvents, RetryUpdateSolanaMintPayload,
SwitchCollectionPayload, TransferMetaplexAssetTransaction, UpdateSolanaMintPayload,
},
MetaplexMasterEditionTransaction, MintMetaplexEditionTransaction,
MintMetaplexMetadataTransaction, NftEventKey, NftEvents, RetryUpdateSolanaMintPayload,
SwitchCollectionPayload, TransferMetaplexAssetTransaction, UpdateSolanaMintPayload,
};

#[derive(Clone)]
pub struct Solana {
producer: Producer<NftEvents>,
}

pub enum MintDropTransaction {
Edition(MintMetaplexEditionTransaction),
Open(MintMetaplexMetadataTransaction),
}

impl Solana {
#[must_use]
pub fn new(producer: Producer<NftEvents>) -> Self {
Expand All @@ -29,7 +40,7 @@ impl Solana {
&self,
) -> impl DropEvent<
MetaplexMasterEditionTransaction,
MintMetaplexEditionTransaction,
MintDropTransaction,
MetaplexMasterEditionTransaction,
> + TransferEvent<TransferMetaplexAssetTransaction>
+ CollectionEvent<
Expand All @@ -45,76 +56,86 @@ impl Solana {
impl
DropEvent<
MetaplexMasterEditionTransaction,
MintMetaplexEditionTransaction,
MintDropTransaction,
MetaplexMasterEditionTransaction,
> for Solana
{
async fn create_drop(
&self,
drop_type: DropType,
key: NftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaCreateDrop(payload)),
let event = match drop_type {
DropType::Edition => Some(SolanaCreateEditionDrop(payload)),
DropType::Open => Some(SolanaCreateOpenDrop(payload)),
};

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

Ok(())
}

async fn retry_create_drop(
&self,
drop_type: DropType,
key: NftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaRetryDrop(payload)),
let event = match drop_type {
DropType::Edition => Some(SolanaRetryEditionDrop(payload)),
DropType::Open => Some(SolanaRetryOpenDrop(payload)),
};

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

Ok(())
}

async fn update_drop(
&self,
drop_type: DropType,
key: NftEventKey,
payload: MetaplexMasterEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaUpdateDrop(payload)),
let event = match drop_type {
DropType::Edition => Some(SolanaUpdateEditionDrop(payload)),
DropType::Open => Some(SolanaUpdateOpenDrop(payload)),
};

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

Ok(())
}

async fn mint_drop(
&self,
key: NftEventKey,
payload: MintMetaplexEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaMintDrop(payload)),
async fn mint_drop(&self, key: NftEventKey, payload: MintDropTransaction) -> Result<()> {
let event = match payload {
MintDropTransaction::Edition(p) => Some(SolanaMintEditionDrop(p)),
MintDropTransaction::Open(p) => Some(SolanaMintOpenDrop(p)),
};

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

Ok(())
}

async fn retry_mint_drop(
&self,
key: NftEventKey,
payload: MintMetaplexEditionTransaction,
) -> Result<()> {
let event = NftEvents {
event: Some(SolanaRetryMintDrop(payload)),
async fn retry_mint_drop(&self, key: NftEventKey, payload: MintDropTransaction) -> Result<()> {
let event = match payload {
MintDropTransaction::Edition(tx) => Some(SolanaRetryMintEditionDrop(tx)),
MintDropTransaction::Open(tx) => Some(SolanaRetryMintOpenDrop(tx)),
};

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

Ok(())
}
Expand Down
11 changes: 5 additions & 6 deletions api/src/dataloaders/collection_mints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ impl DataLoader<String> for OwnerLoader {
Ok(collection_mints
.into_iter()
.fold(HashMap::new(), |mut acc, collection_mint| {
acc.entry(collection_mint.owner.clone())
.or_insert_with(Vec::new);

acc.entry(collection_mint.owner.clone())
.and_modify(|collection_mints| collection_mints.push(collection_mint.into()));

if let Some(owner) = collection_mint.owner.clone() {
acc.entry(owner)
.or_insert_with(Vec::new)
.push(collection_mint.into());
}
acc
}))
}
Expand Down
Loading

0 comments on commit 6d202cb

Please sign in to comment.