@mojaloop/central-ledger 17.7.8 → 17.8.0-orb.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ncurc.yaml +3 -1
- package/.nvmrc +1 -1
- package/.nycrc.yml +16 -1
- package/Dockerfile +9 -10
- package/README.md +39 -9
- package/audit-ci.jsonc +15 -2
- package/config/default.json +17 -1
- package/docker/central-ledger/default.json +9 -0
- package/docker/config-modifier/configs/central-ledger.js +25 -0
- package/docker/env.sh +15 -0
- package/docker/kafka/scripts/provision.sh +4 -1
- package/docker/ml-api-adapter/default.json +4 -1
- package/docker-compose.yml +90 -2
- package/documentation/db/erd-transfer-timeout.png +0 -0
- package/documentation/db/erd-transfer-timeout.txt +81 -0
- package/documentation/fx-implementation/README.md +48 -0
- package/documentation/fx-implementation/assets/fx-position-movements.drawio.svg +4 -0
- package/documentation/fx-implementation/assets/test-scenario.drawio.svg +4 -0
- package/documentation/sequence-diagrams/Handler - FX timeout.plantuml +123 -0
- package/documentation/sequence-diagrams/Handler - FX timeout.png +0 -0
- package/documentation/sequence-diagrams/Handler - timeout.plantuml +81 -0
- package/documentation/sequence-diagrams/Handler - timeout.png +0 -0
- package/documentation/state-diagrams/transfer-ML-spec-states-diagram.png +0 -0
- package/documentation/state-diagrams/transfer-internal-states-diagram.png +0 -0
- package/documentation/state-diagrams/transfer-internal-states.plantuml +75 -0
- package/documentation/state-diagrams/transfer-states.plantuml +13 -0
- package/migrations/310204_transferParticipant-participantId.js +52 -0
- package/migrations/310403_participantPositionChange-participantCurrencyId.js +47 -0
- package/migrations/310404_participantPositionChange-change.js +46 -0
- package/migrations/600010_fxTransferType.js +43 -0
- package/migrations/600011_fxTransferType-indexes.js +38 -0
- package/migrations/600012_fxParticipantCurrencyType.js +43 -0
- package/migrations/600013_fxParticipantCurrencyType-indexes.js +38 -0
- package/migrations/600100_fxTransferDuplicateCheck.js +42 -0
- package/migrations/600110_fxTransferErrorDuplicateCheck.js.js +17 -0
- package/migrations/600200_fxTransfer.js +51 -0
- package/migrations/600201_fxTransfer-indexes.js +40 -0
- package/migrations/600400_fxTransferStateChange.js +46 -0
- package/migrations/600401_fxTransferStateChange-indexes.js +40 -0
- package/migrations/600501_fxWatchList.js +46 -0
- package/migrations/600502_fxWatchList-indexes.js +40 -0
- package/migrations/600600_fxTransferFulfilmentDuplicateCheck.js +43 -0
- package/migrations/600601_fxTransferFulfilmentDuplicateCheck-indexes.js +38 -0
- package/migrations/600700_fxTransferFulfilment.js +47 -0
- package/migrations/600701_fxTransferFulfilment-indexes.js +43 -0
- package/migrations/600800_fxTransferExtension.js +47 -0
- package/migrations/601400_fxTransferTimeout.js +43 -0
- package/migrations/601401_fxTransferTimeout-indexes.js +37 -0
- package/migrations/601500_fxTransferError.js +44 -0
- package/migrations/601501_fxTransferError-indexes.js +37 -0
- package/migrations/610200_fxTransferParticipant.js +52 -0
- package/migrations/610201_fxTransferParticipant-indexes.js +44 -0
- package/migrations/610202_fxTransferParticipant-participantId.js +52 -0
- package/migrations/610403_participantPositionChange-fxTransfer.js +46 -0
- package/migrations/910101_feature904DataMigration.js +46 -52
- package/migrations/910102_feature949DataMigration.js +219 -225
- package/migrations/950104_settlementModel-settlementAccountTypeId.js +15 -20
- package/migrations/950108_participantProxy.js +18 -0
- package/migrations/950109_fxQuote.js +19 -0
- package/migrations/950110_fxQuoteResponse.js +25 -0
- package/migrations/950111_fxQuoteError.js +23 -0
- package/migrations/950113_fxQuoteDuplicateCheck.js +18 -0
- package/migrations/950114_fxQuoteResponseDuplicateCheck.js +21 -0
- package/migrations/950115_fxQuoteConversionTerms.js +36 -0
- package/migrations/950116_fxQuoteConversionTermsExtension.js +21 -0
- package/migrations/950117_fxQuoteResponseConversionTerms.js +39 -0
- package/migrations/950118_fxQuoteResponseConversionTermsExtension.js +21 -0
- package/migrations/950119_fxCharge.js +27 -0
- package/migrations/960100_create_externalParticipant.js +47 -0
- package/migrations/960110_alter_transferParticipant__addFiled_externalParticipantId.js +50 -0
- package/migrations/960111_alter_fxTransferParticipant__addFiled_externalParticipantId.js +50 -0
- package/package.json +27 -20
- package/seeds/endpointType.js +18 -0
- package/seeds/fxParticipantCurrencyType.js +45 -0
- package/seeds/fxTransferType.js +45 -0
- package/seeds/participant.js +2 -1
- package/seeds/transferParticipantRoleType.js +9 -0
- package/seeds/transferState.js +10 -0
- package/src/api/interface/swagger.json +23 -30
- package/src/api/participants/handler.js +6 -2
- package/src/api/participants/routes.js +8 -7
- package/src/api/root/handler.js +15 -5
- package/src/domain/fx/cyril.js +466 -0
- package/src/domain/fx/index.js +107 -0
- package/src/domain/participant/index.js +108 -1
- package/src/domain/position/abort.js +215 -0
- package/src/domain/position/binProcessor.js +361 -99
- package/src/domain/position/fulfil.js +252 -111
- package/src/domain/position/fx-fulfil.js +138 -0
- package/src/domain/position/fx-prepare.js +280 -0
- package/src/domain/position/fx-timeout-reserved.js +159 -0
- package/src/domain/position/index.js +1 -0
- package/src/domain/position/prepare.js +69 -49
- package/src/domain/position/timeout-reserved.js +162 -0
- package/src/domain/timeout/index.js +26 -2
- package/src/domain/transfer/index.js +22 -5
- package/src/domain/transfer/transform.js +19 -6
- package/src/handlers/admin/handler.js +0 -2
- package/src/handlers/bulk/fulfil/handler.js +5 -5
- package/src/handlers/bulk/get/handler.js +5 -5
- package/src/handlers/bulk/prepare/handler.js +9 -9
- package/src/handlers/bulk/processing/handler.js +8 -7
- package/src/handlers/bulk/shared/validator.js +1 -1
- package/src/handlers/positions/handler.js +23 -10
- package/src/handlers/positions/handlerBatch.js +54 -26
- package/src/handlers/register.js +2 -1
- package/src/handlers/timeouts/handler.js +212 -68
- package/src/handlers/transfers/FxFulfilService.js +387 -0
- package/src/handlers/transfers/createRemittanceEntity.js +106 -0
- package/src/handlers/transfers/dto.js +53 -0
- package/src/handlers/transfers/handler.js +609 -571
- package/src/handlers/transfers/prepare.js +572 -0
- package/src/handlers/transfers/validator.js +75 -14
- package/src/lib/cache.js +1 -1
- package/src/lib/config.js +6 -3
- package/src/lib/healthCheck/subServiceHealth.js +12 -2
- package/src/lib/proxyCache.js +131 -0
- package/src/models/bulkTransfer/facade.js +58 -82
- package/src/models/fxTransfer/duplicateCheck.js +153 -0
- package/src/models/fxTransfer/fxTransfer.js +578 -0
- package/src/models/fxTransfer/fxTransferError.js +53 -0
- package/src/models/fxTransfer/fxTransferExtension.js +41 -0
- package/src/models/fxTransfer/fxTransferTimeout.js +68 -0
- package/src/models/fxTransfer/index.js +15 -0
- package/src/models/fxTransfer/stateChange.js +47 -0
- package/src/models/fxTransfer/watchList.js +49 -0
- package/src/models/ledgerAccountType/ledgerAccountType.js +8 -32
- package/src/models/misc/segment.js +0 -1
- package/src/models/participant/externalParticipant.js +96 -0
- package/src/models/participant/externalParticipantCached.js +148 -0
- package/src/models/participant/facade.js +192 -123
- package/src/models/participant/participant.js +2 -1
- package/src/models/participant/participantCurrency.js +1 -1
- package/src/models/participant/participantPosition.js +2 -8
- package/src/models/position/batch.js +90 -1
- package/src/models/position/facade.js +5 -5
- package/src/models/position/participantPositionChanges.js +68 -0
- package/src/models/settlement/settlementModel.js +5 -23
- package/src/models/transfer/facade.js +806 -447
- package/src/shared/constants.js +52 -0
- package/src/shared/fspiopErrorFactory.js +131 -0
- package/src/shared/logger/index.js +8 -0
- package/src/shared/loggingPlugin.js +43 -0
- package/src/shared/plugins.js +6 -0
- package/src/shared/setup.js +10 -0
- package/test-integration.Dockerfile +1 -1
- package/test.Dockerfile +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*****
|
|
2
|
+
License
|
|
3
|
+
--------------
|
|
4
|
+
Copyright © 2017 Bill & Melinda Gates Foundation
|
|
5
|
+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
8
|
+
Contributors
|
|
9
|
+
--------------
|
|
10
|
+
This is the official list of the Mojaloop project contributors for this file.
|
|
11
|
+
Names of the original copyright holders (individuals or organizations)
|
|
12
|
+
should be listed with a '*' in the first column. People who have
|
|
13
|
+
contributed from an organization can be listed under the organization
|
|
14
|
+
that actually holds the copyright for their contributions (see the
|
|
15
|
+
Gates Foundation organization for an example). Those individuals should have
|
|
16
|
+
their names indented and be marked with a '-'. Email address can be added
|
|
17
|
+
optionally within square brackets <email>.
|
|
18
|
+
* Gates Foundation
|
|
19
|
+
- Name Surname <name.surname@gatesfoundation.com>
|
|
20
|
+
|
|
21
|
+
* Vijaya Kumar Guthi <vijaya.guthi@infitx.com>
|
|
22
|
+
--------------
|
|
23
|
+
******/
|
|
24
|
+
|
|
25
|
+
'use strict'
|
|
26
|
+
|
|
27
|
+
const Db = require('../../lib/db')
|
|
28
|
+
const Logger = require('@mojaloop/central-services-logger')
|
|
29
|
+
const Enum = require('@mojaloop/central-services-shared').Enum
|
|
30
|
+
|
|
31
|
+
const getReservedPositionChangesByCommitRequestId = async (commitRequestId) => {
|
|
32
|
+
try {
|
|
33
|
+
const knex = await Db.getKnex()
|
|
34
|
+
const participantPositionChanges = await knex('fxTransferStateChange')
|
|
35
|
+
.where('fxTransferStateChange.commitRequestId', commitRequestId)
|
|
36
|
+
.where('fxTransferStateChange.transferStateId', Enum.Transfers.TransferInternalState.RESERVED)
|
|
37
|
+
.innerJoin('participantPositionChange AS ppc', 'ppc.fxTransferStateChangeId', 'fxTransferStateChange.fxTransferStateChangeId')
|
|
38
|
+
.select(
|
|
39
|
+
'ppc.*'
|
|
40
|
+
)
|
|
41
|
+
return participantPositionChanges
|
|
42
|
+
} catch (err) {
|
|
43
|
+
Logger.isErrorEnabled && Logger.error(err)
|
|
44
|
+
throw err
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const getReservedPositionChangesByTransferId = async (transferId) => {
|
|
49
|
+
try {
|
|
50
|
+
const knex = await Db.getKnex()
|
|
51
|
+
const participantPositionChanges = await knex('transferStateChange')
|
|
52
|
+
.where('transferStateChange.transferId', transferId)
|
|
53
|
+
.where('transferStateChange.transferStateId', Enum.Transfers.TransferInternalState.RESERVED)
|
|
54
|
+
.innerJoin('participantPositionChange AS ppc', 'ppc.transferStateChangeId', 'transferStateChange.transferStateChangeId')
|
|
55
|
+
.select(
|
|
56
|
+
'ppc.*'
|
|
57
|
+
)
|
|
58
|
+
return participantPositionChanges
|
|
59
|
+
} catch (err) {
|
|
60
|
+
Logger.isErrorEnabled && Logger.error(err)
|
|
61
|
+
throw err
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
getReservedPositionChangesByCommitRequestId,
|
|
67
|
+
getReservedPositionChangesByTransferId
|
|
68
|
+
}
|
|
@@ -32,7 +32,7 @@ const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
|
|
32
32
|
exports.create = async (name, isActive, settlementGranularityId, settlementInterchangeId, settlementDelayId, currencyId, requireLiquidityCheck, ledgerAccountTypeId, settlementAccountTypeId, autoPositionReset, trx = null) => {
|
|
33
33
|
try {
|
|
34
34
|
const knex = Db.getKnex()
|
|
35
|
-
const trxFunction = async (trx
|
|
35
|
+
const trxFunction = async (trx) => {
|
|
36
36
|
try {
|
|
37
37
|
await knex('settlementModel')
|
|
38
38
|
.insert({
|
|
@@ -48,18 +48,12 @@ exports.create = async (name, isActive, settlementGranularityId, settlementInter
|
|
|
48
48
|
autoPositionReset
|
|
49
49
|
})
|
|
50
50
|
.transacting(trx)
|
|
51
|
-
if (doCommit) {
|
|
52
|
-
await trx.commit
|
|
53
|
-
}
|
|
54
51
|
} catch (err) {
|
|
55
|
-
if (doCommit) {
|
|
56
|
-
await trx.rollback
|
|
57
|
-
}
|
|
58
52
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
59
53
|
}
|
|
60
54
|
}
|
|
61
55
|
if (trx) {
|
|
62
|
-
return trxFunction(trx
|
|
56
|
+
return trxFunction(trx)
|
|
63
57
|
} else {
|
|
64
58
|
return knex.transaction(trxFunction)
|
|
65
59
|
}
|
|
@@ -77,19 +71,13 @@ exports.getByName = async (name, trx = null) => {
|
|
|
77
71
|
.select()
|
|
78
72
|
.where('name', name)
|
|
79
73
|
.transacting(trx)
|
|
80
|
-
if (doCommit) {
|
|
81
|
-
await trx.commit
|
|
82
|
-
}
|
|
83
74
|
return result.length > 0 ? result[0] : null
|
|
84
75
|
} catch (err) {
|
|
85
|
-
if (doCommit) {
|
|
86
|
-
await trx.rollback
|
|
87
|
-
}
|
|
88
76
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
89
77
|
}
|
|
90
78
|
}
|
|
91
79
|
if (trx) {
|
|
92
|
-
return trxFunction(trx
|
|
80
|
+
return trxFunction(trx)
|
|
93
81
|
} else {
|
|
94
82
|
return knex.transaction(trxFunction)
|
|
95
83
|
}
|
|
@@ -116,25 +104,19 @@ exports.update = async (settlementModel, isActive) => {
|
|
|
116
104
|
exports.getSettlementModelsByName = async (names, trx = null) => {
|
|
117
105
|
try {
|
|
118
106
|
const knex = Db.getKnex()
|
|
119
|
-
const trxFunction = async (trx
|
|
107
|
+
const trxFunction = async (trx) => {
|
|
120
108
|
try {
|
|
121
109
|
const settlementModelNames = knex('settlementModel')
|
|
122
110
|
.select('name')
|
|
123
111
|
.whereIn('name', names)
|
|
124
112
|
.transacting(trx)
|
|
125
|
-
if (doCommit) {
|
|
126
|
-
await trx.commit
|
|
127
|
-
}
|
|
128
113
|
return settlementModelNames
|
|
129
114
|
} catch (err) {
|
|
130
|
-
if (doCommit) {
|
|
131
|
-
await trx.rollback
|
|
132
|
-
}
|
|
133
115
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
|
134
116
|
}
|
|
135
117
|
}
|
|
136
118
|
if (trx) {
|
|
137
|
-
return trxFunction(trx
|
|
119
|
+
return trxFunction(trx)
|
|
138
120
|
} else {
|
|
139
121
|
return knex.transaction(trxFunction)
|
|
140
122
|
}
|