Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sanducb committed Dec 28, 2024
1 parent 8dd4ebd commit 2194e97
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 8 deletions.
4 changes: 4 additions & 0 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.alterTable('outgoingPayments', function (table) {
table.uuid('tenantId').notNullable()
table.foreign('tenantId').references('tenants.id').onDelete('CASCADE')
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.alterTable('outgoingPayments', function (table) {
table.dropForeign('tenantId')
table.dropColumn('tenantId')
})
}
32 changes: 32 additions & 0 deletions packages/backend/src/graphql/generated/graphql.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/backend/src/graphql/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/backend/src/graphql/resolvers/liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export const depositEventLiquidity: MutationResolvers<ApolloContext>['depositEve
)
const paymentOrErr = await outgoingPaymentService.fund({
id: event.data.id,
tenantId: args.input.tenantId,
amount: BigInt(event.data.debitAmount.value),
transferId: event.id
})
Expand Down Expand Up @@ -478,6 +479,7 @@ export const depositOutgoingPaymentLiquidity: MutationResolvers<ApolloContext>['
})
const paymentOrErr = await outgoingPaymentService.fund({
id: outgoingPaymentId,
tenantId: args.input.tenantId,
amount: BigInt(event.data.debitAmount.value),
transferId: event.id
})
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ input VoidLiquidityWithdrawalInput {
input DepositOutgoingPaymentLiquidityInput {
"Unique identifier of the outgoing payment to deposit liquidity into."
outgoingPaymentId: String!
"Unique identifier of the tenant under which the quote was created."
tenantId: String!
"Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)."
idempotencyKey: String!
}
Expand All @@ -552,6 +554,8 @@ input CreateOutgoingPaymentWithdrawalInput {
input DepositEventLiquidityInput {
"Unique identifier of the event to deposit liquidity into."
eventId: String!
"Unique identifier of the tenant under which the quote was created."
tenantId: String!
"Unique key to ensure duplicate or retried requests are processed only once. For more information, refer to [idempotency](https://rafiki.dev/apis/graphql/admin-api-overview/#idempotency)."
idempotencyKey: String!
}
Expand Down
11 changes: 11 additions & 0 deletions packages/backend/src/open_payments/payment/outgoing/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
OutgoingPayment as OpenPaymentsOutgoingPayment,
OutgoingPaymentWithSpentAmounts
} from '@interledger/open-payments'
import { Tenant } from '../../../tenants/model'

export class OutgoingPaymentGrant extends DbErrors(Model) {
public static get modelPaths(): string[] {
Expand Down Expand Up @@ -125,6 +126,8 @@ export class OutgoingPayment
// Outgoing peer
public peerId?: string

public tenantId!: string

static get relationMappings() {
return {
...super.relationMappings,
Expand All @@ -135,6 +138,14 @@ export class OutgoingPayment
from: 'outgoingPayments.id',
to: 'quotes.id'
}
},
tenant: {
relation: Model.BelongsToOneRelation,
modelClass: Tenant,
join: {
from: 'outgoingPayments.tenantId',
to: 'tenants.id'
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ describe('OutgoingPaymentService', (): void => {
).resolves.toEqual(payment)
await expect(
outgoingPaymentService.fund({
tenantId,
id: payment.id,
amount: payment.debitAmount.value,
transferId: uuid()
Expand Down Expand Up @@ -538,6 +539,7 @@ describe('OutgoingPaymentService', (): void => {
await expect(
outgoingPaymentService.fund({
id: payment.id,
tenantId,
amount: payment.debitAmount.value,
transferId: uuid()
})
Expand Down Expand Up @@ -1336,6 +1338,7 @@ describe('OutgoingPaymentService', (): void => {
await expect(
outgoingPaymentService.fund({
id: payment.id,
tenantId,
amount: payment.debitAmount.value,
transferId: uuid()
})
Expand Down Expand Up @@ -1842,6 +1845,7 @@ describe('OutgoingPaymentService', (): void => {
await expect(
outgoingPaymentService.fund({
id: uuid(),
tenantId,
amount: quoteAmount,
transferId: uuid()
})
Expand All @@ -1852,6 +1856,7 @@ describe('OutgoingPaymentService', (): void => {
await expect(
outgoingPaymentService.fund({
id: payment.id,
tenantId,
amount: quoteAmount,
transferId: uuid()
})
Expand All @@ -1871,6 +1876,7 @@ describe('OutgoingPaymentService', (): void => {
await expect(
outgoingPaymentService.fund({
id: payment.id,
tenantId,
amount: quoteAmount - BigInt(1),
transferId: uuid()
})
Expand All @@ -1890,6 +1896,7 @@ describe('OutgoingPaymentService', (): void => {
await expect(
outgoingPaymentService.fund({
id: payment.id,
tenantId,
amount: quoteAmount,
transferId: uuid()
})
Expand Down
24 changes: 17 additions & 7 deletions packages/backend/src/open_payments/payment/outgoing/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,20 @@ export function isCreateFromIncomingPayment(
): options is CreateFromIncomingPayment {
return 'incomingPayment' in options && 'debitAmount' in options
}
//TODO use tenantId in outgoing payment changes

async function cancelOutgoingPayment(
deps: ServiceDependencies,
options: CancelOutgoingPaymentOptions
): Promise<OutgoingPayment | OutgoingPaymentError> {
const { id } = options
const { id, tenantId } = options

return deps.knex.transaction(async (trx) => {
let payment = await OutgoingPayment.query(trx).findById(id).forUpdate()
let payment = await OutgoingPayment.query(trx)
.findOne({
id,
tenantId
})
.forUpdate()

if (!payment) return OutgoingPaymentError.UnknownPayment
if (payment.state !== OutgoingPaymentState.Funding) {
Expand Down Expand Up @@ -247,7 +252,7 @@ async function createOutgoingPayment(
description: 'Time to create an outgoing payment'
}
)
const { walletAddressId } = options
const { walletAddressId, tenantId } = options
let quoteId: string

if (isCreateFromIncomingPayment(options)) {
Expand All @@ -260,7 +265,7 @@ async function createOutgoingPayment(
)
const { debitAmount, incomingPayment } = options
const quoteOrError = await deps.quoteService.create({
tenantId: options.tenantId,
tenantId,
receiver: incomingPayment,
debitAmount,
method: 'ilp',
Expand Down Expand Up @@ -321,6 +326,7 @@ async function createOutgoingPayment(
const payment = await OutgoingPayment.query(trx)
.insertAndFetch({
id: quoteId,
tenantId,
walletAddressId: walletAddressId,
client: options.client,
metadata: options.metadata,
Expand Down Expand Up @@ -626,17 +632,21 @@ async function validateGrantAndAddSpentAmountsToPayment(

export interface FundOutgoingPaymentOptions {
id: string
tenantId: string
amount: bigint
transferId: string
}

async function fundPayment(
deps: ServiceDependencies,
{ id, amount, transferId }: FundOutgoingPaymentOptions
{ id, tenantId, amount, transferId }: FundOutgoingPaymentOptions
): Promise<OutgoingPayment | FundingError> {
return await deps.knex.transaction(async (trx) => {
const payment = await OutgoingPayment.query(trx)
.findById(id)
.findOne({
id,
tenantId
})
.forUpdate()
.withGraphFetched('quote')
if (!payment) return FundingError.UnknownPayment
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/tests/outgoingPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export async function createOutgoingPaymentWithReceiver(
)

const outgoingPayment = await createOutgoingPayment(deps, {
//TODO fix this in outgoing payments changes
//TODO get this from WA
tenantId: args.quoteOptions?.tenantId || uuid(),
walletAddressId: args.sendingWalletAddress.id,
method: args.method,
Expand All @@ -143,6 +143,8 @@ export async function createOutgoingPaymentWithReceiver(
const outgoingPaymentService = await deps.use('outgoingPaymentService')
await outgoingPaymentService.fund({
id: outgoingPayment.id,
//TODO
tenantId: '',
amount: outgoingPayment.debitAmount.value,
transferId: uuid()
})
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/app/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/mock-account-service-lib/src/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/integration/lib/generated/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2194e97

Please sign in to comment.