vaimee / desmo-sdk

MIT License
2 stars 1 forks source link

Use the `obsTask` function from iExec SDK to simplify `getQueryResult` #4

Closed iosonopersia closed 2 years ago

iosonopersia commented 2 years ago

See documentation of iExec SDK: IExecTaskModule:obsTask.

The obsTask function could be of great help in refactoring and vastly simplifying the code from getQueryResult in the Desmo module.

Code would become something like this:

const taskId = await this.retrieveTaskID();

const taskObservable = await this.iexec.task.obsTask(taskId, {
  dealid: this.dealId,
});

const taskCompletion: Promise<ethers.Bytes> = new Promise((resolve, reject) => {
  taskObservable.subscribe({
    next: ({ message }) => console.log(message),
    error: (e) => reject(e),
    complete: async () => {
      const tx = await this.contract.receiveResult(taskId, '0x00');
      await tx.wait();
      const result: ethers.Bytes = await this.contract.getQueryResult(taskId);
      resolve(result);
    },
  });
});

const result = await taskCompletion;
// TODO: Decode the result
return { requestId: '', taskId, result: result.toString() };
iosonopersia commented 2 years ago

These changes were proposed in PR #7.

iosonopersia commented 2 years ago

Done in #7.