-
Notifications
You must be signed in to change notification settings - Fork 89
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
chore(backend): remove wallet address middleware #2708
Conversation
…-middleware # Conflicts: # packages/backend/src/open_payments/wallet_address/model.test.ts # packages/backend/src/payment-method/ilp/spsp/middleware.test.ts # packages/backend/src/payment-method/ilp/spsp/middleware.ts
…-middleware # Conflicts: # packages/backend/src/open_payments/wallet_address/model.test.ts # packages/backend/src/payment-method/ilp/spsp/middleware.test.ts # packages/backend/src/payment-method/ilp/spsp/middleware.ts
@@ -181,12 +188,13 @@ async function getWalletAddress( | |||
|
|||
async function getOrPollByUrl( | |||
deps: ServiceDependencies, | |||
url: string | |||
url: string, | |||
options: GetOrPollByUrlOptions = { mustBeActive: true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we primarily use this method when resolving the wallet address in Open Payments routes, we should expect it to always be active
const incomingPaymentService = await ctx.container.use( | ||
'incomingPaymentService' | ||
) | ||
const incomingPayment = await incomingPaymentService.get({ | ||
id: ctx.params.id | ||
}) | ||
|
||
if (!incomingPayment?.walletAddress) { | ||
throw new OpenPaymentsServerRouteError(401, 'Unauthorized', { | ||
description: 'Failed to get wallet address from incoming payment', | ||
id: ctx.params.id | ||
}) | ||
} | ||
|
||
ctx.walletAddressUrl = incomingPayment.walletAddress.url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not get a specific wallet address in the following OP requests (either in the query params or request body):
GET /incoming-payments/:id
GET /outgoing-payments/:id
GET /quotes/:id
POST /incoming-payments/:id/complete
We need the walletAddressUrl
in order to pass down into createTokenIntrospectionMiddleware
, as the middleware needs to determine whether the possible identifier
on the grant matches up to the resource for the particular wallet address.
This is why we still need to get the resource first, before we can proceed with handling the request. The status quo is returning a 401/Unauthorized response code (to not give away information about whether resource exists or not). Maybe this should be 400, but I don't have a strong opinion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to add tests for this, but I would need to do some work about splitting apart these in-line middlewares into separate functions. I can handle it in a separate PR where I do a little more refactoring, since I don't want to balloon this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the following:
GET /incoming-payments/:id
GET /outgoing-payments/:id
GET /quotes/:id
we could just store these on ctx.state
and not have to call the <resource>Routes.get
/fetch the resource from the DB again, but a) could be done in separate PR, or b) not worth doing at all for the consistency of having the routes as they are
@@ -100,9 +102,18 @@ async function createOutgoingPayment( | |||
deps: ServiceDependencies, | |||
ctx: CreateContext<CreateBody> | |||
): Promise<void> { | |||
const walletAddress = await deps.walletAddressService.getOrPollByUrl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still want to poll here? Typically, the polling probably necessary only on the receiving side, i.e. incoming payment creation only. (since that is the most likely place where we would need to allow the ASE to make a request to their backend to create the corresponding wallet addresses)
const walletAddress = await walletAddressService.getByUrl( | ||
const walletAddress = await walletAddressService.getOrPollByUrl( | ||
ctx.walletAddressUrl | ||
) | ||
|
||
if (!walletAddress?.isActive) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already handled in getOrPollByUrl
by default. However, this comment still stands: https://github.com/interledger/rafiki/pull/2708/files#r1592829255
# Conflicts: # packages/backend/src/open_payments/wallet_address/model.test.ts # packages/backend/src/payment-method/ilp/spsp/middleware.test.ts # packages/backend/src/payment-method/ilp/spsp/middleware.ts
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
@@ -107,27 +107,4 @@ describe('SPSP Middleware', (): void => { | |||
expect(spspGetRouteSpy).not.toHaveBeenCalled() | |||
} | |||
}) | |||
|
|||
test('throws error if inactive wallet address', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already handled: https://github.com/interledger/rafiki/pull/2708/files#r1592830278
@@ -20,14 +20,12 @@ export function parsePaginationQueryParameters({ | |||
type GetPageInfoArgs<T extends BaseModel> = { | |||
getPage: (pagination: Pagination, sortOrder?: SortOrder) => Promise<T[]> | |||
page: T[] | |||
walletAddress?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was unused
Changes proposed in this pull request
To finalize the standardization of Open Payments route errors in
backend
, this PR removeswalletAddressMiddleware
.The benefits:
openPaymentsServerErrorMiddleware
(i.e. we don't usectx.throw
at all in other places)walletAddressUrl
is determined as an inline-middleware per route, meaning the complex logicwalletAddressMiddleware
can be removedwalletAddressService.getOrPollByUrl
or justgetByUrl
)Context
Completion of
backend
changes for #1905Checklist
fixes #number