@sentio/sdk 1.27.8 → 1.27.10

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.
@@ -1 +1 @@
1
- {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/cli/upload.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAwC;AACxC,mCAAmC;AACnC,0DAAgC;AAChC,4CAAmB;AACnB,wDAA+B;AAE/B,+BAA+B;AAC/B,gDAAuB;AACvB,kDAAyB;AACzB,mCAAwC;AACxC,4DAA8B;AAC9B,mCAAuC;AAEvC,KAAK,UAAU,aAAa,CAAC,OAA4B,EAAE,MAAc;IACvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACrD,OAAO,IAAA,oBAAK,EAAC,GAAG,EAAE;QAChB,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,SAAS,EAAE,MAAM;SAClB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;KACvE,CAAC,CAAA;AACJ,CAAC;AAEM,KAAK,UAAU,UAAU,CAAC,OAA4B,EAAE,cAAsB;IACnF,IAAI,OAAO,CAAC,KAAK,EAAE;QACjB,MAAM,IAAA,sBAAc,EAAC,KAAK,CAAC,CAAA;KAC5B;IAED,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAA;IAE5C,MAAM,cAAc,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAA;IAE9D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,cAAc,IAAI,IAAA,aAAO,EAAC,OAAO,CAAC,IAA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AAK,CAAC,eAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC,CAAA;4BACjD,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;4BACpD,OAAM;yBACP;wBACD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;wBAC3C,MAAM,MAAM,EAAE,CAAA;qBACf;yBAAM,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EAAE;wBACrD,EAAE,CAAC,KAAK,EAAE,CAAA;qBACX;yBAAM;wBACL,MAAM,MAAM,EAAE,CAAA;qBACf;gBACH,CAAC,CAAA;gBACD,MAAM,MAAM,EAAE,CAAA;aACf;SACF;IACH,CAAC,CAAA;IAED,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;QAC9B,IAAI,UAAU,EAAE,IAAI,CAAC,EAAE;YACrB,OAAM;SACP;QACD,IAAI;YACF,MAAM,MAAM,EAAE,CAAA;SACf;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YACd,IAAI,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE;gBACpF,MAAM,YAAY,EAAE,CAAA;aACrB;SACF;IACH,CAAC,CAAA;IAED,MAAM,YAAY,EAAE,CAAA;AACtB,CAAC;AAvHD,gCAuHC","sourcesContent":["import { execSync } from 'child_process'\nimport { createHash } from 'crypto'\nimport FormData from 'form-data'\nimport fs from 'fs'\nimport readline from 'readline'\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'\nimport { getCliVersion } from './utils'\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n return fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug: options.project, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false)\n }\n\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const url = new URL('/api/v1/processors', 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 let triedCount = 0\n const upload = async () => {\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 try {\n const gitUrl = execSync('git remote get-url origin').toString().trim()\n data.append('gitUrl', gitUrl)\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n project: options.project,\n version: getCliVersion(),\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 if (res.status === 404) {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red((await res.json()).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n }\n }\n\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n return\n }\n try {\n await upload()\n } catch (e) {\n console.log(e)\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n await tryUploading()\n }\n }\n }\n\n await tryUploading()\n}\n"]}
1
+ {"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/cli/upload.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAwC;AACxC,mCAAmC;AACnC,0DAAgC;AAChC,4CAAmB;AACnB,wDAA+B;AAE/B,+BAA+B;AAC/B,gDAAuB;AACvB,kDAAyB;AACzB,mCAAwC;AACxC,4DAA8B;AAC9B,mCAAuC;AAEvC,KAAK,UAAU,aAAa,CAAC,OAA4B,EAAE,MAAc;IACvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACrD,OAAO,IAAA,oBAAK,EAAC,GAAG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D,MAAM,MAAM,EAAE,CAAA;aACf;SACF;IACH,CAAC,CAAA;IAED,IAAI,KAAY,CAAA;IAChB,MAAM,YAAY,GAAG,KAAK,IAAI,EAAE;QAC9B,IAAI,UAAU,EAAE,IAAI,CAAC,EAAE;YACrB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACpB,OAAM;SACP;QACD,IAAI;YACF,MAAM,MAAM,EAAE,CAAA;SACf;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE;gBACpF,KAAK,GAAG,CAAC,CAAA;gBACT,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;gBACzD,MAAM,YAAY,EAAE,CAAA;aACrB;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;aACjB;SACF;IACH,CAAC,CAAA;IAED,MAAM,YAAY,EAAE,CAAA;AACtB,CAAC;AA5HD,gCA4HC","sourcesContent":["import { execSync } from 'child_process'\nimport { createHash } from 'crypto'\nimport FormData from 'form-data'\nimport fs from 'fs'\nimport readline from 'readline'\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'\nimport { getCliVersion } from './utils'\n\nasync function createProject(options: SentioProjectConfig, apiKey: string) {\n const url = new URL('/api/v1/projects', options.host)\n return fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n },\n body: JSON.stringify({ slug: options.project, visibility: 'PRIVATE' }),\n })\n}\n\nexport async function uploadFile(options: SentioProjectConfig, apiKeyOverride: string) {\n if (options.build) {\n await buildProcessor(false)\n }\n\n console.log(chalk.blue('Prepare to upload'))\n\n const PROCESSOR_FILE = path.join(process.cwd(), 'dist/lib.js')\n\n const url = new URL('/api/v1/processors', 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 let triedCount = 0\n const upload = async () => {\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 try {\n const gitUrl = execSync('git remote get-url origin').toString().trim()\n data.append('gitUrl', gitUrl)\n } catch (e) {\n // skip errors\n }\n console.log(chalk.blue(triedCount > 1 ? 'Retry uploading' : 'Uploading'))\n const res = await fetch(url, {\n method: 'POST',\n headers: {\n 'api-key': apiKey,\n project: options.project,\n version: getCliVersion(),\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 if (res.status === 404) {\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n\n const prompt = async () => {\n const answer: string = await new Promise((resolve) =>\n rl.question(`Do you want to create it and continue the uploading process? (yes/no) `, resolve)\n )\n if (['y', 'yes'].includes(answer.toLowerCase())) {\n rl.close()\n const res = await createProject(options, apiKey)\n if (!res.ok) {\n console.error(chalk.red('Create Project Failed'))\n console.error(chalk.red((await res.json()).message))\n return\n }\n console.log(chalk.green('Project created'))\n await upload()\n } else if (['n', 'no'].includes(answer.toLowerCase())) {\n rl.close()\n } else {\n await prompt()\n }\n }\n await prompt()\n }\n }\n }\n\n let error: Error\n const tryUploading = async () => {\n if (triedCount++ >= 5) {\n console.error(error)\n return\n }\n try {\n await upload()\n } catch (e) {\n if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {\n error = e\n await new Promise((resolve) => setTimeout(resolve, 1000))\n await tryUploading()\n } else {\n console.error(e)\n }\n }\n }\n\n await tryUploading()\n}\n"]}
@@ -9,7 +9,11 @@ import { Trace } from './trace';
9
9
  export declare abstract class BaseProcessorTemplate<TContract extends BaseContract, TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>> {
10
10
  id: number;
11
11
  binds: Set<string>;
12
- blockHandlers: ((block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid)[];
12
+ blockHandlers: {
13
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid;
14
+ blockInterval?: number;
15
+ timeIntervalInMinutes?: number;
16
+ }[];
13
17
  traceHandlers: {
14
18
  signature: string;
15
19
  handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid;
@@ -22,6 +26,9 @@ export declare abstract class BaseProcessorTemplate<TContract extends BaseContra
22
26
  bind(options: BindOptions): BaseProcessor<TContract, TBoundContractView> | undefined;
23
27
  onEvent(handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: EventFilter | EventFilter[]): this;
24
28
  onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
29
+ onBlockInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number): this;
30
+ onTimeInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number): this;
31
+ onInterval(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeInterval: number | undefined, blockInterval: number | undefined): this;
25
32
  onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
26
33
  protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>;
27
34
  }
@@ -28,7 +28,7 @@ class BaseProcessorTemplate {
28
28
  processor.onEvent(eh.handler, eh.filter);
29
29
  }
30
30
  for (const bh of this.blockHandlers) {
31
- processor.onBlock(bh);
31
+ processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval);
32
32
  }
33
33
  const instance = {
34
34
  templateId: this.id,
@@ -68,7 +68,16 @@ class BaseProcessorTemplate {
68
68
  return this;
69
69
  }
70
70
  onBlock(handler) {
71
- this.blockHandlers.push(handler);
71
+ return this.onBlockInterval(handler);
72
+ }
73
+ onBlockInterval(handler, blockInterval = 1000) {
74
+ return this.onInterval(handler, undefined, blockInterval);
75
+ }
76
+ onTimeInterval(handler, timeIntervalInMinutes = 240) {
77
+ return this.onInterval(handler, timeIntervalInMinutes, undefined);
78
+ }
79
+ onInterval(handler, timeInterval, blockInterval) {
80
+ this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval });
72
81
  return this;
73
82
  }
74
83
  onTrace(signature, handler) {
@@ -1 +1 @@
1
- {"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/core/base-processor-template.ts"],"names":[],"mappings":";;;;;;AAKA,iDAAiE;AAEjE,gDAAuB;AACvB,wDAAqD;AAIrD,MAAsB,qBAAqB;IAIzC,EAA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@ethersproject/abstract-provider'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Event } from '@ethersproject/contracts'\nimport { BaseProcessor } from './base-processor'\nimport { BindOptions, getOptionsSignature } from './bind-options'\nimport { TemplateInstance } from '../gen'\nimport Long from 'long'\nimport { getNetwork } from '@ethersproject/providers'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: ((block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid)[] = []\n traceHandlers: {\n signature: string\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n }[] = []\n eventHandlers: {\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: EventFilter | EventFilter[]\n }[] = []\n\n constructor() {\n this.id = global.PROCESSOR_STATE.templates.length\n global.PROCESSOR_STATE.templates.push(this)\n }\n\n public bind(options: BindOptions) {\n const sig = getOptionsSignature(options)\n if (this.binds.has(sig)) {\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter)\n }\n for (const bh of this.blockHandlers) {\n processor.onBlock(bh)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network ? getNetwork(options.network).chainId.toString() : '1',\n abi: '',\n },\n startBlock: Long.ZERO,\n endBlock: Long.ZERO,\n }\n if (options.startBlock) {\n if (typeof options.startBlock === 'number') {\n instance.startBlock = Long.fromNumber(options.startBlock)\n } else {\n instance.startBlock = options.startBlock\n }\n }\n if (options.endBlock) {\n if (typeof options.endBlock === 'number') {\n instance.endBlock = Long.fromNumber(options.endBlock)\n } else {\n instance.endBlock = options.endBlock\n }\n }\n global.PROCESSOR_STATE.templatesInstances.push(instance)\n\n return processor\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n this.blockHandlers.push(handler)\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n this.traceHandlers.push({ signature, handler })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
1
+ {"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/core/base-processor-template.ts"],"names":[],"mappings":";;;;;;AAKA,iDAAiE;AAEjE,gDAAuB;AACvB,wDAAqD;AAIrD,MAAsB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IACzB,aAAa,GAIP,EAAE,CAAA;IACR,aAAa,GAGP,EAAE,CAAA;IACR,aAAa,GAGP,EAAE,CAAA;IAER;QACE,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,CAAA;QACjD,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC7C,CAAC;IAEM,IAAI,CAAC,OAAoB;QAC9B,MAAM,GAAG,GAAG,IAAA,kCAAmB,EAAC,OAAO,CAAC,CAAA;QACxC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACvB,OAAM;SACP;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAEnB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QAE5C,KAAK,MAAM,EAAE,IAAI,I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ACrC;SACF;QACD,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAExD,OAAO,SAAS,CAAA;IAClB,CAAC;IAEM,OAAO,CACZ,OAA6F,EAC7F,MAAmC;QAEnC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YACtB,OAAO,EAAE,OAAO;YAChB,MAAM,EAAE,MAAM;SACf,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CAAC,OAA6F;QAC1G,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IACtC,CAAC;IAEM,eAAe,CACpB,OAA6F,EAC7F,aAAa,GAAG,IAAI;QAEpB,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAA;IAC3D,CAAC;IAEM,cAAc,CACnB,OAA6F,EAC7F,qBAAqB,GAAG,GAAG;QAE3B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,qBAAqB,EAAE,SAAS,CAAC,CAAA;IACnE,CAAC;IAEM,UAAU,CACf,OAA6F,EAC7F,YAAgC,EAChC,aAAiC;QAEjC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC,CAAA;QACvG,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAA6F;QAE7F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;CAGF;AAtHD,sDAsHC","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from './context'\nimport { Block } from '@ethersproject/abstract-provider'\nimport { BaseContract, EventFilter } from 'ethers'\nimport { Event } from '@ethersproject/contracts'\nimport { BaseProcessor } from './base-processor'\nimport { BindOptions, getOptionsSignature } from './bind-options'\nimport { TemplateInstance } from '../gen'\nimport Long from 'long'\nimport { getNetwork } from '@ethersproject/providers'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: {\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n blockInterval?: number\n timeIntervalInMinutes?: number\n }[] = []\n traceHandlers: {\n signature: string\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n }[] = []\n eventHandlers: {\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: EventFilter | EventFilter[]\n }[] = []\n\n constructor() {\n this.id = global.PROCESSOR_STATE.templates.length\n global.PROCESSOR_STATE.templates.push(this)\n }\n\n public bind(options: BindOptions) {\n const sig = getOptionsSignature(options)\n if (this.binds.has(sig)) {\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter)\n }\n for (const bh of this.blockHandlers) {\n processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: options.network ? getNetwork(options.network).chainId.toString() : '1',\n abi: '',\n },\n startBlock: Long.ZERO,\n endBlock: Long.ZERO,\n }\n if (options.startBlock) {\n if (typeof options.startBlock === 'number') {\n instance.startBlock = Long.fromNumber(options.startBlock)\n } else {\n instance.startBlock = options.startBlock\n }\n }\n if (options.endBlock) {\n if (typeof options.endBlock === 'number') {\n instance.endBlock = Long.fromNumber(options.endBlock)\n } else {\n instance.endBlock = options.endBlock\n }\n }\n global.PROCESSOR_STATE.templatesInstances.push(instance)\n\n return processor\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n return this.onBlockInterval(handler)\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000\n ) {\n return this.onInterval(handler, undefined, blockInterval)\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 240\n ) {\n return this.onInterval(handler, timeIntervalInMinutes, undefined)\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: number | undefined,\n blockInterval: number | undefined\n ) {\n this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval })\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n this.traceHandlers.push({ signature, handler })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
@@ -14,7 +14,7 @@ export declare class TraceHandler {
14
14
  signature: string;
15
15
  handler: (trace: Trace) => Promise<ProcessResult>;
16
16
  }
17
- declare class BlockHandlder {
17
+ export declare class BlockHandlder {
18
18
  blockInterval?: number;
19
19
  timeIntervalInMinutes?: number;
20
20
  handler: (block: Block) => Promise<ProcessResult>;
@@ -35,4 +35,3 @@ export declare abstract class BaseProcessor<TContract extends BaseContract, TBou
35
35
  onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
36
36
  protected onTrace(signature: string, handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid): this;
37
37
  }
38
- export {};
@@ -3,7 +3,7 @@ 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.BaseProcessor = exports.TraceHandler = exports.EventsHandler = void 0;
6
+ exports.BaseProcessor = exports.BlockHandlder = exports.TraceHandler = exports.EventsHandler = void 0;
7
7
  const providers_1 = require("@ethersproject/providers");
8
8
  const long_1 = __importDefault(require("long"));
9
9
  const context_1 = require("./context");
@@ -23,6 +23,7 @@ class BlockHandlder {
23
23
  timeIntervalInMinutes;
24
24
  handler;
25
25
  }
26
+ exports.BlockHandlder = BlockHandlder;
26
27
  class BaseProcessor {
27
28
  blockHandlers = [];
28
29
  eventHandlers = [];
@@ -90,12 +91,12 @@ class BaseProcessor {
90
91
  return this;
91
92
  }
92
93
  onBlock(handler) {
93
- return this.onBlockInterval(handler, 1);
94
+ return this.onBlockInterval(handler);
94
95
  }
95
- onBlockInterval(handler, blockInterval = 240) {
96
+ onBlockInterval(handler, blockInterval = 1000) {
96
97
  return this.onInterval(handler, undefined, blockInterval);
97
98
  }
98
- onTimeInterval(handler, timeIntervalInMinutes = 60) {
99
+ onTimeInterval(handler, timeIntervalInMinutes = 60 * 4) {
99
100
  return this.onInterval(handler, timeIntervalInMinutes, undefined);
100
101
  }
101
102
  onInterval(handler, timeInterval, blockInterval) {
@@ -1 +1 @@
1
- {"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAA4E;AAC5E,gCAAsC;AAQtC,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAM,aAAa;IACjB,aAAa,CAAS;IACtB,qBAAqB,C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AAC,CAAA;gBACzB,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAhLD,sCAgLC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\nimport { MoveResource } from 'aptos-sdk/src/generated'\nimport { AptosResourceContext } from '../aptos'\nimport { MoveResourcesWithVersionPayload } from '../aptos/aptos-processor'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nclass BlockHandlder {\n blockInterval?: number\n timeIntervalInMinutes?: number\n handler: (block: Block) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: BlockHandlder[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log\n )\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n return this.onBlockInterval(handler, 1)\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 240\n ) {\n return this.onInterval(handler, undefined, blockInterval)\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60\n ) {\n return this.onInterval(handler, timeIntervalInMinutes, undefined)\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: number | undefined,\n blockInterval: number | undefined\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push({\n handler: async function (block: Block) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined\n )\n await handler(block, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return ProcessResult.fromPartial({})\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n undefined,\n trace\n )\n await handler(trace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"base-processor.js","sourceRoot":"","sources":["../../src/core/base-processor.ts"],"names":[],"mappings":";;;;;;AAEA,wDAAiE;AAEjE,gDAAuB;AAEvB,uCAA4E;AAC5E,gCAAsC;AAKtC,MAAa,aAAa;IACxB,OAAO,CAAe;IACtB,OAAO,CAAwC;CAChD;AAHD,sCAGC;AAED,MAAa,YAAY;IACvB,SAAS,CAAQ;IACjB,OAAO,CAA0C;CAClD;AAHD,oCAGC;AAED,MAAa,aAAa;IACxB,aAAa,CAAS;IACtB,qBAAqB,CAAS;IAC9B,OAAO,CAA0C;CAClD;AAJD,sCAIC;AAED,MAAsB,aAAa;IAIjC,aAAa,G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CAAC;SACF,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAhLD,sCAgLC","sourcesContent":["import { Event } from '@ethersproject/contracts'\nimport { BytesLike } from '@ethersproject/bytes'\nimport { Block, Log, getNetwork } from '@ethersproject/providers'\nimport { BaseContract, EventFilter } from '@ethersproject/contracts'\nimport Long from 'long'\n\nimport { BoundContractView, ContractContext, ContractView } from './context'\nimport { ProcessResult } from '../gen'\nimport { BindInternalOptions, BindOptions } from './bind-options'\nimport { PromiseOrVoid } from '../promise-or-void'\nimport { Trace } from './trace'\n\nexport class EventsHandler {\n filters: EventFilter[]\n handler: (event: Log) => Promise<ProcessResult>\n}\n\nexport class TraceHandler {\n signature: string\n handler: (trace: Trace) => Promise<ProcessResult>\n}\n\nexport class BlockHandlder {\n blockInterval?: number\n timeIntervalInMinutes?: number\n handler: (block: Block) => Promise<ProcessResult>\n}\n\nexport abstract class BaseProcessor<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n blockHandlers: BlockHandlder[] = []\n eventHandlers: EventsHandler[] = []\n traceHandlers: TraceHandler[] = []\n\n config: BindInternalOptions\n\n constructor(config: BindOptions) {\n this.config = {\n address: config.address,\n name: config.name || '',\n network: config.network ? config.network : 1,\n startBlock: new Long(0),\n }\n if (config.startBlock) {\n if (typeof config.startBlock === 'number') {\n this.config.startBlock = Long.fromNumber(config.startBlock)\n } else {\n this.config.startBlock = config.startBlock\n }\n }\n if (config.endBlock) {\n if (typeof config.endBlock === 'number') {\n this.config.endBlock = Long.fromNumber(config.endBlock)\n } else {\n this.config.endBlock = config.endBlock\n }\n }\n }\n\n protected abstract CreateBoundContractView(): TBoundContractView\n\n public getChainId(): number {\n return getNetwork(this.config.network).chainId\n }\n\n public onEvent(\n handler: (event: Event, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: EventFilter | EventFilter[]\n ) {\n const chainId = this.getChainId()\n\n let _filters: EventFilter[] = []\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n this.eventHandlers.push({\n filters: _filters,\n handler: async function (log) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n log\n )\n // let event: Event = <Event>deepCopy(log);\n const event: Event = <Event>log\n const parsed = contractView.rawContract.interface.parseLog(log)\n if (parsed) {\n event.args = parsed.args\n event.decode = (data: BytesLike, topics?: Array<any>) => {\n return contractView.rawContract.interface.decodeEventLog(parsed.eventFragment, data, topics)\n }\n event.event = parsed.name\n event.eventSignature = parsed.signature\n\n // TODO fix this bug\n await handler(event, ctx)\n return ctx.getProcessResult()\n }\n return ProcessResult.fromPartial({})\n },\n })\n return this\n }\n\n public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n return this.onBlockInterval(handler)\n }\n\n public onBlockInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000\n ) {\n return this.onInterval(handler, undefined, blockInterval)\n }\n\n public onTimeInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60 * 4\n ) {\n return this.onInterval(handler, timeIntervalInMinutes, undefined)\n }\n\n public onInterval(\n handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: number | undefined,\n blockInterval: number | undefined\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.blockHandlers.push({\n handler: async function (block: Block) {\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n block,\n undefined\n )\n await handler(block, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n blockInterval: blockInterval,\n })\n return this\n }\n\n public onAllEvents(handler: (event: Log, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {\n const _filters: EventFilter[] = []\n const tmpContract = this.CreateBoundContractView()\n\n for (const key in tmpContract.filters) {\n _filters.push(tmpContract.filters[key]())\n }\n return this.onEvent(function (log, ctx) {\n return handler(log, ctx)\n }, _filters)\n }\n\n protected onTrace(\n signature: string,\n handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n ) {\n const chainId = this.getChainId()\n const contractView = this.CreateBoundContractView()\n const contractName = this.config.name\n\n this.traceHandlers.push({\n signature,\n handler: async function (trace: Trace) {\n const contractInterface = contractView.rawContract.interface\n const fragment = contractInterface.getFunction(signature)\n if (!trace.action.input) {\n return ProcessResult.fromPartial({})\n }\n const traceData = '0x' + trace.action.input.slice(10)\n trace.args = contractInterface._abiCoder.decode(fragment.inputs, traceData)\n\n const ctx = new ContractContext<TContract, TBoundContractView>(\n contractName,\n contractView,\n chainId,\n undefined,\n undefined,\n trace\n )\n await handler(trace, ctx)\n return ctx.getProcessResult()\n },\n })\n return this\n }\n}\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.27.8",
4
+ "version": "1.27.10",
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 && cp src/utils/*.csv lib/utils",
@@ -143,7 +143,7 @@ export class AccountCodegen {
143
143
  const info = this.loader.accountImports.get(address)
144
144
 
145
145
  if (info) {
146
- for (const [account, moduleImported] of info.imports.entries()) {
146
+ for (const [account] of info.imports.entries()) {
147
147
  // Remap to user's filename if possible, TODO codepath not well tested
148
148
  let tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)
149
149
  if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {
@@ -154,12 +154,9 @@ export class AccountCodegen {
154
154
  }
155
155
  tsAccountModule = `@sentio/sdk/${srcRoot}/builtin/aptos/${account}`
156
156
  }
157
- const items = Array.from(moduleImported)
158
- moduleImports.push(`import { ${items.join(',')} } from "${tsAccountModule}"`)
157
+ moduleImports.push(`import * as _${account} from "${tsAccountModule}"`)
159
158
 
160
- // Ideally we should use per module's load types, but it doesn't matter since we are loading the entire
161
- // account modules anyway
162
- items.forEach((m) => dependedAccounts.push(m))
159
+ dependedAccounts.push(account)
163
160
  }
164
161
  }
165
162
 
@@ -176,8 +173,8 @@ export class AccountCodegen {
176
173
 
177
174
  ${this.modules.map((m) => generateModule(m, this.config.network)).join('\n')}
178
175
 
179
- function loadAllTypes(_r: aptos.TypeRegistry) {
180
- ${dependedAccounts.map((m) => `${m}.loadTypes(_r)`).join('\n')}
176
+ export function loadAllTypes(_r: aptos.TypeRegistry) {
177
+ ${dependedAccounts.map((a) => `_${a}.loadAllTypes(_r)`).join('\n')}
181
178
 
182
179
  ${this.modules
183
180
  .map((m) => {
@@ -268,7 +265,7 @@ function generateStructs(module: MoveModule, struct: MoveStruct, events: Set<str
268
265
  const genericStringAny = generateStructTypeParameters(struct, true)
269
266
 
270
267
  const fields = struct.fields.map((field) => {
271
- return `${field.name}: ${generateType(field.type)}`
268
+ return `${field.name}: ${generateType(field.type, module.address)}`
272
269
  })
273
270
 
274
271
  let eventPayload = ''
@@ -325,7 +322,7 @@ function generateCallArgsStructs(module: MoveModule, func: MoveFunction) {
325
322
  }
326
323
 
327
324
  const fields = getMeaningfulFunctionParams(func).map((param) => {
328
- return `${generateType(param)}`
325
+ return `${generateType(param, module.address)}`
329
326
  })
330
327
 
331
328
  const camelFuncName = capitalizeFirstChar(camelize(func.name))
@@ -2,7 +2,7 @@ import { MoveModule } from 'aptos-sdk/src/generated'
2
2
  import { TypeDescriptor } from '../aptos/types'
3
3
  import { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../aptos/utils'
4
4
 
5
- function generateTypeForDescriptor(type: TypeDescriptor): string {
5
+ function generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {
6
6
  // TODO &signer is defintely an address, but what if &OTHER_TYPE?
7
7
  if (type.qname.startsWith('&')) {
8
8
  return 'Address'
@@ -34,10 +34,10 @@ function generateTypeForDescriptor(type: TypeDescriptor): string {
34
34
  if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {
35
35
  return `${elementTypeQname}[] | string`
36
36
  }
37
- return generateTypeForDescriptor(type.typeArgs[0]) + '[]'
37
+ return generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]'
38
38
  }
39
39
 
40
- const simpleName = generateSimpleType(type.qname)
40
+ const simpleName = generateSimpleType(type.qname, currentAddress)
41
41
  if (simpleName.length === 0) {
42
42
  console.error('unexpected error')
43
43
  }
@@ -46,18 +46,20 @@ function generateTypeForDescriptor(type: TypeDescriptor): string {
46
46
  }
47
47
  if (type.typeArgs.length > 0) {
48
48
  // return simpleName
49
- return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t)).join(',') + '>'
49
+ return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t, currentAddress)).join(',') + '>'
50
50
  }
51
51
  return simpleName
52
52
  }
53
53
 
54
- function generateSimpleType(type: string): string {
54
+ function generateSimpleType(type: string, currentAddress: string): string {
55
55
  const parts = type.split(SPLITTER)
56
56
  if (parts.length < 2) {
57
57
  return parts[0]
58
58
  }
59
-
60
- return parts.slice(1).join('.')
59
+ if (parts[0] === currentAddress) {
60
+ return parts.slice(1).join('.')
61
+ }
62
+ return '_' + parts.join('.')
61
63
  }
62
64
 
63
65
  export function parseMoveType(type: string): TypeDescriptor {
@@ -127,8 +129,8 @@ export function parseMoveType(type: string): TypeDescriptor {
127
129
  }
128
130
 
129
131
  // TODO ctx need to have type parameters
130
- export function generateType(type: string, ctx?: any): string {
131
- return generateTypeForDescriptor(parseMoveType(type))
132
+ export function generateType(type: string, currentAddress: string): string {
133
+ return generateTypeForDescriptor(parseMoveType(type), currentAddress)
132
134
  }
133
135
 
134
136
  export class AccountModulesImportInfo {
@@ -4140,7 +4140,7 @@ export namespace transaction_validation {
4140
4140
  );
4141
4141
  }
4142
4142
 
4143
- function loadAllTypes(_r: aptos.TypeRegistry) {
4143
+ export function loadAllTypes(_r: aptos.TypeRegistry) {
4144
4144
  _r.load(acl.ABI);
4145
4145
  _r.load(any.ABI);
4146
4146
  _r.load(bcs.ABI);
@@ -7,7 +7,7 @@
7
7
  import { aptos } from "@sentio/sdk";
8
8
  import { Address, MoveModule } from "aptos-sdk/src/generated";
9
9
 
10
- import { table, event, simple_map, type_info } from "./0x1";
10
+ import * as _0x1 from "./0x1";
11
11
 
12
12
  export class token extends aptos.AptosBaseProcessor {
13
13
  constructor(options: aptos.AptosBindOptions) {
@@ -248,11 +248,11 @@ export namespace token {
248
248
 
249
249
  export class Collections {
250
250
  static TYPE_QNAME = "0x3::token::Collections";
251
- collection_data: table.Table<string, token.CollectionData>;
252
- token_data: table.Table<token.TokenDataId, token.TokenData>;
253
- create_collection_events: event.EventHandle<token.CreateCollectionEvent>;
254
- create_token_data_events: event.EventHandle<token.CreateTokenDataEvent>;
255
- mint_token_events: event.EventHandle<token.MintTokenEvent>;
251
+ collection_data: _0x1.table.Table<string, token.CollectionData>;
252
+ token_data: _0x1.table.Table<token.TokenDataId, token.TokenData>;
253
+ create_collection_events: _0x1.event.EventHandle<token.CreateCollectionEvent>;
254
+ create_token_data_events: _0x1.event.EventHandle<token.CreateTokenDataEvent>;
255
+ mint_token_events: _0x1.event.EventHandle<token.MintTokenEvent>;
256
256
  }
257
257
 
258
258
  export class CreateCollectionEvent {
@@ -382,12 +382,12 @@ export namespace token {
382
382
 
383
383
  export class TokenStore {
384
384
  static TYPE_QNAME = "0x3::token::TokenStore";
385
- tokens: table.Table<token.TokenId, token.Token>;
385
+ tokens: _0x1.table.Table<token.TokenId, token.Token>;
386
386
  direct_transfer: Boolean;
387
- deposit_events: event.EventHandle<token.DepositEvent>;
388
- withdraw_events: event.EventHandle<token.WithdrawEvent>;
389
- burn_events: event.EventHandle<token.BurnTokenEvent>;
390
- mutate_token_property_events: event.EventHandle<token.MutateTokenPropertyMapEvent>;
387
+ deposit_events: _0x1.event.EventHandle<token.DepositEvent>;
388
+ withdraw_events: _0x1.event.EventHandle<token.WithdrawEvent>;
389
+ burn_events: _0x1.event.EventHandle<token.BurnTokenEvent>;
390
+ mutate_token_property_events: _0x1.event.EventHandle<token.MutateTokenPropertyMapEvent>;
391
391
  }
392
392
 
393
393
  export class WithdrawCapability {
@@ -535,7 +535,7 @@ export namespace token {
535
535
  export namespace property_map {
536
536
  export class PropertyMap {
537
537
  static TYPE_QNAME = "0x3::property_map::PropertyMap";
538
- map: simple_map.SimpleMap<string, property_map.PropertyValue>;
538
+ map: _0x1.simple_map.SimpleMap<string, property_map.PropertyValue>;
539
539
  }
540
540
 
541
541
  export class PropertyValue {
@@ -630,7 +630,7 @@ export namespace token_coin_swap {
630
630
  amount: bigint;
631
631
  min_price: bigint;
632
632
  locked_until_secs: bigint;
633
- coin_type_info: type_info.TypeInfo;
633
+ coin_type_info: _0x1.type_info.TypeInfo;
634
634
  }
635
635
 
636
636
  export interface TokenListingEventInstance
@@ -641,14 +641,17 @@ export namespace token_coin_swap {
641
641
 
642
642
  export class TokenListings<T0> {
643
643
  static TYPE_QNAME = "0x3::token_coin_swap::TokenListings";
644
- listings: table.Table<token.TokenId, token_coin_swap.TokenCoinSwap<T0>>;
645
- listing_events: event.EventHandle<token_coin_swap.TokenListingEvent>;
646
- swap_events: event.EventHandle<token_coin_swap.TokenSwapEvent>;
644
+ listings: _0x1.table.Table<
645
+ token.TokenId,
646
+ token_coin_swap.TokenCoinSwap<T0>
647
+ >;
648
+ listing_events: _0x1.event.EventHandle<token_coin_swap.TokenListingEvent>;
649
+ swap_events: _0x1.event.EventHandle<token_coin_swap.TokenSwapEvent>;
647
650
  }
648
651
 
649
652
  export class TokenStoreEscrow {
650
653
  static TYPE_QNAME = "0x3::token_coin_swap::TokenStoreEscrow";
651
- token_escrows: table.Table<token.TokenId, token_coin_swap.TokenEscrow>;
654
+ token_escrows: _0x1.table.Table<token.TokenId, token_coin_swap.TokenEscrow>;
652
655
  }
653
656
 
654
657
  export class TokenSwapEvent {
@@ -657,7 +660,7 @@ export namespace token_coin_swap {
657
660
  token_buyer: Address;
658
661
  token_amount: bigint;
659
662
  coin_amount: bigint;
660
- coin_type_info: type_info.TypeInfo;
663
+ coin_type_info: _0x1.type_info.TypeInfo;
661
664
  }
662
665
 
663
666
  export interface TokenSwapEventInstance
@@ -784,10 +787,10 @@ export class token_transfers extends aptos.AptosBaseProcessor {
784
787
  export namespace token_transfers {
785
788
  export class PendingClaims {
786
789
  static TYPE_QNAME = "0x3::token_transfers::PendingClaims";
787
- pending_claims: table.Table<token_transfers.TokenOfferId, token.Token>;
788
- offer_events: event.EventHandle<token_transfers.TokenOfferEvent>;
789
- cancel_offer_events: event.EventHandle<token_transfers.TokenCancelOfferEvent>;
790
- claim_events: event.EventHandle<token_transfers.TokenClaimEvent>;
790
+ pending_claims: _0x1.table.Table<token_transfers.TokenOfferId, token.Token>;
791
+ offer_events: _0x1.event.EventHandle<token_transfers.TokenOfferEvent>;
792
+ cancel_offer_events: _0x1.event.EventHandle<token_transfers.TokenCancelOfferEvent>;
793
+ claim_events: _0x1.event.EventHandle<token_transfers.TokenClaimEvent>;
791
794
  }
792
795
 
793
796
  export class TokenCancelOfferEvent {
@@ -875,11 +878,8 @@ export namespace token_transfers {
875
878
  );
876
879
  }
877
880
 
878
- function loadAllTypes(_r: aptos.TypeRegistry) {
879
- table.loadTypes(_r);
880
- event.loadTypes(_r);
881
- simple_map.loadTypes(_r);
882
- type_info.loadTypes(_r);
881
+ export function loadAllTypes(_r: aptos.TypeRegistry) {
882
+ _0x1.loadAllTypes(_r);
883
883
 
884
884
  _r.load(token.ABI);
885
885
  _r.load(property_map.ABI);
package/src/cli/upload.ts CHANGED
@@ -126,16 +126,21 @@ export async function uploadFile(options: SentioProjectConfig, apiKeyOverride: s
126
126
  }
127
127
  }
128
128
 
129
+ let error: Error
129
130
  const tryUploading = async () => {
130
131
  if (triedCount++ >= 5) {
132
+ console.error(error)
131
133
  return
132
134
  }
133
135
  try {
134
136
  await upload()
135
137
  } catch (e) {
136
- console.log(e)
137
138
  if (e.constructor.name === 'FetchError' && e.type === 'system' && e.code === 'EPIPE') {
139
+ error = e
140
+ await new Promise((resolve) => setTimeout(resolve, 1000))
138
141
  await tryUploading()
142
+ } else {
143
+ console.error(e)
139
144
  }
140
145
  }
141
146
  }
@@ -16,7 +16,11 @@ export abstract class BaseProcessorTemplate<
16
16
  > {
17
17
  id: number
18
18
  binds = new Set<string>()
19
- blockHandlers: ((block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid)[] = []
19
+ blockHandlers: {
20
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
21
+ blockInterval?: number
22
+ timeIntervalInMinutes?: number
23
+ }[] = []
20
24
  traceHandlers: {
21
25
  signature: string
22
26
  handler: (trace: Trace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid
@@ -44,7 +48,7 @@ export abstract class BaseProcessorTemplate<
44
48
  processor.onEvent(eh.handler, eh.filter)
45
49
  }
46
50
  for (const bh of this.blockHandlers) {
47
- processor.onBlock(bh)
51
+ processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval)
48
52
  }
49
53
 
50
54
  const instance: TemplateInstance = {
@@ -89,7 +93,29 @@ export abstract class BaseProcessorTemplate<
89
93
  }
90
94
 
91
95
  public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {
92
- this.blockHandlers.push(handler)
96
+ return this.onBlockInterval(handler)
97
+ }
98
+
99
+ public onBlockInterval(
100
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
101
+ blockInterval = 1000
102
+ ) {
103
+ return this.onInterval(handler, undefined, blockInterval)
104
+ }
105
+
106
+ public onTimeInterval(
107
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
108
+ timeIntervalInMinutes = 240
109
+ ) {
110
+ return this.onInterval(handler, timeIntervalInMinutes, undefined)
111
+ }
112
+
113
+ public onInterval(
114
+ handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
115
+ timeInterval: number | undefined,
116
+ blockInterval: number | undefined
117
+ ) {
118
+ this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval: blockInterval })
93
119
  return this
94
120
  }
95
121
 
@@ -9,9 +9,6 @@ import { ProcessResult } from '../gen'
9
9
  import { BindInternalOptions, BindOptions } from './bind-options'
10
10
  import { PromiseOrVoid } from '../promise-or-void'
11
11
  import { Trace } from './trace'
12
- import { MoveResource } from 'aptos-sdk/src/generated'
13
- import { AptosResourceContext } from '../aptos'
14
- import { MoveResourcesWithVersionPayload } from '../aptos/aptos-processor'
15
12
 
16
13
  export class EventsHandler {
17
14
  filters: EventFilter[]
@@ -23,7 +20,7 @@ export class TraceHandler {
23
20
  handler: (trace: Trace) => Promise<ProcessResult>
24
21
  }
25
22
 
26
- class BlockHandlder {
23
+ export class BlockHandlder {
27
24
  blockInterval?: number
28
25
  timeIntervalInMinutes?: number
29
26
  handler: (block: Block) => Promise<ProcessResult>
@@ -116,19 +113,19 @@ export abstract class BaseProcessor<
116
113
  }
117
114
 
118
115
  public onBlock(handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid) {
119
- return this.onBlockInterval(handler, 1)
116
+ return this.onBlockInterval(handler)
120
117
  }
121
118
 
122
119
  public onBlockInterval(
123
120
  handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
124
- blockInterval = 240
121
+ blockInterval = 1000
125
122
  ) {
126
123
  return this.onInterval(handler, undefined, blockInterval)
127
124
  }
128
125
 
129
126
  public onTimeInterval(
130
127
  handler: (block: Block, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,
131
- timeIntervalInMinutes = 60
128
+ timeIntervalInMinutes = 60 * 4
132
129
  ) {
133
130
  return this.onInterval(handler, timeIntervalInMinutes, undefined)
134
131
  }
@@ -9,7 +9,7 @@ const rewardPerBlock = new Gauge('reward_per_block', {
9
9
  })
10
10
  const tokenCounter = new Counter('token')
11
11
 
12
- X2y2Processor.bind({ address: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1' }).onBlock(async (_, ctx) => {
12
+ X2y2Processor.bind({ address: '0xB329e39Ebefd16f40d38f07643652cE17Ca5Bac1' }).onBlockInterval(async (_, ctx) => {
13
13
  const phase = (await ctx.contract.currentPhase()).toString()
14
14
  const reward = token.scaleDown(await ctx.contract.rewardPerBlockForStaking(), 18)
15
15
  rewardPerBlock.record(ctx, reward, { phase })