Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce submitAndAwait graphql endpoint support #1563

Closed
nedsalk opened this issue Dec 19, 2023 · 1 comment · Fixed by #1615 or #1495
Closed

Introduce submitAndAwait graphql endpoint support #1563

nedsalk opened this issue Dec 19, 2023 · 1 comment · Fixed by #1615 or #1495
Assignees
Labels
feat Issue is a feature

Comments

@nedsalk
Copy link
Contributor

nedsalk commented Dec 19, 2023

Submitting a transaction and getting its results is currently a two-step process:

  1. Submit the transaction,
  2. Get its results via the TransactionResponse class

This is the default workflow and should remain the default one because a transaction can take an indefinite amount of time to execute on the node and using submitAndAwait as the default would block our users from executing anything on their side until the node executes the transaction.

However, we should allow our users to submit and await the results of the transaction execution in one call if they wish to do so. The main benefit of this single call over splitting it into two calls (submit and and subscribe to statusChange) is that the transaction might fail or be squeezed out in-between the submitting and subscribing, which would result in the subscription call never getting an update and thus never ending. This would be because the node immediately deletes a failed and squeezed-out transaction and us requesting that deleted transaction would hang to infinity.

A possible implementation of this would be to expand the current ProviderSendTxParams type:

export type ProviderSendTxParams = EstimateTransactionParams & {
  awaitExecution: boolean;
}

export class Provider {
// ...
  async sendTransaction(..., params: ProviderSendTxParams) {
  // ...
    if (params.awaitExecution) {
    const subscription = await this.operations.submitAndAwait({encodedTransaction});
    for await (const statusAndReceipts of subscription) {
      if(statusAndReceipts.type === "SubmittedStatus") continue;
      const transactionId = hashTransaction(encodedTransaction);
      return TransactionResponse(transactionId, statusAndReceipts);
    }
  }
  const { submit: { id: transactionId } } = await this.operations.submit({ encodedTransaction });
  return TransactionResponse(transactionId, this);
  }
}

These ProviderSendTxParams can then be forwarded via FunctionInvocationScope.call(), Account.transfer() and the like so the user can set the desired behavior through a flag, e.g.:

const response: TransactionResponse = await my_contract
  .functions
  .my_fn()
  .call(..., {awaitExecution: true});
@nedsalk nedsalk added feat Issue is a feature blocked labels Dec 19, 2023
@arboleya
Copy link
Member

Blocked by:

@arboleya arboleya removed the blocked label Dec 22, 2023
@arboleya arboleya added this to the 2 - Beetle milestone Dec 22, 2023
@nedsalk nedsalk linked a pull request Jan 5, 2024 that will close this issue
@nedsalk nedsalk modified the milestones: 2 - Beetle, 1 - Salamander Jan 8, 2024
@nedsalk nedsalk linked a pull request Jan 18, 2024 that will close this issue
44 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants