Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- clear all the data
delete from candy_machine_config_lines;

alter table candy_machine_config_lines
rename column candy_machine_address to address;

alter table candy_machine_config_lines
drop constraint candy_machine_address_idx_pkey,
drop column idx,
drop column taken,
add constraint candy_machine_config_lines_pkey primary key (address);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
alter table candy_machine_config_lines
rename column address to candy_machine_address;

alter table candy_machine_config_lines
add column idx int not null,
add column taken bool not null,
drop constraint candy_machine_config_lines_pkey,
add constraint candy_machine_address_idx_pkey primary key (candy_machine_address, idx);
6 changes: 5 additions & 1 deletion crates/core/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,15 @@ pub struct CandyMachineData<'a> {
#[table_name = "candy_machine_config_lines"]
pub struct CMConfigLine<'a> {
/// ConfigLine account address
pub address: Cow<'a, str>,
pub candy_machine_address: Cow<'a, str>,
/// Name
pub name: Cow<'a, str>,
/// URI pointing to JSON representing the asset
pub uri: Cow<'a, str>,
/// The index of the config line within the candy machine data
pub idx: i32,
/// Bool indicating if this config line has been minted (true) or not minted (false)
pub taken: bool,
}

/// A row in the `candy_machine_creators` table
Expand Down
6 changes: 4 additions & 2 deletions crates/core/src/db/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ table! {
use diesel_full_text_search::{TsVector as Tsvector, TsQuery as Tsquery};
use crate::db::custom_types::{ListingEventLifecycle as Listingeventlifecycle, Mode, ProposalState as Proposalstate, InstructionExecutionFlags as Instructionexecutionflags, ProposalVoteType as Proposalvotetype, OptionVoteResult as Optionvoteresult, MintMaxVoteType as Mintmaxvotetype, VoteTipping as Votetipping, VoteWeightV1 as Voteweightv1, VoteRecordV2Vote as Vote_record_v2_vote, VoteThresholdType as Votethresholdtype, GovernanceAccountType as Governanceaccounttype, TransactionExecutionStatus as Transactionexecutionstatus, OfferEventLifecycle as Offereventlifecycle, SettingType as Settingtype, TokenStandard as Token_standard, };

candy_machine_config_lines (address) {
address -> Varchar,
candy_machine_config_lines (candy_machine_address, idx) {
candy_machine_address -> Varchar,
name -> Text,
uri -> Text,
idx -> Int4,
taken -> Bool,
}
}

Expand Down
46 changes: 22 additions & 24 deletions crates/graphql/src/schema/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use objects::{
ah_purchase::Purchase as AhPurchase,
auction_house::AuctionHouse,
bid_receipt::BidReceipt,
candymachine::{
candy_machine::{
CandyMachine, CandyMachineCollectionPda, CandyMachineConfigLine, CandyMachineCreator,
CandyMachineEndSetting, CandyMachineWhitelistMintSetting,
CandyMachineEndSetting, CandyMachineGateKeeperConfig, CandyMachineHiddenSetting,
CandyMachineWhitelistMintSetting,
},
genopets::{GenoHabitat, GenoRentalAgreement},
graph_connection::GraphConnection,
Expand All @@ -34,10 +35,7 @@ use scalars::{
PublicKey,
};

use super::{
objects::candymachine::{CandyMachineGateKeeperConfig, CandyMachineHiddenSetting},
prelude::*,
};
use super::prelude::*;

#[derive(Clone)]
pub struct AppContext {
Expand All @@ -49,18 +47,18 @@ pub struct AppContext {
pub auction_house_loader: Loader<PublicKey<AuctionHouse>, Option<AuctionHouse>>,
pub bid_receipt_loader: Loader<PublicKey<BidReceipt>, Option<BidReceipt>>,
pub bid_receipts_loader: Loader<PublicKey<Nft>, Vec<BidReceipt>>,
pub candymachine_collection_pda_loader:
pub candy_machine_collection_pda_loader:
Loader<PublicKey<CandyMachine>, Option<CandyMachineCollectionPda>>,
pub candymachine_config_line_loader:
pub candy_machine_config_line_loader:
Loader<PublicKey<CandyMachine>, Vec<CandyMachineConfigLine>>,
pub candymachine_creator_loader: Loader<PublicKey<CandyMachine>, Vec<CandyMachineCreator>>,
pub candymachine_end_settings_loader:
pub candy_machine_creator_loader: Loader<PublicKey<CandyMachine>, Vec<CandyMachineCreator>>,
pub candy_machine_end_settings_loader:
Loader<PublicKey<CandyMachine>, Option<CandyMachineEndSetting>>,
pub candymachine_gatekeeper_configs_loader:
pub candy_machine_gatekeeper_configs_loader:
Loader<PublicKey<CandyMachine>, Option<CandyMachineGateKeeperConfig>>,
pub candymachine_hidden_settings_loader:
pub candy_machine_hidden_settings_loader:
Loader<PublicKey<CandyMachine>, Option<CandyMachineHiddenSetting>>,
pub candymachine_whitelist_mint_settings_loader:
pub candy_machine_whitelist_mint_settings_loader:
Loader<PublicKey<CandyMachine>, Option<CandyMachineWhitelistMintSetting>>,
pub collection_count_loader: Loader<PublicKey<StoreCreator>, Option<i32>>,
pub collection_floor_price_loader: Loader<PublicKey<Collection>, Option<CollectionFloorPrice>>,
Expand Down Expand Up @@ -90,15 +88,15 @@ pub struct AppContext {
pub purchase_receipts_loader: Loader<PublicKey<Nft>, Vec<PurchaseReceipt>>,
pub purchases_loader: Loader<PublicKey<Nft>, Vec<AhPurchase>>,
pub spl_approve_vote_choices_loader: Loader<PublicKey<VoteRecordV2>, Vec<VoteChoice>>,
pub spl_governance_loader: Loader<PublicKey<Governance>, Option<Governance>>,
pub spl_governance_config_loader: Loader<PublicKey<Governance>, Option<GovernanceConfig>>,
pub spl_governance_loader: Loader<PublicKey<Governance>, Option<Governance>>,
pub spl_proposal_loader: Loader<PublicKey<Proposal>, Option<Proposal>>,
pub spl_proposal_multi_choice_loader: Loader<PublicKey<ProposalV2>, Option<MultiChoice>>,
pub spl_proposal_options_loader: Loader<PublicKey<ProposalV2>, Vec<ProposalOption>>,
pub spl_proposalv1_loader: Loader<PublicKey<ProposalV1>, Option<ProposalV1>>,
pub spl_proposalv2_loader: Loader<PublicKey<ProposalV2>, Option<ProposalV2>>,
pub spl_realm_loader: Loader<PublicKey<Realm>, Option<Realm>>,
pub spl_realm_config_loader: Loader<PublicKey<Realm>, Option<RealmConfig>>,
pub spl_realm_loader: Loader<PublicKey<Realm>, Option<Realm>>,
pub spl_token_owner_record_loader:
Loader<PublicKey<TokenOwnerRecord>, Option<TokenOwnerRecord>>,
pub spl_vote_record_token_owner_loader: Loader<PublicKey<Wallet>, Vec<TokenOwnerRecord>>,
Expand Down Expand Up @@ -126,13 +124,13 @@ impl AppContext {
auction_house_loader: Loader::new(batcher.clone()),
bid_receipt_loader: Loader::new(batcher.clone()),
bid_receipts_loader: Loader::new(batcher.clone()),
candymachine_collection_pda_loader: Loader::new(batcher.clone()),
candymachine_config_line_loader: Loader::new(batcher.clone()),
candymachine_creator_loader: Loader::new(batcher.clone()),
candymachine_end_settings_loader: Loader::new(batcher.clone()),
candymachine_gatekeeper_configs_loader: Loader::new(batcher.clone()),
candymachine_hidden_settings_loader: Loader::new(batcher.clone()),
candymachine_whitelist_mint_settings_loader: Loader::new(batcher.clone()),
candy_machine_collection_pda_loader: Loader::new(batcher.clone()),
candy_machine_config_line_loader: Loader::new(batcher.clone()),
candy_machine_creator_loader: Loader::new(batcher.clone()),
candy_machine_end_settings_loader: Loader::new(batcher.clone()),
candy_machine_gatekeeper_configs_loader: Loader::new(batcher.clone()),
candy_machine_hidden_settings_loader: Loader::new(batcher.clone()),
candy_machine_whitelist_mint_settings_loader: Loader::new(batcher.clone()),
collection_count_loader: Loader::new(batcher.clone()),
collection_floor_price_loader: Loader::new(batcher.clone()),
collection_loader: Loader::new(batcher.clone()),
Expand Down Expand Up @@ -161,15 +159,15 @@ impl AppContext {
purchase_receipts_loader: Loader::new(batcher.clone()),
purchases_loader: Loader::new(batcher.clone()),
spl_approve_vote_choices_loader: Loader::new(batcher.clone()),
spl_governance_loader: Loader::new(batcher.clone()),
spl_governance_config_loader: Loader::new(batcher.clone()),
spl_governance_loader: Loader::new(batcher.clone()),
spl_proposal_loader: Loader::new(batcher.clone()),
spl_proposal_multi_choice_loader: Loader::new(batcher.clone()),
spl_proposal_options_loader: Loader::new(batcher.clone()),
spl_proposalv1_loader: Loader::new(batcher.clone()),
spl_proposalv2_loader: Loader::new(batcher.clone()),
spl_realm_loader: Loader::new(batcher.clone()),
spl_realm_config_loader: Loader::new(batcher.clone()),
spl_realm_loader: Loader::new(batcher.clone()),
spl_token_owner_record_loader: Loader::new(batcher.clone()),
spl_vote_record_token_owner_loader: Loader::new(batcher.clone()),
store_auction_houses_loader: Loader::new(batcher.clone()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use objects::candymachine::{
use objects::candy_machine::{
CandyMachine, CandyMachineCollectionPda, CandyMachineConfigLine, CandyMachineCreator,
CandyMachineEndSetting, CandyMachineGateKeeperConfig, CandyMachineHiddenSetting,
CandyMachineWhitelistMintSetting,
Expand Down Expand Up @@ -61,13 +61,13 @@ impl TryBatchFn<PublicKey<CandyMachine>, Vec<CandyMachineConfigLine>> for Batche
let conn = self.db()?;

let rows: Vec<models::CMConfigLine> = candy_machine_config_lines::table
.filter(candy_machine_config_lines::address.eq(any(addresses)))
.filter(candy_machine_config_lines::candy_machine_address.eq(any(addresses)))
.load(&conn)
.context("Failed to candy machine config lines")?;

Ok(rows
.into_iter()
.map(|r| (r.address.clone(), r.try_into()))
.map(|r| (r.candy_machine_address.clone(), r.try_into()))
.batch(addresses))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/graphql/src/schema/dataloaders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod ah_offer;
pub mod ah_purchase;
pub mod auction_house;
pub mod bid_receipt;
pub mod candymachine;
pub mod candy_machine;
pub mod collection;
pub mod genopets;
pub mod graph_connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl CandyMachine {

#[graphql(description = "NOTE - this is currently bugged and will only return one creator")]
pub async fn creators(&self, ctx: &AppContext) -> FieldResult<Vec<CandyMachineCreator>> {
ctx.candymachine_creator_loader
ctx.candy_machine_creator_loader
.load(self.address.clone())
.await
.map_err(Into::into)
Expand All @@ -97,15 +97,15 @@ impl CandyMachine {
&self,
ctx: &AppContext,
) -> FieldResult<Option<CandyMachineCollectionPda>> {
ctx.candymachine_collection_pda_loader
ctx.candy_machine_collection_pda_loader
.load(self.address.clone())
.await
.map_err(Into::into)
}

#[graphql(description = "NOTE - this is currently bugged and will always be empty")]
pub async fn config_lines(&self, ctx: &AppContext) -> FieldResult<Vec<CandyMachineConfigLine>> {
ctx.candymachine_config_line_loader
ctx.candy_machine_config_line_loader
.load(self.address.clone())
.await
.map_err(Into::into)
Expand All @@ -115,7 +115,7 @@ impl CandyMachine {
&self,
ctx: &AppContext,
) -> FieldResult<Option<CandyMachineEndSetting>> {
ctx.candymachine_end_settings_loader
ctx.candy_machine_end_settings_loader
.load(self.address.clone())
.await
.map_err(Into::into)
Expand All @@ -125,7 +125,7 @@ impl CandyMachine {
&self,
ctx: &AppContext,
) -> FieldResult<Option<CandyMachineWhitelistMintSetting>> {
ctx.candymachine_whitelist_mint_settings_loader
ctx.candy_machine_whitelist_mint_settings_loader
.load(self.address.clone())
.await
.map_err(Into::into)
Expand All @@ -135,7 +135,7 @@ impl CandyMachine {
&self,
ctx: &AppContext,
) -> FieldResult<Option<CandyMachineHiddenSetting>> {
ctx.candymachine_hidden_settings_loader
ctx.candy_machine_hidden_settings_loader
.load(self.address.clone())
.await
.map_err(Into::into)
Expand All @@ -145,7 +145,7 @@ impl CandyMachine {
&self,
ctx: &AppContext,
) -> FieldResult<Option<CandyMachineGateKeeperConfig>> {
ctx.candymachine_gatekeeper_configs_loader
ctx.candy_machine_gatekeeper_configs_loader
.load(self.address.clone())
.await
.map_err(Into::into)
Expand Down Expand Up @@ -253,14 +253,26 @@ pub struct CandyMachineConfigLine {
pub candy_machine_address: PublicKey<CandyMachine>,
pub name: String,
pub uri: String,
pub idx: i32,
pub taken: bool,
}

impl<'a> From<models::CMConfigLine<'a>> for CandyMachineConfigLine {
fn from(models::CMConfigLine { address, name, uri }: models::CMConfigLine) -> Self {
fn from(
models::CMConfigLine {
candy_machine_address,
name,
uri,
idx,
taken,
}: models::CMConfigLine,
) -> Self {
Self {
candy_machine_address: address.into(),
candy_machine_address: candy_machine_address.into(),
name: name.into_owned(),
uri: uri.into_owned(),
idx,
taken,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/graphql/src/schema/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod ah_purchase;
pub mod auction_house;
pub mod bid_receipt;
pub mod bonding_change;
pub mod candymachine;
pub mod candy_machine;
pub mod chart;
pub mod creator;
pub mod denylist;
Expand Down
55 changes: 33 additions & 22 deletions crates/graphql/src/schema/query_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use objects::{
auction_house::AuctionHouse,
bid_receipt::BidReceipt,
bonding_change::EnrichedBondingChange,
candymachine::CandyMachine,
candy_machine::CandyMachine,
chart::PriceChart,
creator::Creator,
denylist::Denylist,
Expand Down Expand Up @@ -53,6 +53,29 @@ impl From<AttributeFilter> for queries::metadatas::AttributeFilter {
}
}

impl QueryRoot {
fn candy_machine(context: &AppContext, address: String) -> FieldResult<Option<CandyMachine>> {
let conn = context.shared.db.get()?;

candy_machines::table
.inner_join(
candy_machine_datas::table
.on(candy_machines::address.eq(candy_machine_datas::candy_machine_address)),
)
.filter(candy_machines::address.eq(address))
.select((
candy_machines::all_columns,
candy_machine_datas::all_columns,
))
.first::<(models::CandyMachine, models::CandyMachineData)>(&conn)
.optional()
.context("Failed to load candy machine by address.")?
.map(TryInto::try_into)
.transpose()
.map_err(Into::into)
}
}

#[graphql_object(Context = AppContext)]
impl QueryRoot {
#[graphql(
Expand Down Expand Up @@ -651,30 +674,18 @@ impl QueryRoot {
.map_err(Into::into)
}

#[graphql(description = "Get a candymachine by the candymachine config address")]
fn candymachine(
#[graphql(deprecated = "Deprecated alias for candyMachine")]
fn candymachine(&self, ctx: &AppContext, addr: String) -> FieldResult<Option<CandyMachine>> {
Self::candy_machine(ctx, addr)
}

#[graphql(description = "Get a candy machine by the candy machine config address")]
fn candy_machine(
&self,
context: &AppContext,
#[graphql(description = "address of the candymachine config")] address: String,
#[graphql(description = "address of the candy machine config")] address: String,
) -> FieldResult<Option<CandyMachine>> {
let conn = context.shared.db.get()?;

candy_machines::table
.inner_join(
candy_machine_datas::table
.on(candy_machines::address.eq(candy_machine_datas::candy_machine_address)),
)
.filter(candy_machines::address.eq(address))
.select((
candy_machines::all_columns,
candy_machine_datas::all_columns,
))
.first::<(models::CandyMachine, models::CandyMachineData)>(&conn)
.optional()
.context("Failed to load candy machine by address.")?
.map(TryInto::try_into)
.transpose()
.map_err(Into::into)
Self::candy_machine(context, address)
}

fn storefronts(&self, context: &AppContext) -> FieldResult<Vec<Storefront>> {
Expand Down
Loading