@0xsequence/indexer 0.0.0-2021823181734

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.
@@ -0,0 +1,415 @@
1
+ /* eslint-disable */
2
+ // sequence-indexer v0.4.0 af55f42a2e22fda0417a49eaefd8db7c5ad28a6a
3
+ // --
4
+ // This file has been generated by https://github.com/webrpc/webrpc using gen/typescript
5
+ // Do not edit by hand. Update your webrpc schema and re-generate.
6
+
7
+ // WebRPC description and code-gen version
8
+ export const WebRPCVersion = "v1"
9
+
10
+ // Schema version of your RIDL schema
11
+ export const WebRPCSchemaVersion = "v0.4.0"
12
+
13
+ // Schema hash generated from your RIDL schema
14
+ export const WebRPCSchemaHash = "af55f42a2e22fda0417a49eaefd8db7c5ad28a6a"
15
+
16
+
17
+ //
18
+ // Types
19
+ //
20
+ export enum ContractType {
21
+ UNKNOWN = 'UNKNOWN',
22
+ ERC20 = 'ERC20',
23
+ ERC721 = 'ERC721',
24
+ ERC1155 = 'ERC1155',
25
+ SEQUENCE_WALLET = 'SEQUENCE_WALLET'
26
+ }
27
+
28
+ export enum EventLogType {
29
+ UNKNOWN = 'UNKNOWN',
30
+ BLOCK_ADDED = 'BLOCK_ADDED',
31
+ BLOCK_REMOVED = 'BLOCK_REMOVED'
32
+ }
33
+
34
+ export enum EventLogDataType {
35
+ UNKNOWN = 'UNKNOWN',
36
+ TOKEN_TRANSFER = 'TOKEN_TRANSFER',
37
+ SEQUENCE_TXN = 'SEQUENCE_TXN'
38
+ }
39
+
40
+ export enum TxnTransferType {
41
+ UNKNOWN = 'UNKNOWN',
42
+ SEND = 'SEND',
43
+ RECEIVE = 'RECEIVE'
44
+ }
45
+
46
+ export enum SortOrder {
47
+ DESC = 'DESC',
48
+ ASC = 'ASC'
49
+ }
50
+
51
+ export interface Version {
52
+ webrpcVersion: string
53
+ schemaVersion: string
54
+ schemaHash: string
55
+ appVersion: string
56
+ }
57
+
58
+ export interface RuntimeStatus {
59
+ healthOK: boolean
60
+ indexerEnabled: boolean
61
+ startTime: string
62
+ uptime: number
63
+ ver: string
64
+ branch: string
65
+ commitHash: string
66
+ chainID: number
67
+ checks: RuntimeChecks
68
+ }
69
+
70
+ export interface RuntimeChecks {
71
+ running: boolean
72
+ syncMode: string
73
+ lastBlockNum: number
74
+ }
75
+
76
+ export interface EtherBalance {
77
+ accountAddress: string
78
+ balanceWei: string
79
+ }
80
+
81
+ export interface IndexState {
82
+ lastBlockNum: number
83
+ }
84
+
85
+ export interface EventLog {
86
+ id: number
87
+ type: EventLogType
88
+ blockNumber: number
89
+ blockHash: string
90
+ contractAddress: string
91
+ contractType: ContractType
92
+ txnHash: string
93
+ txnIndex: number
94
+ txnLogIndex: number
95
+ logDataType: EventLogDataType
96
+ ts: string
97
+ logData: string
98
+ }
99
+
100
+ export interface TokenBalance {
101
+ id: number
102
+
103
+ contractAddress: string
104
+ contractType: ContractType
105
+ accountAddress: string
106
+ tokenID: string
107
+ balance: string
108
+ blockHash: string
109
+ blockNumber: number
110
+ chainId: number
111
+ }
112
+
113
+ export interface TokenHistory {
114
+ id: number
115
+ blockNumber: number
116
+ blockHash: string
117
+ contractAddress: string
118
+ contractType: ContractType
119
+ fromAddress: string
120
+ toAddress: string
121
+ txnHash: string
122
+ txnIndex: number
123
+ txnLogIndex: number
124
+ logData: string
125
+ ts: string
126
+ }
127
+
128
+ export interface Transaction {
129
+ txnHash: string
130
+ blockNumber: number
131
+ blockHash: string
132
+ chainId: number
133
+ metaTxnID?: string
134
+ transfers?: Array<TxnTransfer>
135
+ timestamp: string
136
+ }
137
+
138
+ export interface TxnTransfer {
139
+ transferType: TxnTransferType
140
+ contractAddress: string
141
+ contractType: ContractType
142
+ from: string
143
+ to: string
144
+ tokenIds?: Array<string>
145
+ amounts: Array<string>
146
+ }
147
+
148
+ export interface TransactionHistoryFilter {
149
+ accountAddresses?: Array<string>
150
+ contractAddresses?: Array<string>
151
+ transactionHashes?: Array<string>
152
+ metaTransactionIDs?: Array<string>
153
+ fromBlock?: number
154
+ toBlock?: number
155
+ }
156
+
157
+ export interface Page {
158
+ pageSize?: number
159
+ page?: number
160
+ totalRecords?: number
161
+ column?: string
162
+ before?: any
163
+ after?: any
164
+ sort?: Array<SortBy>
165
+ }
166
+
167
+ export interface SortBy {
168
+ column: string
169
+ order: SortOrder
170
+ }
171
+
172
+ export interface Indexer {
173
+ ping(headers?: object): Promise<PingReturn>
174
+ version(headers?: object): Promise<VersionReturn>
175
+ runtimeStatus(headers?: object): Promise<RuntimeStatusReturn>
176
+ getChainID(headers?: object): Promise<GetChainIDReturn>
177
+ getEtherBalance(args: GetEtherBalanceArgs, headers?: object): Promise<GetEtherBalanceReturn>
178
+ getTokenBalances(args: GetTokenBalancesArgs, headers?: object): Promise<GetTokenBalancesReturn>
179
+ getTokenSupplies(args: GetTokenSuppliesArgs, headers?: object): Promise<GetTokenSuppliesReturn>
180
+ getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object): Promise<GetBalanceUpdatesReturn>
181
+ getTransactionHistory(args: GetTransactionHistoryArgs, headers?: object): Promise<GetTransactionHistoryReturn>
182
+ }
183
+
184
+ export interface PingArgs {
185
+ }
186
+
187
+ export interface PingReturn {
188
+ status: boolean
189
+ }
190
+ export interface VersionArgs {
191
+ }
192
+
193
+ export interface VersionReturn {
194
+ version: Version
195
+ }
196
+ export interface RuntimeStatusArgs {
197
+ }
198
+
199
+ export interface RuntimeStatusReturn {
200
+ status: RuntimeStatus
201
+ }
202
+ export interface GetChainIDArgs {
203
+ }
204
+
205
+ export interface GetChainIDReturn {
206
+ chainID: number
207
+ }
208
+ export interface GetEtherBalanceArgs {
209
+ accountAddress?: string
210
+ }
211
+
212
+ export interface GetEtherBalanceReturn {
213
+ balance: EtherBalance
214
+ }
215
+ export interface GetTokenBalancesArgs {
216
+ accountAddress?: string
217
+ contractAddress?: string
218
+ }
219
+
220
+ export interface GetTokenBalancesReturn {
221
+ balances: Array<TokenBalance>
222
+ }
223
+ export interface GetTokenSuppliesArgs {
224
+ tokenMap: {[key: string]: Array<string>}
225
+ }
226
+
227
+ export interface GetTokenSuppliesReturn {
228
+ supplies: {[key: string]: Array<TokenBalance>}
229
+ }
230
+ export interface GetBalanceUpdatesArgs {
231
+ contractAddress: string
232
+ lastBalanceID: number
233
+ page?: Page
234
+ }
235
+
236
+ export interface GetBalanceUpdatesReturn {
237
+ page?: Page
238
+ balances: Array<TokenBalance>
239
+ }
240
+ export interface GetTransactionHistoryArgs {
241
+ filter: TransactionHistoryFilter
242
+ page?: Page
243
+ }
244
+
245
+ export interface GetTransactionHistoryReturn {
246
+ page: Page
247
+ transactions: Array<Transaction>
248
+ }
249
+
250
+
251
+
252
+ //
253
+ // Client
254
+ //
255
+ export class Indexer implements Indexer {
256
+ protected hostname: string
257
+ protected fetch: Fetch
258
+ protected path = '/rpc/Indexer/'
259
+
260
+ constructor(hostname: string, fetch: Fetch) {
261
+ this.hostname = hostname
262
+ this.fetch = fetch
263
+ }
264
+
265
+ private url(name: string): string {
266
+ return this.hostname + this.path + name
267
+ }
268
+
269
+ ping = (headers?: object): Promise<PingReturn> => {
270
+ return this.fetch(
271
+ this.url('Ping'),
272
+ createHTTPRequest({}, headers)
273
+ ).then((res) => {
274
+ return buildResponse(res).then(_data => {
275
+ return {
276
+ status: <boolean>(_data.status)
277
+ }
278
+ })
279
+ })
280
+ }
281
+
282
+ version = (headers?: object): Promise<VersionReturn> => {
283
+ return this.fetch(
284
+ this.url('Version'),
285
+ createHTTPRequest({}, headers)
286
+ ).then((res) => {
287
+ return buildResponse(res).then(_data => {
288
+ return {
289
+ version: <Version>(_data.version)
290
+ }
291
+ })
292
+ })
293
+ }
294
+
295
+ runtimeStatus = (headers?: object): Promise<RuntimeStatusReturn> => {
296
+ return this.fetch(
297
+ this.url('RuntimeStatus'),
298
+ createHTTPRequest({}, headers)
299
+ ).then((res) => {
300
+ return buildResponse(res).then(_data => {
301
+ return {
302
+ status: <RuntimeStatus>(_data.status)
303
+ }
304
+ })
305
+ })
306
+ }
307
+
308
+ getChainID = (headers?: object): Promise<GetChainIDReturn> => {
309
+ return this.fetch(
310
+ this.url('GetChainID'),
311
+ createHTTPRequest({}, headers)
312
+ ).then((res) => {
313
+ return buildResponse(res).then(_data => {
314
+ return {
315
+ chainID: <number>(_data.chainID)
316
+ }
317
+ })
318
+ })
319
+ }
320
+
321
+ getEtherBalance = (args: GetEtherBalanceArgs, headers?: object): Promise<GetEtherBalanceReturn> => {
322
+ return this.fetch(
323
+ this.url('GetEtherBalance'),
324
+ createHTTPRequest(args, headers)).then((res) => {
325
+ return buildResponse(res).then(_data => {
326
+ return {
327
+ balance: <EtherBalance>(_data.balance)
328
+ }
329
+ })
330
+ })
331
+ }
332
+
333
+ getTokenBalances = (args: GetTokenBalancesArgs, headers?: object): Promise<GetTokenBalancesReturn> => {
334
+ return this.fetch(
335
+ this.url('GetTokenBalances'),
336
+ createHTTPRequest(args, headers)).then((res) => {
337
+ return buildResponse(res).then(_data => {
338
+ return {
339
+ balances: <Array<TokenBalance>>(_data.balances)
340
+ }
341
+ })
342
+ })
343
+ }
344
+
345
+ getTokenSupplies = (args: GetTokenSuppliesArgs, headers?: object): Promise<GetTokenSuppliesReturn> => {
346
+ return this.fetch(
347
+ this.url('GetTokenSupplies'),
348
+ createHTTPRequest(args, headers)).then((res) => {
349
+ return buildResponse(res).then(_data => {
350
+ return {
351
+ supplies: <{[key: string]: Array<TokenBalance>}>(_data.supplies)
352
+ }
353
+ })
354
+ })
355
+ }
356
+
357
+ getBalanceUpdates = (args: GetBalanceUpdatesArgs, headers?: object): Promise<GetBalanceUpdatesReturn> => {
358
+ return this.fetch(
359
+ this.url('GetBalanceUpdates'),
360
+ createHTTPRequest(args, headers)).then((res) => {
361
+ return buildResponse(res).then(_data => {
362
+ return {
363
+ page: <Page>(_data.page),
364
+ balances: <Array<TokenBalance>>(_data.balances)
365
+ }
366
+ })
367
+ })
368
+ }
369
+
370
+ getTransactionHistory = (args: GetTransactionHistoryArgs, headers?: object): Promise<GetTransactionHistoryReturn> => {
371
+ return this.fetch(
372
+ this.url('GetTransactionHistory'),
373
+ createHTTPRequest(args, headers)).then((res) => {
374
+ return buildResponse(res).then(_data => {
375
+ return {
376
+ page: <Page>(_data.page),
377
+ transactions: <Array<Transaction>>(_data.transactions)
378
+ }
379
+ })
380
+ })
381
+ }
382
+
383
+ }
384
+
385
+
386
+ export interface WebRPCError extends Error {
387
+ code: string
388
+ msg: string
389
+ status: number
390
+ }
391
+
392
+ const createHTTPRequest = (body: object = {}, headers: object = {}): object => {
393
+ return {
394
+ method: 'POST',
395
+ headers: { ...headers, 'Content-Type': 'application/json' },
396
+ body: JSON.stringify(body || {})
397
+ }
398
+ }
399
+
400
+ const buildResponse = (res: Response): Promise<any> => {
401
+ return res.text().then(text => {
402
+ let data
403
+ try {
404
+ data = JSON.parse(text)
405
+ } catch(err) {
406
+ throw { code: 'unknown', msg: `expecting JSON, got: ${text}`, status: res.status } as WebRPCError
407
+ }
408
+ if (!res.ok) {
409
+ throw data // webrpc error response
410
+ }
411
+ return data
412
+ })
413
+ }
414
+
415
+ export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>