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

adjust query to support ordering #107

Merged
merged 28 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-namespace": "off"
},
"overrides": [
{
"files": ["src/schema.ts"],
Expand Down
3 changes: 3 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
}

type EventData {
accountUpdateId: String!

Check notice on line 26 in schema.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector

Field 'accountUpdateId' was added to object type 'EventData'

Field 'accountUpdateId' was added to object type 'EventData'
transactionInfo: TransactionInfo
data: [String]!
}
Expand Down Expand Up @@ -50,6 +51,8 @@
hash: String!
memo: String!
authorizationKind: String!
sequenceNumber: Int! # TODO: Is it ok to make this required?

Check notice on line 54 in schema.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector

Field 'sequenceNumber' was added to object type 'TransactionInfo'

Field 'sequenceNumber' was added to object type 'TransactionInfo'
zkappAccountUpdateIds: [Int]!

Check notice on line 55 in schema.graphql

View workflow job for this annotation

GitHub Actions / GraphQL Inspector

Field 'zkappAccountUpdateIds' was added to object type 'TransactionInfo'

Field 'zkappAccountUpdateIds' was added to object type 'TransactionInfo'
}

type ActionStates {
Expand Down
3 changes: 3 additions & 0 deletions src/blockchain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum BlockStatusFilter {
}

export type Event = {
accountUpdateId: string;
transactionInfo: TransactionInfo;
data: string[];
};
Expand Down Expand Up @@ -41,6 +42,8 @@ export type TransactionInfo = {
hash: string;
memo: string;
authorizationKind: string;
sequenceNumber: number;
zkappAccountUpdateIds: number[];
};

export type Events = {
Expand Down
4 changes: 4 additions & 0 deletions src/blockchain/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ export function createTransactionInfo(
hash: row.hash,
memo: row.memo,
authorizationKind: row.authorization_kind,
sequenceNumber: row.sequence_number,
zkappAccountUpdateIds: row.zkapp_account_updates_ids,
};
}

export function createEvent(
accountUpdateId: string,
data: string[],
transactionInfo: TransactionInfo
): Event {
return {
accountUpdateId,
data,
transactionInfo,
};
Expand Down
153 changes: 140 additions & 13 deletions src/db/sql/events-actions/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,23 @@ function emittedZkAppCommandsCTE(db_client: postgres.Sql) {
return db_client`
emitted_zkapp_commands AS (
SELECT
blocks_accessed.*,
blocks_accessed.requesting_zkapp_account_identifier_id,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanding * queries is optional, but I think it will be more clear for the next person who has to dig here. I struggled to make sense of these queries at first.

blocks_accessed.block_id,
blocks_accessed.account_identifier_id,
blocks_accessed.zkapp_id,
blocks_accessed.account_access_id,
blocks_accessed.state_hash,
blocks_accessed.parent_hash,
blocks_accessed.height,
blocks_accessed.global_slot_since_genesis,
blocks_accessed.global_slot_since_hard_fork,
blocks_accessed.timestamp,
blocks_accessed.chain_status,
blocks_accessed.ledger_hash,
blocks_accessed.distance_from_max_block_height,
blocks_accessed.last_vrf_output,
zkcu.id AS zkapp_account_update_id,
bzkc.sequence_no AS sequence_number,
zkapp_fee_payer_body_id,
zkapp_account_updates_ids,
authorization_kind,
Expand All @@ -133,13 +148,41 @@ function emittedEventsCTE(db_client: postgres.Sql) {
return db_client`
emitted_events AS (
SELECT
*,
zke.id AS zkapp_event_id,
zke.element_ids AS zkapp_event_element_ids,
zkfa.id AS zkapp_event_array_id
emitted_zkapp_commands.requesting_zkapp_account_identifier_id,
emitted_zkapp_commands.block_id,
emitted_zkapp_commands.account_identifier_id,
emitted_zkapp_commands.zkapp_id,
emitted_zkapp_commands.account_access_id,
emitted_zkapp_commands.state_hash,
emitted_zkapp_commands.parent_hash,
emitted_zkapp_commands.height,
emitted_zkapp_commands.global_slot_since_genesis,
emitted_zkapp_commands.global_slot_since_hard_fork,
emitted_zkapp_commands.timestamp,
emitted_zkapp_commands.chain_status,
emitted_zkapp_commands.ledger_hash,
emitted_zkapp_commands.distance_from_max_block_height,
emitted_zkapp_commands.last_vrf_output,
emitted_zkapp_commands.zkapp_account_update_id,
emitted_zkapp_commands.sequence_number,
emitted_zkapp_commands.zkapp_fee_payer_body_id,
emitted_zkapp_commands.zkapp_account_updates_ids,
emitted_zkapp_commands.authorization_kind,
emitted_zkapp_commands.status,
emitted_zkapp_commands.memo,
emitted_zkapp_commands.hash,
emitted_zkapp_commands.body_id,
emitted_zkapp_commands.events_id,
emitted_zkapp_commands.actions_id,
zke.id AS account_update_event_id,
zke.element_ids AS event_element_ids,
zkfa.element_ids AS event_field_element_ids,
zkfa.id AS event_field_elements_id,
zkf.id AS field_id,
zkf.field AS field_value
FROM
emitted_zkapp_commands
INNER JOIN zkapp_events zke ON zke.id = events_id
INNER JOIN zkapp_events zke ON zke.id = emitted_zkapp_commands.events_id
INNER JOIN zkapp_field_array zkfa ON zkfa.id = ANY(zke.element_ids)
INNER JOIN zkapp_field zkf ON zkf.id = ANY(zkfa.element_ids)
)
Expand All @@ -150,13 +193,38 @@ function emittedActionsCTE(db_client: postgres.Sql) {
return db_client`
emitted_actions AS (
SELECT
*,
zke.id AS zkapp_event_id,
zke.element_ids AS zkapp_event_element_ids,
zkfa.id AS zkapp_event_array_id
emitted_zkapp_commands.block_id,
emitted_zkapp_commands.zkapp_id,
emitted_zkapp_commands.state_hash,
emitted_zkapp_commands.parent_hash,
emitted_zkapp_commands.height,
emitted_zkapp_commands.global_slot_since_genesis,
emitted_zkapp_commands.global_slot_since_hard_fork,
emitted_zkapp_commands.timestamp,
emitted_zkapp_commands.chain_status,
emitted_zkapp_commands.ledger_hash,
emitted_zkapp_commands.distance_from_max_block_height,
emitted_zkapp_commands.last_vrf_output,
emitted_zkapp_commands.zkapp_account_update_id,
emitted_zkapp_commands.sequence_number,
emitted_zkapp_commands.zkapp_fee_payer_body_id,
emitted_zkapp_commands.zkapp_account_updates_ids,
emitted_zkapp_commands.authorization_kind,
emitted_zkapp_commands.status,
emitted_zkapp_commands.memo,
emitted_zkapp_commands.hash,
emitted_zkapp_commands.body_id,
emitted_zkapp_commands.events_id,
emitted_zkapp_commands.actions_id,
zke.id AS account_update_event_id,
zke.element_ids AS event_element_ids,
zkfa.element_ids AS event_field_element_ids,
zkfa.id AS event_field_elements_id,
zkf.id AS field_id,
zkf.field AS field_value
FROM
emitted_zkapp_commands
INNER JOIN zkapp_events zke ON zke.id = actions_id
INNER JOIN zkapp_events zke ON zke.id = emitted_zkapp_commands.actions_id
INNER JOIN zkapp_field_array zkfa ON zkfa.id = ANY(zke.element_ids)
INNER JOIN zkapp_field zkf ON zkf.id = ANY(zkfa.element_ids)
)
Expand All @@ -176,7 +244,36 @@ function emittedActionStateCTE(
zkf2.field AS action_state_value3,
zkf3.field AS action_state_value4,
zkf4.field AS action_state_value5,
emitted_actions.*
emitted_actions.last_vrf_output,
emitted_actions.block_id,
emitted_actions.zkapp_id,
emitted_actions.state_hash,
emitted_actions.parent_hash,
emitted_actions.height,
emitted_actions.global_slot_since_genesis,
emitted_actions.global_slot_since_hard_fork,
emitted_actions.timestamp,
emitted_actions.chain_status,
emitted_actions.ledger_hash,
emitted_actions.distance_from_max_block_height,
emitted_actions.last_vrf_output,
emitted_actions.zkapp_account_update_id,
emitted_actions.sequence_number,
emitted_actions.zkapp_fee_payer_body_id,
emitted_actions.zkapp_account_updates_ids,
emitted_actions.authorization_kind,
emitted_actions.status,
emitted_actions.memo,
emitted_actions.hash,
emitted_actions.body_id,
emitted_actions.events_id,
emitted_actions.actions_id,
emitted_actions.account_update_event_id,
emitted_actions.event_element_ids,
emitted_actions.event_field_element_ids,
emitted_actions.event_field_elements_id,
emitted_actions.field_id,
emitted_actions.field_value
FROM
emitted_actions
INNER JOIN zkapp_accounts zkacc ON zkacc.id = emitted_actions.zkapp_id
Expand Down Expand Up @@ -216,7 +313,37 @@ export function getEventsQuery(
${blocksAccessedCTE(db_client, status, to, from)},
${emittedZkAppCommandsCTE(db_client)},
${emittedEventsCTE(db_client)}
SELECT *
SELECT
last_vrf_output,
block_id,
zkapp_id,
state_hash,
parent_hash,
height,
global_slot_since_genesis,
global_slot_since_hard_fork,
timestamp,
chain_status,
ledger_hash,
distance_from_max_block_height,
last_vrf_output,
zkapp_account_update_id,
sequence_number,
zkapp_fee_payer_body_id,
zkapp_account_updates_ids,
authorization_kind,
status,
memo,
hash,
body_id,
events_id,
actions_id,
account_update_event_id,
event_element_ids,
event_field_element_ids,
event_field_elements_id,
field_id,
field_value
FROM emitted_events
`;
}
Expand Down
Loading
Loading