2019-01-22 12:15:29 +00:00
|
|
|
-- +goose Up
|
2018-01-23 18:43:35 +00:00
|
|
|
CREATE VIEW block_stats AS
|
|
|
|
SELECT
|
|
|
|
max(block_number) AS max_block,
|
|
|
|
min(block_number) AS min_block
|
2019-07-18 21:24:25 +00:00
|
|
|
FROM full_sync_logs;
|
2018-01-23 18:43:35 +00:00
|
|
|
|
|
|
|
CREATE VIEW watched_event_logs AS
|
|
|
|
SELECT
|
|
|
|
log_filters.name,
|
2019-07-18 21:24:25 +00:00
|
|
|
full_sync_logs.id,
|
2018-01-23 18:43:35 +00:00
|
|
|
block_number,
|
2019-07-18 21:24:25 +00:00
|
|
|
full_sync_logs.address,
|
2018-01-23 18:43:35 +00:00
|
|
|
tx_hash,
|
|
|
|
index,
|
2019-07-18 21:24:25 +00:00
|
|
|
full_sync_logs.topic0,
|
|
|
|
full_sync_logs.topic1,
|
|
|
|
full_sync_logs.topic2,
|
|
|
|
full_sync_logs.topic3,
|
2018-01-23 18:43:35 +00:00
|
|
|
data,
|
|
|
|
receipt_id
|
|
|
|
FROM log_filters
|
|
|
|
CROSS JOIN block_stats
|
2019-07-18 21:24:25 +00:00
|
|
|
JOIN full_sync_logs ON full_sync_logs.address = log_filters.address
|
|
|
|
AND full_sync_logs.block_number >= coalesce(log_filters.from_block, block_stats.min_block)
|
|
|
|
AND full_sync_logs.block_number <= coalesce(log_filters.to_block, block_stats.max_block)
|
|
|
|
WHERE (log_filters.topic0 = full_sync_logs.topic0 OR log_filters.topic0 ISNULL)
|
|
|
|
AND (log_filters.topic1 = full_sync_logs.topic1 OR log_filters.topic1 ISNULL)
|
|
|
|
AND (log_filters.topic2 = full_sync_logs.topic2 OR log_filters.topic2 ISNULL)
|
|
|
|
AND (log_filters.topic3 = full_sync_logs.topic3 OR log_filters.topic3 ISNULL);
|
2019-01-22 12:15:29 +00:00
|
|
|
|
|
|
|
-- +goose Down
|
|
|
|
DROP VIEW watched_event_logs;
|
|
|
|
DROP VIEW block_stats;
|