@sentio/sdk 1.19.3 → 1.19.5

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 (114) hide show
  1. package/lib/aptos/aptos-processor.d.ts +40 -0
  2. package/lib/aptos/aptos-processor.js +126 -0
  3. package/lib/aptos/aptos-processor.js.map +1 -0
  4. package/lib/aptos/bind-options.d.ts +11 -0
  5. package/lib/aptos/bind-options.js +17 -0
  6. package/lib/aptos/bind-options.js.map +1 -0
  7. package/lib/aptos/context.d.ts +12 -0
  8. package/lib/aptos/context.js +33 -0
  9. package/lib/aptos/context.js.map +1 -0
  10. package/lib/aptos/index.d.ts +5 -0
  11. package/lib/aptos/index.js +11 -0
  12. package/lib/aptos/index.js.map +1 -0
  13. package/lib/core/base-processor-template.js.map +1 -1
  14. package/lib/core/base-processor.d.ts +1 -1
  15. package/lib/core/base-processor.js.map +1 -1
  16. package/lib/core/bind-options.d.ts +0 -2
  17. package/lib/core/bind-options.js +1 -4
  18. package/lib/core/bind-options.js.map +1 -1
  19. package/lib/core/context.d.ts +10 -10
  20. package/lib/core/context.js +65 -11
  21. package/lib/core/context.js.map +1 -1
  22. package/lib/core/generic-processor.test.js +1 -1
  23. package/lib/core/generic-processor.test.js.map +1 -1
  24. package/lib/core/index.d.ts +1 -2
  25. package/lib/core/index.js +1 -4
  26. package/lib/core/index.js.map +1 -1
  27. package/lib/core/logger.d.ts +6 -3
  28. package/lib/core/logger.js +15 -9
  29. package/lib/core/logger.js.map +1 -1
  30. package/lib/core/metadata.d.ts +1 -1
  31. package/lib/core/metadata.js +3 -79
  32. package/lib/core/metadata.js.map +1 -1
  33. package/lib/core/meter.d.ts +1 -1
  34. package/lib/core/meter.js +2 -2
  35. package/lib/core/meter.js.map +1 -1
  36. package/lib/core/numberish.d.ts +1 -1
  37. package/lib/core/numberish.js +7 -7
  38. package/lib/core/numberish.js.map +1 -1
  39. package/lib/core/numberish.test.js.map +1 -1
  40. package/lib/core/solana-processor.d.ts +1 -1
  41. package/lib/core/solana-processor.js.map +1 -1
  42. package/lib/core/sui-processor.d.ts +1 -1
  43. package/lib/core/sui-processor.js.map +1 -1
  44. package/lib/gen/index.d.ts +1 -0
  45. package/lib/gen/index.js +18 -0
  46. package/lib/gen/index.js.map +1 -0
  47. package/lib/gen/processor/protos/processor.d.ts +165 -163
  48. package/lib/gen/processor/protos/processor.js +455 -482
  49. package/lib/gen/processor/protos/processor.js.map +1 -1
  50. package/lib/index.d.ts +2 -1
  51. package/lib/index.js +15 -2
  52. package/lib/index.js.map +1 -1
  53. package/lib/processor-state.d.ts +2 -1
  54. package/lib/processor-state.js.map +1 -1
  55. package/lib/service.d.ts +13 -7
  56. package/lib/service.js +133 -44
  57. package/lib/service.js.map +1 -1
  58. package/lib/testing/metric-utils.d.ts +1 -1
  59. package/lib/testing/metric-utils.js +2 -2
  60. package/lib/testing/metric-utils.js.map +1 -1
  61. package/lib/testing/test-processor-server.d.ts +16 -15
  62. package/lib/testing/test-processor-server.js +19 -14
  63. package/lib/testing/test-processor-server.js.map +1 -1
  64. package/lib/testing/test-provider.js +2 -2
  65. package/lib/testing/test-provider.js.map +1 -1
  66. package/lib/tests/aptos.test.js +44 -12
  67. package/lib/tests/aptos.test.js.map +1 -1
  68. package/lib/tests/erc20.test.js +1 -1
  69. package/lib/tests/erc20.test.js.map +1 -1
  70. package/lib/tests/logger.test.js +1 -1
  71. package/lib/tests/logger.test.js.map +1 -1
  72. package/lib/tests/souffl3.js +16 -4
  73. package/lib/tests/souffl3.js.map +1 -1
  74. package/lib/utils/chain.d.ts +1 -0
  75. package/lib/utils/chain.js +3 -1
  76. package/lib/utils/chain.js.map +1 -1
  77. package/lib/utils/erc20.test.js +0 -1
  78. package/lib/utils/erc20.test.js.map +1 -1
  79. package/package.json +3 -5
  80. package/src/aptos/aptos-processor.ts +156 -0
  81. package/src/aptos/bind-options.ts +15 -0
  82. package/src/aptos/context.ts +35 -0
  83. package/src/aptos/index.ts +8 -0
  84. package/src/core/base-processor-template.ts +1 -1
  85. package/src/core/base-processor.ts +1 -1
  86. package/src/core/bind-options.ts +0 -1
  87. package/src/core/context.ts +74 -15
  88. package/src/core/generic-processor.test.ts +1 -1
  89. package/src/core/index.ts +2 -2
  90. package/src/core/logger.ts +13 -5
  91. package/src/core/metadata.ts +4 -76
  92. package/src/core/meter.ts +1 -1
  93. package/src/core/numberish.test.ts +1 -1
  94. package/src/core/numberish.ts +1 -1
  95. package/src/core/solana-processor.ts +1 -1
  96. package/src/core/sui-processor.ts +1 -1
  97. package/src/gen/index.ts +1 -0
  98. package/src/gen/processor/protos/processor.ts +606 -650
  99. package/src/index.ts +4 -1
  100. package/src/processor-state.ts +3 -1
  101. package/src/service.ts +153 -61
  102. package/src/testing/metric-utils.ts +2 -2
  103. package/src/testing/test-processor-server.ts +31 -33
  104. package/src/testing/test-provider.ts +1 -1
  105. package/src/tests/aptos.test.ts +47 -11
  106. package/src/tests/erc20.test.ts +1 -1
  107. package/src/tests/logger.test.ts +1 -1
  108. package/src/tests/souffl3.ts +30 -12
  109. package/src/utils/chain.ts +2 -0
  110. package/src/utils/erc20.test.ts +1 -4
  111. package/lib/core/aptos-processor.d.ts +0 -22
  112. package/lib/core/aptos-processor.js +0 -67
  113. package/lib/core/aptos-processor.js.map +0 -1
  114. package/src/core/aptos-processor.ts +0 -77
@@ -32,7 +32,7 @@ describe('Test Generic Processor', () => {
32
32
  const counters = res.result?.counters;
33
33
  (0, chai_1.expect)(counters).length(2);
34
34
  (0, chai_1.expect)((0, testing_1.firstCounterValue)(res.result, 'event_num')).equals(1n);
35
- (0, chai_1.expect)(counters?.[0].runtimeInfo?.from).equals(__1.HandlerType.LOG);
35
+ (0, chai_1.expect)(counters?.[0].runtimeInfo?.from).equals(__1.HandlerType.ETH_LOG);
36
36
  });
37
37
  test('Check log dispatch no buffer over rune', async () => {
38
38
  const logStr = '{"address":"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f","topics":["0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081"],"data":"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24","blockNumber":"0xc9d6d7","transactionHash":"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2","transactionIndex":"0xf3","blockHash":"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6","logIndex":"0x14b","removed":false}';
@@ -1 +1 @@
1
- {"version":3,"file":"generic-processor.test.js","sourceRoot":"","sources":["../../src/core/generic-processor.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;AAEhC,+BAA6B;AAE7B,0BAAgC;AAEhC,2DAAsD;AACtD,wCAAmE;AAEnE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAI,6BAAmB,CAAC,GAAG,EAAE;QAC3C,oCAAgB,CAAC,IAAI,CACnB;YACE,yEAAyE;YACzE,yEAAyE;SAC1E,EACD,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAC1D,CAAC,WAAW,CAAC,UAAU,GAAG,EAAE,GAAG;YAC9B,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACvC,CAAC,CAAC,CAAA;QAEF,oCAAgB,CAAC,IAAI,CAAC,oDAAoD,EAAE;YAC1E,OAAO,EAAE,4CAA4C;SACtD,CAAC,CAAC,WAAW,CAAC,UAAU,GAAG,EAAE,GAAG;YAC/B,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAA;IACvB,CAAC,CAAC,CAAA;IAEF,I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AAO,GAAG;QACd,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,oEAAoE;QAC/E,gBAAgB,EAAE,GAAG;QACrB,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,4CAA4C;QACrD,IAAI,EAAE,oEAAoE;QAC1E,MAAM,EAAE;YACN,oEAAoE;YACpE,oEAAoE;YACpE,oEAAoE;SACrE;QACD,eAAe,EAAE,oEAAoE;QACrF,QAAQ,EAAE,GAAG;KACd,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '..'\n\nimport { GenericProcessor } from './generic-processor'\nimport { TestProcessorServer, firstCounterValue } from '../testing'\n\ndescribe('Test Generic Processor', () => {\n const service = new TestProcessorServer(() => {\n GenericProcessor.bind(\n [\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed from, address indexed to, uint256 value)',\n ],\n { address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9' }\n ).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('event_num').add(1)\n })\n\n GenericProcessor.bind('event WalletCreated(address wallet, address owner)', {\n address: '0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f',\n }).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('wallet').add(1)\n })\n })\n\n beforeAll(async () => {\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[0].contract?.name).equals('Generic')\n })\n\n test('Check log dispatch', async () => {\n const res = await service.testLogs([logData, logData])\n const counters = res.result?.counters\n expect(counters).length(2)\n expect(firstCounterValue(res.result, 'event_num')).equals(1n)\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.LOG)\n })\n\n test('Check log dispatch no buffer over rune', async () => {\n const logStr =\n '{\"address\":\"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f\",\"topics\":[\"0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081\"],\"data\":\"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24\",\"blockNumber\":\"0xc9d6d7\",\"transactionHash\":\"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2\",\"transactionIndex\":\"0xf3\",\"blockHash\":\"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6\",\"logIndex\":\"0x14b\",\"removed\":false}'\n const res = await service.testLog(JSON.parse(logStr))\n console.log(JSON.stringify(res))\n })\n\n const logData = {\n blockNumber: 14213252,\n blockHash: '0x83d646fac9350b281def8c4c37626f9d8efc95df801287b848c719edf35cdbaf',\n transactionIndex: 347,\n removed: false,\n address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9',\n data: '0x00000000000000000000000000000000000000000000009a71db64810aaa0000',\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n '0x0000000000000000000000000000000000000000000000000000000000000000',\n '0x000000000000000000000000b329e39ebefd16f40d38f07643652ce17ca5bac1',\n ],\n transactionHash: '0x93355e0cb2c3490cb8a747029ff2dc8cdbde2407025b8391398436955afae303',\n logIndex: 428,\n }\n})\n"]}
1
+ {"version":3,"file":"generic-processor.test.js","sourceRoot":"","sources":["../../src/core/generic-processor.test.ts"],"names":[],"mappings":";AAAA,gCAAgC;;AAEhC,+BAA6B;AAE7B,0BAAgC;AAEhC,2DAAsD;AACtD,wCAAmE;AAEnE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAI,6BAAmB,CAAC,GAAG,EAAE;QAC3C,oCAAgB,CAAC,IAAI,CACnB;YACE,yEAAyE;YACzE,yEAAyE;SAC1E,EACD,EAAE,OAAO,EAAE,4CAA4C,EAAE,CAC1D,CAAC,WAAW,CAAC,UAAU,GAAG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CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC7D,IAAA,aAAM,EAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,eAAW,CAAC,OAAO,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,MAAM,GACV,ohBAAohB,CAAA;QACthB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;QACrD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,QAAQ;QACrB,SAAS,EAAE,oEAAoE;QAC/E,gBAAgB,EAAE,GAAG;QACrB,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,4CAA4C;QACrD,IAAI,EAAE,oEAAoE;QAC1E,MAAM,EAAE;YACN,oEAAoE;YACpE,oEAAoE;YACpE,oEAAoE;SACrE;QACD,eAAe,EAAE,oEAAoE;QACrF,QAAQ,EAAE,GAAG;KACd,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["// TODO move out of this package\n\nimport { expect } from 'chai'\n\nimport { HandlerType } from '..'\n\nimport { GenericProcessor } from './generic-processor'\nimport { TestProcessorServer, firstCounterValue } from '../testing'\n\ndescribe('Test Generic Processor', () => {\n const service = new TestProcessorServer(() => {\n GenericProcessor.bind(\n [\n 'event Transfer(address indexed from, address indexed to, uint256 value)',\n 'event Approval(address indexed from, address indexed to, uint256 value)',\n ],\n { address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9' }\n ).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('event_num').add(1)\n })\n\n GenericProcessor.bind('event WalletCreated(address wallet, address owner)', {\n address: '0x57E037F4d2c8BEa011Ad8a9A5AF4AaEEd508650f',\n }).onAllEvents(function (log, ctx) {\n ctx.meter.Counter('wallet').add(1)\n })\n })\n\n beforeAll(async () => {\n await service.start()\n })\n\n test('check configuration', async () => {\n const config = await service.getConfig({})\n expect(config.contractConfigs).length(2)\n expect(config.contractConfigs?.[0].contract?.name).equals('Generic')\n })\n\n test('Check log dispatch', async () => {\n const res = await service.testLogs([logData, logData])\n const counters = res.result?.counters\n expect(counters).length(2)\n expect(firstCounterValue(res.result, 'event_num')).equals(1n)\n expect(counters?.[0].runtimeInfo?.from).equals(HandlerType.ETH_LOG)\n })\n\n test('Check log dispatch no buffer over rune', async () => {\n const logStr =\n '{\"address\":\"0x57e037f4d2c8bea011ad8a9a5af4aaeed508650f\",\"topics\":[\"0x5b03bfed1c14a02bdeceb5fa582eb1a5765fc0bc64ca0e6af4c20afc9487f081\"],\"data\":\"0x00000000000000000000000093269483a70c68d5c5bb63aac1e8f4ac59f498800000000000000000000000000c520e51c055cf63bab075715c1b860b2e9b8e24\",\"blockNumber\":\"0xc9d6d7\",\"transactionHash\":\"0x208af3250499672c2f07138b9aa236153c65c78ae4341b23c2763017afdd61a2\",\"transactionIndex\":\"0xf3\",\"blockHash\":\"0x6e3b100c34b510049e922fbe1c1dab1b0793be3d1229b632688e6a518cdd11b6\",\"logIndex\":\"0x14b\",\"removed\":false}'\n const res = await service.testLog(JSON.parse(logStr))\n console.log(JSON.stringify(res))\n })\n\n const logData = {\n blockNumber: 14213252,\n blockHash: '0x83d646fac9350b281def8c4c37626f9d8efc95df801287b848c719edf35cdbaf',\n transactionIndex: 347,\n removed: false,\n address: '0x1E4EDE388cbc9F4b5c79681B7f94d36a11ABEBC9',\n data: '0x00000000000000000000000000000000000000000000009a71db64810aaa0000',\n topics: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n '0x0000000000000000000000000000000000000000000000000000000000000000',\n '0x000000000000000000000000b329e39ebefd16f40d38f07643652ce17ca5bac1',\n ],\n transactionHash: '0x93355e0cb2c3490cb8a747029ff2dc8cdbde2407025b8391398436955afae303',\n logIndex: 428,\n }\n})\n"]}
@@ -2,11 +2,10 @@ export { BigNumber as BigDecimal } from 'bignumber.js';
2
2
  export { Context, ContractView, BoundContractView, SolanaContext } from './context';
3
3
  export { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter';
4
4
  export { type Numberish, toBigInteger, toMetricValue } from './numberish';
5
- export { BindOptions, SolanaBindOptions, SuiBindOptions, AptosBindOptions } from './bind-options';
5
+ export { BindOptions, SolanaBindOptions, SuiBindOptions } from './bind-options';
6
6
  export { BaseProcessor } from './base-processor';
7
7
  export { GenericProcessor } from './generic-processor';
8
8
  export { BaseProcessorTemplate } from './base-processor-template';
9
9
  export { SolanaBaseProcessor } from './solana-processor';
10
10
  export { SuiBaseProcessor } from './sui-processor';
11
- export { AptosBaseProcessor } from './aptos-processor';
12
11
  export type { TypedCallTrace, Trace } from './trace';
package/lib/core/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AptosBaseProcessor = exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.AptosBindOptions = exports.SuiBindOptions = exports.SolanaBindOptions = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.MetricDescriptorOption = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.BigDecimal = void 0;
3
+ exports.SuiBaseProcessor = exports.SolanaBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.SuiBindOptions = exports.SolanaBindOptions = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.MetricDescriptorOption = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.SolanaContext = exports.BoundContractView = exports.ContractView = exports.Context = exports.BigDecimal = void 0;
4
4
  var bignumber_js_1 = require("bignumber.js");
5
5
  Object.defineProperty(exports, "BigDecimal", { enumerable: true, get: function () { return bignumber_js_1.BigNumber; } });
6
6
  var context_1 = require("./context");
@@ -22,7 +22,6 @@ var bind_options_1 = require("./bind-options");
22
22
  Object.defineProperty(exports, "BindOptions", { enumerable: true, get: function () { return bind_options_1.BindOptions; } });
23
23
  Object.defineProperty(exports, "SolanaBindOptions", { enumerable: true, get: function () { return bind_options_1.SolanaBindOptions; } });
24
24
  Object.defineProperty(exports, "SuiBindOptions", { enumerable: true, get: function () { return bind_options_1.SuiBindOptions; } });
25
- Object.defineProperty(exports, "AptosBindOptions", { enumerable: true, get: function () { return bind_options_1.AptosBindOptions; } });
26
25
  var base_processor_1 = require("./base-processor");
27
26
  Object.defineProperty(exports, "BaseProcessor", { enumerable: true, get: function () { return base_processor_1.BaseProcessor; } });
28
27
  var generic_processor_1 = require("./generic-processor");
@@ -33,6 +32,4 @@ var solana_processor_1 = require("./solana-processor");
33
32
  Object.defineProperty(exports, "SolanaBaseProcessor", { enumerable: true, get: function () { return solana_processor_1.SolanaBaseProcessor; } });
34
33
  var sui_processor_1 = require("./sui-processor");
35
34
  Object.defineProperty(exports, "SuiBaseProcessor", { enumerable: true, get: function () { return sui_processor_1.SuiBaseProcessor; } });
36
- var aptos_processor_1 = require("./aptos-processor");
37
- Object.defineProperty(exports, "AptosBaseProcessor", { enumerable: true, get: function () { return aptos_processor_1.AptosBaseProcessor; } });
38
35
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAA7C,0GAAA,SAAS,OAAc;AAChC,qCAAmF;AAA1E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AAChE,iCAAqG;AAA5F,uGAAA,cAAc,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,+GAAA,sBAAsB,OAAA;AACpF,yCAAyE;AAAhD,yGAAA,YAAY,OAAA;AAAE,0GAAA,aAAa,OAAA;AAEpD,+CAAiG;AAAxF,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAAE,8GAAA,cAAc,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAEzE,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,iDAAkD;AAAzC,iHAAA,gBAAgB,OAAA;AACzB,qDAAsD;AAA7C,qHAAA,kBAAkB,OAAA","sourcesContent":["export { BigNumber as BigDecimal } from 'bignumber.js'\nexport { Context, ContractView, BoundContractView, SolanaContext } from './context'\nexport { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter'\nexport { type Numberish, toBigInteger, toMetricValue } from './numberish'\n\nexport { BindOptions, SolanaBindOptions, SuiBindOptions, AptosBindOptions } from './bind-options'\n\nexport { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { SuiBaseProcessor } from './sui-processor'\nexport { AptosBaseProcessor } from './aptos-processor'\n\nexport type { TypedCallTrace, Trace } from './trace'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAA7C,0GAAA,SAAS,OAAc;AAChC,qCAAmF;AAA1E,kGAAA,OAAO,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,4GAAA,iBAAiB,OAAA;AAAE,wGAAA,aAAa,OAAA;AAChE,iCAAqG;AAA5F,uGAAA,cAAc,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,gGAAA,OAAO,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,+GAAA,sBAAsB,OAAA;AACpF,yCAAyE;AAAhD,yGAAA,YAAY,OAAA;AAAE,0GAAA,aAAa,OAAA;AAEpD,+CAA+E;AAAtE,2GAAA,WAAW,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAAE,8GAAA,cAAc,OAAA;AAEvD,mDAAgD;AAAvC,+GAAA,aAAa,OAAA;AACtB,yDAAsD;AAA7C,qHAAA,gBAAgB,OAAA;AACzB,qEAAiE;AAAxD,gIAAA,qBAAqB,OAAA;AAC9B,uDAAwD;AAA/C,uHAAA,mBAAmB,OAAA;AAC5B,iDAAkD;AAAzC,iHAAA,gBAAgB,OAAA","sourcesContent":["export { BigNumber as BigDecimal } from 'bignumber.js'\nexport { Context, ContractView, BoundContractView, SolanaContext } from './context'\nexport { CounterBinding, Meter, GaugeBinding, Counter, Gauge, MetricDescriptorOption } from './meter'\nexport { type Numberish, toBigInteger, toMetricValue } from './numberish'\n\nexport { BindOptions, SolanaBindOptions, SuiBindOptions } from './bind-options'\n\nexport { BaseProcessor } from './base-processor'\nexport { GenericProcessor } from './generic-processor'\nexport { BaseProcessorTemplate } from './base-processor-template'\nexport { SolanaBaseProcessor } from './solana-processor'\nexport { SuiBaseProcessor } from './sui-processor'\n// export * from '../aptos'\n\nexport type { TypedCallTrace, Trace } from './trace'\n"]}
@@ -1,10 +1,13 @@
1
1
  import { BaseContext } from './context';
2
2
  import { Labels } from './metadata';
3
- import { LogLevel } from '@sentio/sdk';
3
+ import { LogLevel } from '../gen';
4
+ export declare type Attributes = Record<string, any>;
4
5
  export declare class Logger {
5
6
  private readonly ctx;
6
- constructor(ctx: BaseContext);
7
- log(level: LogLevel, message: any, labels?: Labels): void;
7
+ private readonly name;
8
+ constructor(ctx: BaseContext, name?: string);
9
+ withName(name: string): Logger;
10
+ log(level: LogLevel, message: any, attributes?: Attributes): void;
8
11
  info(msg: any, labels?: Labels): void;
9
12
  warn(msg: any, labels?: Labels): void;
10
13
  error(msg: any, labels?: Labels): void;
@@ -2,35 +2,41 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = void 0;
4
4
  const metadata_1 = require("./metadata");
5
- const sdk_1 = require("@sentio/sdk");
5
+ const gen_1 = require("../gen");
6
6
  class Logger {
7
7
  ctx;
8
- constructor(ctx) {
8
+ name;
9
+ constructor(ctx, name = '') {
9
10
  this.ctx = ctx;
11
+ this.name = name;
10
12
  }
11
- log(level, message, labels = {}) {
12
- // TODO
13
+ withName(name) {
14
+ return new Logger(this.ctx, name);
15
+ }
16
+ log(level, message, attributes = {}) {
13
17
  if (typeof message !== 'string' && !(message instanceof String)) {
14
18
  message = message.toString();
15
19
  }
16
20
  this.ctx.logs.push({
17
- metadata: (0, metadata_1.GetRecordMetaData)(this.ctx, undefined, labels),
21
+ name: this.name,
22
+ metadata: (0, metadata_1.GetRecordMetaData)(this.ctx, undefined, {}),
18
23
  level,
19
24
  message,
25
+ attributes: JSON.stringify(attributes),
20
26
  runtimeInfo: undefined,
21
27
  });
22
28
  }
23
29
  info(msg, labels = {}) {
24
- this.log(sdk_1.LogLevel.INFO, msg, labels);
30
+ this.log(gen_1.LogLevel.INFO, msg, labels);
25
31
  }
26
32
  warn(msg, labels = {}) {
27
- this.log(sdk_1.LogLevel.WARNING, msg, labels);
33
+ this.log(gen_1.LogLevel.WARNING, msg, labels);
28
34
  }
29
35
  error(msg, labels = {}) {
30
- this.log(sdk_1.LogLevel.ERROR, msg, labels);
36
+ this.log(gen_1.LogLevel.ERROR, msg, labels);
31
37
  }
32
38
  critical(msg, labels = {}) {
33
- this.log(sdk_1.LogLevel.CRITICAL, msg, labels);
39
+ this.log(gen_1.LogLevel.CRITICAL, msg, labels);
34
40
  }
35
41
  }
36
42
  exports.Logger = Logger;
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AACA,yCAAsD;AACtD,qCAAsC;AAEtC,MAAa,MAAM;IACA,GAAG,CAAa;IAEjC,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,GAAG,CAAC,KAAe,EAAE,OAAY,EAAE,SAAiB,EAAE;QACpD,OAAO;QAEP,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,YAAY,MAAM,CAAC,EAAE;YAC/D,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;SAC7B;QAED,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YACjB,QAAQ,EAAE,IAAA,4BAAiB,EAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC;YACxD,KAAK;YACL,OAAO;YACP,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,SAAiB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,SAAiB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,GAAQ,EAAE,SAAiB,EAAE;QACjC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACvC,CAAC;IAED,QAAQ,CAAC,GAAQ,EAAE,SAAiB,EAAE;QACpC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC;CACF;AArCD,wBAqCC","sourcesContent":["import { BaseContext } from './context'\nimport { Labels, GetRecordMetaData } from './metadata'\nimport { LogLevel } from '@sentio/sdk'\n\nexport class Logger {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n log(level: LogLevel, message: any, labels: Labels = {}) {\n // TODO\n\n if (typeof message !== 'string' && !(message instanceof String)) {\n message = message.toString()\n }\n\n this.ctx.logs.push({\n metadata: GetRecordMetaData(this.ctx, undefined, labels),\n level,\n message,\n runtimeInfo: undefined,\n })\n }\n\n info(msg: any, labels: Labels = {}) {\n this.log(LogLevel.INFO, msg, labels)\n }\n\n warn(msg: any, labels: Labels = {}) {\n this.log(LogLevel.WARNING, msg, labels)\n }\n\n error(msg: any, labels: Labels = {}) {\n this.log(LogLevel.ERROR, msg, labels)\n }\n\n critical(msg: any, labels: Labels = {}) {\n this.log(LogLevel.CRITICAL, msg, labels)\n }\n}\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/core/logger.ts"],"names":[],"mappings":";;;AACA,yCAAsD;AACtD,gCAAiC;AAIjC,MAAa,MAAM;IACA,GAAG,CAAa;IAChB,IAAI,CAAQ;IAE7B,YAAY,GAAgB,EAAE,IAAI,GAAG,EAAE;QACrC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC;IAED,GAAG,CAAC,KAAe,EAAE,OAAY,EAAE,aAAyB,EAAE;QAC5D,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,YAAY,MAAM,CAAC,EAAE;YAC/D,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;SAC7B;QAED,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAA,4BAAiB,EAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC;YACpD,KAAK;YACL,OAAO;YACP,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;YACtC,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,SAAiB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,GAAQ,EAAE,SAAiB,EAAE;QAChC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACzC,CAAC;IAED,KAAK,CAAC,GAAQ,EAAE,SAAiB,EAAE;QACjC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IACvC,CAAC;IAED,QAAQ,CAAC,GAAQ,EAAE,SAAiB,EAAE;QACpC,IAAI,CAAC,GAAG,CAAC,cAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC;CACF;AA3CD,wBA2CC","sourcesContent":["import { BaseContext } from './context'\nimport { Labels, GetRecordMetaData } from './metadata'\nimport { LogLevel } from '../gen'\n\nexport type Attributes = Record<string, any>\n\nexport class Logger {\n private readonly ctx: BaseContext\n private readonly name: string\n\n constructor(ctx: BaseContext, name = '') {\n this.ctx = ctx\n this.name = name\n }\n\n withName(name: string) {\n return new Logger(this.ctx, name)\n }\n\n log(level: LogLevel, message: any, attributes: Attributes = {}) {\n if (typeof message !== 'string' && !(message instanceof String)) {\n message = message.toString()\n }\n\n this.ctx.logs.push({\n name: this.name,\n metadata: GetRecordMetaData(this.ctx, undefined, {}),\n level,\n message,\n attributes: JSON.stringify(attributes),\n runtimeInfo: undefined,\n })\n }\n\n info(msg: any, labels: Labels = {}) {\n this.log(LogLevel.INFO, msg, labels)\n }\n\n warn(msg: any, labels: Labels = {}) {\n this.log(LogLevel.WARNING, msg, labels)\n }\n\n error(msg: any, labels: Labels = {}) {\n this.log(LogLevel.ERROR, msg, labels)\n }\n\n critical(msg: any, labels: Labels = {}) {\n this.log(LogLevel.CRITICAL, msg, labels)\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { BaseContext } from './context';
2
- import { RecordMetaData } from '@sentio/sdk';
2
+ import { RecordMetaData } from '../gen';
3
3
  import { Metric } from './meter';
4
4
  export declare type Labels = {
5
5
  [key: string]: string;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetRecordMetaData = void 0;
4
- const context_1 = require("./context");
5
- const sdk_1 = require("@sentio/sdk");
6
- const chain_1 = require("../utils/chain");
4
+ const gen_1 = require("../gen");
7
5
  const meter_1 = require("./meter");
8
6
  function GetRecordMetaData(ctx, metric, labels) {
9
7
  let descriptor = undefined;
@@ -11,85 +9,11 @@ function GetRecordMetaData(ctx, metric, labels) {
11
9
  descriptor = metric.descriptor;
12
10
  if (metric.usage > 0) {
13
11
  // Other setting don't need to be write multiple times
14
- descriptor = sdk_1.MetricDescriptor.fromPartial({ name: descriptor.name });
12
+ descriptor = gen_1.MetricDescriptor.fromPartial({ name: descriptor.name });
15
13
  }
16
14
  descriptor.name = (0, meter_1.normalizeName)(descriptor.name);
17
15
  }
18
- if (ctx instanceof context_1.Context) {
19
- if (ctx.log) {
20
- return {
21
- contractAddress: ctx.contract.rawContract.address,
22
- blockNumber: ctx.blockNumber,
23
- transactionIndex: ctx.log.transactionIndex,
24
- transactionHash: ctx.transactionHash || '',
25
- logIndex: ctx.log.logIndex,
26
- chainId: ctx.chainId.toString(),
27
- descriptor: descriptor,
28
- labels: (0, meter_1.normalizeLabels)(labels),
29
- };
30
- }
31
- if (ctx.block) {
32
- return {
33
- contractAddress: ctx.contract.rawContract.address,
34
- blockNumber: ctx.blockNumber,
35
- transactionIndex: -1,
36
- transactionHash: '',
37
- logIndex: -1,
38
- chainId: ctx.chainId.toString(),
39
- descriptor: descriptor,
40
- labels: (0, meter_1.normalizeLabels)(labels),
41
- };
42
- }
43
- if (ctx.trace) {
44
- return {
45
- contractAddress: ctx.contract.rawContract.address,
46
- blockNumber: ctx.blockNumber,
47
- transactionIndex: ctx.trace.transactionPosition,
48
- transactionHash: ctx.transactionHash || '',
49
- logIndex: -1,
50
- chainId: ctx.chainId.toString(),
51
- descriptor: descriptor,
52
- labels: (0, meter_1.normalizeLabels)(labels),
53
- };
54
- }
55
- }
56
- else if (ctx instanceof context_1.SolanaContext) {
57
- return {
58
- contractAddress: ctx.address,
59
- blockNumber: ctx.blockNumber,
60
- transactionIndex: 0,
61
- transactionHash: '',
62
- logIndex: 0,
63
- chainId: chain_1.SOL_MAINMET_ID,
64
- descriptor: descriptor,
65
- labels: (0, meter_1.normalizeLabels)(labels),
66
- };
67
- }
68
- else if (ctx instanceof context_1.SuiContext) {
69
- return {
70
- contractAddress: ctx.address,
71
- blockNumber: ctx.blockNumber,
72
- transactionIndex: 0,
73
- transactionHash: '',
74
- logIndex: 0,
75
- chainId: chain_1.SUI_DEVNET_ID,
76
- descriptor: descriptor,
77
- labels: (0, meter_1.normalizeLabels)(labels),
78
- };
79
- }
80
- else if (ctx instanceof context_1.AptosContext) {
81
- return {
82
- contractAddress: ctx.address,
83
- blockNumber: ctx.blockNumber,
84
- transactionIndex: 0,
85
- transactionHash: '',
86
- logIndex: 0,
87
- chainId: chain_1.APTOS_TESTNET_ID,
88
- descriptor: descriptor,
89
- labels: (0, meter_1.normalizeLabels)(labels),
90
- };
91
- }
92
- throw new Error("This can't happen");
16
+ return ctx.getMetaData(descriptor, labels);
93
17
  }
94
18
  exports.GetRecordMetaData = GetRecordMetaData;
95
19
  //# sourceMappingURL=metadata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":";;;AAAA,uCAAyF;AACzF,qCAA8D;AAC9D,0CAAgF;AAChF,mCAAgE;AAIhE,SAAgB,iBAAiB,CAAC,GAAgB,EAAE,MAA0B,EAAE,MAAc;IAC5F,IAAI,UAAU,GAAG,SAAS,CAAA;IAC1B,IAAI,MAAM,EAAE;QACV,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QAC9B,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE;YACpB,sDAAsD;YACtD,UAAU,GAAG,sBAAgB,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAA;SACrE;QAED,UAAU,CAAC,IAAI,GAAG,IAAA,qBAAa,EAAC,UAAU,CAAC,IAAI,CAAC,CAAA;KACjD;IAED,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,GAAG,CAAC,WAAW;gBAC5B,gBAAgB,EAAE,GAAG,CAAC,GAAG,CAAC,gBAAgB;gBAC1C,eAAe,EAAE,GAAG,CAAC,eAAe,IAAI,EAAE;gBAC1C,QAAQ,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ;gBAC1B,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE;gBAC/B,UAAU,EAAE,UAAU;gBACtB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;aAChC,CAAA;SACF;QACD,IAAI,GAAG,CAAC,KAAK,EAAE;YACb,OAAO;gBACL,eAAe,EAAE,GAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,OAAO;gBACjD,W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,EAAE,qBAAa;YACtB,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;KACF;SAAM,IAAI,GAAG,YAAY,sBAAY,EAAE;QACtC,OAAO;YACL,eAAe,EAAE,GAAG,CAAC,OAAO;YAC5B,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,wBAAgB;YACzB,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,IAAA,uBAAe,EAAC,MAAM,CAAC;SAChC,CAAA;KACF;IACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;AACtC,CAAC;AApFD,8CAoFC","sourcesContent":["import { AptosContext, BaseContext, Context, SolanaContext, SuiContext } from './context'\nimport { MetricDescriptor, RecordMetaData } from '@sentio/sdk'\nimport { APTOS_TESTNET_ID, SOL_MAINMET_ID, SUI_DEVNET_ID } from '../utils/chain'\nimport { Metric, normalizeLabels, normalizeName } from './meter'\n\nexport type Labels = { [key: string]: string }\n\nexport function GetRecordMetaData(ctx: BaseContext, metric: Metric | undefined, labels: Labels): RecordMetaData {\n let descriptor = undefined\n if (metric) {\n descriptor = metric.descriptor\n if (metric.usage > 0) {\n // Other setting don't need to be write multiple times\n descriptor = MetricDescriptor.fromPartial({ name: descriptor.name })\n }\n\n descriptor.name = normalizeName(descriptor.name)\n }\n\n if (ctx instanceof Context) {\n if (ctx.log) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: ctx.blockNumber,\n transactionIndex: ctx.log.transactionIndex,\n transactionHash: ctx.transactionHash || '',\n logIndex: ctx.log.logIndex,\n chainId: ctx.chainId.toString(),\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (ctx.block) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: ctx.blockNumber,\n transactionIndex: -1,\n transactionHash: '',\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n if (ctx.trace) {\n return {\n contractAddress: ctx.contract.rawContract.address,\n blockNumber: ctx.blockNumber,\n transactionIndex: ctx.trace.transactionPosition,\n transactionHash: ctx.transactionHash || '',\n logIndex: -1,\n chainId: ctx.chainId.toString(),\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n } else if (ctx instanceof SolanaContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: ctx.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO add\n logIndex: 0,\n chainId: SOL_MAINMET_ID, // TODO set in context\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n } else if (ctx instanceof SuiContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: ctx.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO\n logIndex: 0,\n chainId: SUI_DEVNET_ID, // TODO set in context\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n } else if (ctx instanceof AptosContext) {\n return {\n contractAddress: ctx.address,\n blockNumber: ctx.blockNumber,\n transactionIndex: 0,\n transactionHash: '', // TODO\n logIndex: 0,\n chainId: APTOS_TESTNET_ID, // TODO set in context\n descriptor: descriptor,\n labels: normalizeLabels(labels),\n }\n }\n throw new Error(\"This can't happen\")\n}\n"]}
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/core/metadata.ts"],"names":[],"mappings":";;;AACA,gCAAyD;AACzD,mCAA+C;AAI/C,SAAgB,iBAAiB,CAAC,GAAgB,EAAE,MAA0B,EAAE,MAAc;IAC5F,IAAI,UAAU,GAAG,SAAS,CAAA;IAC1B,IAAI,MAAM,EAAE;QACV,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QAC9B,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE;YACpB,sDAAsD;YACtD,UAAU,GAAG,sBAAgB,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAA;SACrE;QAED,UAAU,CAAC,IAAI,GAAG,IAAA,qBAAa,EAAC,UAAU,CAAC,IAAI,CAAC,CAAA;KACjD;IAED,OAAO,GAAG,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;AAC5C,CAAC;AAbD,8CAaC","sourcesContent":["import { BaseContext } from './context'\nimport { MetricDescriptor, RecordMetaData } from '../gen'\nimport { Metric, normalizeName } from './meter'\n\nexport type Labels = { [key: string]: string }\n\nexport function GetRecordMetaData(ctx: BaseContext, metric: Metric | undefined, labels: Labels): RecordMetaData {\n let descriptor = undefined\n if (metric) {\n descriptor = metric.descriptor\n if (metric.usage > 0) {\n // Other setting don't need to be write multiple times\n descriptor = MetricDescriptor.fromPartial({ name: descriptor.name })\n }\n\n descriptor.name = normalizeName(descriptor.name)\n }\n\n return ctx.getMetaData(descriptor, labels)\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { MetricDescriptor } from '../gen/processor/protos/processor';
1
+ import { MetricDescriptor } from '../gen';
2
2
  import { BaseContext } from './context';
3
3
  import { Numberish } from './numberish';
4
4
  import { Labels } from './metadata';
package/lib/core/meter.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Meter = exports.GaugeBinding = exports.Gauge = exports.CounterBinding = exports.Counter = exports.Metric = exports.MetricDescriptorOption = exports.normalizeLabels = exports.normalizeValue = exports.normalizeKey = exports.normalizeName = void 0;
4
- const processor_1 = require("../gen/processor/protos/processor");
4
+ const gen_1 = require("../gen");
5
5
  const numberish_1 = require("./numberish");
6
6
  const metadata_1 = require("./metadata");
7
7
  function normalizeName(name) {
@@ -35,7 +35,7 @@ class MetricDescriptorOption {
35
35
  }
36
36
  exports.MetricDescriptorOption = MetricDescriptorOption;
37
37
  class Metric {
38
- descriptor = processor_1.MetricDescriptor.fromPartial({});
38
+ descriptor = gen_1.MetricDescriptor.fromPartial({});
39
39
  usage = 0;
40
40
  constructor(name, option) {
41
41
  this.descriptor.name = name;
@@ -1 +1 @@
1
- {"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AAAA,iEAAoE;AAEpE,2CAAsD;AACtD,yCAAsD;AAEtD,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,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,OAAO,SAAS,CAAA;KACjB;IACD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AALD,oCAKC;AAED,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC3B,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe,CAAC,MAAc;IAC5C,MAAM,UAAU,GAAW,EAAE,CAAA;IAC7B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;QACxB,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;KAC5D;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAND,0CAMC;AAED,MAAa,sBAAsB;IACjC,IAAI,CAAS;IACb,WAAW,CAAS;IACpB,MAAM,CAAU;CACjB;AAJD,wDAIC;AAED,MAAa,MAAM;IACjB,UAAU,GAAqB,4BAAgB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;IAC/D,KAAK,GAAG,CAAC,CAAA;IAET,YAAY,IAAY,EAAE,MAA+B;QACvD,IAAI,CAAC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AC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF;AAdD,sBAcC","sourcesContent":["import { MetricDescriptor } from '../gen/processor/protos/processor'\nimport { BaseContext } from './context'\nimport { toMetricValue, Numberish } from './numberish'\nimport { GetRecordMetaData, Labels } from './metadata'\n\nexport function normalizeName(name: string): string {\n const regex = new RegExp('![_.a-zA-Z0-9]')\n return name.slice(0, 100).replace(regex, '_')\n}\n\nexport function normalizeKey(name: string): string {\n if (name === 'labels') {\n return 'labels_'\n }\n return normalizeName(name)\n}\n\nexport function normalizeValue(name: string): string {\n return name.slice(0, 100)\n}\n\nexport function normalizeLabels(labels: Labels): Labels {\n const normLabels: Labels = {}\n for (const key in labels) {\n normLabels[normalizeKey(key)] = normalizeValue(labels[key])\n }\n return normLabels\n}\n\nexport class MetricDescriptorOption {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\nexport class Metric {\n descriptor: MetricDescriptor = MetricDescriptor.fromPartial({})\n usage = 0\n\n constructor(name: string, option?: MetricDescriptorOption) {\n this.descriptor.name = name\n if (option) {\n if (option.unit) {\n this.descriptor.unit = option.unit\n }\n if (option.description) {\n this.descriptor.description = option.description\n }\n if (option.sparse) {\n this.descriptor.sparse = option.sparse\n }\n }\n }\n}\n\nexport class Counter extends Metric {\n add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, true)\n }\n\n sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, false)\n }\n\n private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {\n ctx.counters.push({\n metadata: GetRecordMetaData(ctx, this, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n this.usage++\n }\n}\n\nexport class CounterBinding {\n private readonly ctx: BaseContext\n private readonly counter: Counter\n\n constructor(name: string, ctx: BaseContext) {\n this.counter = new Counter(name)\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.counter.add(this.ctx, value, labels)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.counter.sub(this.ctx, value, labels)\n }\n}\n\nexport class Gauge extends Metric {\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx.gauges.push({\n metadata: GetRecordMetaData(ctx, this, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n this.usage++\n }\n}\n\nexport class GaugeBinding {\n private readonly gauge: Gauge\n private readonly ctx: BaseContext\n\n constructor(name: string, ctx: BaseContext) {\n this.gauge = new Gauge(name)\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.gauge.record(this.ctx, value, labels)\n }\n}\n\nexport class Meter {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): CounterBinding {\n return new CounterBinding(name, this.ctx)\n }\n\n Gauge(name: string): GaugeBinding {\n return new GaugeBinding(name, this.ctx)\n }\n}\n"]}
1
+ {"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AAAA,gCAAyC;AAEzC,2CAAsD;AACtD,yCAAsD;AAEtD,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,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,OAAO,SAA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;QAC5D,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;YACd,QAAQ,EAAE,IAAA,4BAAiB,EAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC;YAC9C,WAAW,EAAE,IAAA,yBAAa,EAAC,KAAK,CAAC;YACjC,WAAW,EAAE,SAAS;SACvB,CAAC,CAAA;QACF,IAAI,CAAC,KAAK,EAAE,CAAA;IACd,CAAC;CACF;AATD,sBASC;AAED,MAAa,YAAY;IACN,KAAK,CAAO;IACZ,GAAG,CAAa;IAEjC,YAAY,IAAY,EAAE,GAAgB;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,MAAM,CAAC,KAAgB,EAAE,SAAiB,EAAE;QAC1C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;CACF;AAZD,oCAYC;AAED,MAAa,KAAK;IACC,GAAG,CAAa;IAEjC,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF;AAdD,sBAcC","sourcesContent":["import { MetricDescriptor } from '../gen'\nimport { BaseContext } from './context'\nimport { toMetricValue, Numberish } from './numberish'\nimport { GetRecordMetaData, Labels } from './metadata'\n\nexport function normalizeName(name: string): string {\n const regex = new RegExp('![_.a-zA-Z0-9]')\n return name.slice(0, 100).replace(regex, '_')\n}\n\nexport function normalizeKey(name: string): string {\n if (name === 'labels') {\n return 'labels_'\n }\n return normalizeName(name)\n}\n\nexport function normalizeValue(name: string): string {\n return name.slice(0, 100)\n}\n\nexport function normalizeLabels(labels: Labels): Labels {\n const normLabels: Labels = {}\n for (const key in labels) {\n normLabels[normalizeKey(key)] = normalizeValue(labels[key])\n }\n return normLabels\n}\n\nexport class MetricDescriptorOption {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\nexport class Metric {\n descriptor: MetricDescriptor = MetricDescriptor.fromPartial({})\n usage = 0\n\n constructor(name: string, option?: MetricDescriptorOption) {\n this.descriptor.name = name\n if (option) {\n if (option.unit) {\n this.descriptor.unit = option.unit\n }\n if (option.description) {\n this.descriptor.description = option.description\n }\n if (option.sparse) {\n this.descriptor.sparse = option.sparse\n }\n }\n }\n}\n\nexport class Counter extends Metric {\n add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, true)\n }\n\n sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, false)\n }\n\n private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {\n ctx.counters.push({\n metadata: GetRecordMetaData(ctx, this, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n this.usage++\n }\n}\n\nexport class CounterBinding {\n private readonly ctx: BaseContext\n private readonly counter: Counter\n\n constructor(name: string, ctx: BaseContext) {\n this.counter = new Counter(name)\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.counter.add(this.ctx, value, labels)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.counter.sub(this.ctx, value, labels)\n }\n}\n\nexport class Gauge extends Metric {\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx.gauges.push({\n metadata: GetRecordMetaData(ctx, this, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n this.usage++\n }\n}\n\nexport class GaugeBinding {\n private readonly gauge: Gauge\n private readonly ctx: BaseContext\n\n constructor(name: string, ctx: BaseContext) {\n this.gauge = new Gauge(name)\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.gauge.record(this.ctx, value, labels)\n }\n}\n\nexport class Meter {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): CounterBinding {\n return new CounterBinding(name, this.ctx)\n }\n\n Gauge(name: string): GaugeBinding {\n return new GaugeBinding(name, this.ctx)\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { BigNumber } from 'ethers';
2
- import { BigInteger, MetricValue } from '../gen/processor/protos/processor';
2
+ import { BigInteger, MetricValue } from '../gen';
3
3
  import { BigDecimal } from '.';
4
4
  export declare type Numberish = number | BigNumber | bigint | BigDecimal;
5
5
  export declare function toMetricValue(value: Numberish): MetricValue;
@@ -2,19 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toBigInteger = exports.toMetricValue = void 0;
4
4
  const ethers_1 = require("ethers");
5
- const processor_1 = require("../gen/processor/protos/processor");
5
+ const gen_1 = require("../gen");
6
6
  const _1 = require(".");
7
7
  const anchor_1 = require("@project-serum/anchor");
8
8
  function toMetricValue(value) {
9
9
  if (value instanceof ethers_1.BigNumber) {
10
- return processor_1.MetricValue.fromPartial({
10
+ return gen_1.MetricValue.fromPartial({
11
11
  bigInteger: toBigInteger(value.toBigInt()),
12
12
  });
13
13
  }
14
14
  if (value instanceof _1.BigDecimal) {
15
15
  // Carefully consider the use case here
16
16
  if (value.isInteger()) {
17
- return processor_1.MetricValue.fromPartial({
17
+ return gen_1.MetricValue.fromPartial({
18
18
  bigInteger: bigDecimalToBigInteger(value),
19
19
  });
20
20
  }
@@ -26,22 +26,22 @@ function toMetricValue(value) {
26
26
  // NaN also not finite
27
27
  throw new Error('Record infinite value');
28
28
  }
29
- return processor_1.MetricValue.fromPartial({
29
+ return gen_1.MetricValue.fromPartial({
30
30
  bigDecimal: value.toString(), // e.g. -7.350918e-428
31
31
  });
32
32
  }
33
33
  }
34
34
  if (anchor_1.BN.isBN(value)) {
35
- return processor_1.MetricValue.fromPartial({
35
+ return gen_1.MetricValue.fromPartial({
36
36
  bigInteger: bnToBigInteger(value),
37
37
  });
38
38
  }
39
39
  if (typeof value === 'bigint' || Number.isInteger(value)) {
40
- return processor_1.MetricValue.fromPartial({
40
+ return gen_1.MetricValue.fromPartial({
41
41
  bigInteger: toBigInteger(value),
42
42
  });
43
43
  }
44
- return processor_1.MetricValue.fromPartial({
44
+ return gen_1.MetricValue.fromPartial({
45
45
  doubleValue: Number(value),
46
46
  });
47
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"numberish.js","sourceRoot":"","sources":["../../src/core/numberish.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,iEAA2E;AAC3E,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,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE;gBACjB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;aACpC;YACD,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE;gBACrB,sBAAsB;gBACtB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;aACzC;YACD,OAAO,uBAAW,CAAC,WAAW,CAAC;gBAC7B,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,sBAAsB;a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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 if (value.isNaN()) {\n throw new Error('Record NaN value')\n }\n if (!value.isFinite()) {\n // NaN also not finite\n throw new Error('Record infinite value')\n }\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
+ {"version":3,"file":"numberish.js","sourceRoot":"","sources":["../../src/core/numberish.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,gCAAgD;AAChD,wBAA8B;AAC9B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D;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'\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 if (value.isNaN()) {\n throw new Error('Record NaN value')\n }\n if (!value.isFinite()) {\n // NaN also not finite\n throw new Error('Record infinite value')\n }\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 +1 @@
1
- {"version":3,"file":"numberish.test.js","sourceRoot":"","sources":["../../src/core/numberish.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,2CAAyD;AACzD,mCAAkC;AAClC,mCAAkC;AAClC,2CAAwC;AAExC,wBAA8B;AAE9B,oCAAoC;AACpC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,MAAM,GAAa,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,sCAAsC,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,CAAA;IAE3G,IAAI,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACrD,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;YACtB,MAAM,CAAC,GAAG,IAAA,wBAAY,EAAC,CAAC,CAAC,CAAA;YACzB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;YAC/B,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC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QACd,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;KAChB;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,kBAAkB,CAAC,CAAa;IACvC,IAAI,GAAG,GAAG,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC3C,IAAI,CAAC,CAAC,QAAQ,EAAE;QACd,GAAG,GAAG,CAAC,GAAG,CAAA;KACX;IACD,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { expect } from 'chai'\nimport { toBigInteger, toMetricValue } from './numberish'\nimport { webcrypto } from 'crypto'\nimport { BigNumber } from 'ethers'\nimport { performance } from 'perf_hooks'\nimport { BigInteger } from '../gen/processor/protos/processor'\nimport { BigDecimal } from '.'\n\n// TODO add test for type conversion\ndescribe('Numberish tests', () => {\n const values: bigint[] = [0n, -0n, 3815372408723498172304781320847103784n, 2132n, -18708707n, 123n << 100n]\n\n test('big integer conversion correctness ', async () => {\n for (const v of values) {\n const b = toBigInteger(v)\n const hex1 = BigIntegerToHex(b)\n const hex2 = v.toString(16)\n expect(hex1).equals(hex2)\n }\n })\n\n test('random big integer conversion correctness ', async () => {\n for (let i = 0; i < 1000; i++) {\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = BigNumber.from(random).toBigInt()\n const b = toBigInteger(v)\n\n expect(BigNumber.from(b.data).eq(v)).to.equals(true)\n }\n })\n\n test.skip('random big integer performance', async () => {\n jest.setTimeout(100000)\n jest.retryTimes(3)\n\n let timer1 = 0\n let timer2 = 0\n for (let i = 0; i < 1000; i++) {\n // Use higher value for local debugging\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = BigNumber.from(random).toBigInt()\n\n let start = performance.now()\n toBigInteger(v)\n timer1 += performance.now() - start\n\n start = performance.now()\n v.toString(16)\n timer2 += performance.now() - start\n }\n\n console.log(timer1, timer2)\n expect(timer1).to.lessThan(timer2 * 3)\n })\n\n test('metric values', async () => {\n const longDec = '12.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002'\n expect(toMetricValue(new BigDecimal(longDec)).bigDecimal == longDec)\n\n const complexDec = '-7.350918e-428'\n expect(toMetricValue(new BigDecimal(complexDec)).bigDecimal == complexDec)\n\n expect(BigIntegerToBigInt(toMetricValue(new BigDecimal('100000')).bigInteger!) === 100000n)\n })\n})\n\n// Performance very bad\nfunction BigIntegerToHex(b: BigInteger): string {\n let res = BigNumber.from(b.data).toBigInt().toString(16)\n if (b.negative) {\n res = '-' + res\n }\n return res\n}\n\nfunction BigIntegerToBigInt(b: BigInteger): bigint {\n let res = BigNumber.from(b.data).toBigInt()\n if (b.negative) {\n res = -res\n }\n return res\n}\n"]}
1
+ {"version":3,"file":"numberish.test.js","sourceRoot":"","sources":["../../src/core/numberish.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,2CAAyD;AACzD,mCAAkC;AAClC,mCAAkC;AAClC,2CAAwC;AAExC,wBAA8B;AAE9B,oCAAoC;AACpC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,MAAM,GAAa,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,sCAAsC,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,CAAA;IAE3G,IAAI,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACrD,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;YACtB,MAAM,CAAC,GAAG,IAAA,wBAAY,EAAC,CAAC,CAAC,CAAA;YACzB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;YAC/B,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YAC3B,IAAA,aAAM,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;SAC1B;IACH,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,4CAA4C,EAAE,KAAK,IAAI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C,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC3C,IAAI,CAAC,CAAC,QAAQ,EAAE;QACd,GAAG,GAAG,CAAC,GAAG,CAAA;KACX;IACD,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { expect } from 'chai'\nimport { toBigInteger, toMetricValue } from './numberish'\nimport { webcrypto } from 'crypto'\nimport { BigNumber } from 'ethers'\nimport { performance } from 'perf_hooks'\nimport { BigInteger } from '../gen'\nimport { BigDecimal } from '.'\n\n// TODO add test for type conversion\ndescribe('Numberish tests', () => {\n const values: bigint[] = [0n, -0n, 3815372408723498172304781320847103784n, 2132n, -18708707n, 123n << 100n]\n\n test('big integer conversion correctness ', async () => {\n for (const v of values) {\n const b = toBigInteger(v)\n const hex1 = BigIntegerToHex(b)\n const hex2 = v.toString(16)\n expect(hex1).equals(hex2)\n }\n })\n\n test('random big integer conversion correctness ', async () => {\n for (let i = 0; i < 1000; i++) {\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = BigNumber.from(random).toBigInt()\n const b = toBigInteger(v)\n\n expect(BigNumber.from(b.data).eq(v)).to.equals(true)\n }\n })\n\n test.skip('random big integer performance', async () => {\n jest.setTimeout(100000)\n jest.retryTimes(3)\n\n let timer1 = 0\n let timer2 = 0\n for (let i = 0; i < 1000; i++) {\n // Use higher value for local debugging\n const random = webcrypto.getRandomValues(new Uint8Array(256))\n const v = BigNumber.from(random).toBigInt()\n\n let start = performance.now()\n toBigInteger(v)\n timer1 += performance.now() - start\n\n start = performance.now()\n v.toString(16)\n timer2 += performance.now() - start\n }\n\n console.log(timer1, timer2)\n expect(timer1).to.lessThan(timer2 * 3)\n })\n\n test('metric values', async () => {\n const longDec = '12.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002'\n expect(toMetricValue(new BigDecimal(longDec)).bigDecimal == longDec)\n\n const complexDec = '-7.350918e-428'\n expect(toMetricValue(new BigDecimal(complexDec)).bigDecimal == complexDec)\n\n expect(BigIntegerToBigInt(toMetricValue(new BigDecimal('100000')).bigInteger!) === 100000n)\n })\n})\n\n// Performance very bad\nfunction BigIntegerToHex(b: BigInteger): string {\n let res = BigNumber.from(b.data).toBigInt().toString(16)\n if (b.negative) {\n res = '-' + res\n }\n return res\n}\n\nfunction BigIntegerToBigInt(b: BigInteger): bigint {\n let res = BigNumber.from(b.data).toBigInt()\n if (b.negative) {\n res = -res\n }\n return res\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { ProcessResult } from '../gen/processor/protos/processor';
1
+ import { ProcessResult } from '../gen';
2
2
  import { SolanaContext } from './context';
3
3
  import Long from 'long';
4
4
  import { Instruction } from '@project-serum/anchor';
@@ -1 +1 @@
1
- {"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../../src/core/solana-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAyC;AACzC,gDAAuB;AASvB,MAAa,mBAAmB;IACvB,qBAAqB,GAAwE,IAAI,GAAG,EAAE,CAAA;IAC7G,OAAO,CAAQ;IACf,QAAQ,CAAQ;IAChB,YAAY,CAAQ;IACpB,uBAAuB,CAAS;IAChC,MAAM,GAAmB,EAAE,SAAS,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACnD,iBAAiB,CAAgD;IACjE,qBAAqB,CAAkE;IAEvF,YAAY,OAA0B;QACpC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,MAAM,CAAC,eAAe,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAED,IAAI,CAAC,OAA0B;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,IAAI,EAAE,CAAA;QACtC,IAAI,CAAC,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,IAAI,KAAK,CAAA;QACvE,IAAI,OAAO,CAAC,U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qBAAqB,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;gBACtE,IAAI,OAAO,EAAE;oBACX,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAA;iBAChC;aACF;SACF;QACD,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,IAAI,EAAE,GAAG,CAAC,IAAI;SACf,CAAA;IACH,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAA;IAC9B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA9FD,kDA8FC","sourcesContent":["import { ProcessResult } from '../gen/processor/protos/processor'\nimport { SolanaContext } from './context'\nimport Long from 'long'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './bind-options'\n\ntype IndexConfigure = {\n startSlot: Long\n endSlot?: Long\n}\n\nexport class SolanaBaseProcessor {\n public instructionHanlderMap: Map<string, (instruction: Instruction, ctx: SolanaContext) => void> = new Map()\n address: string\n endpoint: string\n contractName: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: new Long(0) }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.solanaProcessors.push(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n innerInstruction(flag: boolean) {\n this.processInnerInstruction = flag\n return this\n }\n\n public onInstruction(instructionName: string, handler: (instruction: Instruction, ctx: SolanaContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHanlderMap.set(instructionName, handler)\n\n return this\n }\n\n public handleInstruction(ins: string | { type: string; info: any }, slot: Long): ProcessResult | null {\n const ctx = new SolanaContext(this.address, slot)\n let parsedInstruction: Instruction | null = null\n\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n if (this.fromParsedInstruction == null) {\n return null\n }\n parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })\n } else {\n if (this.decodeInstruction == null) {\n return null\n }\n parsedInstruction = this.decodeInstruction(ins as string)\n }\n if (parsedInstruction) {\n const handler = this.instructionHanlderMap.get(parsedInstruction.name)\n if (handler) {\n handler(parsedInstruction, ctx)\n }\n }\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSlot = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSlot = endBlock\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"solana-processor.js","sourceRoot":"","sources":["../../src/core/solana-processor.ts"],"names":[],"mappings":";;;;;;AACA,u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,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;QACjC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA9FD,kDA8FC","sourcesContent":["import { ProcessResult } from '../gen'\nimport { SolanaContext } from './context'\nimport Long from 'long'\nimport { Instruction } from '@project-serum/anchor'\nimport { SolanaBindOptions } from './bind-options'\n\ntype IndexConfigure = {\n startSlot: Long\n endSlot?: Long\n}\n\nexport class SolanaBaseProcessor {\n public instructionHanlderMap: Map<string, (instruction: Instruction, ctx: SolanaContext) => void> = new Map()\n address: string\n endpoint: string\n contractName: string\n processInnerInstruction: boolean\n config: IndexConfigure = { startSlot: new Long(0) }\n decodeInstruction: (rawInstruction: string) => Instruction | null\n fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null\n\n constructor(options: SolanaBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.solanaProcessors.push(this)\n }\n\n bind(options: SolanaBindOptions) {\n this.address = options.address\n this.contractName = options.name || ''\n this.processInnerInstruction = options.processInnerInstruction || false\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'\n }\n\n innerInstruction(flag: boolean) {\n this.processInnerInstruction = flag\n return this\n }\n\n public onInstruction(instructionName: string, handler: (instruction: Instruction, ctx: SolanaContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.instructionHanlderMap.set(instructionName, handler)\n\n return this\n }\n\n public handleInstruction(ins: string | { type: string; info: any }, slot: Long): ProcessResult | null {\n const ctx = new SolanaContext(this.address, slot)\n let parsedInstruction: Instruction | null = null\n\n if (ins) {\n if ((ins as { type: string; info: any }).info) {\n if (this.fromParsedInstruction == null) {\n return null\n }\n parsedInstruction = this.fromParsedInstruction(ins as { type: string; info: any })\n } else {\n if (this.decodeInstruction == null) {\n return null\n }\n parsedInstruction = this.decodeInstruction(ins as string)\n }\n if (parsedInstruction) {\n const handler = this.instructionHanlderMap.get(parsedInstruction.name)\n if (handler) {\n handler(parsedInstruction, ctx)\n }\n }\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSlot = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSlot = endBlock\n return this\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { SuiBindOptions } from './bind-options';
2
2
  import { SuiContext } from './context';
3
- import { ProcessResult } from '..';
3
+ import { ProcessResult } from '../gen';
4
4
  import Long from 'long';
5
5
  declare type IndexConfigure = {
6
6
  startSeqNumber: Long;
@@ -1 +1 @@
1
- {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAsC;AAEtC,gDAAuB;AAOvB,MAAa,gBAAgB;IACpB,kBAAkB,CAA6C;IACtE,OAAO,CAAQ;IACf,MAAM,GAAmB,EAAE,cAAc,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IAExD,YAAY,OAAuB;QACjC,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACnB;QACD,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjD,CAA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AAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAhED,4CAgEC","sourcesContent":["import { SuiBindOptions } from './bind-options'\nimport { SuiContext } from './context'\nimport { ProcessResult } from '..'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n\n constructor(options: SuiBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.suiProcessors.push(this)\n }\n\n bind(options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.transactionHanlder = handler\n\n return this\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/core/sui-processor.ts"],"names":[],"mappings":";;;;;;AACA,uCAAsC;AAE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AC,OAAO,KAAK,IAAI,CAAA;IAC9B,CAAC;IAEM,SAAS,CAAC,SAAwB;QACvC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACjC,SAAS,GAAG,cAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;SACvC;QACD,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,SAAS,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,QAAQ,CAAC,QAAuB;QACrC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,QAAQ,GAAG,cAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;SACrC;QACD,IAAI,CAAC,MAAM,CAAC,YAAY,GAAG,QAAQ,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAhED,4CAgEC","sourcesContent":["import { SuiBindOptions } from './bind-options'\nimport { SuiContext } from './context'\nimport { ProcessResult } from '../gen'\nimport Long from 'long'\n\ntype IndexConfigure = {\n startSeqNumber: Long\n endSeqNumber?: Long\n}\n\nexport class SuiBaseProcessor {\n public transactionHanlder: (transaction: any, ctx: SuiContext) => void\n address: string\n config: IndexConfigure = { startSeqNumber: new Long(0) }\n\n constructor(options: SuiBindOptions) {\n if (options) {\n this.bind(options)\n }\n global.PROCESSOR_STATE.suiProcessors.push(this)\n }\n\n bind(options: SuiBindOptions) {\n this.address = options.address\n if (options.startBlock) {\n this.startSlot(options.startBlock)\n }\n if (options.endBlock) {\n this.endBlock(options.endBlock)\n }\n }\n\n public onTransaction(handler: (transaction: any, ctx: SuiContext) => void) {\n if (!this.isBind()) {\n throw new Error(\"Processor doesn't bind to an address\")\n }\n\n this.transactionHanlder = handler\n\n return this\n }\n\n public handleTransaction(txn: any, slot: Long): ProcessResult | null {\n const ctx = new SuiContext(this.address, slot)\n\n if (txn) {\n this.transactionHanlder(txn, ctx)\n }\n return {\n gauges: ctx.gauges,\n counters: ctx.counters,\n logs: ctx.logs,\n }\n }\n\n public isBind() {\n return this.address !== null\n }\n\n public startSlot(startSlot: Long | number) {\n if (typeof startSlot === 'number') {\n startSlot = Long.fromNumber(startSlot)\n }\n this.config.startSeqNumber = startSlot\n return this\n }\n\n public endBlock(endBlock: Long | number) {\n if (typeof endBlock === 'number') {\n endBlock = Long.fromNumber(endBlock)\n }\n this.config.endSeqNumber = endBlock\n return this\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export * from '../gen/processor/protos/processor';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../gen/processor/protos/processor"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gen/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAiD","sourcesContent":["export * from '../gen/processor/protos/processor'\n"]}