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

suggestions for Client.submitAndWait #2470

Open
rikublock opened this issue Sep 7, 2023 · 3 comments
Open

suggestions for Client.submitAndWait #2470

rikublock opened this issue Sep 7, 2023 · 3 comments

Comments

@rikublock
Copy link

Problem: If a transaction is unsuccessful or is rejected (accepted: false, with tec code), the behavior of the submitAndWait function is quite restricted. In certain cases, we would want to abort early and not wait for the sequence number timeout (can take quite some time). Furthermore, the function also doesn't provide a lot of details about the failure reason.

Possible solutions:

  • add an opts to fail immediately, if transaction is rejected
  • return both a SubmitResponse (like Client.submit) and Promise<TxResponse<T>>, depending on the result one can choose not to resolve the promise
  • expose/export the waitForFinalTransactionOutcome function to allow developers to easily implement their own version of submitAndWait
@JST5000
Copy link
Collaborator

JST5000 commented Sep 7, 2023

It may also be worth considering that the default lastLedgerSequence when autofilling could be too generous. We don't want it to fail accidentally, but as it is now it takes a long time for finality

@mvadari
Copy link
Collaborator

mvadari commented Sep 8, 2023

add an opts to fail immediately, if transaction is rejected

Why not just use submit in that case?

return both a SubmitResponse (like Client.submit) and Promise<TxResponse>, depending on the result one can choose not to resolve the promise

This seems quite complicated to use if you just want the happy path or if you're more of a beginner dev (it took me a couple of minutes to understand how you could use it in the manner described).

expose/export the waitForFinalTransactionOutcome function to allow developers to easily implement their own version of submitAndWait

IMO this is probably the best solution - so that if you want the custom functionality in your other proposed solutions, you can just write it yourself.

It may also be worth considering that the default lastLedgerSequence when autofilling could be too generous. We don't want it to fail accidentally, but as it is now it takes a long time for finality

Do we have any opt for the LastLedgerSequence? This could just be configurable instead of reducing the default.

@rikublock
Copy link
Author

add an opts to fail immediately, if transaction is rejected

Why not just use submit in that case?

I would still want the ability to easily check/wait for finalization. submit alone won't do that.

expose/export the waitForFinalTransactionOutcome function to allow developers to easily implement their own version of submitAndWait

IMO this is probably the best solution - so that if you want the custom functionality in your other proposed solutions, you can just write it yourself.

Agreed. Here a suggestion of how it could look like.

Slightly changing the interface of waitForFinalTransactionOutcome could make it a very easy to use function. All the required information is already contained in a SubmitResponse - just pass that instead:

  • SubmitResponse.result.engine_result
  • SubmitResponse.result.tx_json.hash
  • SubmitResponse.result.tx_json.LastLedgerSequence

For easy access, possibly make waitForFinalTransactionOutcome a member function of Client.

Old:

async function waitForFinalTransactionOutcome<
  T extends BaseTransaction = Transaction,
>(
  client: Client,
  txHash: string,
  lastLedger: number,
  submissionResult: string,
): Promise<TxResponse<T>>

New:

async function waitForFinalTransactionOutcome<
  T extends BaseTransaction = Transaction,
>(
  client: Client,
  submitResponse: SubmitResponse<T>,
): Promise<TxResponse<T>>

Usage:

const submitResponse = await client.submit(...);
const txResponse = await client.waitForFinalTransactionOutcome(submitResponse);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants