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

feat: add submit and wait for transaction submission #528

Merged
merged 43 commits into from
May 11, 2023

Conversation

pdp2121
Copy link
Collaborator

@pdp2121 pdp2121 commented Feb 24, 2023

High Level Overview of Change

Currently, user has to call 2 functions (autofill_and_sign and send_reliable_submission) in order to sign, autofill, submit and verifies that the transaction has been included in a validated ledger. This PR would simplify the workflow to a single call (submit_and_wait) similar to xrpl.js (the old workflow would still work so it is not a breaking change). Tests and snippets are also fixed to use the new method.

Couple of other improvements:

  • Support transaction blob as input
  • Support fail_hard
  • Support is_signed checks for multi-sign transaction

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Copy link

@mworks-proj mworks-proj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this commit, refining the auto fill and sign step into submit_and_wait.

@pdp2121 pdp2121 requested a review from mvadari March 1, 2023 17:13
@pdp2121 pdp2121 marked this pull request as draft March 1, 2023 23:07
@pdp2121 pdp2121 marked this pull request as ready for review March 2, 2023 23:29
@pdp2121 pdp2121 requested a review from JST5000 March 9, 2023 19:58
snippets/multisign.py Outdated Show resolved Hide resolved
pdp2121 and others added 4 commits May 5, 2023 15:45
Co-authored-by: Jackson Mills <aim4math@gmail.com>
Co-authored-by: Jackson Mills <aim4math@gmail.com>
payment_transaction, WALLET, client
)
await accept_ledger_async(delay=1)
payment_transaction_signed_blob = encode(payment_transaction_signed.to_xrpl())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perhaps a separate ticket, but encode(tx.to_xrpl()) feels like a good helper function on the Transaction object (something like tx.blob()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added the helper function for this ticket.

@pdp2121 pdp2121 requested review from JST5000 and mvadari May 10, 2023 22:31
Comment on lines 145 to 151
if transaction.is_signed():
return transaction

if not wallet:
raise XRPLException(
"Wallet must be provided when submitting an unsigned transaction"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd recommend including the else even though it's not strictly necessary because the logic relies on that return to make sense. Each time I've reviewed the PR it's taken me a minute or two to remember why it's guaranteed that at this point the transaction MUST require a signature, and I think adding this else would clarify that.

Suggested change
if transaction.is_signed():
return transaction
if not wallet:
raise XRPLException(
"Wallet must be provided when submitting an unsigned transaction"
)
if transaction.is_signed():
return transaction
else:
if not wallet:
raise XRPLException(
"Wallet must be provided when submitting an unsigned transaction"
)

Copy link
Collaborator Author

@pdp2121 pdp2121 May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a comment saying "Attempts to validate fee, autofill, and sign the transaction when unsigned" would suffice. The return statement already tells that we only proceed to the remaining steps for unsigned transaction and I would prefer not to have many conditional layers in the code. Other functions also add comments when if/else clarification is needed.

signed_transaction = await _get_signed_tx(
transaction, client, wallet, check_fee, autofill
)
return await send_reliable_submission(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for later: If we make send_reliable_submission deprecated, we should move that logic into this function, or a helper.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, we can mention that in the deprecate ticket.

Copy link
Collaborator

@JST5000 JST5000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - couple nitpicks but logic looks solid as far as I can tell :)

@pdp2121 pdp2121 merged commit 9ac4b31 into XRPLF:master May 11, 2023
12 checks passed
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

Successfully merging this pull request may close these issues.

None yet

4 participants