@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,205 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/block-heights.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
import type { Buffer } from 'node:buffer';
|
|
5
|
+
|
|
6
|
+
export type DateOrString = Date | string;
|
|
7
|
+
|
|
8
|
+
/** 'GetLatestProcessedBlockHeight' parameters type */
|
|
9
|
+
export type IGetLatestProcessedBlockHeightParams = void;
|
|
10
|
+
|
|
11
|
+
/** 'GetLatestProcessedBlockHeight' return type */
|
|
12
|
+
export interface IGetLatestProcessedBlockHeightResult {
|
|
13
|
+
block_height: number;
|
|
14
|
+
effectstream_block_hash: Buffer | null;
|
|
15
|
+
main_chain_block_hash: Buffer;
|
|
16
|
+
ms_timestamp: Date;
|
|
17
|
+
seed: string;
|
|
18
|
+
ver: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** 'GetLatestProcessedBlockHeight' query type */
|
|
22
|
+
export interface IGetLatestProcessedBlockHeightQuery {
|
|
23
|
+
params: IGetLatestProcessedBlockHeightParams;
|
|
24
|
+
result: IGetLatestProcessedBlockHeightResult;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const getLatestProcessedBlockHeightIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT * FROM effectstream.effectstream_blocks\nWHERE effectstream_block_hash IS NOT NULL\nORDER BY block_height DESC\nLIMIT 1"};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Query generated from SQL:
|
|
31
|
+
* ```
|
|
32
|
+
* SELECT * FROM effectstream.effectstream_blocks
|
|
33
|
+
* WHERE effectstream_block_hash IS NOT NULL
|
|
34
|
+
* ORDER BY block_height DESC
|
|
35
|
+
* LIMIT 1
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const getLatestProcessedBlockHeight = new PreparedQuery<IGetLatestProcessedBlockHeightParams,IGetLatestProcessedBlockHeightResult>(getLatestProcessedBlockHeightIR);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
/** 'GetBlockSeeds' parameters type */
|
|
42
|
+
export type IGetBlockSeedsParams = void;
|
|
43
|
+
|
|
44
|
+
/** 'GetBlockSeeds' return type */
|
|
45
|
+
export interface IGetBlockSeedsResult {
|
|
46
|
+
seed: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 'GetBlockSeeds' query type */
|
|
50
|
+
export interface IGetBlockSeedsQuery {
|
|
51
|
+
params: IGetBlockSeedsParams;
|
|
52
|
+
result: IGetBlockSeedsResult;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const getBlockSeedsIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT seed FROM effectstream.effectstream_blocks\nWHERE effectstream_block_hash IS NOT NULL\nORDER BY block_height DESC\nLIMIT 25"};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Query generated from SQL:
|
|
59
|
+
* ```
|
|
60
|
+
* SELECT seed FROM effectstream.effectstream_blocks
|
|
61
|
+
* WHERE effectstream_block_hash IS NOT NULL
|
|
62
|
+
* ORDER BY block_height DESC
|
|
63
|
+
* LIMIT 25
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export const getBlockSeeds = new PreparedQuery<IGetBlockSeedsParams,IGetBlockSeedsResult>(getBlockSeedsIR);
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/** 'GetBlockHeights' parameters type */
|
|
70
|
+
export interface IGetBlockHeightsParams {
|
|
71
|
+
block_heights: readonly (number)[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** 'GetBlockHeights' return type */
|
|
75
|
+
export interface IGetBlockHeightsResult {
|
|
76
|
+
block_height: number;
|
|
77
|
+
effectstream_block_hash: Buffer | null;
|
|
78
|
+
main_chain_block_hash: Buffer;
|
|
79
|
+
ms_timestamp: Date;
|
|
80
|
+
seed: string;
|
|
81
|
+
ver: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 'GetBlockHeights' query type */
|
|
85
|
+
export interface IGetBlockHeightsQuery {
|
|
86
|
+
params: IGetBlockHeightsParams;
|
|
87
|
+
result: IGetBlockHeightsResult;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const getBlockHeightsIR: any = {"usedParamSet":{"block_heights":true},"params":[{"name":"block_heights","required":true,"transform":{"type":"array_spread"},"locs":[{"a":70,"b":84}]}],"statement":"SELECT * FROM effectstream.effectstream_blocks \nWHERE block_height IN :block_heights!\nORDER BY block_height ASC"};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Query generated from SQL:
|
|
94
|
+
* ```
|
|
95
|
+
* SELECT * FROM effectstream.effectstream_blocks
|
|
96
|
+
* WHERE block_height IN :block_heights!
|
|
97
|
+
* ORDER BY block_height ASC
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export const getBlockHeights = new PreparedQuery<IGetBlockHeightsParams,IGetBlockHeightsResult>(getBlockHeightsIR);
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/** 'GetBlockByHash' parameters type */
|
|
104
|
+
export interface IGetBlockByHashParams {
|
|
105
|
+
block_hash: Buffer;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 'GetBlockByHash' return type */
|
|
109
|
+
export interface IGetBlockByHashResult {
|
|
110
|
+
block_height: number;
|
|
111
|
+
effectstream_block_hash: Buffer | null;
|
|
112
|
+
main_chain_block_hash: Buffer;
|
|
113
|
+
ms_timestamp: Date;
|
|
114
|
+
prev_block: Buffer | null;
|
|
115
|
+
seed: string;
|
|
116
|
+
ver: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 'GetBlockByHash' query type */
|
|
120
|
+
export interface IGetBlockByHashQuery {
|
|
121
|
+
params: IGetBlockByHashParams;
|
|
122
|
+
result: IGetBlockByHashResult;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const getBlockByHashIR: any = {"usedParamSet":{"block_hash":true},"params":[{"name":"block_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":233,"b":244},{"a":278,"b":289}]}],"statement":"SELECT curr.*, prev.effectstream_block_hash as \"prev_block\"\nFROM effectstream.effectstream_blocks curr\nLEFT JOIN effectstream.effectstream_blocks prev ON prev.block_height = curr.block_height - 1\nWHERE curr.effectstream_block_hash = :block_hash! OR curr.main_chain_block_hash = :block_hash!"};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Query generated from SQL:
|
|
129
|
+
* ```
|
|
130
|
+
* SELECT curr.*, prev.effectstream_block_hash as "prev_block"
|
|
131
|
+
* FROM effectstream.effectstream_blocks curr
|
|
132
|
+
* LEFT JOIN effectstream.effectstream_blocks prev ON prev.block_height = curr.block_height - 1
|
|
133
|
+
* WHERE curr.effectstream_block_hash = :block_hash! OR curr.main_chain_block_hash = :block_hash!
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export const getBlockByHash = new PreparedQuery<IGetBlockByHashParams,IGetBlockByHashResult>(getBlockByHashIR);
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
/** 'SaveLastBlock' parameters type */
|
|
140
|
+
export interface ISaveLastBlockParams {
|
|
141
|
+
block_height: number;
|
|
142
|
+
main_chain_block_hash: Buffer;
|
|
143
|
+
ms_timestamp: DateOrString;
|
|
144
|
+
seed: string;
|
|
145
|
+
ver: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** 'SaveLastBlock' return type */
|
|
149
|
+
export type ISaveLastBlockResult = void;
|
|
150
|
+
|
|
151
|
+
/** 'SaveLastBlock' query type */
|
|
152
|
+
export interface ISaveLastBlockQuery {
|
|
153
|
+
params: ISaveLastBlockParams;
|
|
154
|
+
result: ISaveLastBlockResult;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const saveLastBlockIR: any = {"usedParamSet":{"block_height":true,"ver":true,"main_chain_block_hash":true,"seed":true,"ms_timestamp":true},"params":[{"name":"block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":140,"b":153}]},{"name":"ver","required":true,"transform":{"type":"scalar"},"locs":[{"a":156,"b":160}]},{"name":"main_chain_block_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":163,"b":185}]},{"name":"seed","required":true,"transform":{"type":"scalar"},"locs":[{"a":188,"b":193}]},{"name":"ms_timestamp","required":true,"transform":{"type":"scalar"},"locs":[{"a":196,"b":209}]}],"statement":"INSERT INTO effectstream.effectstream_blocks(block_height, ver, main_chain_block_hash, seed, ms_timestamp, effectstream_block_hash)\nVALUES (:block_height!, :ver!, :main_chain_block_hash!, :seed!, :ms_timestamp!, NULL)\nON CONFLICT (block_height)\nDO UPDATE SET\nblock_height = EXCLUDED.block_height,\nver = EXCLUDED.ver,\nmain_chain_block_hash = EXCLUDED.main_chain_block_hash,\nseed = EXCLUDED.seed,\nms_timestamp = EXCLUDED.ms_timestamp,\neffectstream_block_hash = EXCLUDED.effectstream_block_hash"};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Query generated from SQL:
|
|
161
|
+
* ```
|
|
162
|
+
* INSERT INTO effectstream.effectstream_blocks(block_height, ver, main_chain_block_hash, seed, ms_timestamp, effectstream_block_hash)
|
|
163
|
+
* VALUES (:block_height!, :ver!, :main_chain_block_hash!, :seed!, :ms_timestamp!, NULL)
|
|
164
|
+
* ON CONFLICT (block_height)
|
|
165
|
+
* DO UPDATE SET
|
|
166
|
+
* block_height = EXCLUDED.block_height,
|
|
167
|
+
* ver = EXCLUDED.ver,
|
|
168
|
+
* main_chain_block_hash = EXCLUDED.main_chain_block_hash,
|
|
169
|
+
* seed = EXCLUDED.seed,
|
|
170
|
+
* ms_timestamp = EXCLUDED.ms_timestamp,
|
|
171
|
+
* effectstream_block_hash = EXCLUDED.effectstream_block_hash
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export const saveLastBlock = new PreparedQuery<ISaveLastBlockParams,ISaveLastBlockResult>(saveLastBlockIR);
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
/** 'BlockHeightDone' parameters type */
|
|
178
|
+
export interface IBlockHeightDoneParams {
|
|
179
|
+
block_hash: Buffer;
|
|
180
|
+
block_height: number;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** 'BlockHeightDone' return type */
|
|
184
|
+
export type IBlockHeightDoneResult = void;
|
|
185
|
+
|
|
186
|
+
/** 'BlockHeightDone' query type */
|
|
187
|
+
export interface IBlockHeightDoneQuery {
|
|
188
|
+
params: IBlockHeightDoneParams;
|
|
189
|
+
result: IBlockHeightDoneResult;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const blockHeightDoneIR: any = {"usedParamSet":{"block_hash":true,"block_height":true},"params":[{"name":"block_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":70,"b":81}]},{"name":"block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":104,"b":117}]}],"statement":"UPDATE effectstream.effectstream_blocks\nSET\neffectstream_block_hash = :block_hash!\nWHERE block_height = :block_height!"};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Query generated from SQL:
|
|
196
|
+
* ```
|
|
197
|
+
* UPDATE effectstream.effectstream_blocks
|
|
198
|
+
* SET
|
|
199
|
+
* effectstream_block_hash = :block_hash!
|
|
200
|
+
* WHERE block_height = :block_height!
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export const blockHeightDone = new PreparedQuery<IBlockHeightDoneParams,IBlockHeightDoneResult>(blockHeightDoneIR);
|
|
204
|
+
|
|
205
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* @name getLatestProcessedBlockHeight */
|
|
2
|
+
SELECT * FROM effectstream.effectstream_blocks
|
|
3
|
+
WHERE effectstream_block_hash IS NOT NULL
|
|
4
|
+
ORDER BY block_height DESC
|
|
5
|
+
LIMIT 1;
|
|
6
|
+
|
|
7
|
+
/* @name getBlockSeeds */
|
|
8
|
+
SELECT seed FROM effectstream.effectstream_blocks
|
|
9
|
+
WHERE effectstream_block_hash IS NOT NULL
|
|
10
|
+
ORDER BY block_height DESC
|
|
11
|
+
LIMIT 25;
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
@name getBlockHeights
|
|
15
|
+
@param block_heights -> (...)
|
|
16
|
+
*/
|
|
17
|
+
SELECT * FROM effectstream.effectstream_blocks
|
|
18
|
+
WHERE block_height IN :block_heights!
|
|
19
|
+
ORDER BY block_height ASC;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
@name getBlockByHash
|
|
23
|
+
*/
|
|
24
|
+
SELECT curr.*, prev.effectstream_block_hash as "prev_block"
|
|
25
|
+
FROM effectstream.effectstream_blocks curr
|
|
26
|
+
LEFT JOIN effectstream.effectstream_blocks prev ON prev.block_height = curr.block_height - 1
|
|
27
|
+
WHERE curr.effectstream_block_hash = :block_hash! OR curr.main_chain_block_hash = :block_hash!;
|
|
28
|
+
|
|
29
|
+
/* @name saveLastBlock */
|
|
30
|
+
INSERT INTO effectstream.effectstream_blocks(block_height, ver, main_chain_block_hash, seed, ms_timestamp, effectstream_block_hash)
|
|
31
|
+
VALUES (:block_height!, :ver!, :main_chain_block_hash!, :seed!, :ms_timestamp!, NULL)
|
|
32
|
+
ON CONFLICT (block_height)
|
|
33
|
+
DO UPDATE SET
|
|
34
|
+
block_height = EXCLUDED.block_height,
|
|
35
|
+
ver = EXCLUDED.ver,
|
|
36
|
+
main_chain_block_hash = EXCLUDED.main_chain_block_hash,
|
|
37
|
+
seed = EXCLUDED.seed,
|
|
38
|
+
ms_timestamp = EXCLUDED.ms_timestamp,
|
|
39
|
+
effectstream_block_hash = EXCLUDED.effectstream_block_hash;
|
|
40
|
+
|
|
41
|
+
/* @name blockHeightDone */
|
|
42
|
+
UPDATE effectstream.effectstream_blocks
|
|
43
|
+
SET
|
|
44
|
+
effectstream_block_hash = :block_hash!
|
|
45
|
+
WHERE block_height = :block_height!;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/events.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
5
|
+
|
|
6
|
+
/** 'GetEvents' parameters type */
|
|
7
|
+
export interface IGetEventsParams {
|
|
8
|
+
address?: string | null | void;
|
|
9
|
+
from?: number | null | void;
|
|
10
|
+
to?: number | null | void;
|
|
11
|
+
topic: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** 'GetEvents' return type */
|
|
15
|
+
export interface IGetEventsResult {
|
|
16
|
+
address: string;
|
|
17
|
+
block_height: number;
|
|
18
|
+
data: Json;
|
|
19
|
+
id: number;
|
|
20
|
+
log_index: number;
|
|
21
|
+
topic: string;
|
|
22
|
+
tx_index: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 'GetEvents' query type */
|
|
26
|
+
export interface IGetEventsQuery {
|
|
27
|
+
params: IGetEventsParams;
|
|
28
|
+
result: IGetEventsResult;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const getEventsIR: any = {"usedParamSet":{"from":true,"to":true,"address":true,"topic":true},"params":[{"name":"from","required":false,"transform":{"type":"scalar"},"locs":[{"a":66,"b":70}]},{"name":"to","required":false,"transform":{"type":"scalar"},"locs":[{"a":109,"b":111}]},{"name":"address","required":false,"transform":{"type":"scalar"},"locs":[{"a":144,"b":151}]},{"name":"topic","required":true,"transform":{"type":"scalar"},"locs":[{"a":173,"b":179}]}],"statement":"SELECT * FROM effectstream.event WHERE\n COALESCE(block_height >= :from, 1=1) AND\n COALESCE(block_height <= :to, 1=1) AND\n COALESCE(address = :address, 1=1) AND\n topic = :topic!"};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Query generated from SQL:
|
|
35
|
+
* ```
|
|
36
|
+
* SELECT * FROM effectstream.event WHERE
|
|
37
|
+
* COALESCE(block_height >= :from, 1=1) AND
|
|
38
|
+
* COALESCE(block_height <= :to, 1=1) AND
|
|
39
|
+
* COALESCE(address = :address, 1=1) AND
|
|
40
|
+
* topic = :topic!
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const getEvents = new PreparedQuery<IGetEventsParams,IGetEventsResult>(getEventsIR);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
/** 'InsertEvent' parameters type */
|
|
47
|
+
export interface IInsertEventParams {
|
|
48
|
+
address: string;
|
|
49
|
+
block_height: number;
|
|
50
|
+
data: Json;
|
|
51
|
+
log_index: number;
|
|
52
|
+
topic: string;
|
|
53
|
+
tx_index: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 'InsertEvent' return type */
|
|
57
|
+
export type IInsertEventResult = void;
|
|
58
|
+
|
|
59
|
+
/** 'InsertEvent' query type */
|
|
60
|
+
export interface IInsertEventQuery {
|
|
61
|
+
params: IInsertEventParams;
|
|
62
|
+
result: IInsertEventResult;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const insertEventIR: any = {"usedParamSet":{"topic":true,"address":true,"data":true,"block_height":true,"tx_index":true,"log_index":true},"params":[{"name":"topic","required":true,"transform":{"type":"scalar"},"locs":[{"a":114,"b":120}]},{"name":"address","required":true,"transform":{"type":"scalar"},"locs":[{"a":125,"b":133}]},{"name":"data","required":true,"transform":{"type":"scalar"},"locs":[{"a":138,"b":143}]},{"name":"block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":148,"b":161}]},{"name":"tx_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":166,"b":175}]},{"name":"log_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":180,"b":190}]}],"statement":"INSERT INTO effectstream.event (\n topic,\n address,\n data,\n block_height,\n tx_index,\n log_index\n) VALUES (\n :topic!,\n :address!,\n :data!,\n :block_height!,\n :tx_index!,\n :log_index!\n)"};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Query generated from SQL:
|
|
69
|
+
* ```
|
|
70
|
+
* INSERT INTO effectstream.event (
|
|
71
|
+
* topic,
|
|
72
|
+
* address,
|
|
73
|
+
* data,
|
|
74
|
+
* block_height,
|
|
75
|
+
* tx_index,
|
|
76
|
+
* log_index
|
|
77
|
+
* ) VALUES (
|
|
78
|
+
* :topic!,
|
|
79
|
+
* :address!,
|
|
80
|
+
* :data!,
|
|
81
|
+
* :block_height!,
|
|
82
|
+
* :tx_index!,
|
|
83
|
+
* :log_index!
|
|
84
|
+
* )
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export const insertEvent = new PreparedQuery<IInsertEventParams,IInsertEventResult>(insertEventIR);
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/** 'RegisterEventType' parameters type */
|
|
91
|
+
export interface IRegisterEventTypeParams {
|
|
92
|
+
name: string;
|
|
93
|
+
topic: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** 'RegisterEventType' return type */
|
|
97
|
+
export type IRegisterEventTypeResult = void;
|
|
98
|
+
|
|
99
|
+
/** 'RegisterEventType' query type */
|
|
100
|
+
export interface IRegisterEventTypeQuery {
|
|
101
|
+
params: IRegisterEventTypeParams;
|
|
102
|
+
result: IRegisterEventTypeResult;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const registerEventTypeIR: any = {"usedParamSet":{"name":true,"topic":true},"params":[{"name":"name","required":true,"transform":{"type":"scalar"},"locs":[{"a":73,"b":78}]},{"name":"topic","required":true,"transform":{"type":"scalar"},"locs":[{"a":83,"b":89}]}],"statement":"INSERT INTO effectstream.registered_event (\n name,\n topic\n) VALUES (\n :name!,\n :topic!\n)"};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Query generated from SQL:
|
|
109
|
+
* ```
|
|
110
|
+
* INSERT INTO effectstream.registered_event (
|
|
111
|
+
* name,
|
|
112
|
+
* topic
|
|
113
|
+
* ) VALUES (
|
|
114
|
+
* :name!,
|
|
115
|
+
* :topic!
|
|
116
|
+
* )
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export const registerEventType = new PreparedQuery<IRegisterEventTypeParams,IRegisterEventTypeResult>(registerEventTypeIR);
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/** 'GetTopicsForEvent' parameters type */
|
|
123
|
+
export interface IGetTopicsForEventParams {
|
|
124
|
+
name: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 'GetTopicsForEvent' return type */
|
|
128
|
+
export interface IGetTopicsForEventResult {
|
|
129
|
+
topic: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 'GetTopicsForEvent' query type */
|
|
133
|
+
export interface IGetTopicsForEventQuery {
|
|
134
|
+
params: IGetTopicsForEventParams;
|
|
135
|
+
result: IGetTopicsForEventResult;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const getTopicsForEventIR: any = {"usedParamSet":{"name":true},"params":[{"name":"name","required":true,"transform":{"type":"scalar"},"locs":[{"a":61,"b":66}]}],"statement":"SELECT topic FROM effectstream.registered_event WHERE name = :name!"};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Query generated from SQL:
|
|
142
|
+
* ```
|
|
143
|
+
* SELECT topic FROM effectstream.registered_event WHERE name = :name!
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export const getTopicsForEvent = new PreparedQuery<IGetTopicsForEventParams,IGetTopicsForEventResult>(getTopicsForEventIR);
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
/** 'GetTopics' parameters type */
|
|
150
|
+
export type IGetTopicsParams = void;
|
|
151
|
+
|
|
152
|
+
/** 'GetTopics' return type */
|
|
153
|
+
export interface IGetTopicsResult {
|
|
154
|
+
name: string;
|
|
155
|
+
topic: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 'GetTopics' query type */
|
|
159
|
+
export interface IGetTopicsQuery {
|
|
160
|
+
params: IGetTopicsParams;
|
|
161
|
+
result: IGetTopicsResult;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const getTopicsIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT name, topic FROM effectstream.registered_event"};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Query generated from SQL:
|
|
168
|
+
* ```
|
|
169
|
+
* SELECT name, topic FROM effectstream.registered_event
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export const getTopics = new PreparedQuery<IGetTopicsParams,IGetTopicsResult>(getTopicsIR);
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
/** 'GetEventByTopic' parameters type */
|
|
176
|
+
export interface IGetEventByTopicParams {
|
|
177
|
+
topic: string;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** 'GetEventByTopic' return type */
|
|
181
|
+
export interface IGetEventByTopicResult {
|
|
182
|
+
name: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** 'GetEventByTopic' query type */
|
|
186
|
+
export interface IGetEventByTopicQuery {
|
|
187
|
+
params: IGetEventByTopicParams;
|
|
188
|
+
result: IGetEventByTopicResult;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const getEventByTopicIR: any = {"usedParamSet":{"topic":true},"params":[{"name":"topic","required":true,"transform":{"type":"scalar"},"locs":[{"a":61,"b":67}]}],"statement":"SELECT name FROM effectstream.registered_event WHERE topic = :topic!"};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Query generated from SQL:
|
|
195
|
+
* ```
|
|
196
|
+
* SELECT name FROM effectstream.registered_event WHERE topic = :topic!
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export const getEventByTopic = new PreparedQuery<IGetEventByTopicParams,IGetEventByTopicResult>(getEventByTopicIR);
|
|
200
|
+
|
|
201
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* @name getEvents */
|
|
2
|
+
SELECT * FROM effectstream.event WHERE
|
|
3
|
+
COALESCE(block_height >= :from, 1=1) AND
|
|
4
|
+
COALESCE(block_height <= :to, 1=1) AND
|
|
5
|
+
COALESCE(address = :address, 1=1) AND
|
|
6
|
+
topic = :topic!;
|
|
7
|
+
|
|
8
|
+
/* @name insertEvent */
|
|
9
|
+
INSERT INTO effectstream.event (
|
|
10
|
+
topic,
|
|
11
|
+
address,
|
|
12
|
+
data,
|
|
13
|
+
block_height,
|
|
14
|
+
tx_index,
|
|
15
|
+
log_index
|
|
16
|
+
) VALUES (
|
|
17
|
+
:topic!,
|
|
18
|
+
:address!,
|
|
19
|
+
:data!,
|
|
20
|
+
:block_height!,
|
|
21
|
+
:tx_index!,
|
|
22
|
+
:log_index!
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
/* @name registerEventType */
|
|
26
|
+
INSERT INTO effectstream.registered_event (
|
|
27
|
+
name,
|
|
28
|
+
topic
|
|
29
|
+
) VALUES (
|
|
30
|
+
:name!,
|
|
31
|
+
:topic!
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
/* @name getTopicsForEvent */
|
|
35
|
+
SELECT topic FROM effectstream.registered_event WHERE name = :name!;
|
|
36
|
+
|
|
37
|
+
/* @name getTopics */
|
|
38
|
+
SELECT name, topic FROM effectstream.registered_event;
|
|
39
|
+
|
|
40
|
+
/* @name getEventByTopic */
|
|
41
|
+
SELECT name FROM effectstream.registered_event WHERE topic = :topic!;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/nonces.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
/** 'FindNonce' parameters type */
|
|
5
|
+
export interface IFindNonceParams {
|
|
6
|
+
nonce?: string | null | void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** 'FindNonce' return type */
|
|
10
|
+
export interface IFindNonceResult {
|
|
11
|
+
block_height: number;
|
|
12
|
+
nonce: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** 'FindNonce' query type */
|
|
16
|
+
export interface IFindNonceQuery {
|
|
17
|
+
params: IFindNonceParams;
|
|
18
|
+
result: IFindNonceResult;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const findNonceIR: any = {"usedParamSet":{"nonce":true},"params":[{"name":"nonce","required":false,"transform":{"type":"scalar"},"locs":[{"a":48,"b":53}]}],"statement":"SELECT * FROM effectstream.nonces\nWHERE nonce = :nonce"};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Query generated from SQL:
|
|
25
|
+
* ```
|
|
26
|
+
* SELECT * FROM effectstream.nonces
|
|
27
|
+
* WHERE nonce = :nonce
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const findNonce = new PreparedQuery<IFindNonceParams,IFindNonceResult>(findNonceIR);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/** 'DeleteNonces' parameters type */
|
|
34
|
+
export interface IDeleteNoncesParams {
|
|
35
|
+
limit_block_height: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 'DeleteNonces' return type */
|
|
39
|
+
export type IDeleteNoncesResult = void;
|
|
40
|
+
|
|
41
|
+
/** 'DeleteNonces' query type */
|
|
42
|
+
export interface IDeleteNoncesQuery {
|
|
43
|
+
params: IDeleteNoncesParams;
|
|
44
|
+
result: IDeleteNoncesResult;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const deleteNoncesIR: any = {"usedParamSet":{"limit_block_height":true},"params":[{"name":"limit_block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":54,"b":73}]}],"statement":"DELETE FROM effectstream.nonces\nWHERE block_height <= :limit_block_height!"};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Query generated from SQL:
|
|
51
|
+
* ```
|
|
52
|
+
* DELETE FROM effectstream.nonces
|
|
53
|
+
* WHERE block_height <= :limit_block_height!
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const deleteNonces = new PreparedQuery<IDeleteNoncesParams,IDeleteNoncesResult>(deleteNoncesIR);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/** 'InsertNonce' parameters type */
|
|
60
|
+
export interface IInsertNonceParams {
|
|
61
|
+
block_height: number;
|
|
62
|
+
nonce: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 'InsertNonce' return type */
|
|
66
|
+
export type IInsertNonceResult = void;
|
|
67
|
+
|
|
68
|
+
/** 'InsertNonce' query type */
|
|
69
|
+
export interface IInsertNonceQuery {
|
|
70
|
+
params: IInsertNonceParams;
|
|
71
|
+
result: IInsertNonceResult;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const insertNonceIR: any = {"usedParamSet":{"nonce":true,"block_height":true},"params":[{"name":"nonce","required":true,"transform":{"type":"scalar"},"locs":[{"a":61,"b":67}]},{"name":"block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":70,"b":83}]}],"statement":"INSERT INTO effectstream.nonces(nonce, block_height)\nVALUES (:nonce!, :block_height!)"};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Query generated from SQL:
|
|
78
|
+
* ```
|
|
79
|
+
* INSERT INTO effectstream.nonces(nonce, block_height)
|
|
80
|
+
* VALUES (:nonce!, :block_height!)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export const insertNonce = new PreparedQuery<IInsertNonceParams,IInsertNonceResult>(insertNonceIR);
|
|
84
|
+
|
|
85
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* @name findNonce */
|
|
2
|
+
SELECT * FROM effectstream.nonces
|
|
3
|
+
WHERE nonce = :nonce;
|
|
4
|
+
|
|
5
|
+
/* @name deleteNonces */
|
|
6
|
+
DELETE FROM effectstream.nonces
|
|
7
|
+
WHERE block_height <= :limit_block_height!;
|
|
8
|
+
|
|
9
|
+
/* @name insertNonce */
|
|
10
|
+
INSERT INTO effectstream.nonces(nonce, block_height)
|
|
11
|
+
VALUES (:nonce!, :block_height!);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/primitives.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
5
|
+
|
|
6
|
+
/** 'InsertPrimitiveAccounting' parameters type */
|
|
7
|
+
export interface IInsertPrimitiveAccountingParams {
|
|
8
|
+
effectstream_block_height: number;
|
|
9
|
+
payload: Json;
|
|
10
|
+
payload_type: string;
|
|
11
|
+
primitive_name: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** 'InsertPrimitiveAccounting' return type */
|
|
15
|
+
export type IInsertPrimitiveAccountingResult = void;
|
|
16
|
+
|
|
17
|
+
/** 'InsertPrimitiveAccounting' query type */
|
|
18
|
+
export interface IInsertPrimitiveAccountingQuery {
|
|
19
|
+
params: IInsertPrimitiveAccountingParams;
|
|
20
|
+
result: IInsertPrimitiveAccountingResult;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const insertPrimitiveAccountingIR: any = {"usedParamSet":{"primitive_name":true,"effectstream_block_height":true,"payload_type":true,"payload":true},"params":[{"name":"primitive_name","required":true,"transform":{"type":"scalar"},"locs":[{"a":120,"b":135}]},{"name":"effectstream_block_height","required":true,"transform":{"type":"scalar"},"locs":[{"a":138,"b":164}]},{"name":"payload_type","required":true,"transform":{"type":"scalar"},"locs":[{"a":167,"b":180}]},{"name":"payload","required":true,"transform":{"type":"scalar"},"locs":[{"a":183,"b":191}]}],"statement":"INSERT INTO effectstream.primitive_accounting(primitive_name, effectstream_block_height, payload_type, payload)\nVALUES (:primitive_name!, :effectstream_block_height!, :payload_type!, :payload!)\nON CONFLICT (primitive_name, effectstream_block_height, payload_hash) DO NOTHING"};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Query generated from SQL:
|
|
27
|
+
* ```
|
|
28
|
+
* INSERT INTO effectstream.primitive_accounting(primitive_name, effectstream_block_height, payload_type, payload)
|
|
29
|
+
* VALUES (:primitive_name!, :effectstream_block_height!, :payload_type!, :payload!)
|
|
30
|
+
* ON CONFLICT (primitive_name, effectstream_block_height, payload_hash) DO NOTHING
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const insertPrimitiveAccounting = new PreparedQuery<IInsertPrimitiveAccountingParams,IInsertPrimitiveAccountingResult>(insertPrimitiveAccountingIR);
|
|
34
|
+
|
|
35
|
+
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/* @name insertPrimitiveAccounting */
|
|
2
|
+
INSERT INTO effectstream.primitive_accounting(primitive_name, effectstream_block_height, payload_type, payload)
|
|
3
|
+
VALUES (:primitive_name!, :effectstream_block_height!, :payload_type!, :payload!)
|
|
4
|
+
ON CONFLICT (primitive_name, effectstream_block_height, payload_hash) DO NOTHING;
|