@sentio/sdk 1.7.17 → 1.7.20

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/cli/upload.js CHANGED
@@ -73,6 +73,8 @@ async function uploadFile(options, apiKeyOverride) {
73
73
  if (commitSha) {
74
74
  console.log('\t', chalk_1.default.blue('Git commit SHA:'), commitSha);
75
75
  }
76
+ const { ProjectSlug } = await res.json();
77
+ console.log('\t', chalk_1.default.blue('Check status:'), `${options.host}/${ProjectSlug}/datasource`);
76
78
  }
77
79
  else {
78
80
  console.error(chalk_1.default.red('Upload Failed'));
@@ -1 +1 @@
1
- {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/cli/upload.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAwC;AACxC,mCAAmC;AACnC,0DAAgC;AAChC,4CAAmB;AAEnB,+BAA+B;AAC/B,gDAAuB;AACvB,kDAAyB;AACzB,mCAAwC;AACxC,4DAA8B;AAEvB,KAAK,UAAU,UAAU,CAAC,OAA4B,EAAE,cAAsB;IACnF,IAAI,OAAO,CAAC,KAAK,EAAE;QACjB,MAAM,IAAA,sBAAc,EAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;KAC7C;IAED,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;IAEpC,MAAM,cAAc,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAA;IAE9D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,MAAM,MAAM,GAAG,cAAc,IAAI,IAAA,aAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,KAAK,wBAAwB,CAAA;IACxD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,GAAG,MAAM,C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AE,CAAC,CAAC,CAAA;KAC3C;AACH,CAAC;AA1ED,gCA0EC","sourcesContent":["import { execSync } from 'child_process'\nimport { createHash } from 'crypto'\nimport FormData from 'form-data'\nimport fs from 'fs'\nimport { SentioProjectConfig } from './config'\nimport { ReadKey } from './key'\nimport path from 'path'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport fetch from 'node-fetch'\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false, options.targets)\n }\n\n console.log(chalk.blue('Uploading'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const url = new URL(options.host)\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n const data = new FormData()\n data.append('attachment', fs.createReadStream(PROCESSOR_FILE))\n data.append('sha256', digest)\n\n let commitSha\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n data.append('commitSha', commitSha)\n } catch (e) {\n chalk.yellow(e)\n }\n\n url.pathname = '/api/v1/processors'\n\n let packageJson: { version: string }\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n packageJson = require('../package.json')\n } catch (e) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n packageJson = require('../../package.json')\n }\n\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n project: options.project,\n version: packageJson.version,\n },\n body: data,\n })\n\n if (res.ok) {\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n } else {\n console.error(chalk.red('Upload Failed'))\n console.error(chalk.red(await res.text()))\n }\n}\n"]}
1
+ {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/cli/upload.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAwC;AACxC,mCAAmC;AACnC,0DAAgC;AAChC,4CAAmB;AAEnB,+BAA+B;AAC/B,gDAAuB;AACvB,kDAAyB;AACzB,mCAAwC;AACxC,4DAA8B;AAEvB,KAAK,UAAU,UAAU,CAAC,OAA4B,EAAE,cAAsB;IACnF,IAAI,OAAO,CAAC,KAAK,EAAE;QACjB,MAAM,IAAA,sBAAc,EAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;KAC7C;IAED,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAA;IAEpC,MAAM,cAAc,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAA;IAE9D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,MAAM,MAAM,GAAG,cAAc,IAAI,IAAA,aAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,KAAK,wBAAwB,CAAA;IACxD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAA;QAC3E,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,yBAAyB,EAAE,OAAO,CAAC,IAAI,EAA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C,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;KAC3C;AACH,CAAC;AA5ED,gCA4EC","sourcesContent":["import { execSync } from 'child_process'\nimport { createHash } from 'crypto'\nimport FormData from 'form-data'\nimport fs from 'fs'\nimport { SentioProjectConfig } from './config'\nimport { ReadKey } from './key'\nimport path from 'path'\nimport chalk from 'chalk'\nimport { buildProcessor } from './build'\nimport fetch from 'node-fetch'\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false, options.targets)\n }\n\n console.log(chalk.blue('Uploading'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const url = new URL(options.host)\n const apiKey = apiKeyOverride || ReadKey(options.host)\n\n const isProd = options.host === 'https://app.sentio.xyz'\n if (!apiKey) {\n const cmd = isProd ? 'sentio login' : 'sentio login --host=' + options.host\n console.error(chalk.red('No Credential found for', options.host, '. Please run `' + cmd + '`.'))\n process.exit(1)\n }\n\n if (!fs.existsSync(PROCESSOR_FILE)) {\n console.error(chalk.red('File not existed ', PROCESSOR_FILE, \"don't use --nobuild\"))\n process.exit(1)\n }\n\n const stat = fs.statSync(PROCESSOR_FILE)\n console.log('Packed processor file size', Math.floor(stat.size / 1024) + 'K, last modified', stat.mtime)\n const content = fs.readFileSync(PROCESSOR_FILE)\n const hash = createHash('sha256')\n hash.update(content)\n const digest = hash.digest('hex')\n\n const data = new FormData()\n data.append('attachment', fs.createReadStream(PROCESSOR_FILE))\n data.append('sha256', digest)\n\n let commitSha\n try {\n commitSha = execSync('git rev-parse HEAD').toString().trim()\n data.append('commitSha', commitSha)\n } catch (e) {\n chalk.yellow(e)\n }\n\n url.pathname = '/api/v1/processors'\n\n let packageJson: { version: string }\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n packageJson = require('../package.json')\n } catch (e) {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n packageJson = require('../../package.json')\n }\n\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n project: options.project,\n version: packageJson.version,\n },\n body: data,\n })\n\n if (res.ok) {\n console.log(chalk.green('Upload success: '))\n console.log('\\t', chalk.blue('sha256:'), digest)\n if (commitSha) {\n console.log('\\t', chalk.blue('Git commit SHA:'), commitSha)\n }\n const { ProjectSlug } = await res.json()\n console.log('\\t', chalk.blue('Check status:'), `${options.host}/${ProjectSlug}/datasource`)\n } else {\n console.error(chalk.red('Upload Failed'))\n console.error(chalk.red(await res.text()))\n }\n}\n"]}
package/lib/error.d.ts CHANGED
@@ -1,2 +1,7 @@
1
1
  import { Context } from './context';
2
+ export declare class EthersError extends Error {
3
+ e: Error;
4
+ constructor(message: string, e: Error);
5
+ toString(): string;
6
+ }
2
7
  export declare function transformEtherError(e: Error, ctx: Context<any, any> | undefined): Error;
package/lib/error.js CHANGED
@@ -1,16 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformEtherError = void 0;
3
+ exports.transformEtherError = exports.EthersError = void 0;
4
4
  const ethers_1 = require("ethers");
5
5
  class EthersError extends Error {
6
- constructor(message, stack) {
6
+ e;
7
+ constructor(message, e) {
7
8
  super(message);
8
- this.stack = stack;
9
+ this.stack = e.stack;
9
10
  }
10
11
  toString() {
11
12
  return this.message + '\n' + this.stack?.toString();
12
13
  }
13
14
  }
15
+ exports.EthersError = EthersError;
14
16
  function transformEtherError(e, ctx) {
15
17
  let msg = '';
16
18
  // @ts-ignore expected error fields
@@ -28,7 +30,7 @@ function transformEtherError(e, ctx) {
28
30
  msg = "jsonrpc eth_call return '0x' (likely contract not existed): " + JSON.stringify(e);
29
31
  }
30
32
  }
31
- return new EthersError(msg, e.stack);
33
+ return new EthersError(msg, e);
32
34
  }
33
35
  if (e instanceof EthersError) {
34
36
  return e;
package/lib/error.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAEA,mCAA+B;AAE/B,MAAM,WAAY,SAAQ,KAAK;IAC7B,YAAY,OAAe,EAAE,KAAc;QACzC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACrD,CAAC;CACF;AAED,SAAgB,mBAAmB,CAAC,CAAQ,EAAE,GAAkC;IAC9E,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,mCAAmC;IACnC,IAAI,CAAC,CAAC,IAAI,KAAK,eAAM,CAAC,cAAc,EAAE;QACpC,mCAAmC;QACnC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,IAAI,GAAG,EAAE;gBACP,GAAG;oBACD,sEAAsE;wBACtE,GAAG,CAAC,OAAO;wBACX,IAAI;wBACJ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACpB;iBAAM;gBACL,GAAG,GAAG,8DAA8D,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACzF;SACF;QACD,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA;KACrC;IAED,IAAI,CAAC,YAAY,WAAW,EAAE;QAC5B,OAAO,CAAC,CAAA;KACT;IAED,qCAAqC;IAErC,GAAG,GAAG,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACpE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC;AA3BD,kDA2BC","sourcesContent":["// Transform error in more readable format\nimport { Context } from './context'\nimport { errors } from 'ethers'\n\nclass EthersError extends Error {\n constructor(message: string, stack?: string) {\n super(message)\n this.stack = stack\n }\n\n toString() {\n return this.message + '\\n' + this.stack?.toString()\n }\n}\n\nexport function transformEtherError(e: Error, ctx: Context<any, any> | undefined): Error {\n let msg = ''\n // @ts-ignore expected error fields\n if (e.code === errors.CALL_EXCEPTION) {\n // @ts-ignore expected error fields\n if (e.data === '0x') {\n if (ctx) {\n msg =\n \"jsonrpc eth_call return '0x' (likely contract not existed) at chain \" +\n ctx.chainId +\n ': ' +\n JSON.stringify(e)\n } else {\n msg = \"jsonrpc eth_call return '0x' (likely contract not existed): \" + JSON.stringify(e)\n }\n }\n return new EthersError(msg, e.stack)\n }\n\n if (e instanceof EthersError) {\n return e\n }\n\n // TODO gracefully handle more errors\n\n msg = 'ethers call error\\n' + e.message + '\\n' + e.stack?.toString()\n return new Error(msg)\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAEA,mCAA+B;AAE/B,MAAa,WAAY,SAAQ,KAAK;IACpC,CAAC,CAAO;IAER,YAAY,OAAe,EAAE,CAAQ;QACnC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;IACtB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACrD,CAAC;CACF;AAXD,kCAWC;AAED,SAAgB,mBAAmB,CAAC,CAAQ,EAAE,GAAkC;IAC9E,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,mCAAmC;IACnC,IAAI,CAAC,CAAC,IAAI,KAAK,eAAM,CAAC,cAAc,EAAE;QACpC,mCAAmC;QACnC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,IAAI,GAAG,EAAE;gBACP,GAAG;oBACD,sEAAsE;wBACtE,GAAG,CAAC,OAAO;wBACX,IAAI;wBACJ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACpB;iBAAM;gBACL,GAAG,GAAG,8DAA8D,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;aACzF;SACF;QACD,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;KAC/B;IAED,IAAI,CAAC,YAAY,WAAW,EAAE;QAC5B,OAAO,CAAC,CAAA;KACT;IAED,qCAAqC;IAErC,GAAG,GAAG,qBAAqB,GAAG,CAAC,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IACpE,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;AACvB,CAAC;AA3BD,kDA2BC","sourcesContent":["// Transform error in more readable format\nimport { Context } from './context'\nimport { errors } from 'ethers'\n\nexport class EthersError extends Error {\n e: Error\n\n constructor(message: string, e: Error) {\n super(message)\n this.stack = e.stack\n }\n\n toString() {\n return this.message + '\\n' + this.stack?.toString()\n }\n}\n\nexport function transformEtherError(e: Error, ctx: Context<any, any> | undefined): Error {\n let msg = ''\n // @ts-ignore expected error fields\n if (e.code === errors.CALL_EXCEPTION) {\n // @ts-ignore expected error fields\n if (e.data === '0x') {\n if (ctx) {\n msg =\n \"jsonrpc eth_call return '0x' (likely contract not existed) at chain \" +\n ctx.chainId +\n ': ' +\n JSON.stringify(e)\n } else {\n msg = \"jsonrpc eth_call return '0x' (likely contract not existed): \" + JSON.stringify(e)\n }\n }\n return new EthersError(msg, e)\n }\n\n if (e instanceof EthersError) {\n return e\n }\n\n // TODO gracefully handle more errors\n\n msg = 'ethers call error\\n' + e.message + '\\n' + e.stack?.toString()\n return new Error(msg)\n}\n"]}
@@ -3,8 +3,8 @@ import { BoundContractView, ContractView } from './context';
3
3
  import { BindOptions } from './bind-options';
4
4
  import { BaseProcessor } from './base-processor';
5
5
  export declare class GenericProcessor extends BaseProcessor<BaseContract, BoundContractView<BaseContract, ContractView<BaseContract>>> {
6
- eventAbi: string[];
7
- constructor(eventAbi: string[], options: BindOptions);
6
+ eventABI: string[];
7
+ constructor(eventABI: string[], options: BindOptions);
8
8
  protected CreateBoundContractView(): BoundContractView<BaseContract, ContractView<BaseContract>>;
9
- static bind(eventAbi: string[] | string, options: BindOptions): GenericProcessor;
9
+ static bind(eventABI: string[] | string, options: BindOptions): GenericProcessor;
10
10
  }
@@ -7,27 +7,24 @@ const base_processor_1 = require("./base-processor");
7
7
  const provider_1 = require("./provider");
8
8
  const binds_1 = require("./binds");
9
9
  class GenericProcessor extends base_processor_1.BaseProcessor {
10
- eventAbi;
11
- constructor(eventAbi, options) {
10
+ eventABI;
11
+ constructor(eventABI, options) {
12
12
  super(options);
13
- this.eventAbi = eventAbi;
13
+ this.eventABI = eventABI;
14
14
  }
15
15
  CreateBoundContractView() {
16
- const contract = new contracts_1.BaseContract(this.config.address, this.eventAbi, (0, provider_1.getProvider)(this.config.network));
16
+ const contract = new contracts_1.BaseContract(this.config.address, this.eventABI, (0, provider_1.getProvider)(this.config.network));
17
17
  return new context_1.BoundContractView(new context_1.ContractView(contract));
18
18
  }
19
- static bind(eventAbi, options) {
19
+ static bind(eventABI, options) {
20
20
  const AbiName = 'Generic';
21
- if (!Array.isArray(eventAbi)) {
22
- eventAbi = [eventAbi];
21
+ if (!Array.isArray(eventABI)) {
22
+ eventABI = [eventABI];
23
23
  }
24
- // let processor = getProcessor(AbiName, options) as GenericProcessor;
25
- // if (!processor) {
26
24
  const finalOptions = Object.assign({}, options);
27
25
  finalOptions.name = (0, binds_1.getContractName)(AbiName, options.name, options.address, options.network);
28
- const processor = new GenericProcessor(eventAbi, finalOptions);
26
+ const processor = new GenericProcessor(eventABI, finalOptions);
29
27
  (0, binds_1.addProcessor)(AbiName, options, processor);
30
- // }
31
28
  return processor;
32
29
  }
33
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"generic-processor.js","sourceRoot":"","sources":["../src/generic-processor.ts"],"names":[],"mappings":";;;AAAA,wDAAuD;AACvD,uCAA2D;AAE3D,qDAAgD;AAChD,yCAAwC;AACxC,mCAAuD;AAEvD,MAAa,gBAAiB,SAAQ,8BAGrC;IACC,QAAQ,CAAU;IAClB,YAAY,QAAkB,EAAE,OAAoB;QAClD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAES,uBAAuB;QAC/B,MAAM,QAAQ,GAAG,IAAI,wBAAY,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAA,sBAAW,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;QACvG,OAAO,IAAI,2BAAiB,CAAC,IAAI,sBAAY,CAAe,QAAQ,CAAC,CAAC,CAAA;IACxE,CAAC;IAEM,MAAM,CAAC,IAAI,CAAC,QAA2B,EAAE,OAAoB;QAClE,MAAM,OAAO,GAAG,SAAS,CAAA;QACzB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC5B,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAA;SACtB;QAED,sEAAsE;QACtE,oBAAoB;QACpB,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QAC/C,YAAY,CAAC,IAAI,GAAG,IAAA,uBAAe,EAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;QAC5F,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QAC9D,IAAA,oBAAY,EAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;QACzC,IAAI;QACJ,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AA9BD,4CA8BC","sourcesContent":["import { BaseContract } from '@ethersproject/contracts'\nimport { BoundContractView, ContractView } from './context'\nimport { BindOptions } from './bind-options'\nimport { BaseProcessor } from './base-processor'\nimport { getProvider } from './provider'\nimport { addProcessor, getContractName } from './binds'\n\nexport class GenericProcessor extends BaseProcessor<\n BaseContract,\n BoundContractView<BaseContract, ContractView<BaseContract>>\n> {\n eventAbi: string[]\n constructor(eventAbi: string[], options: BindOptions) {\n super(options)\n this.eventAbi = eventAbi\n }\n\n protected CreateBoundContractView(): BoundContractView<BaseContract, ContractView<BaseContract>> {\n const contract = new BaseContract(this.config.address, this.eventAbi, getProvider(this.config.network))\n return new BoundContractView(new ContractView<BaseContract>(contract))\n }\n\n public static bind(eventAbi: string[] | string, options: BindOptions): GenericProcessor {\n const AbiName = 'Generic'\n if (!Array.isArray(eventAbi)) {\n eventAbi = [eventAbi]\n }\n\n // let processor = getProcessor(AbiName, options) as GenericProcessor;\n // if (!processor) {\n const finalOptions = Object.assign({}, options)\n finalOptions.name = getContractName(AbiName, options.name, options.address, options.network)\n const processor = new GenericProcessor(eventAbi, finalOptions)\n addProcessor(AbiName, options, processor)\n // }\n return processor\n }\n}\n"]}
1
+ {"version":3,"file":"generic-processor.js","sourceRoot":"","sources":["../src/generic-processor.ts"],"names":[],"mappings":";;;AAAA,wDAAuD;AACvD,uCAA2D;AAE3D,qDAAgD;AAChD,yCAAwC;AACxC,mCAAuD;AAEvD,MAAa,gBAAiB,SAAQ,8BAGrC;IACC,QAAQ,CAAU;IAClB,YAAY,QAAkB,EAAE,OAAoB;QAClD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAES,uBAAuB;QAC/B,MAAM,QAAQ,GAAG,IAAI,wBAAY,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAA,sBAAW,EAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;QACvG,OAAO,IAAI,2BAAiB,CAAC,IAAI,sBAAY,CAAe,QAAQ,CAAC,CAAC,CAAA;IACxE,CAAC;IAEM,MAAM,CAAC,IAAI,CAAC,QAA2B,EAAE,OAAoB;QAClE,MAAM,OAAO,GAAG,SAAS,CAAA;QACzB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC5B,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAA;SACtB;QAED,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;QAC/C,YAAY,CAAC,IAAI,GAAG,IAAA,uBAAe,EAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;QAC5F,MAAM,SAAS,GAAG,IAAI,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QAC9D,IAAA,oBAAY,EAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;QACzC,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AA3BD,4CA2BC","sourcesContent":["import { BaseContract } from '@ethersproject/contracts'\nimport { BoundContractView, ContractView } from './context'\nimport { BindOptions } from './bind-options'\nimport { BaseProcessor } from './base-processor'\nimport { getProvider } from './provider'\nimport { addProcessor, getContractName } from './binds'\n\nexport class GenericProcessor extends BaseProcessor<\n BaseContract,\n BoundContractView<BaseContract, ContractView<BaseContract>>\n> {\n eventABI: string[]\n constructor(eventABI: string[], options: BindOptions) {\n super(options)\n this.eventABI = eventABI\n }\n\n protected CreateBoundContractView(): BoundContractView<BaseContract, ContractView<BaseContract>> {\n const contract = new BaseContract(this.config.address, this.eventABI, getProvider(this.config.network))\n return new BoundContractView(new ContractView<BaseContract>(contract))\n }\n\n public static bind(eventABI: string[] | string, options: BindOptions): GenericProcessor {\n const AbiName = 'Generic'\n if (!Array.isArray(eventABI)) {\n eventABI = [eventABI]\n }\n\n const finalOptions = Object.assign({}, options)\n finalOptions.name = getContractName(AbiName, options.name, options.address, options.network)\n const processor = new GenericProcessor(eventABI, finalOptions)\n addProcessor(AbiName, options, processor)\n return processor\n }\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { BindOptions, SolanaBindOptions } from './bind-options';
11
11
  export { transformEtherError } from './error';
12
12
  export { ProcessorState } from './processor-state';
13
13
  export { BigNumber as BigDecimal } from 'bignumber.js';
14
+ export { EthersError } from './error';
14
15
  export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds';
15
16
  export * from './gen/processor/protos/processor';
16
17
  export { SPLTokenProcessor } from './solana/builtin';
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.SPLTokenProcessor = exports.getContractName = exports.addContractByABI = exports.getContractByABI = exports.addProcessor = exports.getProcessor = exports.BigDecimal = exports.ProcessorState = exports.transformEtherError = exports.SolanaBindOptions = exports.BindOptions = exports.ContractNamer = exports.SolanaBaseProcessor = exports.DummyProvider = exports.setProvider = exports.getProvider = exports.Gauge = exports.Meter = exports.Counter = exports.ProcessorServiceImpl = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = void 0;
17
+ exports.SPLTokenProcessor = exports.getContractName = exports.addContractByABI = exports.getContractByABI = exports.addProcessor = exports.getProcessor = exports.EthersError = exports.BigDecimal = exports.ProcessorState = exports.transformEtherError = exports.SolanaBindOptions = exports.BindOptions = exports.ContractNamer = exports.SolanaBaseProcessor = exports.DummyProvider = exports.setProvider = exports.getProvider = exports.Gauge = exports.Meter = exports.Counter = exports.ProcessorServiceImpl = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = void 0;
18
18
  var base_processor_1 = require("./base-processor");
19
19
  Object.defineProperty(exports, "BaseProcessor", { enumerable: true, get: function () { return base_processor_1.BaseProcessor; } });
20
20
  var generic_processor_1 = require("./generic-processor");
@@ -49,6 +49,8 @@ var processor_state_1 = require("./processor-state");
49
49
  Object.defineProperty(exports, "ProcessorState", { enumerable: true, get: function () { return processor_state_1.ProcessorState; } });
50
50
  var bignumber_js_1 = require("bignumber.js");
51
51
  Object.defineProperty(exports, "BigDecimal", { enumerable: true, get: function () { return bignumber_js_1.BigNumber; } });
52
+ var error_2 = require("./error");
53
+ Object.defineProperty(exports, "EthersError", { enumerable: true, get: function () { return error_2.EthersError; } });
52
54
  var binds_1 = require("./binds");
53
55
  Object.defineProperty(exports, "getProcessor", { enumerable: true, get: function () { return binds_1.getProcessor; } });
54
56
  Object.defineProperty(exports, "addProcessor", { enumerable: true, get: function () { return binds_1.addProcessor; } });
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,qCAAmF;AAA1E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AAChE,qCAAgD;AAAvC,+GAAA,oBAAoB,OAAA;AAC7B,iCAA+C;AAAtC,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,8FAAA,KAAK,OAAA;AAC9B,uCAAoE;AAA3D,uGAAA,WAAW,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,yGAAA,aAAa,OAAA;AAChD,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,+CAA+D;AAAtD,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AACvC,iCAA6C;AAApC,4GAAA,mBAAmB,OAAA;AAC5B,qDAAkD;AAAzC,iHAAA,cAAc,OAAA;AACvB,6CAAsD;AAA7C,0GAAA,SAAS,OAAc;AAEhC,iCAAyG;AAAhG,qGAAA,YAAY,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAExF,mEAAgD;AAEhD,4CAAoD;AAA3C,4GAAA,iBAAiB,OAAA","sourcesContent":["export { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { Context, ContractView, BoundContractView, SolanaContext } from './context'\nexport { ProcessorServiceImpl } from './service'\nexport { Counter, Meter, Gauge } from './meter'\nexport { getProvider, setProvider, DummyProvider } from './provider'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { ContractNamer } from './contract-namer'\nexport { BindOptions, SolanaBindOptions } from './bind-options'\nexport { transformEtherError } from './error'\nexport { ProcessorState } from './processor-state'\nexport { BigNumber as BigDecimal } from 'bignumber.js'\n\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'\n\nexport * from './gen/processor/protos/processor'\n\nexport { SPLTokenProcessor } from './solana/builtin'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,qCAAmF;AAA1E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AAChE,qCAAgD;AAAvC,+GAAA,oBAAoB,OAAA;AAC7B,iCAA+C;AAAtC,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,8FAAA,KAAK,OAAA;AAC9B,uCAAoE;AAA3D,uGAAA,WAAW,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,yGAAA,aAAa,OAAA;AAChD,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,+CAA+D;AAAtD,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AACvC,iCAA6C;AAApC,4GAAA,mBAAmB,OAAA;AAC5B,qDAAkD;AAAzC,iHAAA,cAAc,OAAA;AACvB,6CAAsD;AAA7C,0GAAA,SAAS,OAAc;AAChC,iCAAqC;AAA5B,oGAAA,WAAW,OAAA;AAEpB,iCAAyG;AAAhG,qGAAA,YAAY,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAExF,mEAAgD;AAEhD,4CAAoD;AAA3C,4GAAA,iBAAiB,OAAA","sourcesContent":["export { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { Context, ContractView, BoundContractView, SolanaContext } from './context'\nexport { ProcessorServiceImpl } from './service'\nexport { Counter, Meter, Gauge } from './meter'\nexport { getProvider, setProvider, DummyProvider } from './provider'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { ContractNamer } from './contract-namer'\nexport { BindOptions, SolanaBindOptions } from './bind-options'\nexport { transformEtherError } from './error'\nexport { ProcessorState } from './processor-state'\nexport { BigNumber as BigDecimal } from 'bignumber.js'\nexport { EthersError } from './error'\n\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'\n\nexport * from './gen/processor/protos/processor'\n\nexport { SPLTokenProcessor } from './solana/builtin'\n"]}
package/lib/meter.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { EthContext, SolanaContext } from './context';
2
2
  import { Numberish } from './numberish';
3
+ export declare function normalizeName(name: string): string;
3
4
  export declare type Labels = {
4
5
  [key: string]: string;
5
6
  };
package/lib/meter.js CHANGED
@@ -3,11 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Meter = exports.Gauge = exports.Counter = void 0;
6
+ exports.Meter = exports.Gauge = exports.Counter = exports.normalizeName = void 0;
7
7
  const context_1 = require("./context");
8
8
  const numberish_1 = require("./numberish");
9
9
  const long_1 = __importDefault(require("long"));
10
+ function normalizeName(name) {
11
+ const regex = new RegExp('![_.a-zA-Z0-9]');
12
+ return name.slice(0, 100).replace(regex, '_');
13
+ }
14
+ exports.normalizeName = normalizeName;
10
15
  function GetRecordMetaData(ctx, name, labels) {
16
+ name = normalizeName(name);
11
17
  if (ctx instanceof context_1.Context) {
12
18
  if (ctx.log) {
13
19
  return {
package/lib/meter.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"meter.js","sourceRoot":"","sources":["../src/meter.ts"],"names":[],"mappings":";;;;;;AACA,uCAA8D;AAC9D,2CAAsD;AACtD,gDAAuB;AAEvB,SAAS,iBAAiB,CAAC,GAA+B,EAAE,IAAY,EAAE,MAAc;IACtF,IAAI,GAAG,YAAY,iBAAO,EAAE;QAC1B,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,OAAO;gBACL,eAAe,EAAE,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO;gBACjD,WAAW,EAAE,cAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC;gBACvD,gBAAgB,EAAE,GAAG,CAAC,GAAG,CAAC,gBAAgB;gBAC1C,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ;gBAC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CAAC,IAAY;QAChB,sCAAsC;QACtC,EAAE;QACF,gBAAgB;QAChB,wCAAwC;QACxC,IAAI;QACJ,eAAe;QACf,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;CACF;AA/BD,sBA+BC","sourcesContent":["import { RecordMetaData } from './gen/processor/protos/processor'\nimport { Context, EthContext, SolanaContext } from './context'\nimport { toMetricValue, Numberish } from './numberish'\nimport Long from 'long'\n\nfunction GetRecordMetaData(ctx: EthContext | SolanaContext, name: string, labels: Labels): RecordMetaData {\n if (ctx instanceof Context) {\n if (ctx.log) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.log.blockNumber, true), // TODO need number type to be long\n transactionIndex: ctx.log.transactionIndex,\n logIndex: ctx.log.logIndex,\n chainId: ctx.chainId.toString(),\n name: name,\n labels: labels,\n }\n }\n if (ctx.block) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.block.number, true),\n transactionIndex: -1,\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n name: name,\n labels: labels,\n }\n }\n } else if (ctx instanceof SolanaContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: Long.ZERO, // TODO need number type to be long\n transactionIndex: 0,\n logIndex: 0,\n chainId: 'SOL:mainnet', // TODO set in context\n name: name,\n labels: labels,\n }\n }\n throw new Error(\"This can't happen\")\n}\n\nexport type Labels = { [key: string]: string }\n\nexport class Counter {\n private readonly ctx: EthContext | SolanaContext\n private readonly name: string\n\n constructor(name: string, ctx: EthContext | SolanaContext) {\n this.name = name\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.record(value, labels, true)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.record(value, labels, false)\n }\n\n private record(value: Numberish, labels: Labels, add: boolean) {\n this.ctx.counters.push({\n metadata: GetRecordMetaData(this.ctx, this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class Gauge {\n private readonly name: string\n private readonly ctx: EthContext | SolanaContext\n\n constructor(name: string, ctx: EthContext | SolanaContext) {\n this.name = name\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.ctx.gauges.push({\n metadata: GetRecordMetaData(this.ctx, this.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class Meter {\n private readonly ctx: EthContext | SolanaContext\n\n // TODO is map necessary since we are sending request remotely?\n // counterMap = new Map<string, Counter>()\n // gaugeMap = new Map<string, Gauge>()\n\n constructor(ctx: EthContext | SolanaContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): Counter {\n // let counter = this.counterMap.get(name)\n\n // if (!counter) {\n // counter = new Counter(name, this.ctx)\n // }\n // return counter\n\n return new Counter(name, this.ctx)\n }\n\n Gauge(name: string): Gauge {\n // let gauge = this.gaugeMap.get(name)\n //\n // if (!gauge) {\n // gauge = new Gauge(name, this.ctx)\n // }\n // return gauge\n return new Gauge(name, this.ctx)\n }\n}\n"]}
1
+ {"version":3,"file":"meter.js","sourceRoot":"","sources":["../src/meter.ts"],"names":[],"mappings":";;;;;;AACA,uCAA8D;AAC9D,2CAAsD;AACtD,gDAAuB;AAEvB,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAA;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAC/C,CAAC;AAHD,sCAGC;AAED,SAAS,iBAAiB,CAAC,GAA+B,EAAE,IAAY,EAAE,MAAc;IACtF,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;IAE1B,IAAI,GAAG,YAAY,iBAAO,EAAE;QAC1B,IAAI,GAAG,CAAC,GAAG,EAAE;YACX,OAAO;gBACL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,YAAY,GAA+B;QACzC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,0CAA0C;QAE1C,kBAAkB;QAClB,6CAA6C;QAC7C,IAAI;QACJ,iBAAiB;QAEjB,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,sCAAsC;QACtC,EAAE;QACF,gBAAgB;QAChB,wCAAwC;QACxC,IAAI;QACJ,eAAe;QACf,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAClC,CAAC;CACF;AA/BD,sBA+BC","sourcesContent":["import { RecordMetaData } from './gen/processor/protos/processor'\nimport { Context, EthContext, SolanaContext } from './context'\nimport { toMetricValue, Numberish } from './numberish'\nimport Long from 'long'\n\nexport function normalizeName(name: string) {\n const regex = new RegExp('![_.a-zA-Z0-9]')\n return name.slice(0, 100).replace(regex, '_')\n}\n\nfunction GetRecordMetaData(ctx: EthContext | SolanaContext, name: string, labels: Labels): RecordMetaData {\n name = normalizeName(name)\n\n if (ctx instanceof Context) {\n if (ctx.log) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.log.blockNumber, true), // TODO need number type to be long\n transactionIndex: ctx.log.transactionIndex,\n logIndex: ctx.log.logIndex,\n chainId: ctx.chainId.toString(),\n name: name,\n labels: labels,\n }\n }\n if (ctx.block) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: Long.fromNumber(ctx.block.number, true),\n transactionIndex: -1,\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n name: name,\n labels: labels,\n }\n }\n } else if (ctx instanceof SolanaContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: Long.ZERO, // TODO need number type to be long\n transactionIndex: 0,\n logIndex: 0,\n chainId: 'SOL:mainnet', // TODO set in context\n name: name,\n labels: labels,\n }\n }\n throw new Error(\"This can't happen\")\n}\n\nexport type Labels = { [key: string]: string }\n\nexport class Counter {\n private readonly ctx: EthContext | SolanaContext\n private readonly name: string\n\n constructor(name: string, ctx: EthContext | SolanaContext) {\n this.name = name\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.record(value, labels, true)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.record(value, labels, false)\n }\n\n private record(value: Numberish, labels: Labels, add: boolean) {\n this.ctx.counters.push({\n metadata: GetRecordMetaData(this.ctx, this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class Gauge {\n private readonly name: string\n private readonly ctx: EthContext | SolanaContext\n\n constructor(name: string, ctx: EthContext | SolanaContext) {\n this.name = name\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.ctx.gauges.push({\n metadata: GetRecordMetaData(this.ctx, this.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class Meter {\n private readonly ctx: EthContext | SolanaContext\n\n // TODO is map necessary since we are sending request remotely?\n // counterMap = new Map<string, Counter>()\n // gaugeMap = new Map<string, Gauge>()\n\n constructor(ctx: EthContext | SolanaContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): Counter {\n // let counter = this.counterMap.get(name)\n\n // if (!counter) {\n // counter = new Counter(name, this.ctx)\n // }\n // return counter\n\n return new Counter(name, this.ctx)\n }\n\n Gauge(name: string): Gauge {\n // let gauge = this.gaugeMap.get(name)\n //\n // if (!gauge) {\n // gauge = new Gauge(name, this.ctx)\n // }\n // return gauge\n return new Gauge(name, this.ctx)\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chai_1 = require("chai");
4
+ const meter_1 = require("./meter");
5
+ describe('meter tests', () => {
6
+ test('test normalization ', async () => {
7
+ (0, chai_1.expect)((0, meter_1.normalizeName)('abc') === 'abc');
8
+ (0, chai_1.expect)((0, meter_1.normalizeName)('a-b-c') === 'a-b-c');
9
+ (0, chai_1.expect)((0, meter_1.normalizeName)('_a-B-1.') === '_a-B-1.');
10
+ (0, chai_1.expect)((0, meter_1.normalizeName)('a/b\\c\n') === 'abc');
11
+ (0, chai_1.expect)((0, meter_1.normalizeName)('abc abc') === 'abc_abc');
12
+ (0, chai_1.expect)((0, meter_1.normalizeName)('*&~') === '___');
13
+ (0, chai_1.expect)((0, meter_1.normalizeName)('x'.repeat(200)).length === 100);
14
+ });
15
+ });
16
+ //# sourceMappingURL=meter.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter.test.js","sourceRoot":"","sources":["../src/meter.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,mCAAuC;AAEvC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACrC,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAA;QACtC,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,OAAO,CAAC,KAAK,OAAO,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,SAAS,CAAC,KAAK,SAAS,CAAC,CAAA;QAE9C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,UAAU,CAAC,KAAK,KAAK,CAAC,CAAA;QAC3C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,SAAS,CAAC,KAAK,SAAS,CAAC,CAAA;QAC9C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAA;QAEtC,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { expect } from 'chai'\nimport { normalizeName } from './meter'\n\ndescribe('meter tests', () => {\n test('test normalization ', async () => {\n expect(normalizeName('abc') === 'abc')\n expect(normalizeName('a-b-c') === 'a-b-c')\n expect(normalizeName('_a-B-1.') === '_a-B-1.')\n\n expect(normalizeName('a/b\\\\c\\n') === 'abc')\n expect(normalizeName('abc abc') === 'abc_abc')\n expect(normalizeName('*&~') === '___')\n\n expect(normalizeName('x'.repeat(200)).length === 100)\n })\n})\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"numberish.js","sourceRoot":"","sources":["../src/numberish.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,gEAA0E;AAC1E,wBAA8B;AAC9B,kDAA0C;AAI1C,SAAgB,aAAa,CAAC,KAAgB;IAC5C,IAAI,KAAK,YAAY,kBAAS,EAAE;QAC9B,OAAO,uBAAW,CAAC,WAAW,CAAC;YAC7B,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;SAC3C,CAAC,CAAA;KACH;IACD,IAAI,KAAK,YAAY,aAAU,EAAE;QAC/B,uCAAuC;QACvC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE;YACrB,OAAO,uBAAW,CAAC,WAAW,CAAC;gBAC7B,UAAU,EAAE,sBAAsB,CAAC,KAAK,CAAC;aAC1C,CAAC,CAAA;SACH;aAAM;YACL,OAAO,uBAAW,CAAC,WAAW,CAAC;gBAC7B,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,sBAAsB;aACrD,CAAC,CAAA;SACH;KACF;IACD,IAAI,WAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QAClB,OAAO,uBAAW,CAAC,WAAW,CAAC;YAC7B,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC;SAClC,CAAC,CAAA;KACH;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC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B;IACD,IAAI,CAAC,YAAY,kBAAS,EAAE;QAC1B,OAAO,eAAe,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;KACrC;IACD,OAAO,eAAe,CAAC,CAAC,CAAC,CAAA;IAEzB,uCAAuC;IACvC,kBAAkB;IAClB,wBAAwB;IACxB,aAAa;IACb,0BAA0B;IAC1B,IAAI;IACJ,EAAE;IACF,WAAW;IACX,sDAAsD;IACtD,IAAI;AACN,CAAC;AAtBD,oCAsBC;AAED,SAAS,eAAe,CAAC,GAAW,EAAE,QAAiB;IACrD,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;KAChB;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAEtC,OAAO;QACL,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC;KAC7B,CAAA;AACH,CAAC","sourcesContent":["import { BigNumber } from 'ethers'\nimport { BigInteger, MetricValue } from './gen/processor/protos/processor'\nimport { BigDecimal } from '.'\nimport { BN } from '@project-serum/anchor'\n\nexport type Numberish = number | BigNumber | bigint | BigDecimal //BigNumberish\n\nexport function toMetricValue(value: Numberish): MetricValue {\n if (value instanceof BigNumber) {\n return MetricValue.fromPartial({\n bigInteger: toBigInteger(value.toBigInt()),\n })\n }\n if (value instanceof BigDecimal) {\n // Carefully consider the use case here\n if (value.isInteger()) {\n return MetricValue.fromPartial({\n bigInteger: bigDecimalToBigInteger(value),\n })\n } else {\n return MetricValue.fromPartial({\n bigDecimal: value.toString(), // e.g. -7.350918e-428\n })\n }\n }\n if (BN.isBN(value)) {\n return MetricValue.fromPartial({\n bigInteger: bnToBigInteger(value),\n })\n }\n if (typeof value === 'bigint' || Number.isInteger(value)) {\n return MetricValue.fromPartial({\n bigInteger: toBigInteger(value),\n })\n }\n\n return MetricValue.fromPartial({\n doubleValue: Number(value),\n })\n}\nfunction bigDecimalToBigInteger(a: BigDecimal): BigInteger {\n const negative = a.isNegative()\n if (negative) {\n a = a.abs()\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nfunction bnToBigInteger(a: BN): BigInteger {\n const negative = a.isNeg()\n if (negative) {\n a = a.abs()\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nfunction intToBigInteger(a: bigint | number): BigInteger {\n const negative = a < 0\n if (negative) {\n a = -a\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nexport function toBigInteger(a: Numberish): BigInteger {\n if (a instanceof BigDecimal) {\n return bigDecimalToBigInteger(a)\n }\n if (a instanceof BN) {\n return bnToBigInteger(a)\n }\n if (a instanceof BigNumber) {\n return intToBigInteger(a.toBigInt())\n }\n return intToBigInteger(a)\n\n // Following code is actually very slow\n // while (a > 0) {\n // const d = a & 0xffn\n // a >>= 8n\n // value.push(Number(d))\n // }\n //\n // return {\n // negative, value: new Uint8Array(value.reverse()),\n // }\n}\n\nfunction hexToBigInteger(hex: string, negative: boolean): BigInteger {\n if (hex.length % 2 === 1) {\n hex = '0' + hex\n }\n const buffer = Buffer.from(hex, 'hex')\n\n return {\n negative: negative,\n data: new Uint8Array(buffer),\n }\n}\n"]}
1
+ {"version":3,"file":"numberish.js","sourceRoot":"","sources":["../src/numberish.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,gEAA0E;AAC1E,wBAA8B;AAC9B,kDAA0C;AAI1C,SAAgB,aAAa,CAAC,KAAgB;IAC5C,IAAI,KAAK,YAAY,kBAAS,EAAE;QAC9B,OAAO,uBAAW,CAAC,WAAW,CAAC;YAC7B,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;SAC3C,CAAC,CAAA;KACH;IACD,IAAI,KAAK,YAAY,aAAU,EAAE;QAC/B,uCAAuC;QACvC,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE;YACrB,OAAO,uBAAW,CA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,CAAC,CAAkB;IACzC,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,CAAA;IACtB,IAAI,QAAQ,EAAE;QACZ,CAAC,GAAG,CAAC,CAAC,CAAA;KACP;IACD,OAAO,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAA;AAClD,CAAC;AAED,SAAgB,YAAY,CAAC,CAAY;IACvC,IAAI,CAAC,YAAY,aAAU,EAAE;QAC3B,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAA;KACjC;IACD,IAAI,CAAC,YAAY,WAAE,EAAE;QACnB,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;KACzB;IACD,IAAI,CAAC,YAAY,kBAAS,EAAE;QAC1B,OAAO,eAAe,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;KACrC;IACD,OAAO,eAAe,CAAC,CAAC,CAAC,CAAA;IAEzB,uCAAuC;IACvC,kBAAkB;IAClB,wBAAwB;IACxB,aAAa;IACb,0BAA0B;IAC1B,IAAI;IACJ,EAAE;IACF,WAAW;IACX,sDAAsD;IACtD,IAAI;AACN,CAAC;AAtBD,oCAsBC;AAED,SAAS,eAAe,CAAC,GAAW,EAAE,QAAiB;IACrD,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;KAChB;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAEtC,OAAO;QACL,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,IAAI,UAAU,CAAC,MAAM,CAAC;KAC7B,CAAA;AACH,CAAC","sourcesContent":["import { BigNumber } from 'ethers'\nimport { BigInteger, MetricValue } from './gen/processor/protos/processor'\nimport { BigDecimal } from '.'\nimport { BN } from '@project-serum/anchor'\n\nexport type Numberish = number | BigNumber | bigint | BigDecimal\n\nexport function toMetricValue(value: Numberish): MetricValue {\n if (value instanceof BigNumber) {\n return MetricValue.fromPartial({\n bigInteger: toBigInteger(value.toBigInt()),\n })\n }\n if (value instanceof BigDecimal) {\n // Carefully consider the use case here\n if (value.isInteger()) {\n return MetricValue.fromPartial({\n bigInteger: bigDecimalToBigInteger(value),\n })\n } else {\n return MetricValue.fromPartial({\n bigDecimal: value.toString(), // e.g. -7.350918e-428\n })\n }\n }\n if (BN.isBN(value)) {\n return MetricValue.fromPartial({\n bigInteger: bnToBigInteger(value),\n })\n }\n if (typeof value === 'bigint' || Number.isInteger(value)) {\n return MetricValue.fromPartial({\n bigInteger: toBigInteger(value),\n })\n }\n\n return MetricValue.fromPartial({\n doubleValue: Number(value),\n })\n}\n\nfunction bigDecimalToBigInteger(a: BigDecimal): BigInteger {\n const negative = a.isNegative()\n if (negative) {\n a = a.abs()\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nfunction bnToBigInteger(a: BN): BigInteger {\n const negative = a.isNeg()\n if (negative) {\n a = a.abs()\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nfunction intToBigInteger(a: bigint | number): BigInteger {\n const negative = a < 0\n if (negative) {\n a = -a\n }\n return hexToBigInteger(a.toString(16), negative)\n}\n\nexport function toBigInteger(a: Numberish): BigInteger {\n if (a instanceof BigDecimal) {\n return bigDecimalToBigInteger(a)\n }\n if (a instanceof BN) {\n return bnToBigInteger(a)\n }\n if (a instanceof BigNumber) {\n return intToBigInteger(a.toBigInt())\n }\n return intToBigInteger(a)\n\n // Following code is actually very slow\n // while (a > 0) {\n // const d = a & 0xffn\n // a >>= 8n\n // value.push(Number(d))\n // }\n //\n // return {\n // negative, value: new Uint8Array(value.reverse()),\n // }\n}\n\nfunction hexToBigInteger(hex: string, negative: boolean): BigInteger {\n if (hex.length % 2 === 1) {\n hex = '0' + hex\n }\n const buffer = Buffer.from(hex, 'hex')\n\n return {\n negative: negative,\n data: new Uint8Array(buffer),\n }\n}\n"]}
@@ -1,3 +1,5 @@
1
1
  import { BigNumber } from 'ethers';
2
- import { BigDecimal } from '@sentio/sdk';
2
+ import { BigDecimal, MetricValue } from '@sentio/sdk';
3
+ import { Numberish } from '../numberish';
3
4
  export declare function toBigDecimal(n: BigNumber): BigDecimal;
5
+ export declare function metricValueToNumberish(v: MetricValue): Numberish;
@@ -1,9 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBigDecimal = void 0;
3
+ exports.metricValueToNumberish = exports.toBigDecimal = void 0;
4
+ const ethers_1 = require("ethers");
4
5
  const sdk_1 = require("@sentio/sdk");
5
6
  function toBigDecimal(n) {
6
7
  return new sdk_1.BigDecimal(n.toString());
7
8
  }
8
9
  exports.toBigDecimal = toBigDecimal;
10
+ function metricValueToNumberish(v) {
11
+ if (v.doubleValue) {
12
+ return v.doubleValue;
13
+ }
14
+ if (v.bigInteger) {
15
+ const bn = ethers_1.BigNumber.from(v.bigInteger.data);
16
+ if (v.bigInteger.negative) {
17
+ return ethers_1.BigNumber.from(0).sub(bn);
18
+ }
19
+ return bn;
20
+ }
21
+ if (v.bigDecimal) {
22
+ return new sdk_1.BigDecimal(v.bigDecimal);
23
+ }
24
+ throw Error("MetricValue doesn't contain any of possible value");
25
+ }
26
+ exports.metricValueToNumberish = metricValueToNumberish;
9
27
  //# sourceMappingURL=convert.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/utils/convert.ts"],"names":[],"mappings":";;;AACA,qCAAwC;AAExC,SAAgB,YAAY,CAAC,CAAY;IACvC,OAAO,IAAI,gBAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;AACrC,CAAC;AAFD,oCAEC","sourcesContent":["import { BigNumber } from 'ethers'\nimport { BigDecimal } from '@sentio/sdk'\n\nexport function toBigDecimal(n: BigNumber) {\n return new BigDecimal(n.toString())\n}\n"]}
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../src/utils/convert.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,qCAAqD;AAGrD,SAAgB,YAAY,CAAC,CAAY;IACvC,OAAO,IAAI,gBAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;AACrC,CAAC;AAFD,oCAEC;AAED,SAAgB,sBAAsB,CAAC,CAAc;IACnD,IAAI,CAAC,CAAC,WAAW,EAAE;QACjB,OAAO,CAAC,CAAC,WAAW,CAAA;KACrB;IACD,IAAI,CAAC,CAAC,UAAU,EAAE;QAChB,MAAM,EAAE,GAAG,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE;YACzB,OAAO,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;SACjC;QACD,OAAO,EAAE,CAAA;KACV;IAED,IAAI,CAAC,CAAC,UAAU,EAAE;QAChB,OAAO,IAAI,gBAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;KACpC;IAED,MAAM,KAAK,CAAC,mDAAmD,CAAC,CAAA;AAClE,CAAC;AAjBD,wDAiBC","sourcesContent":["import { BigNumber } from 'ethers'\nimport { BigDecimal, MetricValue } from '@sentio/sdk'\nimport { Numberish } from '../numberish'\n\nexport function toBigDecimal(n: BigNumber) {\n return new BigDecimal(n.toString())\n}\n\nexport function metricValueToNumberish(v: MetricValue): Numberish {\n if (v.doubleValue) {\n return v.doubleValue\n }\n if (v.bigInteger) {\n const bn = BigNumber.from(v.bigInteger.data)\n if (v.bigInteger.negative) {\n return BigNumber.from(0).sub(bn)\n }\n return bn\n }\n\n if (v.bigDecimal) {\n return new BigDecimal(v.bigDecimal)\n }\n\n throw Error(\"MetricValue doesn't contain any of possible value\")\n}\n"]}
@@ -1,2 +1,2 @@
1
1
  export { getChainName } from './chainmap';
2
- export { toBigDecimal } from './convert';
2
+ export { toBigDecimal, metricValueToNumberish } from './convert';
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBigDecimal = exports.getChainName = void 0;
3
+ exports.metricValueToNumberish = exports.toBigDecimal = exports.getChainName = void 0;
4
4
  var chainmap_1 = require("./chainmap");
5
5
  Object.defineProperty(exports, "getChainName", { enumerable: true, get: function () { return chainmap_1.getChainName; } });
6
6
  var convert_1 = require("./convert");
7
7
  Object.defineProperty(exports, "toBigDecimal", { enumerable: true, get: function () { return convert_1.toBigDecimal; } });
8
+ Object.defineProperty(exports, "metricValueToNumberish", { enumerable: true, get: function () { return convert_1.metricValueToNumberish; } });
8
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAAhC,wGAAA,YAAY,OAAA;AACrB,qCAAwC;AAA/B,uGAAA,YAAY,OAAA","sourcesContent":["export { getChainName } from './chainmap'\nexport { toBigDecimal } from './convert'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAAhC,wGAAA,YAAY,OAAA;AACrB,qCAAgE;AAAvD,uGAAA,YAAY,OAAA;AAAE,iHAAA,sBAAsB,OAAA","sourcesContent":["export { getChainName } from './chainmap'\nexport { toBigDecimal, metricValueToNumberish } from './convert'\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "1.7.17",
4
+ "version": "1.7.20",
5
5
  "scripts": {
6
6
  "compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
7
7
  "compile": "tsc -p . && cp src/cli/webpack.config.js lib/cli",
@@ -57,9 +57,9 @@
57
57
  "@types/node": "^18.0.4",
58
58
  "chai": "^4.3.6",
59
59
  "clean-publish": "^4.0.1",
60
- "jest": "^28.0.1",
60
+ "jest": "^29.0.0",
61
61
  "semantic-release": "^19.0.5",
62
- "ts-jest": "^28.0.8",
62
+ "ts-jest": "^29.0.0",
63
63
  "ts-node": "^10.8.0",
64
64
  "tsconfig-paths": "^4.0.0",
65
65
  "typescript": "^4.8.0"
package/src/cli/upload.ts CHANGED
@@ -79,6 +79,8 @@ export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: s
79
79
  if (commitSha) {
80
80
  console.log('\t', chalk.blue('Git commit SHA:'), commitSha)
81
81
  }
82
+ const { ProjectSlug } = await res.json()
83
+ console.log('\t', chalk.blue('Check status:'), `${options.host}/${ProjectSlug}/datasource`)
82
84
  } else {
83
85
  console.error(chalk.red('Upload Failed'))
84
86
  console.error(chalk.red(await res.text()))
package/src/error.ts CHANGED
@@ -2,10 +2,12 @@
2
2
  import { Context } from './context'
3
3
  import { errors } from 'ethers'
4
4
 
5
- class EthersError extends Error {
6
- constructor(message: string, stack?: string) {
5
+ export class EthersError extends Error {
6
+ e: Error
7
+
8
+ constructor(message: string, e: Error) {
7
9
  super(message)
8
- this.stack = stack
10
+ this.stack = e.stack
9
11
  }
10
12
 
11
13
  toString() {
@@ -29,7 +31,7 @@ export function transformEtherError(e: Error, ctx: Context<any, any> | undefined
29
31
  msg = "jsonrpc eth_call return '0x' (likely contract not existed): " + JSON.stringify(e)
30
32
  }
31
33
  }
32
- return new EthersError(msg, e.stack)
34
+ return new EthersError(msg, e)
33
35
  }
34
36
 
35
37
  if (e instanceof EthersError) {
@@ -9,30 +9,27 @@ export class GenericProcessor extends BaseProcessor<
9
9
  BaseContract,
10
10
  BoundContractView<BaseContract, ContractView<BaseContract>>
11
11
  > {
12
- eventAbi: string[]
13
- constructor(eventAbi: string[], options: BindOptions) {
12
+ eventABI: string[]
13
+ constructor(eventABI: string[], options: BindOptions) {
14
14
  super(options)
15
- this.eventAbi = eventAbi
15
+ this.eventABI = eventABI
16
16
  }
17
17
 
18
18
  protected CreateBoundContractView(): BoundContractView<BaseContract, ContractView<BaseContract>> {
19
- const contract = new BaseContract(this.config.address, this.eventAbi, getProvider(this.config.network))
19
+ const contract = new BaseContract(this.config.address, this.eventABI, getProvider(this.config.network))
20
20
  return new BoundContractView(new ContractView<BaseContract>(contract))
21
21
  }
22
22
 
23
- public static bind(eventAbi: string[] | string, options: BindOptions): GenericProcessor {
23
+ public static bind(eventABI: string[] | string, options: BindOptions): GenericProcessor {
24
24
  const AbiName = 'Generic'
25
- if (!Array.isArray(eventAbi)) {
26
- eventAbi = [eventAbi]
25
+ if (!Array.isArray(eventABI)) {
26
+ eventABI = [eventABI]
27
27
  }
28
28
 
29
- // let processor = getProcessor(AbiName, options) as GenericProcessor;
30
- // if (!processor) {
31
29
  const finalOptions = Object.assign({}, options)
32
30
  finalOptions.name = getContractName(AbiName, options.name, options.address, options.network)
33
- const processor = new GenericProcessor(eventAbi, finalOptions)
31
+ const processor = new GenericProcessor(eventABI, finalOptions)
34
32
  addProcessor(AbiName, options, processor)
35
- // }
36
33
  return processor
37
34
  }
38
35
  }
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export { BindOptions, SolanaBindOptions } from './bind-options'
11
11
  export { transformEtherError } from './error'
12
12
  export { ProcessorState } from './processor-state'
13
13
  export { BigNumber as BigDecimal } from 'bignumber.js'
14
+ export { EthersError } from './error'
14
15
 
15
16
  export { getProcessor, addProcessor, getContractByABI, addContractByABI, getContractName } from './binds'
16
17
 
@@ -0,0 +1,16 @@
1
+ import { expect } from 'chai'
2
+ import { normalizeName } from './meter'
3
+
4
+ describe('meter tests', () => {
5
+ test('test normalization ', async () => {
6
+ expect(normalizeName('abc') === 'abc')
7
+ expect(normalizeName('a-b-c') === 'a-b-c')
8
+ expect(normalizeName('_a-B-1.') === '_a-B-1.')
9
+
10
+ expect(normalizeName('a/b\\c\n') === 'abc')
11
+ expect(normalizeName('abc abc') === 'abc_abc')
12
+ expect(normalizeName('*&~') === '___')
13
+
14
+ expect(normalizeName('x'.repeat(200)).length === 100)
15
+ })
16
+ })
package/src/meter.ts CHANGED
@@ -3,7 +3,14 @@ import { Context, EthContext, SolanaContext } from './context'
3
3
  import { toMetricValue, Numberish } from './numberish'
4
4
  import Long from 'long'
5
5
 
6
+ export function normalizeName(name: string) {
7
+ const regex = new RegExp('![_.a-zA-Z0-9]')
8
+ return name.slice(0, 100).replace(regex, '_')
9
+ }
10
+
6
11
  function GetRecordMetaData(ctx: EthContext | SolanaContext, name: string, labels: Labels): RecordMetaData {
12
+ name = normalizeName(name)
13
+
7
14
  if (ctx instanceof Context) {
8
15
  if (ctx.log) {
9
16
  return {
package/src/numberish.ts CHANGED
@@ -3,7 +3,7 @@ import { BigInteger, MetricValue } from './gen/processor/protos/processor'
3
3
  import { BigDecimal } from '.'
4
4
  import { BN } from '@project-serum/anchor'
5
5
 
6
- export type Numberish = number | BigNumber | bigint | BigDecimal //BigNumberish
6
+ export type Numberish = number | BigNumber | bigint | BigDecimal
7
7
 
8
8
  export function toMetricValue(value: Numberish): MetricValue {
9
9
  if (value instanceof BigNumber) {
@@ -38,6 +38,7 @@ export function toMetricValue(value: Numberish): MetricValue {
38
38
  doubleValue: Number(value),
39
39
  })
40
40
  }
41
+
41
42
  function bigDecimalToBigInteger(a: BigDecimal): BigInteger {
42
43
  const negative = a.isNegative()
43
44
  if (negative) {
@@ -1,6 +1,26 @@
1
1
  import { BigNumber } from 'ethers'
2
- import { BigDecimal } from '@sentio/sdk'
2
+ import { BigDecimal, MetricValue } from '@sentio/sdk'
3
+ import { Numberish } from '../numberish'
3
4
 
4
5
  export function toBigDecimal(n: BigNumber) {
5
6
  return new BigDecimal(n.toString())
6
7
  }
8
+
9
+ export function metricValueToNumberish(v: MetricValue): Numberish {
10
+ if (v.doubleValue) {
11
+ return v.doubleValue
12
+ }
13
+ if (v.bigInteger) {
14
+ const bn = BigNumber.from(v.bigInteger.data)
15
+ if (v.bigInteger.negative) {
16
+ return BigNumber.from(0).sub(bn)
17
+ }
18
+ return bn
19
+ }
20
+
21
+ if (v.bigDecimal) {
22
+ return new BigDecimal(v.bigDecimal)
23
+ }
24
+
25
+ throw Error("MetricValue doesn't contain any of possible value")
26
+ }
@@ -1,2 +1,2 @@
1
1
  export { getChainName } from './chainmap'
2
- export { toBigDecimal } from './convert'
2
+ export { toBigDecimal, metricValueToNumberish } from './convert'