@sentio/sdk 1.37.0-rc.5 → 1.37.0-rc.7

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.
Files changed (89) hide show
  1. package/lib/binds.d.ts +1 -1
  2. package/lib/binds.js +2 -2
  3. package/lib/binds.js.map +1 -1
  4. package/lib/core/account-processor.d.ts +1 -1
  5. package/lib/core/account-processor.js +2 -2
  6. package/lib/core/account-processor.js.map +1 -1
  7. package/lib/core/base-processor-template.d.ts +1 -1
  8. package/lib/core/base-processor-template.js +3 -3
  9. package/lib/core/base-processor-template.js.map +1 -1
  10. package/lib/core/core-plugin.d.ts +6 -0
  11. package/lib/core/core-plugin.js +37 -0
  12. package/lib/core/core-plugin.js.map +1 -0
  13. package/lib/core/eth-plugin.d.ts +5 -3
  14. package/lib/core/eth-plugin.js +34 -11
  15. package/lib/core/eth-plugin.js.map +1 -1
  16. package/lib/core/event-tracker.d.ts +1 -1
  17. package/lib/core/event-tracker.js +2 -2
  18. package/lib/core/event-tracker.js.map +1 -1
  19. package/lib/core/exporter.d.ts +1 -1
  20. package/lib/core/exporter.js +2 -2
  21. package/lib/core/exporter.js.map +1 -1
  22. package/lib/core/generic-processor.js +2 -2
  23. package/lib/core/generic-processor.js.map +1 -1
  24. package/lib/core/index.d.ts +1 -0
  25. package/lib/core/index.js +3 -1
  26. package/lib/core/index.js.map +1 -1
  27. package/lib/core/meter.d.ts +1 -1
  28. package/lib/core/meter.js +2 -2
  29. package/lib/core/meter.js.map +1 -1
  30. package/lib/core/sui-plugin.d.ts +4 -4
  31. package/lib/core/sui-plugin.js +6 -7
  32. package/lib/core/sui-plugin.js.map +1 -1
  33. package/lib/core/sui-processor.d.ts +1 -1
  34. package/lib/core/sui-processor.js +2 -2
  35. package/lib/core/sui-processor.js.map +1 -1
  36. package/lib/index.d.ts +1 -1
  37. package/lib/index.js +4 -4
  38. package/lib/index.js.map +1 -1
  39. package/lib/testing/test-processor-server.d.ts +1 -1
  40. package/lib/testing/test-processor-server.js +5 -10
  41. package/lib/testing/test-processor-server.js.map +1 -1
  42. package/lib/testing/test-provider.js +2 -2
  43. package/lib/testing/test-provider.js.map +1 -1
  44. package/lib/utils/dex-price.test.js.map +1 -1
  45. package/lib/utils/erc20.test.js.map +1 -1
  46. package/lib/utils/price.js +2 -1
  47. package/lib/utils/price.js.map +1 -1
  48. package/package.json +9 -18
  49. package/src/binds.ts +1 -1
  50. package/src/core/account-processor.ts +1 -1
  51. package/src/core/base-processor-template.ts +1 -1
  52. package/src/core/core-plugin.ts +39 -0
  53. package/src/core/eth-plugin.ts +30 -3
  54. package/src/core/event-tracker.ts +1 -1
  55. package/src/core/exporter.ts +1 -1
  56. package/src/core/generic-processor.ts +1 -1
  57. package/src/core/index.ts +1 -0
  58. package/src/core/meter.ts +1 -1
  59. package/src/core/sui-plugin.ts +4 -6
  60. package/src/core/sui-processor.ts +1 -1
  61. package/src/index.ts +1 -1
  62. package/src/testing/test-processor-server.ts +2 -8
  63. package/src/testing/test-provider.ts +1 -2
  64. package/src/utils/price.ts +2 -1
  65. package/lib/chain-config.d.ts +0 -6
  66. package/lib/chain-config.js +0 -3
  67. package/lib/chain-config.js.map +0 -1
  68. package/lib/endpoints.d.ts +0 -6
  69. package/lib/endpoints.js +0 -11
  70. package/lib/endpoints.js.map +0 -1
  71. package/lib/loader.d.ts +0 -5
  72. package/lib/loader.js +0 -30
  73. package/lib/loader.js.map +0 -1
  74. package/lib/processor-runner.d.ts +0 -2
  75. package/lib/processor-runner.js +0 -102
  76. package/lib/processor-runner.js.map +0 -1
  77. package/lib/provider.d.ts +0 -6
  78. package/lib/provider.js +0 -66
  79. package/lib/provider.js.map +0 -1
  80. package/lib/service.d.ts +0 -21
  81. package/lib/service.js +0 -190
  82. package/lib/service.js.map +0 -1
  83. package/src/chain-config.ts +0 -6
  84. package/src/endpoints.ts +0 -9
  85. package/src/loader.ts +0 -24
  86. package/src/processor-runner.ts +0 -93
  87. package/src/provider.ts +0 -74
  88. package/src/service.ts +0 -197
  89. package/src/types/global.d.ts +0 -15
@@ -1,4 +1,4 @@
1
- import { Plugin, PluginManager } from '@sentio/base'
1
+ import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import {
3
3
  AccountConfig,
4
4
  ContractConfig,
@@ -8,16 +8,17 @@ import {
8
8
  LogHandlerConfig,
9
9
  ProcessConfigResponse,
10
10
  ProcessResult,
11
+ StartRequest,
11
12
  } from '@sentio/protos'
12
- import { errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/base'
13
13
 
14
14
  import { ServerError, Status } from 'nice-grpc'
15
15
  import { Block, Log } from '@ethersproject/abstract-provider'
16
16
  import { Trace } from '@sentio/sdk'
17
17
  import { ProcessorState } from '../binds'
18
18
  import { AccountProcessorState } from './account-processor'
19
+ import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template'
19
20
 
20
- export class EthPlugin implements Plugin {
21
+ export class EthPlugin extends Plugin {
21
22
  name: string = 'EthPlugin'
22
23
 
23
24
  private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []
@@ -25,6 +26,9 @@ export class EthPlugin implements Plugin {
25
26
  private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []
26
27
 
27
28
  configure(config: ProcessConfigResponse): void {
29
+ // This syntax is to copy values instead of using references
30
+ config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]
31
+
28
32
  for (const processor of ProcessorState.INSTANCE.getValues()) {
29
33
  // If server favor incremental update this need to change
30
34
  // Start basic config for contract
@@ -175,6 +179,29 @@ export class EthPlugin implements Plugin {
175
179
  }
176
180
  }
177
181
 
182
+ start(request: StartRequest) {
183
+ for (const instance of request.templateInstances) {
184
+ const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId]
185
+ if (!template) {
186
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance)
187
+ }
188
+ if (!instance.contract) {
189
+ throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)
190
+ }
191
+ template.bind({
192
+ name: instance.contract.name,
193
+ address: instance.contract.address,
194
+ network: Number(instance.contract.chainId),
195
+ startBlock: instance.startBlock,
196
+ endBlock: instance.endBlock,
197
+ })
198
+ }
199
+ }
200
+
201
+ stateDiff(config: ProcessConfigResponse): boolean {
202
+ return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
203
+ }
204
+
178
205
  async processLog(request: DataBinding): Promise<ProcessResult> {
179
206
  if (!request.data) {
180
207
  throw new ServerError(Status.INVALID_ARGUMENT, "Log can't be null")
@@ -1,7 +1,7 @@
1
1
  import { BaseContext } from './base-context'
2
2
  import { EventTrackingResult } from '@sentio/protos'
3
3
  import { NamedResultDescriptor } from './metadata'
4
- import { MapStateStorage } from '@sentio/base'
4
+ import { MapStateStorage } from '@sentio/runtime'
5
5
 
6
6
  export interface Event {
7
7
  // The unique identifier of main identity associate with an event
@@ -1,7 +1,7 @@
1
1
  import { BaseContext } from './base-context'
2
2
  import { ExportResult } from '@sentio/sdk'
3
3
  import { NamedResultDescriptor } from './metadata'
4
- import { MapStateStorage } from '@sentio/base'
4
+ import { MapStateStorage } from '@sentio/runtime'
5
5
 
6
6
  export type Export = Record<string, any>
7
7
 
@@ -2,7 +2,7 @@ import { BaseContract } from '@ethersproject/contracts'
2
2
  import { BoundContractView, ContractView } from './context'
3
3
  import { BindOptions } from './bind-options'
4
4
  import { BaseProcessor } from './base-processor'
5
- import { getProvider } from '../provider'
5
+ import { getProvider } from '@sentio/runtime'
6
6
  import { addProcessor } from '../binds'
7
7
 
8
8
  export class GenericProcessor extends BaseProcessor<
package/src/core/index.ts CHANGED
@@ -15,3 +15,4 @@ export type { TypedCallTrace, Trace } from './trace'
15
15
 
16
16
  export { EthPlugin } from './eth-plugin'
17
17
  export { SuiPlugin } from './sui-plugin'
18
+ export { CorePlugin } from './core-plugin'
package/src/core/meter.ts CHANGED
@@ -2,7 +2,7 @@ import { BaseContext } from './base-context'
2
2
  import { Numberish, toMetricValue } from './numberish'
3
3
  import { Labels, NamedResultDescriptor } from './metadata'
4
4
  import { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@sentio/protos'
5
- import { MapStateStorage } from '@sentio/base'
5
+ import { MapStateStorage } from '@sentio/runtime'
6
6
 
7
7
  export function normalizeName(name: string): string {
8
8
  const regex = new RegExp('![_.a-zA-Z0-9]')
@@ -1,15 +1,13 @@
1
- import { Plugin, PluginManager } from '@sentio/base'
1
+ import { Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import { ContractConfig, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos'
3
3
 
4
- import { USER_PROCESSOR } from '../service'
5
-
6
4
  import { ServerError, Status } from 'nice-grpc'
7
5
 
8
6
  import { CHAIN_IDS } from '../utils/chain'
9
7
  import { SuiProcessorState } from './sui-processor'
10
8
 
11
- export class SuiPlugin implements Plugin {
12
- name: string = 'SolanaPlugin'
9
+ export class SuiPlugin extends Plugin {
10
+ name: string = 'SuiPlugin'
13
11
 
14
12
  configure(config: ProcessConfigResponse): void {
15
13
  for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
@@ -34,7 +32,7 @@ export class SuiPlugin implements Plugin {
34
32
  }
35
33
  }
36
34
 
37
- supportedHandlers = [HandlerType.SUI_TRANSACTION]
35
+ supportedHandlers = []
38
36
 
39
37
  processBinding(request: DataBinding): Promise<ProcessResult> {
40
38
  switch (request.handlerType) {
@@ -1,6 +1,6 @@
1
1
  import { SuiContext } from './context'
2
2
  import { ProcessResult } from '@sentio/protos'
3
- import { ListStateStorage } from '@sentio/base'
3
+ import { ListStateStorage } from '@sentio/runtime'
4
4
 
5
5
  type IndexConfigure = {
6
6
  startSeqNumber: bigint
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { getProvider, setProvider, DummyProvider } from './provider'
1
+ export { getProvider, setProvider, DummyProvider } from '@sentio/runtime'
2
2
  export { transformEtherError, EthersError } from './error'
3
3
 
4
4
  export { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds'
@@ -13,23 +13,17 @@ import {
13
13
  } from '@sentio/protos'
14
14
  import { CallContext } from 'nice-grpc-common'
15
15
  import { Empty } from '@sentio/protos/lib/google/protobuf/empty'
16
- import { ChainConfig } from '../chain-config'
16
+ import { ChainConfig, ProcessorServiceImpl, setProvider, Endpoints, State } from '@sentio/runtime'
17
17
  import { CHAIN_MAP } from '../utils/chain'
18
18
  import { Block, Log } from '@ethersproject/abstract-provider'
19
19
  import { getNetwork, Networkish } from '@ethersproject/providers'
20
- import { Endpoints } from '../endpoints'
21
- import { State } from '@sentio/base'
22
- import { ProcessorServiceImpl } from '../service'
23
20
  import { Trace } from '../core/trace'
24
- import { setProvider } from '../provider'
25
21
 
26
22
  export const TEST_CONTEXT: CallContext = <CallContext>{}
27
23
 
28
24
  export function cleanTest() {
29
25
  State.reset()
30
- if (!global.ENDPOINTS) {
31
- global.ENDPOINTS = new Endpoints()
32
- }
26
+ Endpoints.reset()
33
27
  }
34
28
 
35
29
  export class TestProcessorServer implements ProcessorServiceImplementation {
@@ -1,6 +1,5 @@
1
- import { ChainConfig } from '../chain-config'
1
+ import { ChainConfig, setProvider } from '@sentio/runtime'
2
2
  import { CHAIN_MAP } from '../utils/chain'
3
- import { setProvider } from '../provider'
4
3
 
5
4
  export function loadTestProvidersFromEnv(requiredChainIds: string[] | string): boolean {
6
5
  const dummyConfig: Record<string, ChainConfig> = {}
@@ -1,10 +1,11 @@
1
1
  import { PriceServiceClient, PriceServiceDefinition } from '@sentio/protos/lib/service/price/protos/price'
2
2
  import { createChannel, createClientFactory } from 'nice-grpc'
3
3
  import { retryMiddleware, RetryOptions } from 'nice-grpc-client-middleware-retry'
4
+ import { Endpoints } from '@sentio/runtime'
4
5
 
5
6
  export function getPriceClient(address?: string) {
6
7
  if (!address) {
7
- address = global.ENDPOINTS.priceFeedAPI
8
+ address = Endpoints.INSTANCE.priceFeedAPI
8
9
  }
9
10
  const channel = createChannel(address)
10
11
 
@@ -1,6 +0,0 @@
1
- export interface ChainConfig {
2
- ChainID: string;
3
- Https: string[];
4
- WebSockets?: string[];
5
- ChainServer?: string;
6
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=chain-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chain-config.js","sourceRoot":"","sources":["../src/chain-config.ts"],"names":[],"mappings":"","sourcesContent":["export interface ChainConfig {\n ChainID: string\n Https: string[]\n WebSockets?: string[]\n ChainServer?: string\n}\n"]}
@@ -1,6 +0,0 @@
1
- import { Provider } from '@ethersproject/providers';
2
- export declare class Endpoints {
3
- providers: Map<number, Provider>;
4
- chainQueryAPI: string;
5
- priceFeedAPI: string;
6
- }
package/lib/endpoints.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Endpoints = void 0;
4
- class Endpoints {
5
- // evm providers
6
- providers = new Map();
7
- chainQueryAPI = '';
8
- priceFeedAPI = '';
9
- }
10
- exports.Endpoints = Endpoints;
11
- //# sourceMappingURL=endpoints.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../src/endpoints.ts"],"names":[],"mappings":";;;AAEA,MAAa,SAAS;IACpB,gBAAgB;IAChB,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAA;IAEvC,aAAa,GAAG,EAAE,CAAA;IAClB,YAAY,GAAG,EAAE,CAAA;CAClB;AAND,8BAMC","sourcesContent":["import { Provider } from '@ethersproject/providers'\n\nexport class Endpoints {\n // evm providers\n providers = new Map<number, Provider>()\n\n chainQueryAPI = ''\n priceFeedAPI = ''\n}\n"]}
package/lib/loader.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare function load(name: string): {
2
- module: any;
3
- name: string;
4
- path: string;
5
- } | undefined;
package/lib/loader.js DELETED
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.load = void 0;
4
- function load(name) {
5
- const req = eval('require');
6
- try {
7
- let path;
8
- try {
9
- path = req.resolve(name, { paths: [process.cwd()] });
10
- }
11
- catch {
12
- path = req.resolve(name);
13
- }
14
- const module = { module: req(path), name, path };
15
- console.log('Processor Load successfully');
16
- return module;
17
- }
18
- catch (err) {
19
- if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
20
- // this error is expected
21
- console.log("Couldn't load (expected): ", name);
22
- return undefined;
23
- }
24
- else {
25
- throw err;
26
- }
27
- }
28
- }
29
- exports.load = load;
30
- //# sourceMappingURL=loader.js.map
package/lib/loader.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";;;AAAA,SAAgB,IAAI,CAAC,IAAY;IAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;IAE3B,IAAI;QACF,IAAI,IAAY,CAAA;QAChB,IAAI;YACF,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;SACrD;QAAC,MAAM;YACN,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;SACzB;QAED,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QAChD,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAA;QAC1C,OAAO,MAAM,CAAA;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,uBAAuB,IAAI,GAAG,CAAC,EAAE;YAClF,yBAAyB;YACzB,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,CAAA;YAC/C,OAAO,SAAS,CAAA;SACjB;aAAM;YACL,MAAM,GAAG,CAAA;SACV;KACF;AACH,CAAC;AAvBD,oBAuBC","sourcesContent":["export function load(name: string): { module: any; name: string; path: string } | undefined {\n const req = eval('require')\n\n try {\n let path: string\n try {\n path = req.resolve(name, { paths: [process.cwd()] })\n } catch {\n path = req.resolve(name)\n }\n\n const module = { module: req(path), name, path }\n console.log('Processor Load successfully')\n return module\n } catch (err) {\n if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {\n // this error is expected\n console.log(\"Couldn't load (expected): \", name)\n return undefined\n } else {\n throw err\n }\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,102 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- const path_1 = __importDefault(require("path"));
31
- const fs_extra_1 = __importDefault(require("fs-extra"));
32
- const util = __importStar(require("util"));
33
- const command_line_args_1 = __importDefault(require("command-line-args"));
34
- const nice_grpc_1 = require("nice-grpc");
35
- const winston_1 = require("winston");
36
- const compression_algorithms_1 = require("@grpc/grpc-js/build/src/compression-algorithms");
37
- const protos_1 = require("@sentio/protos");
38
- const service_1 = require("./service");
39
- const provider_1 = require("./provider");
40
- const base_1 = require("@sentio/base");
41
- const loader_1 = require("./loader");
42
- const endpoints_1 = require("./endpoints");
43
- base_1.State.reset();
44
- global.ENDPOINTS = new endpoints_1.Endpoints();
45
- const optionDefinitions = [
46
- { name: 'target', type: String, defaultOption: true },
47
- { name: 'port', alias: 'p', type: String, defaultValue: '4000' },
48
- { name: 'concurrency', type: Number, defaultValue: 4 },
49
- { name: 'use-chainserver', type: Boolean, defaultValue: false },
50
- {
51
- name: 'chains-config',
52
- alias: 'c',
53
- type: String,
54
- defaultValue: 'chains-config.json',
55
- },
56
- { name: 'chainquery-server', type: String, defaultValue: '' },
57
- { name: 'pricefeed-server', type: String, defaultValue: '' },
58
- { name: 'log-format', type: String, defaultValue: 'console' },
59
- { name: 'debug', type: Boolean, defaultValue: false },
60
- ];
61
- const options = (0, command_line_args_1.default)(optionDefinitions, { partial: true });
62
- if (options['log-format'] === 'json') {
63
- const utilFormatter = {
64
- transform: (info) => {
65
- const args = info[Symbol.for('splat')];
66
- if (args) {
67
- info.message = util.format(info.message, ...args);
68
- }
69
- return info;
70
- },
71
- };
72
- const logger = (0, winston_1.createLogger)({
73
- format: winston_1.format.combine(winston_1.format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ssZ' }), utilFormatter, winston_1.format.errors({ stack: true }), winston_1.format.json()),
74
- transports: [new winston_1.transports.Console()],
75
- });
76
- console.log = (...args) => logger.info.call(logger, ...args);
77
- console.info = (...args) => logger.info.call(logger, ...args);
78
- console.warn = (...args) => logger.warn.call(logger, ...args);
79
- console.error = (...args) => logger.error.call(logger, ...args);
80
- console.debug = (...args) => logger.debug.call(logger, ...args);
81
- }
82
- if (options.debug) {
83
- console.log('Starting with', options.target);
84
- }
85
- const fullPath = path_1.default.resolve(options['chains-config']);
86
- const chainsConfig = fs_extra_1.default.readJsonSync(fullPath);
87
- (0, provider_1.setProvider)(chainsConfig, options.concurrency, options['use-chainserver']);
88
- globalThis.ENDPOINTS.chainQueryAPI = options['chainquery-server'];
89
- globalThis.ENDPOINTS.priceFeedAPI = options['pricefeed-server'];
90
- if (options.debug) {
91
- console.log('Starting Server', options);
92
- }
93
- const server = (0, nice_grpc_1.createServer)({
94
- 'grpc.max_send_message_length': 128 * 1024 * 1024,
95
- 'grpc.max_receive_message_length': 128 * 1024 * 1024,
96
- 'grpc.default_compression_algorithm': compression_algorithms_1.CompressionAlgorithms.gzip,
97
- });
98
- const service = new service_1.ProcessorServiceImpl(() => (0, loader_1.load)(options.target), server.shutdown);
99
- server.add(protos_1.ProcessorDefinition, service);
100
- server.listen('0.0.0.0:' + options.port);
101
- console.log('Processor Server Started');
102
- //# sourceMappingURL=processor-runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"processor-runner.js","sourceRoot":"","sources":["../src/processor-runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,gDAAuB;AACvB,wDAAyB;AACzB,2CAA4B;AAE5B,0EAA+C;AAC/C,yCAAwC;AACxC,qCAA0D;AAC1D,2FAAsF;AAEtF,2CAAoD;AACpD,uCAAgD;AAChD,yCAAwC;AACxC,uCAAoC;AACpC,qCAA+B;AAC/B,2CAAuC;AAEvC,YAAK,CAAC,KAAK,EAAE,CAAA;AACb,MAAM,CAAC,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAA;AAElC,MAAM,iBAAiB,GAAG;IACxB,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE;IACrD,EAAE,IAAI,EAAE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,GAAG,kBAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;AAE9C,IAAA,sBAAW,EAAC,YAAY,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAA;AAC1E,UAAU,CAAC,SAAS,CAAC,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AACjE,UAAU,CAAC,SAAS,CAAC,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAE/D,IAAI,OAAO,CAAC,KAAK,EAAE;IACjB,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;CACxC;AAED,MAAM,MAAM,GAAG,IAAA,wBAAY,EAAC;IAC1B,8BAA8B,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IACjD,iCAAiC,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IACpD,oCAAoC,EAAE,8CAAqB,CAAC,IAAI;CACjE,CAAC,CAAA;AAEF,MAAM,OAAO,GAAG,IAAI,8BAAoB,CAAC,GAAG,EAAE,CAAC,IAAA,aAAI,EAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;AACrF,MAAM,CAAC,GAAG,CAAC,4BAAmB,EAAE,OAAO,CAAC,CAAA;AAExC,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\n\nimport path from 'path'\nimport fs from 'fs-extra'\nimport * as util from 'util'\n\nimport commandLineArgs from 'command-line-args'\nimport { createServer } from 'nice-grpc'\nimport { createLogger, transports, format } from 'winston'\nimport { CompressionAlgorithms } from '@grpc/grpc-js/build/src/compression-algorithms'\n\nimport { ProcessorDefinition } from '@sentio/protos'\nimport { ProcessorServiceImpl } from './service'\nimport { setProvider } from './provider'\nimport { State } from '@sentio/base'\nimport { load } from './loader'\nimport { Endpoints } from './endpoints'\n\nState.reset()\nglobal.ENDPOINTS = new Endpoints()\n\nconst optionDefinitions = [\n { name: 'target', type: String, defaultOption: true },\n { name: 'port', alias: 'p', type: String, defaultValue: '4000' },\n { name: 'concurrency', type: Number, defaultValue: 4 },\n { name: 'use-chainserver', type: Boolean, defaultValue: false },\n {\n name: 'chains-config',\n alias: 'c',\n type: String,\n defaultValue: 'chains-config.json',\n },\n { name: 'chainquery-server', type: String, defaultValue: '' },\n { name: 'pricefeed-server', type: String, defaultValue: '' },\n { name: 'log-format', type: String, defaultValue: 'console' },\n { name: 'debug', type: Boolean, defaultValue: false },\n]\n\nconst options = commandLineArgs(optionDefinitions, { partial: true })\n\nif (options['log-format'] === 'json') {\n const utilFormatter = {\n transform: (info: any) => {\n const args = info[Symbol.for('splat')]\n if (args) {\n info.message = util.format(info.message, ...args)\n }\n return info\n },\n }\n const logger = createLogger({\n format: format.combine(\n format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ssZ' }),\n utilFormatter,\n format.errors({ stack: true }),\n format.json()\n ),\n transports: [new transports.Console()],\n })\n\n console.log = (...args) => logger.info.call(logger, ...args)\n console.info = (...args) => logger.info.call(logger, ...args)\n console.warn = (...args) => logger.warn.call(logger, ...args)\n console.error = (...args) => logger.error.call(logger, ...args)\n console.debug = (...args) => logger.debug.call(logger, ...args)\n}\nif (options.debug) {\n console.log('Starting with', options.target)\n}\n\nconst fullPath = path.resolve(options['chains-config'])\nconst chainsConfig = fs.readJsonSync(fullPath)\n\nsetProvider(chainsConfig, options.concurrency, options['use-chainserver'])\nglobalThis.ENDPOINTS.chainQueryAPI = options['chainquery-server']\nglobalThis.ENDPOINTS.priceFeedAPI = options['pricefeed-server']\n\nif (options.debug) {\n console.log('Starting Server', options)\n}\n\nconst server = createServer({\n 'grpc.max_send_message_length': 128 * 1024 * 1024,\n 'grpc.max_receive_message_length': 128 * 1024 * 1024,\n 'grpc.default_compression_algorithm': CompressionAlgorithms.gzip,\n})\n\nconst service = new ProcessorServiceImpl(() => load(options.target), server.shutdown)\nserver.add(ProcessorDefinition, service)\n\nserver.listen('0.0.0.0:' + options.port)\n\nconsole.log('Processor Server Started')\n"]}
package/lib/provider.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { Provider, StaticJsonRpcProvider } from '@ethersproject/providers';
2
- import { Networkish } from '@ethersproject/networks';
3
- import { ChainConfig } from './chain-config';
4
- export declare const DummyProvider: StaticJsonRpcProvider;
5
- export declare function getProvider(networkish?: Networkish): Provider;
6
- export declare function setProvider(config: Record<string, ChainConfig>, concurrency?: number, useChainServer?: boolean): void;
package/lib/provider.js DELETED
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setProvider = exports.getProvider = exports.DummyProvider = void 0;
7
- const providers_1 = require("@ethersproject/providers");
8
- const p_queue_1 = __importDefault(require("p-queue"));
9
- exports.DummyProvider = new providers_1.StaticJsonRpcProvider(undefined, 1);
10
- function getProvider(networkish) {
11
- if (!networkish) {
12
- networkish = 1;
13
- }
14
- const network = (0, providers_1.getNetwork)(networkish);
15
- if (!global.ENDPOINTS.providers) {
16
- throw Error('Provider not set');
17
- }
18
- const value = global.ENDPOINTS.providers.get(network.chainId);
19
- if (value === undefined) {
20
- throw Error('Provider not found for chain ' +
21
- network.chainId +
22
- ', configured chains: ' +
23
- [...global.ENDPOINTS.providers.keys()].join(' '));
24
- }
25
- return value;
26
- }
27
- exports.getProvider = getProvider;
28
- function setProvider(config, concurrency = 4, useChainServer = false) {
29
- globalThis.ENDPOINTS.providers = new Map();
30
- for (const chainIdStr in config) {
31
- if (isNaN(Number.parseInt(chainIdStr))) {
32
- continue;
33
- }
34
- const chainConfig = config[chainIdStr];
35
- const chainId = Number(chainIdStr);
36
- // let providers: StaticJsonRpcProvider[] = []
37
- // for (const http of chainConfig.Https) {
38
- // providers.push(new StaticJsonRpcProvider(http, chainId))
39
- // }
40
- // random shuffle
41
- // providers = providers.sort(() => Math.random() - 0.5)
42
- // const provider = new FallbackProvider(providers)
43
- let rpcAddress = '';
44
- if (useChainServer && chainConfig.ChainServer) {
45
- rpcAddress = chainConfig.ChainServer;
46
- }
47
- else {
48
- const idx = Math.floor(Math.random() * chainConfig.Https.length);
49
- rpcAddress = chainConfig.Https[idx];
50
- }
51
- const provider = new QueuedStaticJsonRpcProvider(rpcAddress, chainId, concurrency);
52
- global.ENDPOINTS.providers.set(chainId, provider);
53
- }
54
- }
55
- exports.setProvider = setProvider;
56
- class QueuedStaticJsonRpcProvider extends providers_1.StaticJsonRpcProvider {
57
- executor;
58
- constructor(url, network, concurrency) {
59
- super(url, network);
60
- this.executor = new p_queue_1.default({ concurrency: concurrency });
61
- }
62
- send(method, params) {
63
- return this.executor.add(() => super.send(method, params));
64
- }
65
- }
66
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAsF;AAEtF,sDAA4B;AAIf,QAAA,aAAa,GAAG,IAAI,iCAAqB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;AAEpE,SAAgB,WAAW,CAAC,UAAuB;IACjD,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,CAAC,CAAA;KACf;IACD,MAAM,OAAO,GAAG,IAAA,sBAAU,EAAC,UAAU,CAAC,CAAA;IAEtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE;QAC/B,MAAM,KAAK,CAAC,kBAAkB,CAAC,CAAA;KAChC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7D,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,MAAM,KAAK,CACT,+BAA+B;Y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,MAAM,2BAA4B,SAAQ,iCAAqB;IAC7D,QAAQ,CAAQ;IAEhB,YAAY,GAA4B,EAAE,OAAmB,EAAE,WAAmB;QAChF,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;QACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAM,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAA;IAC1D,CAAC;IAED,IAAI,CAAC,MAAc,EAAE,MAAkB;QACrC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAC5D,CAAC;CACF","sourcesContent":["import { getNetwork, Provider, StaticJsonRpcProvider } from '@ethersproject/providers'\nimport { Networkish } from '@ethersproject/networks'\nimport PQueue from 'p-queue'\nimport { ConnectionInfo } from '@ethersproject/web'\nimport { ChainConfig } from './chain-config'\n\nexport const DummyProvider = new StaticJsonRpcProvider(undefined, 1)\n\nexport function getProvider(networkish?: Networkish): Provider {\n if (!networkish) {\n networkish = 1\n }\n const network = getNetwork(networkish)\n\n if (!global.ENDPOINTS.providers) {\n throw Error('Provider not set')\n }\n const value = global.ENDPOINTS.providers.get(network.chainId)\n if (value === undefined) {\n throw Error(\n 'Provider not found for chain ' +\n network.chainId +\n ', configured chains: ' +\n [...global.ENDPOINTS.providers.keys()].join(' ')\n )\n }\n return value\n}\n\nexport function setProvider(config: Record<string, ChainConfig>, concurrency = 4, useChainServer = false) {\n globalThis.ENDPOINTS.providers = new Map<number, Provider>()\n\n for (const chainIdStr in config) {\n if (isNaN(Number.parseInt(chainIdStr))) {\n continue\n }\n\n const chainConfig = config[chainIdStr]\n const chainId = Number(chainIdStr)\n\n // let providers: StaticJsonRpcProvider[] = []\n // for (const http of chainConfig.Https) {\n // providers.push(new StaticJsonRpcProvider(http, chainId))\n // }\n // random shuffle\n // providers = providers.sort(() => Math.random() - 0.5)\n\n // const provider = new FallbackProvider(providers)\n\n let rpcAddress = ''\n if (useChainServer && chainConfig.ChainServer) {\n rpcAddress = chainConfig.ChainServer\n } else {\n const idx = Math.floor(Math.random() * chainConfig.Https.length)\n rpcAddress = chainConfig.Https[idx]\n }\n\n const provider = new QueuedStaticJsonRpcProvider(rpcAddress, chainId, concurrency)\n global.ENDPOINTS.providers.set(chainId, provider)\n }\n}\n\nclass QueuedStaticJsonRpcProvider extends StaticJsonRpcProvider {\n executor: PQueue\n\n constructor(url: ConnectionInfo | string, network: Networkish, concurrency: number) {\n super(url, network)\n this.executor = new PQueue({ concurrency: concurrency })\n }\n\n send(method: string, params: Array<any>): Promise<any> {\n return this.executor.add(() => super.send(method, params))\n }\n}\n"]}
package/lib/service.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { CallContext } from 'nice-grpc';
2
- import { DataBinding, ProcessBindingResponse, ProcessBindingsRequest, ProcessConfigRequest, ProcessConfigResponse, ProcessorServiceImplementation, ProcessResult, StartRequest } from '@sentio/protos';
3
- import { Empty } from '@sentio/protos/lib/google/protobuf/empty';
4
- export declare const USER_PROCESSOR = "user_processor";
5
- export declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
6
- private started;
7
- private processorConfig;
8
- private readonly loader;
9
- private readonly shutdownHandler?;
10
- constructor(loader: () => void, shutdownHandler?: () => void);
11
- getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse>;
12
- configure(): Promise<void>;
13
- start(request: StartRequest, context: CallContext): Promise<Empty>;
14
- stop(request: Empty, context: CallContext): Promise<Empty>;
15
- processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse>;
16
- processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult>;
17
- processBindingsStream(requests: AsyncIterable<DataBinding>, context: CallContext): AsyncGenerator<{
18
- result: ProcessResult;
19
- configUpdated: boolean;
20
- }, void, unknown>;
21
- }