Skip to content

Commit

Permalink
Merge pull request #167 from holaplex/main
Browse files Browse the repository at this point in the history
Release 8/3
  • Loading branch information
kespinola authored Aug 3, 2023
2 parents 87a0f72 + 0e547a5 commit 7a5770e
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 43 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ strum = { version = "0.24.1", features = ["derive"] }

[dependencies.hub-core]
package = "holaplex-hub-core"
version = "0.2.1"
version = "0.3.1"
git = "https://github.com/holaplex/hub-core"
branch = "stable"
features = ["kafka", "credits", "asset_proxy"]
Expand Down
6 changes: 6 additions & 0 deletions api/src/entities/customer_wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ pub struct Model {
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

impl Entity {
pub fn find_by_address(address: String) -> Select<Self> {
Self::find().filter(Column::Address.eq(address))
}
}
2 changes: 1 addition & 1 deletion api/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl Processor {
let transfer_id = Uuid::from_str(&id)?;

let transfer_charge = transfer_charges::Entity::find()
.filter(transfer_charges::Column::CreditsDeductionId.eq(transfer_id))
.filter(transfer_charges::Column::Id.eq(transfer_id))
.one(conn)
.await?
.context("failed to load transfer charge from db")?;
Expand Down
8 changes: 8 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ pub enum Actions {
RetryMint,
RetryDrop,
TransferAsset,
Mint,
MintCompressed,
CreateCollection,
RetryCollection,
}

impl From<Actions> for hub_core::credits::Action {
Expand All @@ -209,6 +213,10 @@ impl From<Actions> for hub_core::credits::Action {
Actions::RetryMint => hub_core::credits::Action::RetryMint,
Actions::RetryDrop => hub_core::credits::Action::RetryDrop,
Actions::TransferAsset => hub_core::credits::Action::TransferAsset,
Actions::Mint => hub_core::credits::Action::Mint,
Actions::MintCompressed => hub_core::credits::Action::MintCompressed,
Actions::CreateCollection => hub_core::credits::Action::CreateCollection,
Actions::RetryCollection => hub_core::credits::Action::RetryCollection,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/mutations/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Mutation {
balance,
collection: collection.id,
blockchain: input.blockchain,
action: Actions::CreateDrop,
action: Actions::CreateCollection,
})
.await?;

Expand Down Expand Up @@ -246,7 +246,7 @@ impl Mutation {
org_id,
collection: collection.id,
blockchain: collection.blockchain,
action: Actions::RetryDrop,
action: Actions::RetryCollection,
})
.await?;

Expand Down
17 changes: 11 additions & 6 deletions api/src/mutations/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,16 @@ impl Mutation {

let collection = collection.ok_or(Error::new("collection not found"))?;
let blockchain = collection.blockchain;
let compressed = input.compressed.unwrap_or_default();

validate_creators(blockchain, &creators)?;
validate_json(blockchain, &input.metadata_json)?;
check_collection_status(&collection)?;
validate_compress(blockchain, input.compressed)?;
validate_compress(blockchain, compressed)?;

let seller_fee_basis_points = input.seller_fee_basis_points.unwrap_or_default();

let owner_address = fetch_owner(conn, collection.project_id, collection.blockchain).await?;
let owner_address = fetch_owner(conn, collection.project_id, blockchain).await?;

if collection.blockchain == BlockchainEnum::Solana {
validate_solana_creator_verification(&owner_address, &creators)?;
Expand All @@ -378,7 +379,7 @@ impl Mutation {
creation_status: Set(CreationStatus::Pending),
seller_fee_basis_points: Set(collection.seller_fee_basis_points),
created_by: Set(user_id),
compressed: Set(input.compressed),
compressed: Set(compressed),
..Default::default()
};

Expand Down Expand Up @@ -424,7 +425,7 @@ impl Mutation {
.collect::<Result<_>>()?,
}),
recipient_address: input.recipient.to_string(),
compressed: input.compressed,
compressed,
collection_id: collection.id.to_string(),
})
.await?;
Expand Down Expand Up @@ -456,7 +457,11 @@ impl Mutation {
org_id,
mint: collection_mint_model.id,
blockchain: collection.blockchain,
action: Actions::MintEdition,
action: if compressed {
Actions::MintCompressed
} else {
Actions::Mint
},
})
.await?;

Expand Down Expand Up @@ -715,7 +720,7 @@ pub struct MintToCollectionInput {
metadata_json: MetadataJsonInput,
seller_fee_basis_points: Option<u16>,
creators: Vec<Creator>,
compressed: bool,
compressed: Option<bool>,
}

#[derive(Debug, Clone, SimpleObject)]
Expand Down
29 changes: 10 additions & 19 deletions api/src/mutations/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::{Context, Error, InputObject, Object, Result, SimpleObject};
use hub_core::credits::CreditsClient;
use sea_orm::{prelude::*, JoinType, QuerySelect, Set};
use sea_orm::{prelude::*, Set};
use serde::{Deserialize, Serialize};

use super::collection::{validate_evm_address, validate_solana_address};
Expand All @@ -9,8 +9,7 @@ use crate::{
db::Connection,
entities::{
collection_mints::{self, CollectionMint},
collections, customer_wallets, drops,
prelude::{Collections, CustomerWallets, Drops},
prelude::CustomerWallets,
sea_orm_active_enums::{Blockchain, CreationStatus},
transfer_charges,
},
Expand Down Expand Up @@ -68,11 +67,11 @@ impl Mutation {

let TransferAssetInput { id, recipient } = input.clone();

let (collection_mint_model, collection) = collection_mints::Entity::find_by_id(id)
.find_also_related(Collections)
.one(conn)
.await?
.ok_or(Error::new("mint not found"))?;
let (collection_mint_model, collection) =
collection_mints::Entity::find_by_id_with_collection(id)
.one(conn)
.await?
.ok_or(Error::new("mint not found"))?;

if collection_mint_model.creation_status != CreationStatus::Created {
return Err(Error::new("NFT is not minted"));
Expand All @@ -81,20 +80,12 @@ impl Mutation {
let collection = collection.ok_or(Error::new("collection not found"))?;
input.validate_recipient_address(collection.blockchain)?;

let drop = Drops::find()
.join(JoinType::InnerJoin, drops::Relation::Collections.def())
.filter(collections::Column::Id.eq(collection.id))
.one(conn)
.await?
.ok_or(Error::new("drop not found"))?;

let owner_address = collection_mint_model.owner.clone();

CustomerWallets::find()
.filter(customer_wallets::Column::Address.eq(owner_address.clone()))
CustomerWallets::find_by_address(owner_address.clone())
.one(conn)
.await?
.ok_or(Error::new("Sender wallet is not managed by Hub"))?;
.ok_or(Error::new("Sender wallet is not managed by HUB"))?;

let transfer_charges_am = transfer_charges::ActiveModel {
..Default::default()
Expand All @@ -104,7 +95,7 @@ impl Mutation {
let event_key = NftEventKey {
id: transfer_charge_model.id.to_string(),
user_id: user_id.to_string(),
project_id: drop.project_id.to_string(),
project_id: collection.project_id.to_string(),
};

let collection_mint_id = collection_mint_model.id.to_string();
Expand Down
38 changes: 29 additions & 9 deletions credits.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
[MintEdition]
solana = 5
polygon = 10
solana = 60
polygon = 25

[Mint]
solana = 60
polygon = 25

[CreateDrop]
solana = 5
polygon = 15
solana = 40
polygon = 40

[RetryMint]
solana = 5
polygon = 10
solana = 0
polygon = 0

[TransferAsset]
solana = 5
solana = 10
polygon = 10

[CreateWallet]
solana = 10
polygon = 10

[RetryDrop]
solana = 5
polygon = 10
solana = 0
polygon = 0

[CreateCollection]
solana = 40
polygon = 0

[MintCompressed]
solana = 1
polygon = 0

[RetryCollection]
solana = 0
polygon = 0

0 comments on commit 7a5770e

Please sign in to comment.