-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from holaplex/dev
Release - Wallet connection from/to counts, NFT counts, No Dup Attributes
- Loading branch information
Showing
28 changed files
with
569 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Send event to rebuild docs | ||
|
||
on: | ||
push: | ||
branches: [dev, master] | ||
|
||
jobs: | ||
dispatch: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Dispatch event to docs repo | ||
uses: peter-evans/repository-dispatch@v2 | ||
with: | ||
token: ${{ secrets.DOCS_REPO_ACCESS_TOKEN }} | ||
repository: holaplex/marketplace-api-docs | ||
event-type: api_update | ||
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}' |
5 changes: 5 additions & 0 deletions
5
crates/core/migrations/2022-04-07-154737_remove_duplicate_attributes/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
drop table attributes; | ||
|
||
alter table temp_attributes rename to attributes; | ||
|
||
drop function create_temp_attributes_table(); |
34 changes: 34 additions & 0 deletions
34
crates/core/migrations/2022-04-07-154737_remove_duplicate_attributes/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
create function create_temp_attributes_table() | ||
returns void | ||
language plpgsql as | ||
$func$ | ||
begin | ||
if not exists (select from pg_catalog.pg_tables | ||
where schemaname = 'public' | ||
and tablename = 'temp_attributes') then | ||
|
||
alter table attributes rename to temp_attributes; | ||
|
||
create table attributes ( | ||
metadata_address varchar(48) not null, | ||
value text, | ||
trait_type text, | ||
id uuid primary key default gen_random_uuid(), | ||
first_verified_creator varchar(48) null, | ||
unique (metadata_address, value, trait_type) | ||
); | ||
|
||
create index if not exists attr_metadata_address_index on | ||
attributes using hash (metadata_address); | ||
|
||
create index if not exists attr_first_verified_creator_index | ||
on attributes (first_verified_creator); | ||
|
||
create index if not exists attr_trait_type_value_index | ||
on attributes (trait_type, value); | ||
|
||
end if; | ||
end | ||
$func$; | ||
|
||
select create_temp_attributes_table(); |
1 change: 1 addition & 0 deletions
1
crates/core/migrations/2022-04-08-134331_add_buyer_index_to_bid_receipts/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
drop index if exists buyer_bid_receipts_idx; |
2 changes: 2 additions & 0 deletions
2
crates/core/migrations/2022-04-08-134331_add_buyer_index_to_bid_receipts/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
create index if not exists buyer_bid_receipts_idx on | ||
bid_receipts using hash (buyer); |
1 change: 1 addition & 0 deletions
1
crates/core/migrations/2022-04-08-134927_add_seller_index_to_listing_receipts/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
drop index if exists seller_listing_receipts_idx; |
2 changes: 2 additions & 0 deletions
2
crates/core/migrations/2022-04-08-134927_add_seller_index_to_listing_receipts/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
create index if not exists seller_listing_receipts_idx on | ||
listing_receipts using hash (seller); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
//! Query utilities for looking up nft counts | ||
|
||
use diesel::{ | ||
expression::{operators::Eq, AsExpression, NonAggregate}, | ||
pg::Pg, | ||
prelude::*, | ||
query_builder::QueryFragment, | ||
query_source::joins::{Inner, Join, JoinOn}, | ||
serialize::ToSql, | ||
sql_types::Text, | ||
AppearsOnTable, | ||
}; | ||
|
||
use crate::{ | ||
db::{ | ||
any, | ||
tables::{bid_receipts, listing_receipts, metadata_creators, metadatas, token_accounts}, | ||
Connection, | ||
}, | ||
error::prelude::*, | ||
}; | ||
|
||
/// Handles queries for total nfts count | ||
/// | ||
/// # Errors | ||
/// returns an error when the underlying queries throw an error | ||
pub fn total<C: ToSql<Text, Pg>>(conn: &Connection, creators: &[C]) -> Result<i64> { | ||
metadatas::table | ||
.inner_join( | ||
metadata_creators::table.on(metadatas::address.eq(metadata_creators::metadata_address)), | ||
) | ||
.filter(metadata_creators::creator_address.eq(any(creators))) | ||
.filter(metadata_creators::verified.eq(true)) | ||
.count() | ||
.get_result(conn) | ||
.context("failed to load total nfts count") | ||
} | ||
|
||
/// Handles queries for listed nfts count | ||
/// | ||
/// # Errors | ||
/// returns an error when the underlying queries throw an error | ||
pub fn listed<C: ToSql<Text, Pg>, L: ToSql<Text, Pg>>( | ||
conn: &Connection, | ||
creators: &[C], | ||
listed: Option<&[L]>, | ||
) -> Result<i64> { | ||
let mut query = metadatas::table | ||
.inner_join( | ||
metadata_creators::table.on(metadatas::address.eq(metadata_creators::metadata_address)), | ||
) | ||
.inner_join(listing_receipts::table.on(metadatas::address.eq(listing_receipts::metadata))) | ||
.into_boxed(); | ||
|
||
if let Some(listed) = listed { | ||
query = query.filter(listing_receipts::auction_house.eq(any(listed))); | ||
} | ||
|
||
query | ||
.filter(metadata_creators::creator_address.eq(any(creators))) | ||
.filter(metadata_creators::verified.eq(true)) | ||
.filter(listing_receipts::purchase_receipt.is_null()) | ||
.filter(listing_receipts::canceled_at.is_null()) | ||
.count() | ||
.get_result(conn) | ||
.context("failed to load listed nfts count") | ||
} | ||
|
||
/// Handles queries for owned nfts count | ||
/// | ||
/// # Errors | ||
/// returns an error when the underlying queries throw an error | ||
pub fn owned<W: AsExpression<Text>, C: ToSql<Text, Pg>>( | ||
conn: &Connection, | ||
wallet: W, | ||
creators: Option<&[C]>, | ||
) -> Result<i64> | ||
where | ||
W::Expression: NonAggregate | ||
+ QueryFragment<Pg> | ||
+ AppearsOnTable< | ||
JoinOn< | ||
Join< | ||
JoinOn< | ||
Join<metadatas::table, metadata_creators::table, Inner>, | ||
Eq<metadatas::address, metadata_creators::metadata_address>, | ||
>, | ||
token_accounts::table, | ||
Inner, | ||
>, | ||
Eq<metadatas::mint_address, token_accounts::mint_address>, | ||
>, | ||
>, | ||
{ | ||
let mut query = metadatas::table | ||
.inner_join( | ||
metadata_creators::table.on(metadatas::address.eq(metadata_creators::metadata_address)), | ||
) | ||
.inner_join( | ||
token_accounts::table.on(metadatas::mint_address.eq(token_accounts::mint_address)), | ||
) | ||
.into_boxed(); | ||
|
||
if let Some(creators) = creators { | ||
query = query.filter(metadata_creators::creator_address.eq(any(creators))); | ||
} | ||
|
||
query | ||
.filter(metadata_creators::verified.eq(true)) | ||
.filter(token_accounts::amount.eq(1)) | ||
.filter(token_accounts::owner_address.eq(wallet)) | ||
.count() | ||
.get_result(conn) | ||
.context("failed to load owned nfts count") | ||
} | ||
|
||
/// Handles queries for nfts count for a wallet with optional creators and auction house filters | ||
/// | ||
/// # Errors | ||
/// returns an error when the underlying queries throw an error | ||
pub fn offered<W: AsExpression<Text>, C: ToSql<Text, Pg>, H: ToSql<Text, Pg>>( | ||
conn: &Connection, | ||
wallet: W, | ||
creators: Option<&[C]>, | ||
auction_houses: Option<&[H]>, | ||
) -> Result<i64> | ||
where | ||
W::Expression: NonAggregate | ||
+ QueryFragment<Pg> | ||
+ AppearsOnTable< | ||
JoinOn< | ||
Join< | ||
JoinOn< | ||
Join<metadatas::table, metadata_creators::table, Inner>, | ||
Eq<metadatas::address, metadata_creators::metadata_address>, | ||
>, | ||
bid_receipts::table, | ||
Inner, | ||
>, | ||
Eq<metadatas::address, bid_receipts::metadata>, | ||
>, | ||
>, | ||
{ | ||
let mut query = metadatas::table | ||
.inner_join( | ||
metadata_creators::table.on(metadatas::address.eq(metadata_creators::metadata_address)), | ||
) | ||
.inner_join(bid_receipts::table.on(metadatas::address.eq(bid_receipts::metadata))) | ||
.into_boxed(); | ||
|
||
if let Some(auction_houses) = auction_houses { | ||
query = query.filter(bid_receipts::auction_house.eq(any(auction_houses))); | ||
} | ||
|
||
if let Some(creators) = creators { | ||
query = query.filter(metadata_creators::creator_address.eq(any(creators))); | ||
} | ||
|
||
query | ||
.filter(metadata_creators::verified.eq(true)) | ||
.filter(bid_receipts::buyer.eq(wallet)) | ||
.filter(bid_receipts::purchase_receipt.is_null()) | ||
.filter(bid_receipts::canceled_at.is_null()) | ||
.count() | ||
.get_result(conn) | ||
.context("failed to load nfts count of open offers for a wallet") | ||
} | ||
|
||
/// Handles queries for wallet listed nfts count | ||
/// | ||
/// # Errors | ||
/// returns an error when the underlying queries throw an error | ||
pub fn wallet_listed<W: AsExpression<Text>, C: ToSql<Text, Pg>, L: ToSql<Text, Pg>>( | ||
conn: &Connection, | ||
wallet: W, | ||
creators: Option<&[C]>, | ||
listed: Option<&[L]>, | ||
) -> Result<i64> | ||
where | ||
W::Expression: NonAggregate | ||
+ QueryFragment<Pg> | ||
+ AppearsOnTable< | ||
JoinOn< | ||
Join< | ||
JoinOn< | ||
Join<metadatas::table, metadata_creators::table, Inner>, | ||
Eq<metadatas::address, metadata_creators::metadata_address>, | ||
>, | ||
listing_receipts::table, | ||
Inner, | ||
>, | ||
Eq<metadatas::address, listing_receipts::metadata>, | ||
>, | ||
>, | ||
{ | ||
let mut query = metadatas::table | ||
.inner_join( | ||
metadata_creators::table.on(metadatas::address.eq(metadata_creators::metadata_address)), | ||
) | ||
.inner_join(listing_receipts::table.on(metadatas::address.eq(listing_receipts::metadata))) | ||
.into_boxed(); | ||
|
||
if let Some(listed) = listed { | ||
query = query.filter(listing_receipts::auction_house.eq(any(listed))); | ||
} | ||
|
||
if let Some(creators) = creators { | ||
query = query.filter(metadata_creators::creator_address.eq(any(creators))); | ||
} | ||
|
||
query | ||
.filter(metadata_creators::verified.eq(true)) | ||
.filter(listing_receipts::purchase_receipt.is_null()) | ||
.filter(listing_receipts::canceled_at.is_null()) | ||
.filter(listing_receipts::seller.eq(wallet)) | ||
.count() | ||
.get_result(conn) | ||
.context("failed to load listed nfts count") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.