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

Aliter: Implement DeliverMax alias in Payment transactions, through autofill method #2689

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ckeshava
Copy link
Collaborator

@ckeshava ckeshava commented May 3, 2024

High Level Overview of Change

This is an alternative solution for the DeliverMax alias, inspired from this discussion: #2684 (comment)

Note: Only one of these two PRs must be merged.

Both the PRs seek to achieve the same objectives, albeit through different means.

Context of Change

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

Did you update HISTORY.md?

  • Yes
  • No, this change does not impact library users

Test Plan

Added unit tests

@@ -46,6 +47,121 @@ describe('client.autofill', function () {
})
afterEach(async () => teardownClient(testContext))

it('Validate Payment transaction v2 API: Payment Transaction: Specify Only Amount field', async function () {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My conundrum: this unit test fails:

it('Validate Payment transaction v2 API: Payment Transaction: lack of DeliverMax and Amount fields', async function () {
    const amount_ = '1234'
    const deliverMax_ = '5678'
    const paytxn = {
      TransactionType: 'Payment',
      Account: 'rUn84CUYbNjRoTQ6mSW7BVJPSVJNLb1QLo',
      Destination: 'rfkE1aSy9G8Upk4JssnwBxhEv5p4mn2KTy',
      DestinationTag: 1,
      Fee: '12',
      Flags: 2147483648,
      LastLedgerSequence: 65953073,
      Sequence: 65923914,
      SigningPubKey:
        '02F9E33F16DF9507705EC954E3F94EB5F10D1FC4A354606DBE6297DBB1096FE654',
      TxnSignature:
        '3045022100E3FAE0EDEC3D6A8FF6D81BC9CF8288A61B7EEDE8071E90FF9314CB4621058D10022043545CF631706D700CEE65A1DB83EFDD185413808292D9D90F14D87D3DC2D8CB',
      InvoiceID:
        '6F1DFD1D0FE8A32E40E1F2C05CF1C15545BAB56B617F9C6C2D63A6B704BEF59B',
      Paths: [
        [{ currency: 'BTC', issuer: 'r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X' }],
      ],
      SendMax: '100000000',
    } as any

    # this error is never thrown
    await assertRejects(testContext.client.autofill(paytxn), XrplError)
  })

My code change did not affect the behavior of this unit test. But the lack of Amount or DeliverMax field is something that a client library should catch.

This probably needs to be tackled in a separate PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see why it should fail here - that's checked in validate, which is checked at signing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah, that was my confusion. I thought this validation happened in autofill too, my bad

@ckeshava
Copy link
Collaborator Author

ckeshava commented May 3, 2024

Do you guys have any ideas for complying with lint errors? For instance:

error    Unsafe member access .DeliverMax on an `any` value                                @typescript-eslint/no-unsafe-member-access

error    Unsafe return of type `Promise<any>` from function with return type `Promise<T>`  @typescript-eslint/no-unsafe-return

@ckeshava
Copy link
Collaborator Author

ckeshava commented May 8, 2024

@mvadari Do you have any workarounds for the lint errors? type-erasure does not seem to sit well with the linter.

@mvadari
Copy link
Collaborator

mvadari commented May 8, 2024

@mvadari Do you have any workarounds for the lint errors? type-erasure does not seem to sit well with the linter.

Feel free to disable the linter error for that line.

@ckeshava
Copy link
Collaborator Author

ckeshava commented May 9, 2024

thanks, I've fixed the linter errors and warnings. I didn't realize that I could ignore the errors and get away with it haha

I think it's safe to ignore the linter errors because, a malformed input is sure to through an error in signing or serialization steps.

@ckeshava ckeshava requested a review from justinr1234 June 4, 2024 22:06
@@ -666,7 +667,57 @@ class Client extends EventEmitter<EventTypes> {
promises.push(checkAccountDeleteBlockers(this, tx))
}

return Promise.all(promises).then(() => tx)
// further manipulation of tx_ uses non-SubmittableTransaction types, hence we need a typecast to any
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you have ideas for implementing this in a more clean fashion (fewer eslint-disable commands), please let me know

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

2 participants