diff --git a/dlt-connector/src/data/Transaction.logic.ts b/dlt-connector/src/data/Transaction.logic.ts index f61c9a6e9..ec13bf753 100644 --- a/dlt-connector/src/data/Transaction.logic.ts +++ b/dlt-connector/src/data/Transaction.logic.ts @@ -26,13 +26,13 @@ export class TransactionLogic { throw new LogError("local transaction don't has a pairing transaction") } - // check if already on entity - if (this.self.paringTransaction) { - return this.self.paringTransaction + // check if already was loaded from db + if (this.self.pairingTransaction) { + return this.self.pairingTransaction } - if (this.self.paringTransactionId) { - const pairingTransaction = await Transaction.findOneBy({ id: this.self.paringTransactionId }) + if (this.self.pairingTransaction) { + const pairingTransaction = await Transaction.findOneBy({ id: this.self.pairingTransaction }) if (pairingTransaction) { return pairingTransaction } diff --git a/dlt-connector/src/interactions/transmitToIota/InboundTransactionRecipe.role.ts b/dlt-connector/src/interactions/transmitToIota/InboundTransactionRecipe.role.ts index 52e95c12c..2f18b48ac 100644 --- a/dlt-connector/src/interactions/transmitToIota/InboundTransactionRecipe.role.ts +++ b/dlt-connector/src/interactions/transmitToIota/InboundTransactionRecipe.role.ts @@ -23,9 +23,9 @@ export class InboundTransactionRecipeRole extends AbstractTransactionRecipeRole ) } gradidoTransaction.parentMessageId = pairingTransaction.iotaMessageId - this.self.paringTransactionId = pairingTransaction.id - this.self.paringTransaction = pairingTransaction - pairingTransaction.paringTransactionId = this.self.id + this.self.pairingTransactionId = pairingTransaction.id + this.self.pairingTransaction = pairingTransaction + pairingTransaction.pairingTransactionId = this.self.id if (!this.self.otherCommunity) { throw new LogError('missing other community') diff --git a/dlt-connector/src/interactions/transmitToIota/TransmitToIota.context.ts b/dlt-connector/src/interactions/transmitToIota/TransmitToIota.context.ts index f29d1742a..e58cd7e89 100644 --- a/dlt-connector/src/interactions/transmitToIota/TransmitToIota.context.ts +++ b/dlt-connector/src/interactions/transmitToIota/TransmitToIota.context.ts @@ -42,12 +42,12 @@ export class TransmitToIotaContext { logger.debug('transaction sended via iota', new TransactionLoggingView(transaction)) // store changes in db // prevent endless loop - const paringTransaction = transaction.paringTransaction - if (paringTransaction) { - transaction.paringTransaction = undefined + const pairingTransaction = transaction.pairingTransaction + if (pairingTransaction) { + transaction.pairingTransaction = undefined await getDataSource().transaction(async (transactionalEntityManager) => { await transactionalEntityManager.save(transaction) - await transactionalEntityManager.save(paringTransaction) + await transactionalEntityManager.save(pairingTransaction) }) } else { await transaction.save() diff --git a/dlt-connector/src/logging/TransactionLogging.view.ts b/dlt-connector/src/logging/TransactionLogging.view.ts index d04d46556..1bb59cc55 100644 --- a/dlt-connector/src/logging/TransactionLogging.view.ts +++ b/dlt-connector/src/logging/TransactionLogging.view.ts @@ -42,12 +42,12 @@ export class TransactionLoggingView extends AbstractLoggingView { ? new AccountLoggingView(this.self.recipientAccount) : { id: this.self.recipientAccountId }, pairingTransaction: - this.self.paringTransaction && deep === 1 - ? new TransactionLoggingView(this.self.paringTransaction).toJSON( + this.self.pairingTransaction && deep === 1 + ? new TransactionLoggingView(this.self.pairingTransaction).toJSON( showBackendTransactions, deep + 1, ) - : { id: this.self.paringTransactionId }, + : { id: this.self.pairingTransaction }, amount: this.decimalToString(this.self.amount), accountBalanceOnCreation: this.decimalToString(this.self.accountBalanceOnCreation), accountBalanceOnConfirmation: this.decimalToString(this.self.accountBalanceOnConfirmation), diff --git a/dlt-database/entity/0004-fix_spelling/Transaction.ts b/dlt-database/entity/0004-fix_spelling/Transaction.ts new file mode 100644 index 000000000..4d5a304da --- /dev/null +++ b/dlt-database/entity/0004-fix_spelling/Transaction.ts @@ -0,0 +1,128 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + ManyToOne, + OneToOne, + JoinColumn, + BaseEntity, + OneToMany, +} from 'typeorm' +import { Decimal } from 'decimal.js-light' + +import { DecimalTransformer } from '../../src/typeorm/DecimalTransformer' +import { Account } from '../Account' +import { Community } from '../Community' +import { BackendTransaction } from '../BackendTransaction' + +@Entity('transactions') +export class Transaction extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true, type: 'bigint' }) + id: number + + @Column({ name: 'iota_message_id', type: 'binary', length: 32, nullable: true }) + iotaMessageId?: Buffer + + @OneToOne(() => Transaction, { cascade: ['update'] }) + // eslint-disable-next-line no-use-before-define + pairingTransaction?: Transaction + + @Column({ name: 'pairing_transaction_id', type: 'bigint', unsigned: true, nullable: true }) + pairingTransactionId?: number + + // if transaction has a sender than it is also the sender account + @ManyToOne(() => Account, (account) => account.transactionSigning) + @JoinColumn({ name: 'signing_account_id' }) + signingAccount?: Account + + @Column({ name: 'signing_account_id', type: 'int', unsigned: true, nullable: true }) + signingAccountId?: number + + @ManyToOne(() => Account, (account) => account.transactionRecipient) + @JoinColumn({ name: 'recipient_account_id' }) + recipientAccount?: Account + + @Column({ name: 'recipient_account_id', type: 'int', unsigned: true, nullable: true }) + recipientAccountId?: number + + @ManyToOne(() => Community, (community) => community.transactions, { + eager: true, + }) + @JoinColumn({ name: 'community_id' }) + community: Community + + @Column({ name: 'community_id', type: 'int', unsigned: true }) + communityId: number + + @ManyToOne(() => Community, (community) => community.friendCommunitiesTransactions) + @JoinColumn({ name: 'other_community_id' }) + otherCommunity?: Community + + @Column({ name: 'other_community_id', type: 'int', unsigned: true, nullable: true }) + otherCommunityId?: number + + @Column({ + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + amount?: Decimal + + // account balance for sender based on creation date + @Column({ + name: 'account_balance_on_creation', + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + accountBalanceOnCreation?: Decimal + + @Column({ type: 'tinyint' }) + type: number + + @Column({ name: 'created_at', type: 'datetime', precision: 3 }) + createdAt: Date + + @Column({ name: 'body_bytes', type: 'blob' }) + bodyBytes: Buffer + + @Column({ type: 'binary', length: 64, unique: true }) + signature: Buffer + + @Column({ name: 'protocol_version', type: 'varchar', length: 255, default: '1' }) + protocolVersion: string + + @Column({ type: 'bigint', nullable: true }) + nr?: number + + @Column({ name: 'running_hash', type: 'binary', length: 48, nullable: true }) + runningHash?: Buffer + + // account balance for sender based on confirmation date (iota milestone) + @Column({ + name: 'account_balance_on_confirmation', + type: 'decimal', + precision: 40, + scale: 20, + nullable: true, + transformer: DecimalTransformer, + }) + accountBalanceOnConfirmation?: Decimal + + @Column({ name: 'iota_milestone', type: 'bigint', nullable: true }) + iotaMilestone?: number + + // use timestamp from iota milestone which is only in seconds precision, so no need to use 3 Bytes extra here + @Column({ name: 'confirmed_at', type: 'datetime', nullable: true }) + confirmedAt?: Date + + @OneToMany(() => BackendTransaction, (backendTransaction) => backendTransaction.transaction, { + cascade: ['insert', 'update'], + }) + @JoinColumn({ name: 'transaction_id' }) + backendTransactions: BackendTransaction[] +} diff --git a/dlt-database/entity/Transaction.ts b/dlt-database/entity/Transaction.ts index 113eb3450..9db8e6747 100644 --- a/dlt-database/entity/Transaction.ts +++ b/dlt-database/entity/Transaction.ts @@ -1 +1 @@ -export { Transaction } from './0003-refactor_transaction_recipe/Transaction' +export { Transaction } from './0004-fix_spelling/Transaction' diff --git a/dlt-database/migrations/0004-fix_spelling.ts b/dlt-database/migrations/0004-fix_spelling.ts new file mode 100644 index 000000000..3b2153a7d --- /dev/null +++ b/dlt-database/migrations/0004-fix_spelling.ts @@ -0,0 +1,15 @@ +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(` + ALTER TABLE \`transactions\` + RENAME COLUMN \`paring_transaction_id\` TO \`pairing_transaction_id\`, + ; + `) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(` + ALTER TABLE \`transactions\` + RENAME COLUMN \`pairing_transaction_id\` TO \`paring_transaction_id\`, + ; + `) +}