Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sana): reset listing fields on transfer event #449

Merged
Merged
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
14 changes: 9 additions & 5 deletions crates/sana/src/storage/sqlx/default_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl PostgresStorage {
async fn get_block_by_timestamp(&self, ts: u64) -> Result<Option<BlockData>, StorageError> {
let q = "SELECT b.block_number, b.block_status, b.block_timestamp, b.indexer_identifier, i.indexer_version
FROM block as b
INNER JOIN indexer as i ON i.indexer_identifier = b.indexer_identifier
INNER JOIN indexer as i ON i.indexer_identifier = b.indexer_identifier
WHERE block_timestamp = $1";

match sqlx::query(q).bind(ts as i64).fetch_all(&self.pool).await {
Expand Down Expand Up @@ -347,7 +347,11 @@ impl Storage for PostgresStorage {
AND te.event_type IN ('Transfer', 'Burn', 'Mint')
ORDER BY te.block_timestamp DESC
LIMIT 1
)
),
listing_orderhash = null,
listing_start_date = null,
listing_end_date = null,
listing_start_amount = null, listing_end_amount = null
WHERE t.contract_address = $1 AND t.token_id = $2 AND t.chain_id = $3 RETURNING t.current_owner";

let current_owner: Option<String> = sqlx::query_scalar(update_query)
Expand Down Expand Up @@ -450,8 +454,8 @@ impl Storage for PostgresStorage {
}
let _r = if (self.get_block_by_timestamp(block_timestamp).await?).is_some() {
let q = r#"
UPDATE block
SET block_number = $1, block_status = $2, indexer_identifier = $3
UPDATE block
SET block_number = $1, block_status = $2, indexer_identifier = $3
WHERE block_timestamp = $4;
"#;
sqlx::query(q)
Expand Down Expand Up @@ -480,7 +484,7 @@ impl Storage for PostgresStorage {

let q = "SELECT b.block_number, b.block_status, b.block_timestamp, b.indexer_identifier, i.indexer_version
FROM block as b
LEFT JOIN indexer as i ON i.indexer_identifier = b.indexer_identifier
LEFT JOIN indexer as i ON i.indexer_identifier = b.indexer_identifier
WHERE block_number = $1";

match sqlx::query_as::<_, BlockData>(q)
Expand Down
Loading