@sentio/sdk 1.7.22 → 1.8.1
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/lib/base-processor.d.ts +3 -3
- package/lib/base-processor.js +3 -0
- package/lib/base-processor.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +123 -36
- package/lib/gen/processor/protos/processor.js +417 -53
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/meter.js +1 -1
- package/lib/meter.js.map +1 -1
- package/lib/service.d.ts +3 -2
- package/lib/service.js +11 -3
- package/lib/service.js.map +1 -1
- package/lib/solana-processor.d.ts +2 -2
- package/lib/solana-processor.js +1 -0
- package/lib/solana-processor.js.map +1 -1
- package/lib/test/erc20.test.js +9 -11
- package/lib/test/erc20.test.js.map +1 -1
- package/lib/test/index.d.ts +1 -0
- package/lib/test/index.js +3 -1
- package/lib/test/index.js.map +1 -1
- package/lib/test/metric-utils.d.ts +3 -3
- package/lib/test/metric-utils.js.map +1 -1
- package/lib/test/test-processor-server.d.ts +2 -1
- package/lib/test/test-processor-server.js +3 -0
- package/lib/test/test-processor-server.js.map +1 -1
- package/lib/test/test-provider.d.ts +1 -0
- package/lib/test/test-provider.js +25 -0
- package/lib/test/test-provider.js.map +1 -0
- package/lib/utils/chainmap.js +3 -3
- package/lib/utils/chainmap.js.map +1 -1
- package/lib/utils/erc20.test.js +6 -11
- package/lib/utils/erc20.test.js.map +1 -1
- package/package.json +1 -1
- package/src/base-processor.ts +6 -3
- package/src/gen/processor/protos/processor.ts +547 -83
- package/src/meter.ts +1 -1
- package/src/service.ts +25 -14
- package/src/solana-processor.ts +3 -2
- package/src/test/erc20.test.ts +9 -11
- package/src/test/index.ts +1 -0
- package/src/test/metric-utils.ts +3 -3
- package/src/test/test-processor-server.ts +6 -0
- package/src/test/test-provider.ts +25 -0
- package/src/utils/chainmap.ts +3 -3
- package/src/utils/erc20.test.ts +7 -12
package/src/meter.ts
CHANGED
|
@@ -40,7 +40,7 @@ function GetRecordMetaData(ctx: EthContext | SolanaContext, name: string, labels
|
|
|
40
40
|
blockNumber: Long.ZERO, // TODO need number type to be long
|
|
41
41
|
transactionIndex: 0,
|
|
42
42
|
logIndex: 0,
|
|
43
|
-
chainId: '
|
|
43
|
+
chainId: 'SOL_mainnet', // TODO set in context
|
|
44
44
|
name: name,
|
|
45
45
|
labels: labels,
|
|
46
46
|
}
|
package/src/service.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
HandlerType,
|
|
8
8
|
LogFilter,
|
|
9
9
|
LogHandlerConfig,
|
|
10
|
-
|
|
10
|
+
ProcessResult,
|
|
11
11
|
ProcessBlocksRequest,
|
|
12
12
|
ProcessBlocksResponse,
|
|
13
13
|
ProcessConfigRequest,
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
ProcessLogsRequest,
|
|
18
18
|
ProcessLogsResponse,
|
|
19
19
|
ProcessorServiceImplementation,
|
|
20
|
+
ProcessTracesRequest,
|
|
21
|
+
ProcessTracesResponse,
|
|
20
22
|
ProcessTransactionsRequest,
|
|
21
23
|
ProcessTransactionsResponse,
|
|
22
24
|
StartRequest,
|
|
@@ -30,11 +32,11 @@ import { TextDecoder } from 'util'
|
|
|
30
32
|
const DEFAULT_MAX_BLOCK = Long.ZERO
|
|
31
33
|
|
|
32
34
|
export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
33
|
-
private eventHandlers: ((event: Log) => Promise<
|
|
34
|
-
private blockHandlers: ((block: Block) => Promise<
|
|
35
|
+
private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []
|
|
36
|
+
private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []
|
|
35
37
|
|
|
36
38
|
// map from chain id to list of processors
|
|
37
|
-
// private blockHandlers = new Map<string, ((block: Block) => Promise<
|
|
39
|
+
// private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()
|
|
38
40
|
// private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()
|
|
39
41
|
|
|
40
42
|
private started = false
|
|
@@ -143,7 +145,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
143
145
|
processorType: 'user_processor',
|
|
144
146
|
contract: {
|
|
145
147
|
name: solanaProcessor.contractName,
|
|
146
|
-
chainId: '
|
|
148
|
+
chainId: 'SOL_mainnet', // TODO set in processor
|
|
147
149
|
address: solanaProcessor.address,
|
|
148
150
|
abi: '',
|
|
149
151
|
},
|
|
@@ -202,12 +204,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
202
204
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
203
205
|
}
|
|
204
206
|
|
|
205
|
-
const resp:
|
|
207
|
+
const resp: ProcessResult = {
|
|
206
208
|
gauges: [],
|
|
207
209
|
counters: [],
|
|
210
|
+
logs: [],
|
|
208
211
|
}
|
|
209
212
|
|
|
210
|
-
const promises: Promise<
|
|
213
|
+
const promises: Promise<ProcessResult>[] = []
|
|
211
214
|
for (const l of request.logBindings) {
|
|
212
215
|
if (!l.log) {
|
|
213
216
|
throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
|
|
@@ -270,9 +273,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
270
273
|
throw new ServerError(Status.UNAVAILABLE, 'Service not started.')
|
|
271
274
|
}
|
|
272
275
|
|
|
273
|
-
const result:
|
|
276
|
+
const result: ProcessResult = {
|
|
274
277
|
gauges: [],
|
|
275
278
|
counters: [],
|
|
279
|
+
logs: [],
|
|
276
280
|
}
|
|
277
281
|
|
|
278
282
|
// Only have instruction handlers for solana processors
|
|
@@ -287,7 +291,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
287
291
|
new Promise((resolve, _) => {
|
|
288
292
|
for (const processor of global.PROCESSOR_STATE.solanaProcessors) {
|
|
289
293
|
if (processor.address === instruction.programAccountId) {
|
|
290
|
-
let res:
|
|
294
|
+
let res: ProcessResult | null
|
|
291
295
|
if (instruction.parsed) {
|
|
292
296
|
res = processor.handleInstruction(JSON.parse(new TextDecoder().decode(instruction.parsed)))
|
|
293
297
|
} else if (instruction.instructionData) {
|
|
@@ -341,7 +345,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
341
345
|
const promises = request.blockBindings.map((binding) => this.processBlock(binding))
|
|
342
346
|
const results = await Promise.all(promises)
|
|
343
347
|
|
|
344
|
-
const res =
|
|
348
|
+
const res = ProcessResult.fromPartial({})
|
|
345
349
|
|
|
346
350
|
for (const r of results) {
|
|
347
351
|
res.counters = res.counters.concat(r.counters)
|
|
@@ -354,7 +358,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
|
|
357
|
-
async processBlock(binding: BlockBinding): Promise<
|
|
361
|
+
async processBlock(binding: BlockBinding): Promise<ProcessResult> {
|
|
358
362
|
if (!binding.block) {
|
|
359
363
|
throw new ServerError(Status.INVALID_ARGUMENT, "Block can't be empty")
|
|
360
364
|
}
|
|
@@ -362,12 +366,13 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
362
366
|
|
|
363
367
|
const block: Block = JSON.parse(jsonString)
|
|
364
368
|
|
|
365
|
-
const resp:
|
|
369
|
+
const resp: ProcessResult = {
|
|
366
370
|
gauges: [],
|
|
367
371
|
counters: [],
|
|
372
|
+
logs: [],
|
|
368
373
|
}
|
|
369
374
|
|
|
370
|
-
const promises: Promise<
|
|
375
|
+
const promises: Promise<ProcessResult>[] = []
|
|
371
376
|
for (const handlerId of binding.handlerIds) {
|
|
372
377
|
const promise = this.blockHandlers[handlerId](block).catch((e) => {
|
|
373
378
|
throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\n' + e.toString())
|
|
@@ -381,6 +386,12 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
|
381
386
|
}
|
|
382
387
|
return resp
|
|
383
388
|
}
|
|
389
|
+
|
|
390
|
+
async processTraces(request: ProcessTracesRequest, context: CallContext): Promise<ProcessTracesResponse> {
|
|
391
|
+
return {
|
|
392
|
+
result: undefined,
|
|
393
|
+
}
|
|
394
|
+
}
|
|
384
395
|
}
|
|
385
396
|
|
|
386
397
|
// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript
|
|
@@ -424,7 +435,7 @@ function Utf8ArrayToStr(array: Uint8Array) {
|
|
|
424
435
|
return out
|
|
425
436
|
}
|
|
426
437
|
|
|
427
|
-
function recordRuntimeInfo(results:
|
|
438
|
+
function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
|
|
428
439
|
results.gauges.forEach((e) => {
|
|
429
440
|
e.runtimeInfo = {
|
|
430
441
|
from: handlerType,
|
package/src/solana-processor.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProcessResult } from './gen/processor/protos/processor'
|
|
2
2
|
import { SolanaContext } from './context'
|
|
3
3
|
import Long from 'long'
|
|
4
4
|
import { Instruction } from '@project-serum/anchor'
|
|
@@ -54,7 +54,7 @@ export class SolanaBaseProcessor {
|
|
|
54
54
|
return this
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
public handleInstruction(ins: string | { type: string; info: any }):
|
|
57
|
+
public handleInstruction(ins: string | { type: string; info: any }): ProcessResult | null {
|
|
58
58
|
const ctx = new SolanaContext(this.address)
|
|
59
59
|
let parsedInstruction: Instruction | null = null
|
|
60
60
|
|
|
@@ -80,6 +80,7 @@ export class SolanaBaseProcessor {
|
|
|
80
80
|
return {
|
|
81
81
|
gauges: ctx.gauges,
|
|
82
82
|
counters: ctx.counters,
|
|
83
|
+
logs: [],
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
package/src/test/erc20.test.ts
CHANGED
|
@@ -28,21 +28,19 @@ describe('Test Basic Examples', () => {
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
test('Check block dispatch', async () => {
|
|
31
|
-
const res = await service.testBlock(blockData)
|
|
32
|
-
|
|
33
|
-
expect(
|
|
34
|
-
expect(
|
|
35
|
-
expect(firstGaugeValue(o11yRes, 'g1')).equals(10n)
|
|
31
|
+
const res = (await service.testBlock(blockData)).result
|
|
32
|
+
expect(res?.counters).length(0)
|
|
33
|
+
expect(res?.gauges).length(1)
|
|
34
|
+
expect(firstGaugeValue(res, 'g1')).equals(10n)
|
|
36
35
|
|
|
37
|
-
const gauge =
|
|
36
|
+
const gauge = res?.gauges?.[0]
|
|
38
37
|
expect(gauge?.metadata?.blockNumber?.toString()).equals('14373295')
|
|
39
38
|
expect(gauge?.runtimeInfo?.from).equals(HandlerType.BLOCK)
|
|
40
39
|
|
|
41
|
-
const res2 = await service.testBlock(blockData, 56)
|
|
42
|
-
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
45
|
-
expect(firstGaugeValue(o11yRes2, 'g2')).equals(20n)
|
|
40
|
+
const res2 = (await service.testBlock(blockData, 56)).result
|
|
41
|
+
expect(res2?.counters).length(0)
|
|
42
|
+
expect(res2?.gauges).length(1)
|
|
43
|
+
expect(firstGaugeValue(res2, 'g2')).equals(20n)
|
|
46
44
|
})
|
|
47
45
|
|
|
48
46
|
test('Check log dispatch', async () => {
|
package/src/test/index.ts
CHANGED
package/src/test/metric-utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeepPartial } from '../gen/builtin'
|
|
2
|
-
import { BigDecimal, MetricValue,
|
|
2
|
+
import { BigDecimal, MetricValue, ProcessResult } from '@sentio/sdk'
|
|
3
3
|
import { Numberish } from '../numberish'
|
|
4
4
|
import { BigNumber } from 'ethers'
|
|
5
5
|
|
|
@@ -24,7 +24,7 @@ export function MetricValueToNumber(v: DeepPartial<MetricValue> | undefined): Nu
|
|
|
24
24
|
return undefined
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function firstCounterValue(result:
|
|
27
|
+
export function firstCounterValue(result: ProcessResult | undefined, name: string): Numberish | undefined {
|
|
28
28
|
if (!result) {
|
|
29
29
|
return undefined
|
|
30
30
|
}
|
|
@@ -36,7 +36,7 @@ export function firstCounterValue(result: O11yResult | undefined, name: string):
|
|
|
36
36
|
return undefined
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function firstGaugeValue(result:
|
|
39
|
+
export function firstGaugeValue(result: ProcessResult | undefined, name: string): Numberish | undefined {
|
|
40
40
|
if (!result) {
|
|
41
41
|
return undefined
|
|
42
42
|
}
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
ProcessorServiceImpl,
|
|
14
14
|
ProcessorServiceImplementation,
|
|
15
15
|
ProcessorState,
|
|
16
|
+
ProcessTracesRequest,
|
|
17
|
+
ProcessTracesResponse,
|
|
16
18
|
ProcessTransactionsRequest,
|
|
17
19
|
ProcessTransactionsResponse,
|
|
18
20
|
setProvider,
|
|
@@ -82,6 +84,10 @@ export class TestProcessorServer implements ProcessorServiceImplementation {
|
|
|
82
84
|
return this.service.processLogs(request, context)
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
processTraces(request: ProcessTracesRequest, context: CallContext = TEST_CONTEXT): Promise<ProcessTracesResponse> {
|
|
88
|
+
return this.service.processTraces(request, context)
|
|
89
|
+
}
|
|
90
|
+
|
|
85
91
|
processTransactions(
|
|
86
92
|
request: ProcessTransactionsRequest,
|
|
87
93
|
context = TEST_CONTEXT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ChainConfig } from '../chain-config'
|
|
2
|
+
import { setProvider } from '@sentio/sdk'
|
|
3
|
+
|
|
4
|
+
export function loadTestProvidersFromEnv(ids: string[] | string): boolean {
|
|
5
|
+
const dummyConfig: Record<string, ChainConfig> = {}
|
|
6
|
+
|
|
7
|
+
if (!Array.isArray(ids)) {
|
|
8
|
+
ids = [ids]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
for (const k of ids) {
|
|
12
|
+
const envKey = 'TEST_ENDPOINT_' + k
|
|
13
|
+
const http = process.env[envKey]
|
|
14
|
+
if (!http) {
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
17
|
+
dummyConfig[k] = {
|
|
18
|
+
ChainID: k,
|
|
19
|
+
Https: [http],
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
setProvider(dummyConfig)
|
|
24
|
+
return true
|
|
25
|
+
}
|
package/src/utils/chainmap.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// and https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/
|
|
3
3
|
|
|
4
4
|
export const CHAIN_MAP: Record<string, string> = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
SOL_mainnet: 'solana',
|
|
6
|
+
SOL_devnet: 'solana-dev',
|
|
7
|
+
SOL_testnet: 'solana-test',
|
|
8
8
|
0: 'kardia',
|
|
9
9
|
1: 'ethereum',
|
|
10
10
|
2: 'expanse',
|
package/src/utils/erc20.test.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import { ProcessorState
|
|
1
|
+
import { ProcessorState } from '@sentio/sdk'
|
|
2
2
|
import { getERC20TokenInfo } from './erc20'
|
|
3
|
+
import { loadTestProvidersFromEnv } from '../test'
|
|
3
4
|
|
|
4
5
|
describe('erc20 tests', () => {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
global.PROCESSOR_STATE = new ProcessorState()
|
|
7
|
+
const haveProviders = loadTestProvidersFromEnv('1')
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
'1': {
|
|
10
|
-
ChainID: '1',
|
|
11
|
-
Https: ['https://eth-mainnet.alchemyapi.io/v2/Gk024pFA-64RaEPIawL40n__1esXJFb2'], // Use env
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
})
|
|
9
|
+
const testIf = haveProviders ? test : test.skip
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
testIf('test bytes32', async () => {
|
|
17
12
|
const info = await getERC20TokenInfo('0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2')
|
|
18
13
|
|
|
19
14
|
expect(info.decimal).toEqual(18)
|
|
@@ -21,7 +16,7 @@ describe('erc20 tests', () => {
|
|
|
21
16
|
expect(info.name).toEqual('Maker')
|
|
22
17
|
})
|
|
23
18
|
|
|
24
|
-
|
|
19
|
+
testIf('test normal', async () => {
|
|
25
20
|
const info = await getERC20TokenInfo('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48')
|
|
26
21
|
|
|
27
22
|
expect(info.decimal).toEqual(6)
|