rename paringTransaction to pairingTransaction

This commit is contained in:
einhornimmond 2024-02-03 18:54:42 +01:00
parent b2f77ddfbf
commit 07d2e6c846
7 changed files with 159 additions and 16 deletions

View File

@ -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
}

View File

@ -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')

View File

@ -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()

View File

@ -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),

View File

@ -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[]
}

View File

@ -1 +1 @@
export { Transaction } from './0003-refactor_transaction_recipe/Transaction'
export { Transaction } from './0004-fix_spelling/Transaction'

View File

@ -0,0 +1,15 @@
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(`
ALTER TABLE \`transactions\`
RENAME COLUMN \`paring_transaction_id\` TO \`pairing_transaction_id\`,
;
`)
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
await queryFn(`
ALTER TABLE \`transactions\`
RENAME COLUMN \`pairing_transaction_id\` TO \`paring_transaction_id\`,
;
`)
}