-
Notifications
You must be signed in to change notification settings - Fork 22
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
transaction history: add input addresses, metadata and slots filter #173
Changes from 13 commits
f648cde
368050d
5e736bf
945981b
1e83422
1eb8a0c
d683446
28538c0
b0702f8
e1bca8e
cde3ec4
6568a1f
9906695
9ece156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use sea_schema::migration::prelude::*; | ||
|
||
use entity::block::*; | ||
|
||
pub struct Migration; | ||
|
||
impl MigrationName for Migration { | ||
fn name(&self) -> &str { | ||
"m20240229_000019_add_block_tx_count_column" | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(Entity) | ||
.add_column(ColumnDef::new(Column::TxCount).integer()) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.alter_table( | ||
Table::alter() | ||
.table(Entity) | ||
.drop_column(Column::TxCount) | ||
.to_owned(), | ||
) | ||
.await | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v14.17.0 | ||
lts/hydrogen |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** Types generated for queries found in "app/models/pagination/slotBoundsPagination.sql" */ | ||
import { PreparedQuery } from '@pgtyped/runtime'; | ||
|
||
/** 'SlotBoundsPagination' parameters type */ | ||
export interface ISlotBoundsPaginationParams { | ||
high: number; | ||
low: number; | ||
} | ||
|
||
/** 'SlotBoundsPagination' return type */ | ||
export interface ISlotBoundsPaginationResult { | ||
max_tx_id: string | null; | ||
min_tx_id: string | null; | ||
} | ||
|
||
/** 'SlotBoundsPagination' query type */ | ||
export interface ISlotBoundsPaginationQuery { | ||
params: ISlotBoundsPaginationParams; | ||
result: ISlotBoundsPaginationResult; | ||
} | ||
|
||
const slotBoundsPaginationIR: any = {"usedParamSet":{"low":true,"high":true},"params":[{"name":"low","required":true,"transform":{"type":"scalar"},"locs":[{"a":155,"b":159}]},{"name":"high","required":true,"transform":{"type":"scalar"},"locs":[{"a":409,"b":414}]}],"statement":"WITH\n low_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :low! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT\n 1\n ),\n high_block AS (\n SELECT\n \"Block\".id,\n \"Block\".slot\n FROM\n \"Block\"\n WHERE\n slot <= :high! AND tx_count > 0\n ORDER BY\n \"Block\".id DESC\n LIMIT 1\n ),\n min_hash AS (\n (SELECT\n COALESCE(MAX(\"Transaction\".id), -1) AS min_tx_id\n FROM\n \"Transaction\"\n JOIN low_block ON \"Transaction\".block_id = low_block.id\n GROUP BY\n low_block.slot\n LIMIT\n 1\n )\n UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id))\n ORDER BY min_tx_id DESC\n LIMIT\n 1\n ),\n max_hash AS (\n SELECT\n COALESCE(MAX(\"Transaction\".id), -2) AS max_tx_id\n FROM\n \"Transaction\"\n JOIN high_block ON \"Transaction\".block_id = high_block.id\n GROUP BY\n high_block.slot\n )\nSELECT\n *\nFROM min_hash\nLEFT JOIN max_hash ON 1 = 1"}; | ||
|
||
/** | ||
* Query generated from SQL: | ||
* ``` | ||
* WITH | ||
* low_block AS ( | ||
* SELECT | ||
* "Block".id, | ||
* "Block".slot | ||
* FROM | ||
* "Block" | ||
* WHERE | ||
* slot <= :low! AND tx_count > 0 | ||
* ORDER BY | ||
* "Block".id DESC | ||
* LIMIT | ||
* 1 | ||
* ), | ||
* high_block AS ( | ||
* SELECT | ||
* "Block".id, | ||
* "Block".slot | ||
* FROM | ||
* "Block" | ||
* WHERE | ||
* slot <= :high! AND tx_count > 0 | ||
* ORDER BY | ||
* "Block".id DESC | ||
* LIMIT 1 | ||
* ), | ||
* min_hash AS ( | ||
* (SELECT | ||
* COALESCE(MAX("Transaction".id), -1) AS min_tx_id | ||
* FROM | ||
* "Transaction" | ||
* JOIN low_block ON "Transaction".block_id = low_block.id | ||
* GROUP BY | ||
* low_block.slot | ||
* LIMIT | ||
* 1 | ||
* ) | ||
* UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id)) | ||
* ORDER BY min_tx_id DESC | ||
* LIMIT | ||
* 1 | ||
* ), | ||
* max_hash AS ( | ||
* SELECT | ||
* COALESCE(MAX("Transaction".id), -2) AS max_tx_id | ||
* FROM | ||
* "Transaction" | ||
* JOIN high_block ON "Transaction".block_id = high_block.id | ||
* GROUP BY | ||
* high_block.slot | ||
* ) | ||
* SELECT | ||
* * | ||
* FROM min_hash | ||
* LEFT JOIN max_hash ON 1 = 1 | ||
* ``` | ||
*/ | ||
export const slotBoundsPagination = new PreparedQuery<ISlotBoundsPaginationParams,ISlotBoundsPaginationResult>(slotBoundsPaginationIR); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* @name slotBoundsPagination */ | ||
WITH | ||
low_block AS ( | ||
SELECT | ||
"Block".id, | ||
"Block".slot | ||
FROM | ||
"Block" | ||
WHERE | ||
slot <= :low! AND tx_count > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. This is used later as the Also, the lower bound of the slot range is supposed to be exclusive. Although I've been actually asking myself if this was a good idea or not. So if you ask for 1 as the lower bound, potentially the first tx needs to be at least in slot 2. If we put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth adding a comment to explain this |
||
ORDER BY | ||
"Block".id DESC | ||
LIMIT | ||
1 | ||
), | ||
high_block AS ( | ||
SELECT | ||
"Block".id, | ||
"Block".slot | ||
FROM | ||
"Block" | ||
WHERE | ||
slot <= :high! AND tx_count > 0 | ||
ORDER BY | ||
"Block".id DESC | ||
LIMIT 1 | ||
), | ||
min_hash AS ( | ||
(SELECT | ||
COALESCE(MAX("Transaction".id), -1) AS min_tx_id | ||
FROM | ||
"Transaction" | ||
JOIN low_block ON "Transaction".block_id = low_block.id | ||
GROUP BY | ||
low_block.slot | ||
LIMIT | ||
1 | ||
) | ||
UNION (SELECT min_tx_id FROM (values(-1)) s(min_tx_id)) | ||
ORDER BY min_tx_id DESC | ||
LIMIT | ||
1 | ||
), | ||
max_hash AS ( | ||
SELECT | ||
COALESCE(MAX("Transaction".id), -2) AS max_tx_id | ||
FROM | ||
"Transaction" | ||
JOIN high_block ON "Transaction".block_id = high_block.id | ||
GROUP BY | ||
high_block.slot | ||
) | ||
SELECT | ||
* | ||
FROM min_hash | ||
LEFT JOIN max_hash ON 1 = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really should have comments in the code for things like this otherwise it makes it takes a while to understand what is going on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some comments already, not sure if now it's clear enough.