@effectstream/db 0.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets-config.json +28 -0
- package/migrations/assets.ts +35 -0
- package/migrations/readme.md +37 -0
- package/migrations/system-down-v-0.0.0.sql +2 -0
- package/migrations/system-down-v-0.0.1.sql +14 -0
- package/migrations/system-up-v-0.0.0.sql +40 -0
- package/migrations/system-up-v-0.0.1.sql +117 -0
- package/migrations/system-up-v-0.0.2.sql +22 -0
- package/migrations/system-up-v-0.8.1.sql +5 -0
- package/migrations/system-version.ts +147 -0
- package/package.json +33 -0
- package/pgtypedconfig.json +21 -0
- package/scripts/Dockerfile +13 -0
- package/scripts/apply-migrations.ts +49 -0
- package/scripts/pgtyped-internal.ts +43 -0
- package/scripts/pgtyped-update.ts +119 -0
- package/scripts/start-pglite.ts +71 -0
- package/scripts/wait-for-db.ts +43 -0
- package/src/dynamic-tables.ts +110 -0
- package/src/event-indexing.ts +31 -0
- package/src/migrations.ts +28 -0
- package/src/mod.ts +65 -0
- package/src/pg-connection.test.ts +99 -0
- package/src/pg-connection.ts +211 -0
- package/src/register-events.ts +40 -0
- package/src/scheduled-constructors.ts +117 -0
- package/src/snapshot-handler.ts +164 -0
- package/src/sql/accounts.queries.ts +350 -0
- package/src/sql/accounts.sql +77 -0
- package/src/sql/achievements.queries.ts +74 -0
- package/src/sql/achievements.sql +17 -0
- package/src/sql/block-heights.queries.ts +205 -0
- package/src/sql/block-heights.sql +45 -0
- package/src/sql/events.queries.ts +201 -0
- package/src/sql/events.sql +41 -0
- package/src/sql/nonces.queries.ts +85 -0
- package/src/sql/nonces.sql +11 -0
- package/src/sql/primitives.queries.ts +35 -0
- package/src/sql/primitives.sql +4 -0
- package/src/sql/rollup_inputs.queries.ts +654 -0
- package/src/sql/rollup_inputs.sql +227 -0
- package/src/sql/statistics.queries.ts +160 -0
- package/src/sql/statistics.sql +55 -0
- package/src/sql/sync-protocols/page.queries.ts +140 -0
- package/src/sql/sync-protocols/page.sql +39 -0
- package/src/sql/system.queries.ts +356 -0
- package/src/sql/system.sql +75 -0
- package/src/sql/tables.queries.ts +89 -0
- package/src/sql/tables.sql +17 -0
- package/src/system.ts +41 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/* @name newScheduledHeightData */
|
|
2
|
+
WITH
|
|
3
|
+
new_row AS (
|
|
4
|
+
INSERT INTO effectstream.rollup_inputs(from_address, from_address_type, input_data)
|
|
5
|
+
VALUES (:from_address!, :from_address_type!, :input_data!)
|
|
6
|
+
RETURNING id
|
|
7
|
+
),
|
|
8
|
+
insert_origin AS (
|
|
9
|
+
INSERT INTO effectstream.rollup_input_origin(id, primitive_name, caip2, tx_hash, contract_address)
|
|
10
|
+
SELECT (SELECT id FROM new_row), :primitive_name, :caip2, :origin_tx_hash::BYTEA, :origin_contract_address
|
|
11
|
+
)
|
|
12
|
+
INSERT INTO effectstream.rollup_input_future_block(id, future_block_height)
|
|
13
|
+
SELECT (SELECT id FROM new_row), :future_block_height!;
|
|
14
|
+
|
|
15
|
+
/* @name newScheduledTimestampData */
|
|
16
|
+
WITH
|
|
17
|
+
new_row AS (
|
|
18
|
+
INSERT INTO effectstream.rollup_inputs(from_address, from_address_type, input_data)
|
|
19
|
+
VALUES (:from_address!, :from_address_type!, :input_data!)
|
|
20
|
+
RETURNING id
|
|
21
|
+
),
|
|
22
|
+
insert_origin AS (
|
|
23
|
+
INSERT INTO effectstream.rollup_input_origin(id, primitive_name, caip2, tx_hash, contract_address)
|
|
24
|
+
SELECT (SELECT id FROM new_row),null,null,null,null
|
|
25
|
+
)
|
|
26
|
+
INSERT INTO effectstream.rollup_input_future_timestamp(id, future_ms_timestamp)
|
|
27
|
+
SELECT (SELECT id FROM new_row), :future_ms_timestamp!;
|
|
28
|
+
|
|
29
|
+
/* @name newGameInput */
|
|
30
|
+
WITH
|
|
31
|
+
new_row AS (
|
|
32
|
+
INSERT INTO effectstream.rollup_inputs(from_address, from_address_type, input_data)
|
|
33
|
+
VALUES (:from_address!, :from_address_type!, :input_data!)
|
|
34
|
+
RETURNING id
|
|
35
|
+
),
|
|
36
|
+
insert_origin AS (
|
|
37
|
+
INSERT INTO effectstream.rollup_input_origin(id, primitive_name, caip2, tx_hash, contract_address)
|
|
38
|
+
SELECT (SELECT id FROM new_row), :primitive_name!, :caip2!, :origin_tx_hash!::BYTEA, :origin_contract_address
|
|
39
|
+
)
|
|
40
|
+
INSERT INTO effectstream.rollup_input_result(id, success, effectstream_tx_hash, index_in_block, block_height)
|
|
41
|
+
SELECT (SELECT id FROM new_row), :success!, :effectstream_tx_hash!::BYTEA, :index_in_block!, :block_height!;
|
|
42
|
+
|
|
43
|
+
/* @name insertGameInputResult */
|
|
44
|
+
INSERT INTO effectstream.rollup_input_result(id, success, effectstream_tx_hash, index_in_block, block_height)
|
|
45
|
+
VALUES (:id!, :success!, :effectstream_tx_hash!::BYTEA, :index_in_block!, :block_height!);
|
|
46
|
+
|
|
47
|
+
/* @name getAllScheduledData */
|
|
48
|
+
(
|
|
49
|
+
SELECT
|
|
50
|
+
rollup_inputs.id,
|
|
51
|
+
NULL AS future_ms_timestamp,
|
|
52
|
+
rollup_input_future_block.future_block_height,
|
|
53
|
+
rollup_inputs.input_data,
|
|
54
|
+
rollup_inputs.from_address,
|
|
55
|
+
rollup_inputs.from_address_type,
|
|
56
|
+
rollup_input_origin.primitive_name,
|
|
57
|
+
rollup_input_origin.contract_address,
|
|
58
|
+
rollup_input_origin.caip2,
|
|
59
|
+
rollup_input_origin.tx_hash as "origin_tx_hash"
|
|
60
|
+
FROM effectstream.rollup_inputs
|
|
61
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
62
|
+
JOIN effectstream.rollup_input_future_block ON effectstream.rollup_input_future_block.id = effectstream.rollup_inputs.id
|
|
63
|
+
WHERE rollup_inputs.id > :after_id::INT
|
|
64
|
+
ORDER BY rollup_inputs.id ASC
|
|
65
|
+
)
|
|
66
|
+
UNION ALL
|
|
67
|
+
(
|
|
68
|
+
SELECT
|
|
69
|
+
rollup_inputs.id,
|
|
70
|
+
rollup_input_future_timestamp.future_ms_timestamp,
|
|
71
|
+
NULL AS "future_block_height",
|
|
72
|
+
rollup_inputs.input_data,
|
|
73
|
+
rollup_inputs.from_address,
|
|
74
|
+
rollup_inputs.from_address_type,
|
|
75
|
+
rollup_input_origin.primitive_name,
|
|
76
|
+
rollup_input_origin.contract_address,
|
|
77
|
+
rollup_input_origin.caip2,
|
|
78
|
+
rollup_input_origin.tx_hash as "origin_tx_hash"
|
|
79
|
+
FROM effectstream.rollup_inputs
|
|
80
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
81
|
+
JOIN effectstream.rollup_input_future_timestamp ON effectstream.rollup_inputs.id = effectstream.rollup_input_future_timestamp.id
|
|
82
|
+
LEFT OUTER JOIN effectstream.rollup_input_result
|
|
83
|
+
ON (effectstream.rollup_input_result.id = effectstream.rollup_inputs.id)
|
|
84
|
+
WHERE
|
|
85
|
+
effectstream.rollup_input_result.id IS NULL AND
|
|
86
|
+
effectstream.rollup_inputs.id > :after_id::INT
|
|
87
|
+
ORDER BY rollup_input_future_timestamp.future_ms_timestamp ASC
|
|
88
|
+
)
|
|
89
|
+
ORDER BY id ASC
|
|
90
|
+
LIMIT COALESCE(:limit, 999999);
|
|
91
|
+
|
|
92
|
+
/* @name getAllScheduledDataCount */
|
|
93
|
+
SELECT COUNT(*) as total FROM (
|
|
94
|
+
(
|
|
95
|
+
SELECT rollup_inputs.id
|
|
96
|
+
FROM effectstream.rollup_inputs
|
|
97
|
+
JOIN effectstream.rollup_input_future_block ON effectstream.rollup_input_future_block.id = effectstream.rollup_inputs.id
|
|
98
|
+
)
|
|
99
|
+
UNION ALL
|
|
100
|
+
(
|
|
101
|
+
SELECT rollup_inputs.id
|
|
102
|
+
FROM effectstream.rollup_inputs
|
|
103
|
+
JOIN effectstream.rollup_input_future_timestamp ON effectstream.rollup_inputs.id = effectstream.rollup_input_future_timestamp.id
|
|
104
|
+
LEFT OUTER JOIN effectstream.rollup_input_result
|
|
105
|
+
ON (effectstream.rollup_input_result.id = effectstream.rollup_inputs.id)
|
|
106
|
+
WHERE rollup_input_result.id IS NULL
|
|
107
|
+
)
|
|
108
|
+
) AS scheduled_data;
|
|
109
|
+
|
|
110
|
+
/* @name getFutureGameInputByBlockHeight */
|
|
111
|
+
SELECT
|
|
112
|
+
rollup_inputs.id,
|
|
113
|
+
rollup_input_future_block.future_block_height,
|
|
114
|
+
rollup_inputs.input_data,
|
|
115
|
+
rollup_inputs.from_address,
|
|
116
|
+
rollup_inputs.from_address_type,
|
|
117
|
+
rollup_input_origin.primitive_name,
|
|
118
|
+
rollup_input_origin.contract_address,
|
|
119
|
+
rollup_input_origin.caip2,
|
|
120
|
+
rollup_input_origin.tx_hash as "origin_tx_hash"
|
|
121
|
+
FROM effectstream.rollup_inputs
|
|
122
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
123
|
+
JOIN effectstream.rollup_input_future_block ON effectstream.rollup_input_future_block.id = effectstream.rollup_inputs.id
|
|
124
|
+
WHERE rollup_input_future_block.future_block_height = :block_height!
|
|
125
|
+
ORDER BY rollup_inputs.id ASC;
|
|
126
|
+
|
|
127
|
+
/* @name getFutureGameInputByMaxTimestamp */
|
|
128
|
+
SELECT
|
|
129
|
+
rollup_inputs.id,
|
|
130
|
+
rollup_input_future_timestamp.future_ms_timestamp,
|
|
131
|
+
rollup_inputs.input_data,
|
|
132
|
+
rollup_inputs.from_address,
|
|
133
|
+
rollup_inputs.from_address_type,
|
|
134
|
+
rollup_input_origin.primitive_name,
|
|
135
|
+
rollup_input_origin.contract_address,
|
|
136
|
+
rollup_input_origin.caip2,
|
|
137
|
+
rollup_input_origin.tx_hash as "origin_tx_hash"
|
|
138
|
+
FROM effectstream.rollup_inputs
|
|
139
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
140
|
+
JOIN effectstream.rollup_input_future_timestamp ON effectstream.rollup_inputs.id = effectstream.rollup_input_future_timestamp.id
|
|
141
|
+
LEFT OUTER JOIN effectstream.rollup_input_result
|
|
142
|
+
ON (effectstream.rollup_input_result.id = effectstream.rollup_inputs.id)
|
|
143
|
+
WHERE rollup_input_future_timestamp.future_ms_timestamp <= :max_timestamp! AND
|
|
144
|
+
effectstream.rollup_input_result.id IS NULL
|
|
145
|
+
ORDER BY rollup_input_future_timestamp.future_ms_timestamp ASC;
|
|
146
|
+
|
|
147
|
+
/* @name getGameInputResultByBlockHeight */
|
|
148
|
+
SELECT
|
|
149
|
+
rollup_inputs.id,
|
|
150
|
+
effectstream_blocks.block_height,
|
|
151
|
+
rollup_inputs.input_data,
|
|
152
|
+
rollup_inputs.from_address,
|
|
153
|
+
rollup_inputs.from_address_type,
|
|
154
|
+
effectstream_blocks.effectstream_block_hash,
|
|
155
|
+
rollup_input_origin.contract_address,
|
|
156
|
+
rollup_input_result.effectstream_tx_hash,
|
|
157
|
+
rollup_input_result.index_in_block,
|
|
158
|
+
rollup_input_result.success
|
|
159
|
+
FROM effectstream.rollup_inputs
|
|
160
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
161
|
+
JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
162
|
+
JOIN effectstream.effectstream_blocks ON effectstream.rollup_input_result.block_height = effectstream.effectstream_blocks.block_height
|
|
163
|
+
WHERE effectstream_blocks.block_height = :block_height!;
|
|
164
|
+
|
|
165
|
+
/* @name getGameInputResultByTxHash */
|
|
166
|
+
SELECT
|
|
167
|
+
rollup_inputs.id,
|
|
168
|
+
effectstream_blocks.block_height,
|
|
169
|
+
rollup_inputs.input_data,
|
|
170
|
+
rollup_inputs.from_address,
|
|
171
|
+
rollup_inputs.from_address_type,
|
|
172
|
+
effectstream_blocks.effectstream_block_hash,
|
|
173
|
+
rollup_input_result.effectstream_tx_hash,
|
|
174
|
+
rollup_input_result.index_in_block,
|
|
175
|
+
rollup_input_result.success
|
|
176
|
+
FROM effectstream.rollup_inputs
|
|
177
|
+
JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
178
|
+
JOIN effectstream.effectstream_blocks ON effectstream.rollup_input_result.block_height = effectstream.effectstream_blocks.block_height
|
|
179
|
+
WHERE rollup_input_result.effectstream_tx_hash = :tx_hash!;
|
|
180
|
+
|
|
181
|
+
/* @name getGameInputResultByAddress */
|
|
182
|
+
SELECT
|
|
183
|
+
rollup_inputs.id,
|
|
184
|
+
effectstream_blocks.block_height,
|
|
185
|
+
rollup_inputs.input_data,
|
|
186
|
+
rollup_inputs.from_address,
|
|
187
|
+
rollup_inputs.from_address_type,
|
|
188
|
+
effectstream_blocks.effectstream_block_hash,
|
|
189
|
+
rollup_input_result.effectstream_tx_hash,
|
|
190
|
+
rollup_input_result.index_in_block,
|
|
191
|
+
rollup_input_result.success
|
|
192
|
+
FROM effectstream.rollup_inputs
|
|
193
|
+
JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
194
|
+
JOIN effectstream.effectstream_blocks ON effectstream.rollup_input_result.block_height = effectstream.effectstream_blocks.block_height
|
|
195
|
+
WHERE
|
|
196
|
+
rollup_input_result.block_height = :block_height! AND
|
|
197
|
+
rollup_input_result.success = TRUE AND
|
|
198
|
+
lower(rollup_inputs.from_address) = lower(:from_address!);
|
|
199
|
+
|
|
200
|
+
/* @name removeScheduledBlockData */
|
|
201
|
+
DELETE FROM effectstream.rollup_inputs
|
|
202
|
+
WHERE
|
|
203
|
+
input_data = :input_data! AND
|
|
204
|
+
rollup_inputs.id IN (
|
|
205
|
+
SELECT rollup_input_future_block.id
|
|
206
|
+
FROM effectstream.rollup_input_future_block
|
|
207
|
+
WHERE effectstream.rollup_input_future_block.future_block_height = :block_height!
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
/* @name removeScheduledTimestampData */
|
|
211
|
+
DELETE FROM effectstream.rollup_inputs
|
|
212
|
+
WHERE
|
|
213
|
+
input_data = :input_data! AND
|
|
214
|
+
rollup_inputs.id IN (
|
|
215
|
+
SELECT rollup_input_future_timestamp.id
|
|
216
|
+
FROM effectstream.rollup_input_future_timestamp
|
|
217
|
+
WHERE effectstream.rollup_input_future_timestamp.future_ms_timestamp = :ms_timestamp!
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
/* @name removeAllScheduledDataByInputData */
|
|
222
|
+
DELETE FROM effectstream.rollup_inputs
|
|
223
|
+
WHERE input_data = :input_data!;
|
|
224
|
+
|
|
225
|
+
/* @name deleteScheduled */
|
|
226
|
+
DELETE FROM effectstream.rollup_inputs
|
|
227
|
+
WHERE id = :id!;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/statistics.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
import type { Buffer } from 'node:buffer';
|
|
5
|
+
|
|
6
|
+
/** 'GetInputsTotal' parameters type */
|
|
7
|
+
export type IGetInputsTotalParams = void;
|
|
8
|
+
|
|
9
|
+
/** 'GetInputsTotal' return type */
|
|
10
|
+
export interface IGetInputsTotalResult {
|
|
11
|
+
scheduled_data: string;
|
|
12
|
+
submitted_inputs: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 'GetInputsTotal' query type */
|
|
16
|
+
export interface IGetInputsTotalQuery {
|
|
17
|
+
params: IGetInputsTotalParams;
|
|
18
|
+
result: IGetInputsTotalResult;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const getInputsTotalIR: any = {"usedParamSet":{},"params":[],"statement":"WITH scheduled_split AS (\n SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input\n FROM effectstream.rollup_inputs\n JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id\n)\nSELECT\n COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS \"submitted_inputs!\",\n COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS \"scheduled_data!\"\nFROM scheduled_split"};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Query generated from SQL:
|
|
25
|
+
* ```
|
|
26
|
+
* WITH scheduled_split AS (
|
|
27
|
+
* SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
28
|
+
* FROM effectstream.rollup_inputs
|
|
29
|
+
* JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
30
|
+
* )
|
|
31
|
+
* SELECT
|
|
32
|
+
* COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
33
|
+
* COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
34
|
+
* FROM scheduled_split
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export const getInputsTotal = new PreparedQuery<IGetInputsTotalParams,IGetInputsTotalResult>(getInputsTotalIR);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/** 'GetInputsForBlock' parameters type */
|
|
41
|
+
export interface IGetInputsForBlockParams {
|
|
42
|
+
block_height: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 'GetInputsForBlock' return type */
|
|
46
|
+
export interface IGetInputsForBlockResult {
|
|
47
|
+
scheduled_data: string;
|
|
48
|
+
submitted_inputs: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 'GetInputsForBlock' query type */
|
|
52
|
+
export interface IGetInputsForBlockQuery {
|
|
53
|
+
params: IGetInputsForBlockParams;
|
|
54
|
+
result: IGetInputsForBlockResult;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const getInputsForBlockIR: any = {"usedParamSet":{"block_height":true},"params":[{"name":"block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":406,"b":419}]}],"statement":"WITH scheduled_split AS (\n SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input\n FROM effectstream.rollup_inputs\n JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id\n JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id\n WHERE block_height = :block_height!\n)\nSELECT\n COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS \"submitted_inputs!\",\n COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS \"scheduled_data!\"\nFROM scheduled_split"};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Query generated from SQL:
|
|
61
|
+
* ```
|
|
62
|
+
* WITH scheduled_split AS (
|
|
63
|
+
* SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
64
|
+
* FROM effectstream.rollup_inputs
|
|
65
|
+
* JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
66
|
+
* JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
67
|
+
* WHERE block_height = :block_height!
|
|
68
|
+
* )
|
|
69
|
+
* SELECT
|
|
70
|
+
* COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
71
|
+
* COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
72
|
+
* FROM scheduled_split
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export const getInputsForBlock = new PreparedQuery<IGetInputsForBlockParams,IGetInputsForBlockResult>(getInputsForBlockIR);
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/** 'GetInputsForBlockHash' parameters type */
|
|
79
|
+
export interface IGetInputsForBlockHashParams {
|
|
80
|
+
block_hash: Buffer;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 'GetInputsForBlockHash' return type */
|
|
84
|
+
export interface IGetInputsForBlockHashResult {
|
|
85
|
+
scheduled_data: string;
|
|
86
|
+
submitted_inputs: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 'GetInputsForBlockHash' query type */
|
|
90
|
+
export interface IGetInputsForBlockHashQuery {
|
|
91
|
+
params: IGetInputsForBlockHashParams;
|
|
92
|
+
result: IGetInputsForBlockHashResult;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const getInputsForBlockHashIR: any = {"usedParamSet":{"block_hash":true},"params":[{"name":"block_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":553,"b":564},{"a":595,"b":606}]}],"statement":"WITH scheduled_split AS (\n SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input\n FROM effectstream.rollup_inputs\n JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id\n JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id\n JOIN effectstream.effectstream_blocks ON effectstream.effectstream_blocks.block_height = effectstream.rollup_input_result.block_height\n WHERE (main_chain_block_hash = :block_hash! OR effectstream_block_hash = :block_hash!)\n)\nSELECT\n COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS \"submitted_inputs!\",\n COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS \"scheduled_data!\"\nFROM scheduled_split"};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Query generated from SQL:
|
|
99
|
+
* ```
|
|
100
|
+
* WITH scheduled_split AS (
|
|
101
|
+
* SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
102
|
+
* FROM effectstream.rollup_inputs
|
|
103
|
+
* JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
104
|
+
* JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
105
|
+
* JOIN effectstream.effectstream_blocks ON effectstream.effectstream_blocks.block_height = effectstream.rollup_input_result.block_height
|
|
106
|
+
* WHERE (main_chain_block_hash = :block_hash! OR effectstream_block_hash = :block_hash!)
|
|
107
|
+
* )
|
|
108
|
+
* SELECT
|
|
109
|
+
* COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
110
|
+
* COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
111
|
+
* FROM scheduled_split
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export const getInputsForBlockHash = new PreparedQuery<IGetInputsForBlockHashParams,IGetInputsForBlockHashResult>(getInputsForBlockHashIR);
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
/** 'GetInputsForAddress' parameters type */
|
|
118
|
+
export interface IGetInputsForAddressParams {
|
|
119
|
+
addr: string;
|
|
120
|
+
block_height: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 'GetInputsForAddress' return type */
|
|
124
|
+
export interface IGetInputsForAddressResult {
|
|
125
|
+
scheduled_data: string;
|
|
126
|
+
submitted_inputs: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** 'GetInputsForAddress' query type */
|
|
130
|
+
export interface IGetInputsForAddressQuery {
|
|
131
|
+
params: IGetInputsForAddressParams;
|
|
132
|
+
result: IGetInputsForAddressResult;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const getInputsForAddressIR: any = {"usedParamSet":{"addr":true,"block_height":true},"params":[{"name":"addr","required":true,"transform":{"type":"scalar"},"locs":[{"a":439,"b":444},{"a":512,"b":517}]},{"name":"block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":557,"b":570}]}],"statement":"WITH scheduled_split AS (\n SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input\n FROM effectstream.rollup_inputs\n JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id\n JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id\n WHERE\n (\n lower(from_address) = lower(:addr!) OR\n lower(rollup_input_origin.contract_address) = lower(:addr!)\n ) AND\n block_height = :block_height!\n)\nSELECT\n COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS \"submitted_inputs!\",\n COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS \"scheduled_data!\"\nFROM scheduled_split"};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Query generated from SQL:
|
|
139
|
+
* ```
|
|
140
|
+
* WITH scheduled_split AS (
|
|
141
|
+
* SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
142
|
+
* FROM effectstream.rollup_inputs
|
|
143
|
+
* JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
144
|
+
* JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
145
|
+
* WHERE
|
|
146
|
+
* (
|
|
147
|
+
* lower(from_address) = lower(:addr!) OR
|
|
148
|
+
* lower(rollup_input_origin.contract_address) = lower(:addr!)
|
|
149
|
+
* ) AND
|
|
150
|
+
* block_height = :block_height!
|
|
151
|
+
* )
|
|
152
|
+
* SELECT
|
|
153
|
+
* COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
154
|
+
* COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
155
|
+
* FROM scheduled_split
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export const getInputsForAddress = new PreparedQuery<IGetInputsForAddressParams,IGetInputsForAddressResult>(getInputsForAddressIR);
|
|
159
|
+
|
|
160
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* @name getInputsTotal */
|
|
2
|
+
WITH scheduled_split AS (
|
|
3
|
+
SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
4
|
+
FROM effectstream.rollup_inputs
|
|
5
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
6
|
+
)
|
|
7
|
+
SELECT
|
|
8
|
+
COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
9
|
+
COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
10
|
+
FROM scheduled_split;
|
|
11
|
+
|
|
12
|
+
/* @name getInputsForBlock */
|
|
13
|
+
WITH scheduled_split AS (
|
|
14
|
+
SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
15
|
+
FROM effectstream.rollup_inputs
|
|
16
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
17
|
+
JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
18
|
+
WHERE block_height = :block_height!
|
|
19
|
+
)
|
|
20
|
+
SELECT
|
|
21
|
+
COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
22
|
+
COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
23
|
+
FROM scheduled_split;
|
|
24
|
+
|
|
25
|
+
/* @name getInputsForBlockHash */
|
|
26
|
+
WITH scheduled_split AS (
|
|
27
|
+
SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
28
|
+
FROM effectstream.rollup_inputs
|
|
29
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
30
|
+
JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
31
|
+
JOIN effectstream.effectstream_blocks ON effectstream.effectstream_blocks.block_height = effectstream.rollup_input_result.block_height
|
|
32
|
+
WHERE (main_chain_block_hash = :block_hash! OR effectstream_block_hash = :block_hash!)
|
|
33
|
+
)
|
|
34
|
+
SELECT
|
|
35
|
+
COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
36
|
+
COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
37
|
+
FROM scheduled_split;
|
|
38
|
+
|
|
39
|
+
/* @name getInputsForAddress */
|
|
40
|
+
WITH scheduled_split AS (
|
|
41
|
+
SELECT CASE WHEN primitive_name IS NULL AND caip2 IS NOT NULL THEN 1 ELSE 0 END as submitted_input
|
|
42
|
+
FROM effectstream.rollup_inputs
|
|
43
|
+
JOIN effectstream.rollup_input_origin ON effectstream.rollup_inputs.id = effectstream.rollup_input_origin.id
|
|
44
|
+
JOIN effectstream.rollup_input_result ON effectstream.rollup_inputs.id = effectstream.rollup_input_result.id
|
|
45
|
+
WHERE
|
|
46
|
+
(
|
|
47
|
+
lower(from_address) = lower(:addr!) OR
|
|
48
|
+
lower(rollup_input_origin.contract_address) = lower(:addr!)
|
|
49
|
+
) AND
|
|
50
|
+
block_height = :block_height!
|
|
51
|
+
)
|
|
52
|
+
SELECT
|
|
53
|
+
COUNT(CASE WHEN submitted_input = 1 THEN 1 END) AS "submitted_inputs!",
|
|
54
|
+
COUNT(CASE WHEN submitted_input = 0 THEN 1 END) AS "scheduled_data!"
|
|
55
|
+
FROM scheduled_split;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/sync-protocols/page.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
5
|
+
|
|
6
|
+
/** 'GetPage' parameters type */
|
|
7
|
+
export interface IGetPageParams {
|
|
8
|
+
protocol_name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** 'GetPage' return type */
|
|
12
|
+
export interface IGetPageResult {
|
|
13
|
+
page: Json;
|
|
14
|
+
page_number: number;
|
|
15
|
+
protocol_name: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 'GetPage' query type */
|
|
19
|
+
export interface IGetPageQuery {
|
|
20
|
+
params: IGetPageParams;
|
|
21
|
+
result: IGetPageResult;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const getPageIR: any = {"usedParamSet":{"protocol_name":true},"params":[{"name":"protocol_name","required":true,"transform":{"type":"scalar"},"locs":[{"a":74,"b":88}]}],"statement":"SELECT * FROM effectstream.sync_protocol_pagination\nWHERE protocol_name = :protocol_name!\nORDER BY page_number ASC\nLIMIT 1"};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Query generated from SQL:
|
|
28
|
+
* ```
|
|
29
|
+
* SELECT * FROM effectstream.sync_protocol_pagination
|
|
30
|
+
* WHERE protocol_name = :protocol_name!
|
|
31
|
+
* ORDER BY page_number ASC
|
|
32
|
+
* LIMIT 1
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export const getPage = new PreparedQuery<IGetPageParams,IGetPageResult>(getPageIR);
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/** 'GetSyncAndLastPage' parameters type */
|
|
39
|
+
export type IGetSyncAndLastPageParams = void;
|
|
40
|
+
|
|
41
|
+
/** 'GetSyncAndLastPage' return type */
|
|
42
|
+
export interface IGetSyncAndLastPageResult {
|
|
43
|
+
fetched_page: number | null;
|
|
44
|
+
protocol_name: string;
|
|
45
|
+
synced_page: number | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 'GetSyncAndLastPage' query type */
|
|
49
|
+
export interface IGetSyncAndLastPageQuery {
|
|
50
|
+
params: IGetSyncAndLastPageParams;
|
|
51
|
+
result: IGetSyncAndLastPageResult;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const getSyncAndLastPageIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT\n protocol_name,\n MIN(page_number) AS synced_page,\n MAX(page_number) AS fetched_page\nFROM\n effectstream.sync_protocol_pagination\nGROUP BY\n protocol_name\nORDER BY\n protocol_name"};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Query generated from SQL:
|
|
58
|
+
* ```
|
|
59
|
+
* SELECT
|
|
60
|
+
* protocol_name,
|
|
61
|
+
* MIN(page_number) AS synced_page,
|
|
62
|
+
* MAX(page_number) AS fetched_page
|
|
63
|
+
* FROM
|
|
64
|
+
* effectstream.sync_protocol_pagination
|
|
65
|
+
* GROUP BY
|
|
66
|
+
* protocol_name
|
|
67
|
+
* ORDER BY
|
|
68
|
+
* protocol_name
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export const getSyncAndLastPage = new PreparedQuery<IGetSyncAndLastPageParams,IGetSyncAndLastPageResult>(getSyncAndLastPageIR);
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/** 'RemovePages' parameters type */
|
|
75
|
+
export interface IRemovePagesParams {
|
|
76
|
+
page_number: number;
|
|
77
|
+
protocol_name: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 'RemovePages' return type */
|
|
81
|
+
export type IRemovePagesResult = void;
|
|
82
|
+
|
|
83
|
+
/** 'RemovePages' query type */
|
|
84
|
+
export interface IRemovePagesQuery {
|
|
85
|
+
params: IRemovePagesParams;
|
|
86
|
+
result: IRemovePagesResult;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const removePagesIR: any = {"usedParamSet":{"protocol_name":true,"page_number":true},"params":[{"name":"protocol_name","required":true,"transform":{"type":"scalar"},"locs":[{"a":72,"b":86}]},{"name":"page_number","required":true,"transform":{"type":"scalar"},"locs":[{"a":106,"b":118}]}],"statement":"DELETE FROM effectstream.sync_protocol_pagination\nWHERE protocol_name = :protocol_name!\nAND page_number < :page_number!"};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Query generated from SQL:
|
|
93
|
+
* ```
|
|
94
|
+
* DELETE FROM effectstream.sync_protocol_pagination
|
|
95
|
+
* WHERE protocol_name = :protocol_name!
|
|
96
|
+
* AND page_number < :page_number!
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export const removePages = new PreparedQuery<IRemovePagesParams,IRemovePagesResult>(removePagesIR);
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
/** 'UpsertPage' parameters type */
|
|
103
|
+
export interface IUpsertPageParams {
|
|
104
|
+
page: Json;
|
|
105
|
+
page_number: number;
|
|
106
|
+
protocol_name: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 'UpsertPage' return type */
|
|
110
|
+
export type IUpsertPageResult = void;
|
|
111
|
+
|
|
112
|
+
/** 'UpsertPage' query type */
|
|
113
|
+
export interface IUpsertPageQuery {
|
|
114
|
+
params: IUpsertPageParams;
|
|
115
|
+
result: IUpsertPageResult;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const upsertPageIR: any = {"usedParamSet":{"protocol_name":true,"page_number":true,"page":true},"params":[{"name":"protocol_name","required":true,"transform":{"type":"scalar"},"locs":[{"a":131,"b":145}]},{"name":"page_number","required":true,"transform":{"type":"scalar"},"locs":[{"a":152,"b":164}]},{"name":"page","required":true,"transform":{"type":"scalar"},"locs":[{"a":171,"b":176}]}],"statement":"INSERT INTO\n effectstream.sync_protocol_pagination (\n protocol_name,\n page_number,\n page\n )\nVALUES (\n :protocol_name!,\n :page_number!,\n :page!\n)\nON CONFLICT (protocol_name, page_number) DO UPDATE SET\n page = EXCLUDED.page"};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Query generated from SQL:
|
|
122
|
+
* ```
|
|
123
|
+
* INSERT INTO
|
|
124
|
+
* effectstream.sync_protocol_pagination (
|
|
125
|
+
* protocol_name,
|
|
126
|
+
* page_number,
|
|
127
|
+
* page
|
|
128
|
+
* )
|
|
129
|
+
* VALUES (
|
|
130
|
+
* :protocol_name!,
|
|
131
|
+
* :page_number!,
|
|
132
|
+
* :page!
|
|
133
|
+
* )
|
|
134
|
+
* ON CONFLICT (protocol_name, page_number) DO UPDATE SET
|
|
135
|
+
* page = EXCLUDED.page
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export const upsertPage = new PreparedQuery<IUpsertPageParams,IUpsertPageResult>(upsertPageIR);
|
|
139
|
+
|
|
140
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* @name getPage */
|
|
2
|
+
SELECT * FROM effectstream.sync_protocol_pagination
|
|
3
|
+
WHERE protocol_name = :protocol_name!
|
|
4
|
+
ORDER BY page_number ASC
|
|
5
|
+
LIMIT 1;
|
|
6
|
+
|
|
7
|
+
/* @name getSyncAndLastPage */
|
|
8
|
+
SELECT
|
|
9
|
+
protocol_name,
|
|
10
|
+
MIN(page_number) AS synced_page,
|
|
11
|
+
MAX(page_number) AS fetched_page
|
|
12
|
+
FROM
|
|
13
|
+
effectstream.sync_protocol_pagination
|
|
14
|
+
GROUP BY
|
|
15
|
+
protocol_name
|
|
16
|
+
ORDER BY
|
|
17
|
+
protocol_name;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/* @name removePages */
|
|
21
|
+
DELETE FROM effectstream.sync_protocol_pagination
|
|
22
|
+
WHERE protocol_name = :protocol_name!
|
|
23
|
+
AND page_number < :page_number!;
|
|
24
|
+
|
|
25
|
+
/* @name upsertPage */
|
|
26
|
+
INSERT INTO
|
|
27
|
+
effectstream.sync_protocol_pagination (
|
|
28
|
+
protocol_name,
|
|
29
|
+
page_number,
|
|
30
|
+
page
|
|
31
|
+
)
|
|
32
|
+
VALUES (
|
|
33
|
+
:protocol_name!,
|
|
34
|
+
:page_number!,
|
|
35
|
+
:page!
|
|
36
|
+
)
|
|
37
|
+
ON CONFLICT (protocol_name, page_number) DO UPDATE SET
|
|
38
|
+
page = EXCLUDED.page
|
|
39
|
+
;
|