mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
introduce tx-switch for local and x-com sendcoins
This commit is contained in:
parent
f726b9b564
commit
32496a0353
@ -27,6 +27,7 @@ import {
|
||||
sendTransactionReceivedEmail,
|
||||
} from '@/emails/sendEmailVariants'
|
||||
import { EVENT_TRANSACTION_RECEIVE, EVENT_TRANSACTION_SEND } from '@/event/Events'
|
||||
import { SendCoinsResult } from '@/federation/client/1_0/model/SendCoinsResult'
|
||||
import { Context, getUser } from '@/server/context'
|
||||
import { LogError } from '@/server/LogError'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
@ -41,10 +42,12 @@ import { isCommunityAuthenticated, isHomeCommunity } from './util/communities'
|
||||
import { findUserByIdentifier } from './util/findUserByIdentifier'
|
||||
import { getLastTransaction } from './util/getLastTransaction'
|
||||
import { getTransactionList } from './util/getTransactionList'
|
||||
import { processXComCommittingSendCoins, processXComPendingSendCoins } from './util/processXComSendCoins'
|
||||
import {
|
||||
processXComCommittingSendCoins,
|
||||
processXComPendingSendCoins,
|
||||
} from './util/processXComSendCoins'
|
||||
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
|
||||
import { transactionLinkSummary } from './util/transactionLinkSummary'
|
||||
import { SendCoinsResult } from '@/federation/client/1_0/model/SendCoinsResult'
|
||||
|
||||
export const executeTransaction = async (
|
||||
amount: Decimal,
|
||||
@ -537,7 +540,7 @@ export class TransactionResolver {
|
||||
where: { communityUuid: recipientCommunityIdentifier },
|
||||
})
|
||||
let pendingResult: SendCoinsResult
|
||||
let commitingResult: SendCoinsResult
|
||||
let committingResult: SendCoinsResult
|
||||
const creationDate = new Date()
|
||||
|
||||
try {
|
||||
@ -550,8 +553,8 @@ export class TransactionResolver {
|
||||
senderUser,
|
||||
recipientIdentifier,
|
||||
)
|
||||
if(pendingResult.vote && pendingResult.recipGradidoID) {
|
||||
commitingResult = await processXComCommittingSendCoins(
|
||||
if (pendingResult.vote && pendingResult.recipGradidoID) {
|
||||
committingResult = await processXComCommittingSendCoins(
|
||||
recipCom,
|
||||
homeCom,
|
||||
creationDate,
|
||||
@ -560,12 +563,26 @@ export class TransactionResolver {
|
||||
senderUser,
|
||||
pendingResult.recipGradidoID,
|
||||
)
|
||||
if(!commitingResult.vote) {
|
||||
|
||||
if (!committingResult.vote) {
|
||||
logger.fatal('FATAL ERROR: on processXComCommittingSendCoins for', committingResult)
|
||||
throw new LogError(
|
||||
'FATAL ERROR: on processXComCommittingSendCoins with ',
|
||||
recipientCommunityIdentifier,
|
||||
recipientIdentifier,
|
||||
amount.toString(),
|
||||
memo,
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
throw new LogError(
|
||||
'ERROR: on processXComCommittingSendCoins with ',
|
||||
recipientCommunityIdentifier,
|
||||
recipientIdentifier,
|
||||
amount.toString(),
|
||||
memo,
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
@ -135,7 +135,7 @@ export async function processXComCommittingSendCoins(
|
||||
sender: dbUser,
|
||||
recipUuid: string,
|
||||
): Promise<SendCoinsResult> {
|
||||
let sendCoinsResult = new SendCoinsResult()
|
||||
const sendCoinsResult = new SendCoinsResult()
|
||||
try {
|
||||
logger.debug(
|
||||
`XCom: processXComCommittingSendCoins...`,
|
||||
@ -145,7 +145,7 @@ export async function processXComCommittingSendCoins(
|
||||
amount,
|
||||
memo,
|
||||
sender,
|
||||
recipient,
|
||||
recipUuid,
|
||||
)
|
||||
// first find pending Tx with given parameters
|
||||
const pendingTx = await DbPendingTransaction.findOneBy({
|
||||
@ -188,12 +188,20 @@ export async function processXComCommittingSendCoins(
|
||||
args.senderUserName = pendingTx.userName
|
||||
}
|
||||
logger.debug(`X-Com: ready for settleSendCoins with args=`, args)
|
||||
const acknoleged = await client.settleSendCoins(args)
|
||||
logger.debug(`X-Com: returnd from settleSendCoins:`, acknoleged)
|
||||
if (acknoleged) {
|
||||
const acknowledge = await client.settleSendCoins(args)
|
||||
logger.debug(`X-Com: returnd from settleSendCoins:`, acknowledge)
|
||||
if (acknowledge) {
|
||||
// settle the pending transaction on receiver-side was successfull, so now settle the sender side
|
||||
try {
|
||||
await settlePendingSenderTransaction(senderCom, sender, pendingTx)
|
||||
sendCoinsResult.vote = await settlePendingSenderTransaction(
|
||||
senderCom,
|
||||
sender,
|
||||
pendingTx,
|
||||
)
|
||||
if (sendCoinsResult.vote) {
|
||||
sendCoinsResult.recipName = pendingTx.linkedUserName
|
||||
sendCoinsResult.recipGradidoID = pendingTx.linkedUserGradidoID
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`Error in writing sender pending transaction: `, err)
|
||||
// revert the existing pending transaction on receiver side
|
||||
@ -219,6 +227,7 @@ export async function processXComCommittingSendCoins(
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`Error:`, err)
|
||||
sendCoinsResult.vote = false
|
||||
}
|
||||
return true
|
||||
return sendCoinsResult
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user