mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
add trigger to send tx to dlt-connector after tx-creations
This commit is contained in:
parent
f1a31c8156
commit
69a33c7ba2
@ -1,6 +1,7 @@
|
||||
import { IsNull, getConnection } from '@dbTools/typeorm'
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { ContributionMessage } from '@entity/ContributionMessage'
|
||||
import { DltTransaction } from '@entity/DltTransaction'
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
import { UserContact } from '@entity/UserContact'
|
||||
@ -55,6 +56,7 @@ import {
|
||||
} from './util/creations'
|
||||
import { findContributions } from './util/findContributions'
|
||||
import { getLastTransaction } from './util/getLastTransaction'
|
||||
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
|
||||
|
||||
@Resolver()
|
||||
export class ContributionResolver {
|
||||
@ -534,20 +536,16 @@ export class ContributionResolver {
|
||||
contribution.contributionStatus = ContributionStatus.CONFIRMED
|
||||
await queryRunner.manager.update(DbContribution, { id: contribution.id }, contribution)
|
||||
|
||||
const dltTx = DltTransaction.create()
|
||||
dltTx.transactionId = transaction.id
|
||||
await DltTransaction.save(dltTx)
|
||||
|
||||
await queryRunner.commitTransaction()
|
||||
|
||||
/* TODO not the right place, because its inside semaphore locks
|
||||
// send transaction via dlt-connector
|
||||
// notice: must be called after transaction are saved to db to contain also the id
|
||||
// we use catch instead of await to prevent slow down of backend
|
||||
// because iota pow calculation which can be use up several seconds
|
||||
const dltConnector = DltConnectorClient.getInstance()
|
||||
if (dltConnector) {
|
||||
dltConnector.transmitTransaction(transaction).catch(() => {
|
||||
logger.error('error on transmit creation transaction')
|
||||
})
|
||||
}
|
||||
*/
|
||||
// trigger to send transaction via dlt-connector
|
||||
sendTransactionsToDltConnector().catch(() => {
|
||||
logger.error('error on sending transactions to DltConnector')
|
||||
})
|
||||
|
||||
logger.info('creation commited successfuly.')
|
||||
void sendContributionConfirmedEmail({
|
||||
|
||||
@ -3,6 +3,7 @@ import { randomBytes } from 'crypto'
|
||||
import { getConnection } from '@dbTools/typeorm'
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
|
||||
import { DltTransaction } from '@entity/DltTransaction'
|
||||
import { Transaction as DbTransaction } from '@entity/Transaction'
|
||||
import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
|
||||
import { User as DbUser } from '@entity/User'
|
||||
@ -41,6 +42,7 @@ import { calculateBalance } from '@/util/validate'
|
||||
import { executeTransaction } from './TransactionResolver'
|
||||
import { getUserCreation, validateContribution } from './util/creations'
|
||||
import { getLastTransaction } from './util/getLastTransaction'
|
||||
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
|
||||
import { transactionLinkList } from './util/transactionLinkList'
|
||||
|
||||
// TODO: do not export, test it inside the resolver
|
||||
@ -289,20 +291,12 @@ export class TransactionLinkResolver {
|
||||
contribution.transactionId = transaction.id
|
||||
await queryRunner.manager.update(DbContribution, { id: contribution.id }, contribution)
|
||||
|
||||
const dltTx = DltTransaction.create()
|
||||
dltTx.transactionId = transaction.id
|
||||
await DltTransaction.save(dltTx)
|
||||
|
||||
await queryRunner.commitTransaction()
|
||||
|
||||
/* TODO not the right place, because its inside semaphore locks
|
||||
// send transaction via dlt-connector
|
||||
// notice: must be called after transaction are saved to db to contain also the id
|
||||
// we use catch instead of await to prevent slow down of backend
|
||||
// because iota pow calculation which can be use up several seconds
|
||||
const dltConnector = DltConnectorClient.getInstance()
|
||||
if (dltConnector) {
|
||||
dltConnector.transmitTransaction(transaction).catch(() => {
|
||||
logger.error('error on transmit creation transaction')
|
||||
})
|
||||
}
|
||||
*/
|
||||
await EVENT_CONTRIBUTION_LINK_REDEEM(
|
||||
user,
|
||||
transaction,
|
||||
@ -319,6 +313,10 @@ export class TransactionLinkResolver {
|
||||
} finally {
|
||||
releaseLock()
|
||||
}
|
||||
// trigger to send transaction via dlt-connector
|
||||
sendTransactionsToDltConnector().catch(() => {
|
||||
logger.error('error on sending transactions to DltConnector')
|
||||
})
|
||||
return true
|
||||
} else {
|
||||
const now = new Date()
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import { getConnection, In } from '@dbTools/typeorm'
|
||||
import { DltTransaction } from '@entity/DltTransaction'
|
||||
import { Transaction as dbTransaction } from '@entity/Transaction'
|
||||
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
|
||||
import { User as dbUser } from '@entity/User'
|
||||
@ -37,6 +38,7 @@ import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
|
||||
import { findUserByIdentifier } from './util/findUserByIdentifier'
|
||||
import { getLastTransaction } from './util/getLastTransaction'
|
||||
import { getTransactionList } from './util/getTransactionList'
|
||||
import { sendTransactionsToDltConnector } from './util/sendTransactionsToDltConnector'
|
||||
import { transactionLinkSummary } from './util/transactionLinkSummary'
|
||||
|
||||
export const executeTransaction = async (
|
||||
@ -139,6 +141,14 @@ export const executeTransaction = async (
|
||||
)
|
||||
}
|
||||
|
||||
const dltTxSend = DltTransaction.create()
|
||||
dltTxSend.transactionId = transactionSend.id
|
||||
await DltTransaction.save(dltTxSend)
|
||||
|
||||
const dltTxRec = DltTransaction.create()
|
||||
dltTxRec.transactionId = transactionReceive.id
|
||||
await DltTransaction.save(dltTxRec)
|
||||
|
||||
await queryRunner.commitTransaction()
|
||||
logger.info(`commit Transaction successful...`)
|
||||
|
||||
@ -151,21 +161,10 @@ export const executeTransaction = async (
|
||||
transactionReceive.amount,
|
||||
)
|
||||
|
||||
/* TODO not the right place, because its inside semaphore locks
|
||||
// send transaction via dlt-connector
|
||||
// notice: must be called after transactions are saved to db to contain also the id
|
||||
// we use catch instead of await to prevent slow down of backend
|
||||
// because iota pow calculation which can be use up several seconds
|
||||
const dltConnector = DltConnectorClient.getInstance()
|
||||
if (dltConnector) {
|
||||
dltConnector.transmitTransaction(transactionSend).catch(() => {
|
||||
logger.error('error on transmit send transaction')
|
||||
})
|
||||
dltConnector.transmitTransaction(transactionReceive).catch(() => {
|
||||
logger.error('error on transmit receive transaction')
|
||||
})
|
||||
}
|
||||
*/
|
||||
// trigger to send transaction via dlt-connector
|
||||
sendTransactionsToDltConnector().catch(() => {
|
||||
logger.error('error on sending transactions to DltConnector')
|
||||
})
|
||||
} catch (e) {
|
||||
await queryRunner.rollbackTransaction()
|
||||
throw new LogError('Transaction was not successful', e)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user