diff --git a/dlt-connector/src/graphql/resolver/CommunityResolver.ts b/dlt-connector/src/graphql/resolver/CommunityResolver.ts index d4bbeb28e..741de2e6d 100644 --- a/dlt-connector/src/graphql/resolver/CommunityResolver.ts +++ b/dlt-connector/src/graphql/resolver/CommunityResolver.ts @@ -9,8 +9,8 @@ import { TransactionResult } from '@model/TransactionResult' import { CommunityRepository } from '@/data/Community.repository' import { AddCommunityContext } from '@/interactions/backendToDb/community/AddCommunity.context' +import { logger } from '@/logging/logger' import { LogError } from '@/server/LogError' -import { logger } from '@/server/logger' import { iotaTopicFromCommunityUUID } from '@/utils/typeConverter' @Resolver() diff --git a/dlt-connector/src/graphql/resolver/TransactionsResolver.ts b/dlt-connector/src/graphql/resolver/TransactionsResolver.ts index 10b55573e..cc20a1034 100755 --- a/dlt-connector/src/graphql/resolver/TransactionsResolver.ts +++ b/dlt-connector/src/graphql/resolver/TransactionsResolver.ts @@ -1,9 +1,11 @@ -import { Resolver, Arg, Mutation } from 'type-graphql' - import { TransactionDraft } from '@input/TransactionDraft' +import { Resolver, Arg, Mutation } from 'type-graphql' import { TransactionRepository } from '@/data/Transaction.repository' import { CreateTransactionRecipeContext } from '@/interactions/backendToDb/transaction/CreateTransationRecipe.context' +import { BackendTransactionLoggingView } from '@/logging/BackendTransactionLogging.view' +import { logger } from '@/logging/logger' +import { TransactionLoggingView } from '@/logging/TransactionLogging.view' import { LogError } from '@/server/LogError' import { TransactionError } from '../model/TransactionError' @@ -35,8 +37,13 @@ export class TransactionResolver { } const backendTransaction = transactionRecipe.backendTransactions[0] backendTransaction.transactionId = transactionRecipe.id + logger.debug( + 'store backendTransaction', + new BackendTransactionLoggingView(backendTransaction), + ) await backendTransaction.save() } else { + logger.debug('store transaction recipe', new TransactionLoggingView(transactionRecipe)) // we can store the transaction and with that automatic the backend transaction await transactionRecipe.save() } diff --git a/dlt-connector/src/interactions/backendToDb/community/Community.role.ts b/dlt-connector/src/interactions/backendToDb/community/Community.role.ts index 30d91bfed..2b1514ef2 100644 --- a/dlt-connector/src/interactions/backendToDb/community/Community.role.ts +++ b/dlt-connector/src/interactions/backendToDb/community/Community.role.ts @@ -3,7 +3,8 @@ import { Community } from '@entity/Community' import { TransactionErrorType } from '@/graphql/enum/TransactionErrorType' import { CommunityDraft } from '@/graphql/input/CommunityDraft' import { TransactionError } from '@/graphql/model/TransactionError' -import { logger } from '@/server/logger' +import { CommunityLoggingView } from '@/logging/CommunityLogging.view' +import { logger } from '@/logging/logger' export abstract class CommunityRole { protected self: Community @@ -17,9 +18,11 @@ export abstract class CommunityRole { this.self.foreign = communityDraft.foreign } - public store(): Promise { + public async store(): Promise { try { - return this.self.save() + const community = await this.self.save() + logger.debug('store community', new CommunityLoggingView(community)) + return community } catch (error) { logger.error('error saving new community into db: %s', error) throw new TransactionError(TransactionErrorType.DB_ERROR, 'error saving community into db') diff --git a/dlt-connector/src/interactions/backendToDb/community/HomeCommunity.role.ts b/dlt-connector/src/interactions/backendToDb/community/HomeCommunity.role.ts index 256cfe1a5..7a4798368 100644 --- a/dlt-connector/src/interactions/backendToDb/community/HomeCommunity.role.ts +++ b/dlt-connector/src/interactions/backendToDb/community/HomeCommunity.role.ts @@ -8,7 +8,8 @@ import { Mnemonic } from '@/data/Mnemonic' import { TransactionErrorType } from '@/graphql/enum/TransactionErrorType' import { CommunityDraft } from '@/graphql/input/CommunityDraft' import { TransactionError } from '@/graphql/model/TransactionError' -import { logger } from '@/server/logger' +import { CommunityLoggingView } from '@/logging/CommunityLogging.view' +import { logger } from '@/logging/logger' import { getDataSource } from '@/typeorm/DataSource' import { CreateTransactionRecipeContext } from '../transaction/CreateTransationRecipe.context' @@ -38,6 +39,7 @@ export class HomeCommunityRole extends CommunityRole { return await getDataSource().transaction(async (transactionalEntityManager) => { const community = await transactionalEntityManager.save(this.self) await transactionalEntityManager.save(this.transactionRecipe) + logger.debug('store home community', new CommunityLoggingView(community)) return community }) } catch (error) { diff --git a/dlt-connector/src/logging/AbstractLogging.view.ts b/dlt-connector/src/logging/AbstractLogging.view.ts new file mode 100644 index 000000000..3d9c2f811 --- /dev/null +++ b/dlt-connector/src/logging/AbstractLogging.view.ts @@ -0,0 +1,49 @@ +import util from 'util' + +import { Decimal } from 'decimal.js-light' + +import { Timestamp } from '@/data/proto/3_3/Timestamp' +import { TimestampSeconds } from '@/data/proto/3_3/TimestampSeconds' +import { timestampSecondsToDate, timestampToDate } from '@/utils/typeConverter' + +export abstract class AbstractLoggingView { + protected bufferStringFormat: BufferEncoding = 'hex' + + // This function gets called automatically when JSON.stringify() is called on this class instance + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public abstract toJSON(): any + public toString(): string { + return JSON.stringify(this.toJSON(), null, 2) + } + + // called form console.log or log4js logging functions + [util.inspect.custom](): string { + return this.toString() + } + + public dateToString(date: Date | undefined | null): string | undefined { + if (date) { + return date.toISOString() + } + return undefined + } + + public decimalToString(number: Decimal | undefined | null): string | undefined { + if (number) { + return number.toString() + } + return undefined + } + + public timestampSecondsToDateString(timestamp: TimestampSeconds): string | undefined { + if (timestamp && timestamp.seconds) { + return timestampSecondsToDate(timestamp).toISOString() + } + } + + public timestampToDateString(timestamp: Timestamp): string | undefined { + if (timestamp && (timestamp.seconds || timestamp.nanoSeconds)) { + return timestampToDate(timestamp).toISOString() + } + } +} diff --git a/dlt-connector/src/logging/AccountLogging.view.ts b/dlt-connector/src/logging/AccountLogging.view.ts new file mode 100644 index 000000000..e4f00e272 --- /dev/null +++ b/dlt-connector/src/logging/AccountLogging.view.ts @@ -0,0 +1,30 @@ +import { Account } from '@entity/Account' + +import { AddressType } from '@/data/proto/3_3/enum/AddressType' +import { getEnumValue } from '@/utils/typeConverter' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { UserLoggingView } from './UserLogging.view' + +export class AccountLoggingView extends AbstractLoggingView { + public constructor(private account: Account) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + id: this.account.id, + user: this.account.user ? new UserLoggingView(this.account.user).toJSON() : null, + derivationIndex: this.account.derivationIndex, + derive2pubkey: this.account.derive2Pubkey.toString(this.bufferStringFormat), + type: getEnumValue(AddressType, this.account.type), + createdAt: this.dateToString(this.account.createdAt), + confirmedAt: this.dateToString(this.account.confirmedAt), + balanceOnConfirmation: this.decimalToString(this.account.balanceOnConfirmation), + balanceConfirmedAt: this.dateToString(this.account.balanceConfirmedAt), + balanceOnCreation: this.decimalToString(this.account.balanceOnCreation), + balanceCreatedAt: this.dateToString(this.account.balanceCreatedAt), + } + } +} diff --git a/dlt-connector/src/logging/BackendTransactionLogging.view.ts b/dlt-connector/src/logging/BackendTransactionLogging.view.ts new file mode 100644 index 000000000..d21c765aa --- /dev/null +++ b/dlt-connector/src/logging/BackendTransactionLogging.view.ts @@ -0,0 +1,30 @@ +import { BackendTransaction } from '@entity/BackendTransaction' + +import { InputTransactionType } from '@/graphql/enum/InputTransactionType' +import { getEnumValue } from '@/utils/typeConverter' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { TransactionLoggingView } from './TransactionLogging.view' + +export class BackendTransactionLoggingView extends AbstractLoggingView { + public constructor(private self: BackendTransaction) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(showTransaction = true): any { + return { + id: this.self.id, + backendTransactionId: this.self.backendTransactionId, + transaction: + showTransaction && this.self.transaction + ? new TransactionLoggingView(this.self.transaction).toJSON(false) + : undefined, + type: getEnumValue(InputTransactionType, this.self.typeId), + balance: this.decimalToString(this.self.balance), + createdAt: this.dateToString(this.self.createdAt), + confirmedAt: this.dateToString(this.self.confirmedAt), + verifiedOnBackend: this.self.verifiedOnBackend, + } + } +} diff --git a/dlt-connector/src/logging/CommunityLogging.view.ts b/dlt-connector/src/logging/CommunityLogging.view.ts new file mode 100644 index 000000000..22f0a4597 --- /dev/null +++ b/dlt-connector/src/logging/CommunityLogging.view.ts @@ -0,0 +1,24 @@ +import { Community } from '@entity/Community' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { AccountLoggingView } from './AccountLogging.view' + +export class CommunityLoggingView extends AbstractLoggingView { + public constructor(private self: Community) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + id: this.self.id, + iotaTopic: this.self.iotaTopic, + foreign: this.self.foreign, + publicKey: this.self.rootPubkey?.toString(this.bufferStringFormat), + createdAt: this.dateToString(this.self.createdAt), + confirmedAt: this.dateToString(this.self.confirmedAt), + aufAccount: this.self.aufAccount ? new AccountLoggingView(this.self.aufAccount) : undefined, + gmwAccount: this.self.gmwAccount ? new AccountLoggingView(this.self.gmwAccount) : undefined, + } + } +} diff --git a/dlt-connector/src/logging/CommunityRootLogging.view.ts b/dlt-connector/src/logging/CommunityRootLogging.view.ts new file mode 100644 index 000000000..ba2869755 --- /dev/null +++ b/dlt-connector/src/logging/CommunityRootLogging.view.ts @@ -0,0 +1,18 @@ +import { CommunityRoot } from '@/data/proto/3_3/CommunityRoot' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class CommunityRootLoggingView extends AbstractLoggingView { + public constructor(private self: CommunityRoot) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + rootPubkey: Buffer.from(this.self.rootPubkey).toString(this.bufferStringFormat), + gmwPubkey: Buffer.from(this.self.gmwPubkey).toString(this.bufferStringFormat), + aufPubkey: Buffer.from(this.self.aufPubkey).toString(this.bufferStringFormat), + } + } +} diff --git a/dlt-connector/src/logging/ConfirmBackendTransaction.view.ts b/dlt-connector/src/logging/ConfirmBackendTransaction.view.ts new file mode 100644 index 000000000..667d290dd --- /dev/null +++ b/dlt-connector/src/logging/ConfirmBackendTransaction.view.ts @@ -0,0 +1,20 @@ +import { ConfirmBackendTransaction } from '@/graphql/model/ConfirmBackendTransaction' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class ConfirmBackendTransactionView extends AbstractLoggingView { + public constructor(private self: ConfirmBackendTransaction) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + transactionId: this.self.transactionId, + iotaMessageId: this.self.iotaMessageId, + gradidoId: this.self.gradidoId, + balance: this.decimalToString(this.self.balance), + balanceDate: this.self.balanceDate, + } + } +} diff --git a/dlt-connector/src/logging/ConfirmedTransactionLogging.view.ts b/dlt-connector/src/logging/ConfirmedTransactionLogging.view.ts new file mode 100644 index 000000000..8e894a35a --- /dev/null +++ b/dlt-connector/src/logging/ConfirmedTransactionLogging.view.ts @@ -0,0 +1,24 @@ +import { ConfirmedTransaction } from '@/data/proto/3_3/ConfirmedTransaction' +import { timestampSecondsToDate } from '@/utils/typeConverter' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { GradidoTransactionLoggingView } from './GradidoTransactionLogging.view' + +export class ConfirmedTransactionLoggingView extends AbstractLoggingView { + public constructor(private self: ConfirmedTransaction) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + id: this.self.id.toString(), + transaction: new GradidoTransactionLoggingView(this.self.transaction).toJSON(), + confirmedAt: this.dateToString(timestampSecondsToDate(this.self.confirmedAt)), + versionNumber: this.self.versionNumber, + runningHash: Buffer.from(this.self.runningHash).toString(this.bufferStringFormat), + messageId: Buffer.from(this.self.messageId).toString(this.bufferStringFormat), + accountBalance: this.self.accountBalance, + } + } +} diff --git a/dlt-connector/src/logging/DecayLogging.view.ts b/dlt-connector/src/logging/DecayLogging.view.ts new file mode 100644 index 000000000..cf7817f58 --- /dev/null +++ b/dlt-connector/src/logging/DecayLogging.view.ts @@ -0,0 +1,20 @@ +import { Decay } from '@/graphql/model/Decay' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class DecayLoggingView extends AbstractLoggingView { + public constructor(private self: Decay) { + super() + } + + public toJSON() { + return { + balance: this.decimalToString(this.self.balance), + decay: this.decimalToString(this.self.decay), + roundedDecay: this.decimalToString(this.self.roundedDecay), + start: this.dateToString(this.self.start), + end: this.dateToString(this.self.end), + duration: this.self.duration + 's', + } + } +} diff --git a/dlt-connector/src/logging/GradidoCreationLogging.view.ts b/dlt-connector/src/logging/GradidoCreationLogging.view.ts new file mode 100644 index 000000000..43e14b887 --- /dev/null +++ b/dlt-connector/src/logging/GradidoCreationLogging.view.ts @@ -0,0 +1,18 @@ +import { GradidoCreation } from '@/data/proto/3_3/GradidoCreation' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { TransferAmountLoggingView } from './TransferAmountLogging.view' + +export class GradidoCreationLoggingView extends AbstractLoggingView { + public constructor(private self: GradidoCreation) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + recipient: new TransferAmountLoggingView(this.self.recipient).toJSON(), + targetDate: this.timestampSecondsToDateString(this.self.targetDate), + } + } +} diff --git a/dlt-connector/src/logging/GradidoDeferredTransferLogging.view.ts b/dlt-connector/src/logging/GradidoDeferredTransferLogging.view.ts new file mode 100644 index 000000000..89a1f1a29 --- /dev/null +++ b/dlt-connector/src/logging/GradidoDeferredTransferLogging.view.ts @@ -0,0 +1,18 @@ +import { GradidoDeferredTransfer } from '@/data/proto/3_3/GradidoDeferredTransfer' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { GradidoTransferLoggingView } from './GradidoTransferLogging.view' + +export class GradidoDeferredTransferLoggingView extends AbstractLoggingView { + public constructor(private self: GradidoDeferredTransfer) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + ...new GradidoTransferLoggingView(this.self.transfer).toJSON(), + ...{ timeout: this.timestampSecondsToDateString(this.self.timeout) }, + } + } +} diff --git a/dlt-connector/src/logging/GradidoTransactionLogging.view.ts b/dlt-connector/src/logging/GradidoTransactionLogging.view.ts new file mode 100644 index 000000000..f23c0b05e --- /dev/null +++ b/dlt-connector/src/logging/GradidoTransactionLogging.view.ts @@ -0,0 +1,29 @@ +import { GradidoTransaction } from '@/data/proto/3_3/GradidoTransaction' +import { TransactionBody } from '@/data/proto/3_3/TransactionBody' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { SignatureMapLoggingView } from './SignatureMapLogging.view' +import { TransactionBodyLoggingView } from './TransactionBodyLogging.view' + +export class GradidoTransactionLoggingView extends AbstractLoggingView { + public constructor(private self: GradidoTransaction) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + let transactionBody: TransactionBody | null | unknown = null + try { + transactionBody = new TransactionBodyLoggingView(this.self.getTransactionBody()) + } catch (e) { + transactionBody = e + } + return { + sigMap: new SignatureMapLoggingView(this.self.sigMap).toJSON(), + bodyBytes: transactionBody, + parentMessageId: this.self.parentMessageId + ? Buffer.from(this.self.parentMessageId).toString(this.bufferStringFormat) + : undefined, + } + } +} diff --git a/dlt-connector/src/logging/GradidoTransferLogging.view.ts b/dlt-connector/src/logging/GradidoTransferLogging.view.ts new file mode 100644 index 000000000..84b5fe604 --- /dev/null +++ b/dlt-connector/src/logging/GradidoTransferLogging.view.ts @@ -0,0 +1,18 @@ +import { GradidoTransfer } from '@/data/proto/3_3/GradidoTransfer' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { TransferAmountLoggingView } from './TransferAmountLogging.view' + +export class GradidoTransferLoggingView extends AbstractLoggingView { + public constructor(private self: GradidoTransfer) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + sender: new TransferAmountLoggingView(this.self.sender), + recipient: Buffer.from(this.self.recipient).toString(this.bufferStringFormat), + } + } +} diff --git a/dlt-connector/src/logging/GroupFriendsUpdateLogging.view.ts b/dlt-connector/src/logging/GroupFriendsUpdateLogging.view.ts new file mode 100644 index 000000000..8d1159d82 --- /dev/null +++ b/dlt-connector/src/logging/GroupFriendsUpdateLogging.view.ts @@ -0,0 +1,16 @@ +import { GroupFriendsUpdate } from '@/data/proto/3_3/GroupFriendsUpdate' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class GroupFriendsUpdateLoggingView extends AbstractLoggingView { + public constructor(private self: GroupFriendsUpdate) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + colorFusion: this.self.colorFusion, + } + } +} diff --git a/dlt-connector/src/logging/RegisterAddressLogging.view.ts b/dlt-connector/src/logging/RegisterAddressLogging.view.ts new file mode 100644 index 000000000..bb857e2b8 --- /dev/null +++ b/dlt-connector/src/logging/RegisterAddressLogging.view.ts @@ -0,0 +1,22 @@ +import { AddressType } from '@/data/proto/3_3/enum/AddressType' +import { RegisterAddress } from '@/data/proto/3_3/RegisterAddress' +import { getEnumValue } from '@/utils/typeConverter' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class RegisterAddressLoggingView extends AbstractLoggingView { + public constructor(private self: RegisterAddress) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + userPublicKey: Buffer.from(this.self.userPubkey).toString(this.bufferStringFormat), + addressType: getEnumValue(AddressType, this.self.addressType), + nameHash: Buffer.from(this.self.nameHash).toString(this.bufferStringFormat), + accountPublicKey: Buffer.from(this.self.accountPubkey).toString(this.bufferStringFormat), + derivationIndex: this.self.derivationIndex, + } + } +} diff --git a/dlt-connector/src/logging/SignatureMapLogging.view.ts b/dlt-connector/src/logging/SignatureMapLogging.view.ts new file mode 100644 index 000000000..89c331a64 --- /dev/null +++ b/dlt-connector/src/logging/SignatureMapLogging.view.ts @@ -0,0 +1,16 @@ +import { SignatureMap } from '@/data/proto/3_3/SignatureMap' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { SignaturePairLoggingView } from './SignaturePairLogging.view' + +export class SignatureMapLoggingView extends AbstractLoggingView { + public constructor(private self: SignatureMap) { + super() + } + + public toJSON() { + return { + sigPair: this.self.sigPair.map((value) => new SignaturePairLoggingView(value).toJSON()), + } + } +} diff --git a/dlt-connector/src/logging/SignaturePairLogging.view.ts b/dlt-connector/src/logging/SignaturePairLogging.view.ts new file mode 100644 index 000000000..c3317a5ec --- /dev/null +++ b/dlt-connector/src/logging/SignaturePairLogging.view.ts @@ -0,0 +1,17 @@ +import { SignaturePair } from '@/data/proto/3_3/SignaturePair' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class SignaturePairLoggingView extends AbstractLoggingView { + public constructor(private self: SignaturePair) { + super() + } + + public toJSON() { + return { + pubkey: Buffer.from(this.self.pubKey).toString(this.bufferStringFormat), + signature: + Buffer.from(this.self.signature).subarray(0, 31).toString(this.bufferStringFormat) + '..', + } + } +} diff --git a/dlt-connector/src/logging/TransactionBodyLogging.view.ts b/dlt-connector/src/logging/TransactionBodyLogging.view.ts new file mode 100644 index 000000000..9e08bbfa6 --- /dev/null +++ b/dlt-connector/src/logging/TransactionBodyLogging.view.ts @@ -0,0 +1,45 @@ +import { getCrossGroupTypeEnumValue } from '@/data/proto/3_3/enum/CrossGroupType' +import { TransactionBody } from '@/data/proto/3_3/TransactionBody' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { CommunityRootLoggingView } from './CommunityRootLogging.view' +import { GradidoCreationLoggingView } from './GradidoCreationLogging.view' +import { GradidoDeferredTransferLoggingView } from './GradidoDeferredTransferLogging.view' +import { GradidoTransferLoggingView } from './GradidoTransferLogging.view' +import { GroupFriendsUpdateLoggingView } from './GroupFriendsUpdateLogging.view' +import { RegisterAddressLoggingView } from './RegisterAddressLogging.view' + +export class TransactionBodyLoggingView extends AbstractLoggingView { + public constructor(private self: TransactionBody) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + memo: this.self.memo, + createdAt: this.timestampToDateString(this.self.createdAt), + versionNumber: this.self.versionNumber, + type: getCrossGroupTypeEnumValue(this.self.type), + otherGroup: this.self.otherGroup, + transfer: this.self.transfer + ? new GradidoTransferLoggingView(this.self.transfer).toJSON() + : undefined, + creation: this.self.creation + ? new GradidoCreationLoggingView(this.self.creation).toJSON() + : undefined, + groupFriendsUpdate: this.self.groupFriendsUpdate + ? new GroupFriendsUpdateLoggingView(this.self.groupFriendsUpdate).toJSON() + : undefined, + registerAddress: this.self.registerAddress + ? new RegisterAddressLoggingView(this.self.registerAddress).toJSON() + : undefined, + deferredTransfer: this.self.deferredTransfer + ? new GradidoDeferredTransferLoggingView(this.self.deferredTransfer).toJSON() + : undefined, + communityRoot: this.self.communityRoot + ? new CommunityRootLoggingView(this.self.communityRoot).toJSON() + : undefined, + } + } +} diff --git a/dlt-connector/src/logging/TransactionDraftLogging.view.ts b/dlt-connector/src/logging/TransactionDraftLogging.view.ts new file mode 100644 index 000000000..f2115f591 --- /dev/null +++ b/dlt-connector/src/logging/TransactionDraftLogging.view.ts @@ -0,0 +1,24 @@ +import { InputTransactionType } from '@/graphql/enum/InputTransactionType' +import { TransactionDraft } from '@/graphql/input/TransactionDraft' +import { getEnumValue } from '@/utils/typeConverter' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { UserIdentifierLoggingView } from './UserIdentifierLogging.view' + +export class TransactionDraftLoggingView extends AbstractLoggingView { + public constructor(private self: TransactionDraft) { + super() + } + + public toJSON() { + return { + senderUser: new UserIdentifierLoggingView(this.self.senderUser).toJSON(), + recipientUser: new UserIdentifierLoggingView(this.self.recipientUser).toJSON(), + backendTransactionId: this.self.backendTransactionId, + amount: this.decimalToString(this.self.amount), + type: getEnumValue(InputTransactionType, this.self.type), + createdAt: this.self.createdAt, + targetDate: this.self.targetDate, + } + } +} diff --git a/dlt-connector/src/logging/TransactionLogging.view.ts b/dlt-connector/src/logging/TransactionLogging.view.ts new file mode 100644 index 000000000..38443024d --- /dev/null +++ b/dlt-connector/src/logging/TransactionLogging.view.ts @@ -0,0 +1,59 @@ +import { Transaction } from '@entity/Transaction' + +import { TransactionType } from '@/data/proto/3_3/enum/TransactionType' +import { LogError } from '@/server/LogError' +import { getEnumValue } from '@/utils/typeConverter' + +import { AbstractLoggingView } from './AbstractLogging.view' +import { AccountLoggingView } from './AccountLogging.view' +import { BackendTransactionLoggingView } from './BackendTransactionLogging.view' +import { CommunityLoggingView } from './CommunityLogging.view' + +export class TransactionLoggingView extends AbstractLoggingView { + public constructor(private self: Transaction) { + super() + if (this.self.community === undefined) { + throw new LogError('sender community is zero') + } + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(showBackendTransactions = true): any { + return { + id: this.self.id, + nr: this.self.nr, + bodyBytesLength: this.self.bodyBytes.length, + createdAt: this.dateToString(this.self.createdAt), + confirmedAt: this.dateToString(this.self.confirmedAt), + protocolVersion: this.self.protocolVersion, + type: getEnumValue(TransactionType, this.self.type), + signature: this.self.signature.subarray(0, 31).toString(this.bufferStringFormat) + '..', + community: new CommunityLoggingView(this.self.community).toJSON(), + otherCommunity: this.self.otherCommunity + ? new CommunityLoggingView(this.self.otherCommunity) + : undefined, + iotaMessageId: this.self.iotaMessageId + ? this.self.iotaMessageId.toString(this.bufferStringFormat) + : undefined, + signingAccount: this.self.signingAccount + ? new AccountLoggingView(this.self.signingAccount) + : undefined, + recipientAccount: this.self.recipientAccount + ? new AccountLoggingView(this.self.recipientAccount) + : undefined, + amount: this.decimalToString(this.self.amount), + accountBalanceOnCreation: this.decimalToString(this.self.accountBalanceOnCreation), + accountBalanceOnConfirmation: this.decimalToString(this.self.accountBalanceOnConfirmation), + runningHash: this.self.runningHash + ? this.self.runningHash.toString(this.bufferStringFormat) + : undefined, + iotaMilestone: this.self.iotaMilestone, + backendTransactions: + showBackendTransactions && this.self.backendTransactions + ? this.self.backendTransactions.map((backendTransaction) => + new BackendTransactionLoggingView(backendTransaction).toJSON(false), + ) + : undefined, + } + } +} diff --git a/dlt-connector/src/logging/TransferAmountLogging.view.ts b/dlt-connector/src/logging/TransferAmountLogging.view.ts new file mode 100644 index 000000000..8d320b99f --- /dev/null +++ b/dlt-connector/src/logging/TransferAmountLogging.view.ts @@ -0,0 +1,18 @@ +import { TransferAmount } from '@/data/proto/3_3/TransferAmount' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class TransferAmountLoggingView extends AbstractLoggingView { + public constructor(private self: TransferAmount) { + super() + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public toJSON(): any { + return { + publicKey: Buffer.from(this.self.pubkey).toString(this.bufferStringFormat), + amount: this.self.amount, + communityId: this.self.communityId, + } + } +} diff --git a/dlt-connector/src/logging/UserIdentifierLogging.view.ts b/dlt-connector/src/logging/UserIdentifierLogging.view.ts new file mode 100644 index 000000000..b49fb604c --- /dev/null +++ b/dlt-connector/src/logging/UserIdentifierLogging.view.ts @@ -0,0 +1,17 @@ +import { UserIdentifier } from '@/graphql/input/UserIdentifier' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class UserIdentifierLoggingView extends AbstractLoggingView { + public constructor(private self: UserIdentifier) { + super() + } + + public toJSON() { + return { + uuid: this.self.uuid, + communityUuid: this.self.communityUuid, + accountNr: this.self.accountNr, + } + } +} diff --git a/dlt-connector/src/logging/UserLogging.view.ts b/dlt-connector/src/logging/UserLogging.view.ts new file mode 100644 index 000000000..4db4f61fd --- /dev/null +++ b/dlt-connector/src/logging/UserLogging.view.ts @@ -0,0 +1,19 @@ +import { User } from '@entity/User' + +import { AbstractLoggingView } from './AbstractLogging.view' + +export class UserLoggingView extends AbstractLoggingView { + public constructor(private user: User) { + super() + } + + public toJSON() { + return { + id: this.user.id, + gradidoId: this.user.gradidoID, + derive1Pubkey: this.user.derive1Pubkey.toString(this.bufferStringFormat), + createdAt: this.dateToString(this.user.createdAt), + confirmedAt: this.dateToString(this.user.confirmedAt), + } + } +} diff --git a/dlt-connector/src/server/logger.ts b/dlt-connector/src/logging/logger.ts similarity index 100% rename from dlt-connector/src/server/logger.ts rename to dlt-connector/src/logging/logger.ts diff --git a/dlt-connector/src/server/LogError.ts b/dlt-connector/src/server/LogError.ts index 8e145a0ef..69aca1978 100644 --- a/dlt-connector/src/server/LogError.ts +++ b/dlt-connector/src/server/LogError.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-argument */ -import { logger } from './logger' +import { logger } from '@/logging/logger' export class LogError extends Error { // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/dlt-connector/src/server/createServer.ts b/dlt-connector/src/server/createServer.ts index e02cc3073..ed87d54ac 100755 --- a/dlt-connector/src/server/createServer.ts +++ b/dlt-connector/src/server/createServer.ts @@ -9,10 +9,9 @@ import express, { Express } from 'express' import { Logger } from 'log4js' import { schema } from '@/graphql/schema' +import { logger as dltLogger } from '@/logging/logger' import { Connection } from '@/typeorm/DataSource' -import { logger as dltLogger } from './logger' - type ServerDef = { apollo: ApolloServer; app: Express } interface MyContext { diff --git a/dlt-connector/src/typeorm/DataSource.ts b/dlt-connector/src/typeorm/DataSource.ts index ecdfc1b66..a86a061f3 100644 --- a/dlt-connector/src/typeorm/DataSource.ts +++ b/dlt-connector/src/typeorm/DataSource.ts @@ -5,8 +5,8 @@ import { entities } from '@entity/index' import { Migration } from '@entity/Migration' import { CONFIG } from '@/config' +import { logger } from '@/logging/logger' import { LogError } from '@/server/LogError' -import { logger } from '@/server/logger' // eslint-disable-next-line @typescript-eslint/no-extraneous-class export class Connection { diff --git a/dlt-connector/src/utils/typeConverter.ts b/dlt-connector/src/utils/typeConverter.ts index 1fc46ee4b..52dcd2a98 100644 --- a/dlt-connector/src/utils/typeConverter.ts +++ b/dlt-connector/src/utils/typeConverter.ts @@ -7,8 +7,8 @@ import { TransactionBody } from '@/data/proto/3_3/TransactionBody' import { AccountType } from '@/graphql/enum/AccountType' import { TransactionErrorType } from '@/graphql/enum/TransactionErrorType' import { TransactionError } from '@/graphql/model/TransactionError' +import { logger } from '@/logging/logger' import { LogError } from '@/server/LogError' -import { logger } from '@/server/logger' export const uuid4ToBuffer = (uuid: string): Buffer => { // Remove dashes from the UUIDv4 string diff --git a/dlt-connector/test/testSetup.ts b/dlt-connector/test/testSetup.ts index ff619e95d..1a76560ed 100644 --- a/dlt-connector/test/testSetup.ts +++ b/dlt-connector/test/testSetup.ts @@ -1,4 +1,4 @@ -import { logger } from '@/server/logger' +import { logger } from '@/logging/logger' jest.setTimeout(1000000)