Skip to content

Commit

Permalink
Revert "feat(backend): support single phase transfer in connector (#2564
Browse files Browse the repository at this point in the history
)"

This reverts commit 81f8a05.
  • Loading branch information
mkurapov committed Apr 3, 2024
1 parent 2ac2468 commit 67bf304
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export function createBalanceMiddleware(): ILPMiddleware {
}

// Update balances on prepare
const createTransfer = async (
timeout?: number
): Promise<Transaction | undefined> => {
const createPendingTransfer = async (): Promise<
Transaction | undefined
> => {
const trxOrError = await services.accounting.createTransfer({
sourceAccount: accounts.incoming,
destinationAccount: accounts.outgoing,
sourceAmount,
destinationAmount: destinationAmountOrError,
timeout: timeout || 0
timeout: 5
})

if (isTransferError(trxOrError)) {
Expand All @@ -75,11 +75,15 @@ export function createBalanceMiddleware(): ILPMiddleware {

if (state.streamDestination) {
await next()
if (response.fulfill) await createTransfer()
} else {
const trx = await createTransfer(5)
}

await next()
if (!state.streamDestination || response.fulfill) {
// TODO: make this single-phase if streamDestination === true
const trx = await createPendingTransfer()

if (!state.streamDestination) {
await next()
}

if (trx) {
if (response.fulfill) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,6 @@ describe('Balance Middleware', function () {
expect(prepare.amount).toEqual(destinationAmount.toString())
})

test.each`
streamDestination | description
${true} | ${'single phase transfer'}
${false} | ${'two phase transfer'}
`(
'creates $description if state.streamDestination $streamDestination',
async ({ streamDestination }): Promise<void> => {
const prepare = IlpPrepareFactory.build({ amount: '100' })
const fulfill = IlpFulfillFactory.build()
ctx.request.prepare = new ZeroCopyIlpPrepare(prepare)
ctx.state.streamDestination = streamDestination ? 'here' : undefined
const spy = jest.spyOn(accounting, 'createTransfer')
const next = jest.fn().mockImplementation(() => {
ctx.response.fulfill = fulfill
})
await expect(middleware(ctx, next)).resolves.toBeUndefined()
expect(spy).toHaveBeenCalledWith({
destinationAccount: expect.anything(),
destinationAmount: expect.anything(),
sourceAccount: expect.anything(),
sourceAmount: expect.anything(),
timeout: streamDestination ? 0 : 5
})
}
)

test.each`
amount | state | error | createTransfer | description
${'100'} | ${{}} | ${undefined} | ${true} | ${'reject response does not adjust the account balances'}
Expand Down

0 comments on commit 67bf304

Please sign in to comment.