Conversation
| @@ -1,6 +1,6 @@ | |||
| { | |||
| "name": "warp-contracts-plugin-quickjs", | |||
| "version": "1.1.12", | |||
| async readExternal(processIdHandle: QuickJSHandle, actionHandle: QuickJSHandle) { | ||
| const processId = this.vm.getString(processIdHandle); | ||
| const action = this.vm.getString(actionHandle); | ||
| const { dryrun } = await import('@permaweb/aoconnect'); |
| tags: [{ name: 'Action', value: action }], | ||
| data: '1234' | ||
| }); | ||
| return JSON.parse(readRes.Messages[0].Data); |
There was a problem hiding this comment.
maybe there is no point in parsing the response if we need to stringify it again to pass it to the quickjs..
| quickJsEvaluator.evalLogging(); | ||
| quickJsEvaluator.evalPngJS(); | ||
| quickJsEvaluator.evalRedStone(); | ||
| quickJsEvaluator.evalExternal(); |
There was a problem hiding this comment.
shouldn't evalExternal and dummyPromiseEval also be called only if isSourceAsync?
| Date: false, | ||
| Proxy: false, | ||
| Promise: false, | ||
| Promise: true, |
There was a problem hiding this comment.
shouldn't we set this dynamically based on isSourceAsync?
| constructor( | ||
| private readonly vm: QuickJSContext, | ||
| private readonly runtime: QuickJSRuntime, | ||
| private readonly quickJS: QuickJSWASMModule, |
There was a problem hiding this comment.
I guess the QuickJSWASMModule import can also now be removed?
| this.initState(state); | ||
| } | ||
| return this.runContractFunction(message, env); | ||
| return await this.runContractFunction(message, env); |
There was a problem hiding this comment.
technically await is not needed here
| const result = this.vm.evalCode(`(async () => { | ||
| return await __handleDecorator(${JSON.stringify(message)}, ${JSON.stringify(env)}) | ||
| })()`); | ||
| const promiseHandle = this.vm.unwrapResult(result); |
There was a problem hiding this comment.
how are erros how handled? e.g. what if dry-run timeouts?
| evalExternal() { | ||
| const readExternalHandle = this.vm.newFunction('readExternal', (processIdHandle, actionHandle) => { | ||
| const promise = this.vm.newPromise(); | ||
| this.readExternal(processIdHandle, actionHandle).then((result) => { |
There was a problem hiding this comment.
shouldn't we also somehow handle errors here and pass some error info to the quickjs?
| const processId = this.vm.getString(processIdHandle); | ||
| const action = this.vm.getString(actionHandle); | ||
| const { dryrun } = await import('@permaweb/aoconnect'); | ||
| const readRes = await dryrun({ |
There was a problem hiding this comment.
what is the default timeout for the dryrun? maybe we should it limit to sth. like 10s?
There was a problem hiding this comment.
i dont know what's the default but i've added some logic so the error is thrown if dryrun is executing more than 10s
| }); | ||
| return JSON.parse(readRes.Messages[0].Data); | ||
| try { | ||
| const result = await Promise.race<{ |
There was a problem hiding this comment.
the issue with race is that the 'timeout' promise won't be removed even if the 'raced' promise is settled.
https://stackoverflow.com/a/39852372
It is already handled by a timeout implementation in warp sdk - https://github.com/warp-contracts/warp/blob/main/src/utils/utils.ts#L52
No description provided.