-
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
663/mk/use open payments client #706
Conversation
This reverts commit e11ec65.
@@ -0,0 +1,217 @@ | |||
import { IocContract } from '@adonisjs/fold' |
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.
This test looks quite a lot different that the previous OpenPaymentsClientService one, there are some duplicated code but IMO more straightforward
const clientGetIncomingPaymentSpy = jest | ||
.spyOn(openPaymentsClient.incomingPayment, 'get') | ||
.mockImplementationOnce(async () => | ||
incomingPayment.toOpenPaymentsType({ | ||
ilpStreamConnection: connectionService.get(incomingPayment) | ||
}) | ||
) |
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.
Instead of using nock
here, I just stub out the return value of the openPaymentsClient call
interface OpenPaymentsConnectionWithIlpAddress | ||
extends Omit<OpenPaymentsConnection, 'ilpAddress'> { | ||
ilpAddress: IlpAddress | ||
} |
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.
Unfourtunately need this because the base constructor needs to have ilpAddress: IlpAddress
instead of a string
. Using static fromOpenPaymentsConnection
as a wrapper for the constructor, since we can return undefined
from it directly
) {} | ||
} | ||
|
||
export class Connection extends ConnectionBase { |
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.
Moved to its own model.ts
file
const paymentPointer = await createPaymentPointer(deps) | ||
const incomingPayment = await createIncomingPayment(deps, { | ||
paymentPointerId: paymentPointer.id | ||
}) |
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 should be able to just stub out the instances here instead of actually hitting the services/dbs for example, but that is for a future improvement
I merged off of an earlier branch (which is now merged in), hence the many commits |
@@ -112,6 +114,10 @@ export function initIocContainer( | |||
const config = await deps.use('config') | |||
return await createOpenAPI(config.authServerSpec) | |||
}) | |||
container.singleton('openPaymentsClient', async (deps) => { | |||
const logger = await deps.use('logger') | |||
return createOpenPaymentsClient({ logger }) |
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.
Depending on how #722 shapes up, this might also take config.privateKey
+ a key id
import { ILPStreamConnection } from 'open-payments' | ||
import { IncomingPayment } from '../payment/incoming/model' | ||
|
||
export type ConnectionJSON = { |
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.
Doesn't necessarily have to happen in this pr, but I think the routes should use generated types from open-payments
incomingAmount: this.incomingAmount | ||
? { | ||
...this.incomingAmount, | ||
value: this.incomingAmount.value.toString() | ||
} | ||
: undefined, | ||
receivedAmount: { | ||
...this.receivedAmount, | ||
value: this.receivedAmount.value.toString() | ||
}, |
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.
incomingAmount: this.incomingAmount | |
? { | |
...this.incomingAmount, | |
value: this.incomingAmount.value.toString() | |
} | |
: undefined, | |
receivedAmount: { | |
...this.receivedAmount, | |
value: this.receivedAmount.value.toString() | |
}, | |
incomingAmount: this.incomingAmount | |
? serializeAmount(this.incomingAmount) | |
: undefined, | |
receivedAmount: serializeAmount(this.receivedAmount), |
and change AmountJSON
to an open-payments
generated type?
rafiki/packages/backend/src/open_payments/amount.ts
Lines 21 to 27 in 8898075
export function serializeAmount(amount: Amount): AmountJSON { | |
return { | |
value: amount.value.toString(), | |
assetCode: amount.assetCode, | |
assetScale: amount.assetScale | |
} | |
} |
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 will incorporate serializeAmount
but will hold off removing AmountJSON
, as it will balloon this PR a bit. Removing TypeJSON
from the whole package can come as a separate/standalone PR
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 keep having to remind myself that you've managed to avoid changing open-payments
at all in this pr.
Changes proposed in this pull request
open-payments
package to make remote open-payments server calls when trying to find a receiver of a payment, either through anincoming-payment
or aconnection
. This basically incrorporates the client into the existing flow thatOpenPaymentsClientService
had for fetching the remote open-payments resources. SinceOpenPaymentsClientService
will no longer be used in the way that its name suggests, it's been renamed toReceiver
service, which is an abstraction of an OpenPayments incoming-payment or connection..toOpenPaymentsType
method, that enables entities to go from the domain model to an OpenPayments type, the type that comes from the open api spec type generation in theopen-payments
package.Context
Progress toward #663, and roadmap item interledger/roadmap#20
Checklist
fixes #number