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

fix(mojaloop/#2644): missing error-code for the transfer in the central-ledger db #929

92 changes: 46 additions & 46 deletions package-lock.json

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

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/central-ledger",
"version": "16.3.2",
"version": "16.3.3-snapshot.0",
"description": "Central ledger hosted by a scheme to record and settle transfers",
"license": "Apache-2.0",
"author": "ModusBox",
Expand Down Expand Up @@ -76,7 +76,7 @@
},
"dependencies": {
"@hapi/good": "9.0.1",
"@hapi/hapi": "21.0.0",
"@hapi/hapi": "21.1.0",
"@hapi/inert": "7.0.0",
"@hapi/joi": "17.1.1",
"@hapi/vision": "7.0.0",
Expand All @@ -98,7 +98,7 @@
"catbox-memory": "4.0.1",
"commander": "9.4.1",
"cron": "2.1.0",
"decimal.js": "10.4.2",
"decimal.js": "10.4.3",
"docdash": "2.0.0",
"event-stream": "4.0.1",
"five-bells-condition": "5.0.1",
Expand All @@ -119,17 +119,17 @@
},
"devDependencies": {
"async-retry": "1.3.3",
"audit-ci": "^6.3.0",
"audit-ci": "^6.4.0",
"get-port": "5.1.1",
"jsdoc": "4.0.0",
"jsonpath": "1.1.1",
"nodemon": "2.0.20",
"npm-check-updates": "16.4.3",
"npm-check-updates": "16.5.3",
"nyc": "15.1.0",
"pre-commit": "1.2.2",
"proxyquire": "2.1.3",
"replace": "^1.2.2",
"sinon": "14.0.2",
"sinon": "15.0.0",
"standard": "17.0.0",
"standard-version": "^9.5.0",
"tap-spec": "^5.0.0",
Expand Down
32 changes: 26 additions & 6 deletions src/models/transfer/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ const timeoutExpireReserved = async (segmentId, intervalMin, intervalMax) => {
const knex = await Db.getKnex()
await knex.transaction(async (trx) => {
try {
// Insert `transferTimeout` records for transfers found between the interval intervalMin <= intervalMax
await knex.from(knex.raw('transferTimeout (transferId, expirationDate)')).transacting(trx)
.insert(function () {
this.from('transfer AS t')
Expand All @@ -613,9 +614,10 @@ const timeoutExpireReserved = async (segmentId, intervalMin, intervalMax) => {
.whereNull('tt.transferId')
.whereIn('tsc.transferStateId', [`${Enum.Transfers.TransferInternalState.RECEIVED_PREPARE}`, `${Enum.Transfers.TransferState.RESERVED}`])
.select('t.transferId', 't.expirationDate')
})// .toSQL().sql
// console.log('SQL: ' + q)
}) // .toSQL().sql
// console.log('SQL: ' + q1)

// Insert `transferStateChange` records for RECEIVED_PREPARE
await knex.from(knex.raw('transferStateChange (transferId, transferStateId, reason)')).transacting(trx)
.insert(function () {
this.from('transferTimeout AS tt')
Expand All @@ -629,9 +631,10 @@ const timeoutExpireReserved = async (segmentId, intervalMin, intervalMax) => {
.where('tt.expirationDate', '<', transactionTimestamp)
.andWhere('tsc.transferStateId', `${Enum.Transfers.TransferInternalState.RECEIVED_PREPARE}`)
.select('tt.transferId', knex.raw('?', Enum.Transfers.TransferInternalState.EXPIRED_PREPARED), knex.raw('?', 'Aborted by Timeout Handler'))
})// .toSQL().sql
// console.log('SQL: ' + q)
}) // .toSQL().sql
// console.log('SQL: ' + q2)

// Insert `transferStateChange` records for RESERVED
await knex.from(knex.raw('transferStateChange (transferId, transferStateId, reason)')).transacting(trx)
.insert(function () {
this.from('transferTimeout AS tt')
Expand All @@ -645,8 +648,25 @@ const timeoutExpireReserved = async (segmentId, intervalMin, intervalMax) => {
.where('tt.expirationDate', '<', transactionTimestamp)
.andWhere('tsc.transferStateId', `${Enum.Transfers.TransferState.RESERVED}`)
.select('tt.transferId', knex.raw('?', Enum.Transfers.TransferInternalState.RESERVED_TIMEOUT), knex.raw('?', 'Marked for expiration by Timeout Handler'))
})// .toSQL().sql
// console.log('SQL: ' + q)
}) // .toSQL().sql
// console.log('SQL: ' + q3)

// Insert `transferError` records
await knex.from(knex.raw('transferError (transferId, transferStateChangeId, errorCode, errorDescription)')).transacting(trx)
.insert(function () {
this.from('transferTimeout AS tt')
.innerJoin(knex('transferStateChange AS tsc1')
.select('tsc1.transferId')
.max('tsc1.transferStateChangeId AS maxTransferStateChangeId')
.innerJoin('transferTimeout AS tt1', 'tt1.transferId', 'tsc1.transferId')
.groupBy('tsc1.transferId').as('ts'), 'ts.transferId', 'tt.transferId'
)
.innerJoin('transferStateChange AS tsc', 'tsc.transferStateChangeId', 'ts.maxTransferStateChangeId')
.where('tt.expirationDate', '<', transactionTimestamp)
.andWhere('tsc.transferStateId', `${Enum.Transfers.TransferInternalState.RESERVED_TIMEOUT}`)
.select('tt.transferId', 'tsc.transferStateChangeId', knex.raw('?', ErrorHandler.Enums.FSPIOPErrorCodes.TRANSFER_EXPIRED.code), knex.raw('?', ErrorHandler.Enums.FSPIOPErrorCodes.TRANSFER_EXPIRED.message))
}) // .toSQL().sql
// console.log('SQL: ' + q4)

if (segmentId === 0) {
const segment = {
Expand Down
Loading