Skip to content

Commit

Permalink
Filter listings and offers
Browse files Browse the repository at this point in the history

Co-authored-by: Alcibiades Athens <alcibiades.eth@protonmail.com>
  • Loading branch information
thal0x and 0xAlcibiades authored Sep 27, 2022
1 parent b49ea9c commit ce41c88
Show file tree
Hide file tree
Showing 6 changed files with 566 additions and 50 deletions.
88 changes: 45 additions & 43 deletions sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,20 @@
},
"query": "INSERT INTO offers (position, \"order\", item_type, token, identifier_or_criteria, start_amount, end_amount) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (position, \"order\") DO NOTHING"
},
"9fafe48a36b970d2eb6ff83bd65880dd6fbbcb32dfe4fa7991744a1be9f16ee7": {
"a0d912fb0b10dc88734914b3c16a3213febee0c92279d517ee342414e579354f": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "UPDATE networks SET indexed_block = $2 WHERE network = $1"
},
"ad56503eb85d9ca94d11e4d3562e95fdd20e845d112d431b9b58d6ae1a0af5a4": {
"describe": {
"columns": [
{
Expand Down Expand Up @@ -192,24 +205,12 @@
"Left": [
"Text",
"TextArray",
"Text",
"Int8"
]
}
},
"query": "\n SELECT\n O.hash as \"hash!\",\n O.offerer as \"offerer!\",\n O.zone as \"zone!\",\n O.zone_hash as \"zone_hash!\",\n O.start_time as \"start_time!\",\n O.end_time as \"end_time!\",\n O.order_type as \"order_type!\",\n O.total_original_consideration_items as \"total_original_consideration_items!\",\n O.counter as \"counter!\",\n O.salt as \"salt!\",\n O.conduit_key as \"conduit_key!\",\n O.signature as \"signature!\",\n array_agg(DISTINCT (\n OC.position,\n OC.item_type,\n OC.token,\n OC.identifier_or_criteria,\n OC.start_amount,\n OC.end_amount,\n OC.recipient\n )) AS \"considerations!: Vec<DBConsideration>\",\n array_agg(DISTINCT (\n OOF.position,\n OOF.item_type,\n OOF.token,\n OOF.identifier_or_criteria,\n OOF.start_amount,\n OOF.end_amount\n )) AS \"offers!: Vec<DBOffer>\"\n FROM orders O\n INNER JOIN considerations OC ON O.hash = OC.order\n INNER JOIN offers OOF ON O.hash = OOF.order\n WHERE O.hash IN (\n SELECT OF.order FROM offers OF\n WHERE (OF.token = $1)\n AND (OF.identifier_or_criteria = ANY($2::TEXT[]))\n )\n GROUP BY O.hash\n LIMIT $3;\n "
},
"a0d912fb0b10dc88734914b3c16a3213febee0c92279d517ee342414e579354f": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Left": [
"Int4",
"Int8"
]
}
},
"query": "UPDATE networks SET indexed_block = $2 WHERE network = $1"
"query": "\n SELECT\n O.hash as \"hash!\",\n O.offerer as \"offerer!\",\n O.zone as \"zone!\",\n O.zone_hash as \"zone_hash!\",\n O.start_time as \"start_time!\",\n O.end_time as \"end_time!\",\n O.order_type as \"order_type!\",\n O.total_original_consideration_items as \"total_original_consideration_items!\",\n O.counter as \"counter!\",\n O.salt as \"salt!\",\n O.conduit_key as \"conduit_key!\",\n O.signature as \"signature!\",\n array_agg(DISTINCT (\n OC.position,\n OC.item_type,\n OC.token,\n OC.identifier_or_criteria,\n OC.start_amount,\n OC.end_amount,\n OC.recipient\n )) AS \"considerations!: Vec<DBConsideration>\",\n array_agg(DISTINCT (\n OOF.position,\n OOF.item_type,\n OOF.token,\n OOF.identifier_or_criteria,\n OOF.start_amount,\n OOF.end_amount\n )) AS \"offers!: Vec<DBOffer>\"\n FROM orders O\n INNER JOIN considerations OC ON O.hash = OC.order\n INNER JOIN offers OOF ON O.hash = OOF.order\n WHERE O.hash IN (\n SELECT C.order FROM considerations C \n WHERE (C.token = $1 OR $1 = '0x0000000000000000000000000000000000000000000000000000000000000000')\n AND (C.identifier_or_criteria = ANY($2::TEXT[]) OR cardinality($2::TEXT[]) = 0)\n )\n AND (O.offerer = $3 OR $3 = '0x0000000000000000000000000000000000000000000000000000000000000000')\n GROUP BY O.hash\n LIMIT $4;\n "
},
"b4b0f2f367afd2f81a8c130f30519e10232bfce97ca55ad84224fe420fd33dcc": {
"describe": {
Expand Down Expand Up @@ -237,33 +238,7 @@
},
"query": "UPDATE orders SET finalized = $2 WHERE hash = $1"
},
"eb8ce485fbb3e88ecc676e8eed36873ec611eea11c581efb36efaa9d9ffd8ffe": {
"describe": {
"columns": [
{
"name": "network",
"ordinal": 0,
"type_info": "Int4"
},
{
"name": "indexed_block",
"ordinal": 1,
"type_info": "Int8"
}
],
"nullable": [
false,
false
],
"parameters": {
"Left": [
"Int4"
]
}
},
"query": "SELECT network, indexed_block FROM networks WHERE network = $1"
},
"fa47dfaf5042afb6cca933bce92375167a9125f8cd3cecdb792f225cf972a627": {
"e2b72acd1c68faea3654345ea3b1f98bba91eca4035a478111fd9662933e1633": {
"describe": {
"columns": [
{
Expand Down Expand Up @@ -357,10 +332,37 @@
"Left": [
"Text",
"TextArray",
"Text",
"Int8"
]
}
},
"query": "\n SELECT\n O.hash as \"hash!\",\n O.offerer as \"offerer!\",\n O.zone as \"zone!\",\n O.zone_hash as \"zone_hash!\",\n O.start_time as \"start_time!\",\n O.end_time as \"end_time!\",\n O.order_type as \"order_type!\",\n O.total_original_consideration_items as \"total_original_consideration_items!\",\n O.counter as \"counter!\",\n O.salt as \"salt!\",\n O.conduit_key as \"conduit_key!\",\n O.signature as \"signature!\",\n array_agg(DISTINCT (\n OC.position,\n OC.item_type,\n OC.token,\n OC.identifier_or_criteria,\n OC.start_amount,\n OC.end_amount,\n OC.recipient\n )) AS \"considerations!: Vec<DBConsideration>\",\n array_agg(DISTINCT (\n OOF.position,\n OOF.item_type,\n OOF.token,\n OOF.identifier_or_criteria,\n OOF.start_amount,\n OOF.end_amount\n )) AS \"offers!: Vec<DBOffer>\"\n FROM orders O\n INNER JOIN considerations OC ON O.hash = OC.order\n INNER JOIN offers OOF ON O.hash = OOF.order\n WHERE O.hash IN (\n SELECT C.order FROM considerations C \n WHERE (C.token = $1)\n AND (C.identifier_or_criteria = ANY($2::TEXT[]))\n )\n GROUP BY O.hash\n LIMIT $3;\n "
"query": "\n SELECT\n O.hash as \"hash!\",\n O.offerer as \"offerer!\",\n O.zone as \"zone!\",\n O.zone_hash as \"zone_hash!\",\n O.start_time as \"start_time!\",\n O.end_time as \"end_time!\",\n O.order_type as \"order_type!\",\n O.total_original_consideration_items as \"total_original_consideration_items!\",\n O.counter as \"counter!\",\n O.salt as \"salt!\",\n O.conduit_key as \"conduit_key!\",\n O.signature as \"signature!\",\n array_agg(DISTINCT (\n OC.position,\n OC.item_type,\n OC.token,\n OC.identifier_or_criteria,\n OC.start_amount,\n OC.end_amount,\n OC.recipient\n )) AS \"considerations!: Vec<DBConsideration>\",\n array_agg(DISTINCT (\n OOF.position,\n OOF.item_type,\n OOF.token,\n OOF.identifier_or_criteria,\n OOF.start_amount,\n OOF.end_amount\n )) AS \"offers!: Vec<DBOffer>\"\n FROM orders O\n INNER JOIN considerations OC ON O.hash = OC.order\n INNER JOIN offers OOF ON O.hash = OOF.order\n WHERE O.hash IN (\n SELECT OF.order FROM offers OF\n WHERE (OF.token = $1 OR $1 = '0x0000000000000000000000000000000000000000000000000000000000000000')\n AND (OF.identifier_or_criteria = ANY($2::TEXT[]) OR cardinality($2::TEXT[]) = 0)\n )\n AND (O.offerer = $3 OR $3 = '0x0000000000000000000000000000000000000000000000000000000000000000')\n GROUP BY O.hash\n LIMIT $4;\n "
},
"eb8ce485fbb3e88ecc676e8eed36873ec611eea11c581efb36efaa9d9ffd8ffe": {
"describe": {
"columns": [
{
"name": "network",
"ordinal": 0,
"type_info": "Int4"
},
{
"name": "indexed_block",
"ordinal": 1,
"type_info": "Int8"
}
],
"nullable": [
false,
false
],
"parameters": {
"Left": [
"Int4"
]
}
},
"query": "SELECT network, indexed_block FROM networks WHERE network = $1"
}
}
10 changes: 7 additions & 3 deletions src/routes/retrieve_listings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async fn listings(query: web::Query<OrderQuery>, pool: web::Data<PgPool>) -> imp
})
.collect::<Vec<String>>()
.as_slice(),
query.offerer.encode_hex(),
query.limit,
)
.await
Expand All @@ -48,6 +49,7 @@ async fn retrieve_listings(
pool: &PgPool,
asset_contract_address: String,
token_ids: &[String],
offerer: String,
limit: Option<i64>,
) -> Result<RetrieveResponse, Error> {
let db_orders: Vec<DBOrder> = query_as!(
Expand Down Expand Up @@ -88,14 +90,16 @@ async fn retrieve_listings(
INNER JOIN offers OOF ON O.hash = OOF.order
WHERE O.hash IN (
SELECT OF.order FROM offers OF
WHERE (OF.token = $1)
AND (OF.identifier_or_criteria = ANY($2::TEXT[]))
WHERE (OF.token = $1 OR $1 = '0x0000000000000000000000000000000000000000000000000000000000000000')
AND (OF.identifier_or_criteria = ANY($2::TEXT[]) OR cardinality($2::TEXT[]) = 0)
)
AND (O.offerer = $3 OR $3 = '0x0000000000000000000000000000000000000000000000000000000000000000')
GROUP BY O.hash
LIMIT $3;
LIMIT $4;
"#,
asset_contract_address,
&token_ids[..],
offerer,
limit.unwrap_or(1)
)
.fetch_all(pool)
Expand Down
10 changes: 7 additions & 3 deletions src/routes/retrieve_offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async fn offers(query: web::Query<OrderQuery>, pool: web::Data<PgPool>) -> impl
})
.collect::<Vec<String>>()
.as_slice(),
query.offerer.encode_hex(),
query.limit,
)
.await
Expand All @@ -48,6 +49,7 @@ async fn retrieve_offers(
pool: &PgPool,
asset_contract_address: String,
token_ids: &[String],
offerer: String,
limit: Option<i64>,
) -> Result<RetrieveResponse, Error> {
let db_orders: Vec<DBOrder> = query_as!(
Expand Down Expand Up @@ -88,14 +90,16 @@ async fn retrieve_offers(
INNER JOIN offers OOF ON O.hash = OOF.order
WHERE O.hash IN (
SELECT C.order FROM considerations C
WHERE (C.token = $1)
AND (C.identifier_or_criteria = ANY($2::TEXT[]))
WHERE (C.token = $1 OR $1 = '0x0000000000000000000000000000000000000000000000000000000000000000')
AND (C.identifier_or_criteria = ANY($2::TEXT[]) OR cardinality($2::TEXT[]) = 0)
)
AND (O.offerer = $3 OR $3 = '0x0000000000000000000000000000000000000000000000000000000000000000')
GROUP BY O.hash
LIMIT $3;
LIMIT $4;
"#,
asset_contract_address,
&token_ids[..],
offerer,
limit.unwrap_or(1)
)
.fetch_all(pool)
Expand Down
5 changes: 4 additions & 1 deletion src/structs/seaport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ use crate::seaport::{ConsiderationItem, OfferItem, Order, OrderComponents};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct OrderQuery {
#[serde(default)]
pub asset_contract_address: H160,
#[serde(deserialize_with = "token_ids_deserialize")]
#[serde(deserialize_with = "token_ids_deserialize", default)]
pub token_ids: Vec<String>,
#[serde(default)]
pub offerer: H160,
pub limit: Option<i64>,
}

Expand Down
Loading

0 comments on commit ce41c88

Please sign in to comment.