TransactionTypeId to TypeId changed, *10000 removed, graphql refactor

This commit is contained in:
ogerly 2022-03-01 09:32:16 +01:00
parent 289ca9115a
commit 38d53e61c0
28 changed files with 111 additions and 113 deletions

View File

@ -59,6 +59,7 @@ export default {
}, },
}) })
.then((result) => { .then((result) => {
console.log('getTransactions', result.data)
this.items = result.data.transactionList.transactions.filter((t) => t.type === 'creation') this.items = result.data.transactionList.transactions.filter((t) => t.type === 'creation')
}) })
.catch((error) => { .catch((error) => {

View File

@ -15,28 +15,25 @@ export const transactionList = gql`
onlyCreations: $onlyCreations onlyCreations: $onlyCreations
userId: $userId userId: $userId
) { ) {
gdtSum balanceGDT
count count
balance balance
decay decayStartBlock
decayDate
transactions { transactions {
type id
balance typeId
decayStart amount
decayEnd balanceDate
decayDuration
memo memo
transactionId linkedUser {
name firstName
email lastName
date }
decay { decay {
balance decay
decayStart start
decayEnd end
decayDuration duration
decayStartBlock
} }
} }
} }

View File

@ -1,6 +1,6 @@
import { registerEnumType } from 'type-graphql' import { registerEnumType } from 'type-graphql'
export enum TransactionTypeId { export enum TypeId {
CREATION = 1, CREATION = 1,
SEND = 2, SEND = 2,
RECEIVE = 3, RECEIVE = 3,
@ -8,7 +8,7 @@ export enum TransactionTypeId {
DECAY = 4, DECAY = 4,
} }
registerEnumType(TransactionTypeId, { registerEnumType(TypeId, {
name: 'TransactionTypeId', // this one is mandatory name: 'TypeId', // this one is mandatory
description: 'Type of the transaction', // this one is optional description: 'Type of the transaction', // this one is optional
}) })

View File

@ -4,7 +4,7 @@ import { ObjectType, Field } from 'type-graphql'
import { Decay } from './Decay' import { Decay } from './Decay'
import { Transaction as dbTransaction } from '@entity/Transaction' import { Transaction as dbTransaction } from '@entity/Transaction'
import Decimal from 'decimal.js-light' import Decimal from 'decimal.js-light'
import { TransactionTypeId } from '../enum/TransactionTypeId' import { TypeId } from '../enum/TypeId'
import { User } from './User' import { User } from './User'
@ObjectType() @ObjectType()
@ -43,8 +43,8 @@ export class Transaction {
@Field(() => Number, { nullable: true }) @Field(() => Number, { nullable: true })
previous: number | null previous: number | null
@Field(() => TransactionTypeId) @Field(() => TypeId)
typeId: TransactionTypeId typeId: TypeId
@Field(() => Decimal) @Field(() => Decimal)
amount: Decimal amount: Decimal

View File

@ -26,7 +26,7 @@ import { AdminPendingCreation } from '@entity/AdminPendingCreation'
import { hasElopageBuys } from '../../util/hasElopageBuys' import { hasElopageBuys } from '../../util/hasElopageBuys'
import { LoginEmailOptIn } from '@entity/LoginEmailOptIn' import { LoginEmailOptIn } from '@entity/LoginEmailOptIn'
import { User } from '@entity/User' import { User } from '@entity/User'
import { TransactionTypeId } from '../enum/TransactionTypeId' import { TypeId } from '../enum/TypeId'
import Decimal from 'decimal.js-light' import Decimal from 'decimal.js-light'
// const EMAIL_OPT_IN_REGISTER = 1 // const EMAIL_OPT_IN_REGISTER = 1
@ -170,7 +170,7 @@ export class AdminResolver {
if (isCreationValid(creations, amount, creationDateObj)) { if (isCreationValid(creations, amount, creationDateObj)) {
const adminPendingCreation = AdminPendingCreation.create() const adminPendingCreation = AdminPendingCreation.create()
adminPendingCreation.userId = user.id adminPendingCreation.userId = user.id
adminPendingCreation.amount = BigInt(amount * 10000) adminPendingCreation.amount = BigInt(amount)
adminPendingCreation.created = new Date() adminPendingCreation.created = new Date()
adminPendingCreation.date = creationDateObj adminPendingCreation.date = creationDateObj
adminPendingCreation.memo = memo adminPendingCreation.memo = memo
@ -235,7 +235,7 @@ export class AdminResolver {
if (!isCreationValid(creations, amount, creationDateObj)) { if (!isCreationValid(creations, amount, creationDateObj)) {
throw new Error('Creation is not valid') throw new Error('Creation is not valid')
} }
pendingCreationToUpdate.amount = BigInt(amount * 10000) pendingCreationToUpdate.amount = BigInt(amount)
pendingCreationToUpdate.memo = memo pendingCreationToUpdate.memo = memo
pendingCreationToUpdate.date = new Date(creationDate) pendingCreationToUpdate.date = new Date(creationDate)
pendingCreationToUpdate.moderator = moderator pendingCreationToUpdate.moderator = moderator
@ -321,7 +321,7 @@ export class AdminResolver {
newBalance = newBalance.add(new Decimal(Number(pendingCreation.amount))) newBalance = newBalance.add(new Decimal(Number(pendingCreation.amount)))
const transaction = new Transaction() const transaction = new Transaction()
transaction.typeId = TransactionTypeId.CREATION transaction.typeId = TypeId.CREATION
transaction.memo = pendingCreation.memo transaction.memo = pendingCreation.memo
transaction.userId = pendingCreation.userId transaction.userId = pendingCreation.userId
// TODO pending creations decimal // TODO pending creations decimal
@ -367,7 +367,7 @@ async function getUserCreations(ids: number[], includePending = true): Promise<C
SELECT MONTH(date) AS month, sum(amount) AS sum, userId AS id FROM SELECT MONTH(date) AS month, sum(amount) AS sum, userId AS id FROM
(SELECT creation_date AS date, amount AS amount, user_id AS userId FROM transactions (SELECT creation_date AS date, amount AS amount, user_id AS userId FROM transactions
WHERE user_id IN (${ids.toString()}) WHERE user_id IN (${ids.toString()})
AND transaction_type_id = ${TransactionTypeId.CREATION} AND type_id = ${TypeId.CREATION}
AND creation_date >= ${dateFilter} AND creation_date >= ${dateFilter}
${unionString}) AS result ${unionString}) AS result
GROUP BY month, userId GROUP BY month, userId

View File

@ -24,7 +24,7 @@ import { User as dbUser } from '@entity/User'
import { Transaction as dbTransaction } from '@entity/Transaction' import { Transaction as dbTransaction } from '@entity/Transaction'
import { apiPost } from '../../apis/HttpRequest' import { apiPost } from '../../apis/HttpRequest'
import { TransactionTypeId } from '../enum/TransactionTypeId' import { TypeId } from '../enum/TypeId'
import { calculateBalance, isHexPublicKey } from '../../util/validate' import { calculateBalance, isHexPublicKey } from '../../util/validate'
import { RIGHTS } from '../../auth/RIGHTS' import { RIGHTS } from '../../auth/RIGHTS'
import { User } from '../model/User' import { User } from '../model/User'
@ -111,7 +111,7 @@ export class TransactionResolver {
for (let i = 0; i < userTransactions.length; i++) { for (let i = 0; i < userTransactions.length; i++) {
const userTransaction = userTransactions[i] const userTransaction = userTransactions[i]
let linkedUser = null let linkedUser = null
if (userTransaction.typeId === TransactionTypeId.CREATION) { if (userTransaction.typeId === TypeId.CREATION) {
linkedUser = communityUser linkedUser = communityUser
} else { } else {
linkedUser = involvedUsers.find((u) => u.id === userTransaction.linkedUserId) linkedUser = involvedUsers.find((u) => u.id === userTransaction.linkedUserId)
@ -180,7 +180,7 @@ export class TransactionResolver {
try { try {
// transaction // transaction
const transactionSend = new dbTransaction() const transactionSend = new dbTransaction()
transactionSend.typeId = TransactionTypeId.SEND transactionSend.typeId = TypeId.SEND
transactionSend.memo = memo transactionSend.memo = memo
transactionSend.userId = senderUser.id transactionSend.userId = senderUser.id
transactionSend.linkedUserId = recipientUser.id transactionSend.linkedUserId = recipientUser.id
@ -193,7 +193,7 @@ export class TransactionResolver {
await queryRunner.manager.insert(dbTransaction, transactionSend) await queryRunner.manager.insert(dbTransaction, transactionSend)
const transactionReceive = new dbTransaction() const transactionReceive = new dbTransaction()
transactionReceive.typeId = TransactionTypeId.RECEIVE transactionReceive.typeId = TypeId.RECEIVE
transactionReceive.memo = memo transactionReceive.memo = memo
transactionReceive.userId = recipientUser.id transactionReceive.userId = recipientUser.id
transactionReceive.linkedUserId = senderUser.id transactionReceive.linkedUserId = senderUser.id

View File

@ -1,7 +1,7 @@
import { EntityRepository, Repository } from '@dbTools/typeorm' import { EntityRepository, Repository } from '@dbTools/typeorm'
import { Transaction } from '@entity/Transaction' import { Transaction } from '@entity/Transaction'
import { Order } from '../../graphql/enum/Order' import { Order } from '../../graphql/enum/Order'
import { TransactionTypeId } from '../../graphql/enum/TransactionTypeId' import { TypeId } from '../../graphql/enum/TypeId'
@EntityRepository(Transaction) @EntityRepository(Transaction)
export class TransactionRepository extends Repository<Transaction> { export class TransactionRepository extends Repository<Transaction> {
@ -15,8 +15,8 @@ export class TransactionRepository extends Repository<Transaction> {
if (onlyCreation) { if (onlyCreation) {
return this.createQueryBuilder('userTransaction') return this.createQueryBuilder('userTransaction')
.where('userTransaction.userId = :userId', { userId }) .where('userTransaction.userId = :userId', { userId })
.andWhere('userTransaction.transactionTypeId = :transactionTypeId', { .andWhere('userTransaction.typeId = :typeId', {
transactionTypeId: TransactionTypeId.CREATION, typeId: TypeId.CREATION,
}) })
.orderBy('userTransaction.balanceDate', order) .orderBy('userTransaction.balanceDate', order)
.limit(limit) .limit(limit)

View File

@ -3,7 +3,7 @@ import Decimal from 'decimal.js-light'
import { SaveOptions, RemoveOptions } from '@dbTools/typeorm' import { SaveOptions, RemoveOptions } from '@dbTools/typeorm'
import { Transaction as dbTransaction } from '@entity/Transaction' import { Transaction as dbTransaction } from '@entity/Transaction'
import { calculateDecay } from './decay' import { calculateDecay } from './decay'
import { TransactionTypeId } from '../graphql/enum/TransactionTypeId' import { TypeId } from '../graphql/enum/TypeId'
import { Transaction } from '../graphql/model/Transaction' import { Transaction } from '../graphql/model/Transaction'
import { User } from '../graphql/model/User' import { User } from '../graphql/model/User'
@ -19,7 +19,7 @@ const virtualDecayTransaction = (
id: -1, id: -1,
userId: -1, userId: -1,
previous: -1, previous: -1,
typeId: TransactionTypeId.DECAY, typeId: TypeId.DECAY,
amount: decay.decay ? decay.decay : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query amount: decay.decay ? decay.decay : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query
balance: decay.balance, balance: decay.balance,
balanceDate: time, balanceDate: time,

View File

@ -10,8 +10,8 @@ export class Transaction extends BaseEntity {
@Column({ name: 'state_group_id', unsigned: true, default: null }) @Column({ name: 'state_group_id', unsigned: true, default: null })
stateGroupId: number stateGroupId: number
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false }) @Column({ name: 'type_id', unsigned: true, nullable: false })
transactionTypeId: number typeId: number
@Column({ name: 'tx_hash', type: 'binary', length: 48, default: null }) @Column({ name: 'tx_hash', type: 'binary', length: 48, default: null })
txHash: Buffer txHash: Buffer

View File

@ -11,8 +11,8 @@ export class UserTransaction extends BaseEntity {
@Column({ name: 'transaction_id' }) @Column({ name: 'transaction_id' })
transactionId: number transactionId: number
@Column({ name: 'transaction_type_id' }) @Column({ name: 'type_id' })
transactionTypeId: number typeId: number
@Column({ name: 'balance', type: 'bigint' }) @Column({ name: 'balance', type: 'bigint' })
balance: number balance: number

View File

@ -8,8 +8,8 @@ export class Transaction extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true }) @PrimaryGeneratedColumn('increment', { unsigned: true })
id: number id: number
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false }) @Column({ name: 'type_id', unsigned: true, nullable: false })
transactionTypeId: number typeId: number
@Column({ name: 'tx_hash', type: 'binary', length: 48, default: null }) @Column({ name: 'tx_hash', type: 'binary', length: 48, default: null })
txHash: Buffer txHash: Buffer

View File

@ -6,8 +6,8 @@ export class Transaction extends BaseEntity {
@PrimaryGeneratedColumn('increment', { unsigned: true }) @PrimaryGeneratedColumn('increment', { unsigned: true })
id: number id: number
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false }) @Column({ name: 'type_id', unsigned: true, nullable: false })
transactionTypeId: number typeId: number
@Column({ name: 'user_id', unsigned: true, nullable: false }) @Column({ name: 'user_id', unsigned: true, nullable: false })
userId: number userId: number

View File

@ -11,8 +11,8 @@ export class Transaction extends BaseEntity {
@Column({ name: 'transaction_id', unsigned: true, nullable: false }) @Column({ name: 'transaction_id', unsigned: true, nullable: false })
transactionId: number transactionId: number
@Column({ name: 'transaction_type_id', unsigned: true, nullable: false }) @Column({ name: 'type_id', unsigned: true, nullable: false })
transactionTypeId: number typeId: number
@Column({ type: 'bigint', nullable: false }) @Column({ type: 'bigint', nullable: false })
amount: BigInt amount: BigInt

View File

@ -140,7 +140,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
CREATE TABLE IF NOT EXISTS \`state_errors\` ( CREATE TABLE IF NOT EXISTS \`state_errors\` (
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
\`state_user_id\` int(10) unsigned NOT NULL, \`state_user_id\` int(10) unsigned NOT NULL,
\`transaction_type_id\` int(10) unsigned NOT NULL, \`type_id\` int(10) unsigned NOT NULL,
\`created\` datetime NOT NULL, \`created\` datetime NOT NULL,
\`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL, \`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (\`id\`) PRIMARY KEY (\`id\`)
@ -196,7 +196,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
\`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT,
\`state_user_id\` int UNSIGNED NOT NULL, \`state_user_id\` int UNSIGNED NOT NULL,
\`transaction_id\` int UNSIGNED NOT NULL, \`transaction_id\` int UNSIGNED NOT NULL,
\`transaction_type_id\` int UNSIGNED NOT NULL, \`type_id\` int UNSIGNED NOT NULL,
\`balance\` bigint(20) DEFAULT 0, \`balance\` bigint(20) DEFAULT 0,
\`balance_date\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, \`balance_date\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (\`id\`) PRIMARY KEY (\`id\`)
@ -304,7 +304,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
CREATE TABLE IF NOT EXISTS \`transactions\` ( CREATE TABLE IF NOT EXISTS \`transactions\` (
\`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT, \`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
\`state_group_id\` int(10) unsigned DEFAULT NULL, \`state_group_id\` int(10) unsigned DEFAULT NULL,
\`transaction_type_id\` int(10) unsigned NOT NULL, \`type_id\` int(10) unsigned NOT NULL,
\`tx_hash\` binary(48) DEFAULT NULL, \`tx_hash\` binary(48) DEFAULT NULL,
\`memo\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, \`memo\` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
\`received\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, \`received\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

View File

@ -292,7 +292,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
CREATE TABLE \`state_errors\` ( CREATE TABLE \`state_errors\` (
\`id\` int(10) unsigned NOT NULL AUTO_INCREMENT, \`id\` int(10) unsigned NOT NULL AUTO_INCREMENT,
\`state_user_id\` int(10) unsigned NOT NULL, \`state_user_id\` int(10) unsigned NOT NULL,
\`transaction_type_id\` int(10) unsigned NOT NULL, \`type_id\` int(10) unsigned NOT NULL,
\`created\` datetime NOT NULL, \`created\` datetime NOT NULL,
\`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL, \`message_json\` text COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (\`id\`) PRIMARY KEY (\`id\`)

View File

@ -9,7 +9,7 @@
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) { export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// Remove transactions with type 9 (start decay block). This should affect exactly 1 row // Remove transactions with type 9 (start decay block). This should affect exactly 1 row
await queryFn(`DELETE FROM transactions WHERE transaction_type_id = 9;`) await queryFn(`DELETE FROM transactions WHERE type_id = 9;`)
} }
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) { export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {

View File

@ -9,7 +9,7 @@
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) { export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
// Create new `user_id` column (former `state_user_id`), with a temporary default of null // Create new `user_id` column (former `state_user_id`), with a temporary default of null
await queryFn( await queryFn(
'ALTER TABLE `transactions` ADD COLUMN `user_id` int(10) unsigned DEFAULT NULL AFTER `transaction_type_id`;', 'ALTER TABLE `transactions` ADD COLUMN `user_id` int(10) unsigned DEFAULT NULL AFTER `type_id`;',
) )
// Create new `amount` column, with a temporary default of null // Create new `amount` column, with a temporary default of null
await queryFn( await queryFn(
@ -105,7 +105,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
send_receiver_public_key AS receiver_public_key, send_receiver_user_id AS receiver_user_id, send_receiver_public_key AS receiver_public_key, send_receiver_user_id AS receiver_user_id,
amount, send_sender_final_balance AS sender_final_balance amount, send_sender_final_balance AS sender_final_balance
FROM transactions FROM transactions
WHERE transaction_type_id = 2 ); WHERE type_id = 2 );
`) `)
await queryFn(` await queryFn(`
@ -115,7 +115,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
( SELECT id AS transaction_id, user_id AS state_user_id, ( SELECT id AS transaction_id, user_id AS state_user_id,
amount, creation_ident_hash AS ident_hash, creation_date AS target_date amount, creation_ident_hash AS ident_hash, creation_date AS target_date
FROM transactions FROM transactions
WHERE transaction_type_id = 1 ); WHERE type_id = 1 );
`) `)
await queryFn('ALTER TABLE `transactions` DROP COLUMN `send_sender_final_balance`;') await queryFn('ALTER TABLE `transactions` DROP COLUMN `send_sender_final_balance`;')

View File

@ -31,7 +31,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
await queryFn('ALTER TABLE `state_user_transactions` RENAME COLUMN state_user_id TO user_id;') await queryFn('ALTER TABLE `state_user_transactions` RENAME COLUMN state_user_id TO user_id;')
// Create new `amount` column, with a temporary default of null // Create new `amount` column, with a temporary default of null
await queryFn( await queryFn(
'ALTER TABLE `state_user_transactions` ADD COLUMN `amount` bigint(20) DEFAULT NULL AFTER `transaction_type_id`;', 'ALTER TABLE `state_user_transactions` ADD COLUMN `amount` bigint(20) DEFAULT NULL AFTER `type_id`;',
) )
// Create new `send_sender_final_balance` // Create new `send_sender_final_balance`
await queryFn( await queryFn(
@ -89,7 +89,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
state_user_transactions.signature = transactions.signature, state_user_transactions.signature = transactions.signature,
state_user_transactions.pubkey = transactions.pubkey, state_user_transactions.pubkey = transactions.pubkey,
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash state_user_transactions.creation_ident_hash = transactions.creation_ident_hash
WHERE state_user_transactions.transaction_type_id = 1; WHERE state_user_transactions.type_id = 1;
`) `)
// Insert Data from `transactions` for sendCoin sender // Insert Data from `transactions` for sendCoin sender
@ -104,7 +104,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
state_user_transactions.linked_user_id = transactions.send_receiver_user_id, state_user_transactions.linked_user_id = transactions.send_receiver_user_id,
state_user_transactions.linked_state_user_transaction_id = ( state_user_transactions.linked_state_user_transaction_id = (
SELECT id FROM state_user_transactions AS sut SELECT id FROM state_user_transactions AS sut
WHERE sut.transaction_type_id = 2 WHERE sut.type_id = 2
AND sut.transaction_id = state_user_transactions.transaction_id AND sut.transaction_id = state_user_transactions.transaction_id
AND sut.user_id = transactions.send_receiver_user_id AND sut.user_id = transactions.send_receiver_user_id
), ),
@ -112,7 +112,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
state_user_transactions.signature = transactions.signature, state_user_transactions.signature = transactions.signature,
state_user_transactions.pubkey = transactions.pubkey, state_user_transactions.pubkey = transactions.pubkey,
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash state_user_transactions.creation_ident_hash = transactions.creation_ident_hash
WHERE state_user_transactions.transaction_type_id = 2 WHERE state_user_transactions.type_id = 2
AND state_user_transactions.user_id = transactions.user_id; AND state_user_transactions.user_id = transactions.user_id;
`) `)
@ -128,7 +128,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
state_user_transactions.linked_user_id = transactions.user_id, state_user_transactions.linked_user_id = transactions.user_id,
state_user_transactions.linked_state_user_transaction_id = ( state_user_transactions.linked_state_user_transaction_id = (
SELECT id FROM state_user_transactions AS sut SELECT id FROM state_user_transactions AS sut
WHERE sut.transaction_type_id = 2 WHERE sut.type_id = 2
AND sut.transaction_id = state_user_transactions.transaction_id AND sut.transaction_id = state_user_transactions.transaction_id
AND sut.user_id = transactions.user_id AND sut.user_id = transactions.user_id
), ),
@ -136,8 +136,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
state_user_transactions.signature = transactions.signature, state_user_transactions.signature = transactions.signature,
state_user_transactions.pubkey = transactions.send_receiver_public_key, state_user_transactions.pubkey = transactions.send_receiver_public_key,
state_user_transactions.creation_ident_hash = transactions.creation_ident_hash, state_user_transactions.creation_ident_hash = transactions.creation_ident_hash,
state_user_transactions.transaction_type_id = 3 state_user_transactions.type_id = 3
WHERE state_user_transactions.transaction_type_id = 2 WHERE state_user_transactions.type_id = 2
AND state_user_transactions.user_id = transactions.send_receiver_user_id; AND state_user_transactions.user_id = transactions.send_receiver_user_id;
`) `)
@ -161,7 +161,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
await queryFn('RENAME TABLE `transactions` TO `state_user_transactions`;') await queryFn('RENAME TABLE `transactions` TO `state_user_transactions`;')
await queryFn(`CREATE TABLE \`transactions\` ( await queryFn(`CREATE TABLE \`transactions\` (
\`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT, \`id\` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
\`transaction_type_id\` int(10) unsigned NOT NULL, \`type_id\` int(10) unsigned NOT NULL,
\`user_id\` int(10) unsigned NOT NULL, \`user_id\` int(10) unsigned NOT NULL,
\`amount\` bigint(20) NOT NULL, \`amount\` bigint(20) NOT NULL,
\`tx_hash\` binary(48) DEFAULT NULL, \`tx_hash\` binary(48) DEFAULT NULL,
@ -179,13 +179,13 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
`) `)
await queryFn(` await queryFn(`
INSERT INTO transactions ( INSERT INTO transactions (
id, transaction_type_id, user_id, amount, id, type_id, user_id, amount,
tx_hash, memo, received, signature, pubkey, tx_hash, memo, received, signature, pubkey,
creation_ident_hash, creation_date, creation_ident_hash, creation_date,
send_receiver_public_key, send_receiver_user_id, send_receiver_public_key, send_receiver_user_id,
send_sender_final_balance send_sender_final_balance
) )
SELECT transaction_id AS id, transaction_type_id, SELECT transaction_id AS id, type_id,
user_id, amount, tx_hash, memo, received, user_id, amount, tx_hash, memo, received,
signature, pubkey, creation_ident_hash, signature, pubkey, creation_ident_hash,
creation_date, send_receiver_public_key, creation_date, send_receiver_public_key,
@ -194,12 +194,12 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
FROM state_user_transactions LEFT JOIN ( FROM state_user_transactions LEFT JOIN (
SELECT id, pubkey AS send_receiver_public_key SELECT id, pubkey AS send_receiver_public_key
FROM state_user_transactions AS sut FROM state_user_transactions AS sut
WHERE sut.transaction_type_id = 3 WHERE sut.type_id = 3
) AS sutj ON sutj.id = state_user_transactions.id ) AS sutj ON sutj.id = state_user_transactions.id
WHERE transaction_type_id IN (1,2) WHERE type_id IN (1,2)
`) `)
await queryFn( await queryFn(
'UPDATE state_user_transactions SET transaction_type_id = 2 WHERE transaction_type_id = 3;', 'UPDATE state_user_transactions SET type_id = 2 WHERE type_id = 3;',
) )
await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `creation_ident_hash`;') await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `creation_ident_hash`;')
await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `pubkey`;') await queryFn('ALTER TABLE `state_user_transactions` DROP COLUMN `pubkey`;')

View File

@ -23,8 +23,8 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
// drop column `creation_ident_hash`, it is not needed // drop column `creation_ident_hash`, it is not needed
await queryFn('ALTER TABLE `transactions` DROP COLUMN `creation_ident_hash`;') await queryFn('ALTER TABLE `transactions` DROP COLUMN `creation_ident_hash`;')
// rename `transaction_type_id` to `type_id` // rename `type_id` to `type_id`
await queryFn('ALTER TABLE `transactions` RENAME COLUMN transaction_type_id TO type_id;') await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO type_id;')
// rename `linked_state_user_transaction_id` to `linked_transaction_id` // rename `linked_state_user_transaction_id` to `linked_transaction_id`
await queryFn( await queryFn(
'ALTER TABLE `transactions` RENAME COLUMN linked_state_user_transaction_id TO linked_transaction_id;', 'ALTER TABLE `transactions` RENAME COLUMN linked_state_user_transaction_id TO linked_transaction_id;',
@ -43,7 +43,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
await queryFn( await queryFn(
'ALTER TABLE `transactions` RENAME COLUMN linked_transaction_id TO linked_state_user_transaction_id;', 'ALTER TABLE `transactions` RENAME COLUMN linked_transaction_id TO linked_state_user_transaction_id;',
) )
await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO transaction_type_id;') await queryFn('ALTER TABLE `transactions` RENAME COLUMN type_id TO type_id;')
await queryFn( await queryFn(
'ALTER TABLE `transactions` ADD COLUMN `creation_ident_hash` binary(32) DEFAULT NULL AFTER `linked_state_user_transaction_id`;', 'ALTER TABLE `transactions` ADD COLUMN `creation_ident_hash` binary(32) DEFAULT NULL AFTER `linked_state_user_transaction_id`;',
) )

View File

@ -40,7 +40,7 @@ interface Decay {
duration: number | null duration: number | null
} }
export enum TransactionTypeId { export enum TypeId {
CREATION = 1, CREATION = 1,
SEND = 2, SEND = 2,
RECEIVE = 3, RECEIVE = 3,
@ -162,7 +162,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
// This should also fix the rounding error on amount // This should also fix the rounding error on amount
let decAmount = new Decimal(transaction.amount).dividedBy(10000).toDecimalPlaces(2) let decAmount = new Decimal(transaction.amount).dividedBy(10000).toDecimalPlaces(2)
if (transaction.type_id === TransactionTypeId.SEND) { if (transaction.type_id === TypeId.SEND) {
decAmount = decAmount.mul(-1) decAmount = decAmount.mul(-1)
} }
const decayStartDate = previous ? previous.balance_date : transaction.balance_date const decayStartDate = previous ? previous.balance_date : transaction.balance_date

View File

@ -61,7 +61,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
await queryFn(` await queryFn(`
INSERT INTO \`state_balances\` INSERT INTO \`state_balances\`
(state_user_id, modified, record_date, amount) (state_user_id, modified, record_date, amount)
SELECT user_id as state_user_id, balance_date as modified, balance_date as record_date, amount * 10000 as amount FROM SELECT user_id as state_user_id, balance_date as modified, balance_date as record_date, amount as amount FROM
(SELECT user_id as uid, MAX(balance_date) AS date FROM transactions GROUP BY uid) AS t (SELECT user_id as uid, MAX(balance_date) AS date FROM transactions GROUP BY uid) AS t
LEFT JOIN transactions ON t.uid = transactions.user_id AND t.date = transactions.balance_date; LEFT JOIN transactions ON t.uid = transactions.user_id AND t.date = transactions.balance_date;
`) `)
@ -96,9 +96,9 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
temp_dec_old_balance = dec_balance, temp_dec_old_balance = dec_balance,
temp_dec_diff_send_sender_final_balance = 0, temp_dec_diff_send_sender_final_balance = 0,
temp_dec_send_sender_final_balance = dec_balance, temp_dec_send_sender_final_balance = dec_balance,
balance = dec_balance * 10000, balance = dec_balance,
send_sender_final_balance = dec_balance * 10000, send_sender_final_balance = dec_balance,
amount = dec_amount * 10000; amount = dec_amount;
`) `)
await queryFn('ALTER TABLE `transactions` MODIFY COLUMN `amount` bigint(20) NOT NULL;') await queryFn('ALTER TABLE `transactions` MODIFY COLUMN `amount` bigint(20) NOT NULL;')

File diff suppressed because one or more lines are too long

View File

@ -126,7 +126,7 @@ CREATE TABLE `state_created` (
CREATE TABLE `state_errors` ( CREATE TABLE `state_errors` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL,
`state_user_id` int(11) NOT NULL, `state_user_id` int(11) NOT NULL,
`transaction_type_id` int(11) NOT NULL, `type_id` int(11) NOT NULL,
`created` datetime NOT NULL, `created` datetime NOT NULL,
`message_json` text NOT NULL `message_json` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@ -194,7 +194,7 @@ CREATE TABLE `state_users` (
CREATE TABLE `transactions` ( CREATE TABLE `transactions` (
`id` bigint(20) NOT NULL, `id` bigint(20) NOT NULL,
`group_id` int(11) NOT NULL, `group_id` int(11) NOT NULL,
`transaction_type_id` int(11) NOT NULL, `type_id` int(11) NOT NULL,
`tx_hash` binary(32) NOT NULL, `tx_hash` binary(32) NOT NULL,
`memo` varchar(255) COLLATE utf8_bin NOT NULL, `memo` varchar(255) COLLATE utf8_bin NOT NULL,
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP `received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

View File

@ -126,7 +126,7 @@ CREATE TABLE `state_created` (
CREATE TABLE `state_errors` ( CREATE TABLE `state_errors` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL,
`state_user_id` int(11) NOT NULL, `state_user_id` int(11) NOT NULL,
`transaction_type_id` int(11) NOT NULL, `type_id` int(11) NOT NULL,
`created` datetime NOT NULL, `created` datetime NOT NULL,
`message_json` text NOT NULL `message_json` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@ -194,7 +194,7 @@ CREATE TABLE `state_users` (
CREATE TABLE `transactions` ( CREATE TABLE `transactions` (
`id` bigint(20) NOT NULL, `id` bigint(20) NOT NULL,
`group_id` int(11) NOT NULL, `group_id` int(11) NOT NULL,
`transaction_type_id` int(11) NOT NULL, `type_id` int(11) NOT NULL,
`tx_hash` binary(32) NOT NULL, `tx_hash` binary(32) NOT NULL,
`memo` varchar(255) COLLATE utf8_bin NOT NULL, `memo` varchar(255) COLLATE utf8_bin NOT NULL,
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP `received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

View File

@ -27,7 +27,7 @@ state_users
id index group_id public_key email first_name last_name id index group_id public_key email first_name last_name
state_errors state_errors
id state_user_id transaction_type_id created message_json id state_user_id type_id created message_json
state_balances state_balances
id state_user_id modified amount id state_user_id modified amount
@ -48,7 +48,7 @@ id transaction_id signature pubkey
transactions transactions
int64 int64
id state_group_id transaction_type_id tx_hash received id state_group_id type_id tx_hash received
transaction_send_coins transaction_send_coins
id transaction_id state_user_id receiver_public receiver_user_id amount sender_final_balance id transaction_id state_user_id receiver_public receiver_user_id amount sender_final_balance

View File

@ -8,7 +8,7 @@ id transaction_id signature pubkey
transactions transactions
int64 int64
id group_id timestamp transaction_type_id hash received id group_id timestamp type_id hash received
transaction_bins transaction_bins
id transaction_id filename start size id transaction_id filename start size
@ -16,5 +16,5 @@ id transaction_id filename start size
state_created state_created
id transaction_id month year short_ident_hash id transaction_id month year short_ident_hash
Für mehr Performance, jeweils eine transactions, transaction_bins und transaction_signatures F<EFBFBD>r mehr Performance, jeweils eine transactions, transaction_bins und transaction_signatures
Tabelle pro Gruppe Tabelle pro Gruppe

View File

@ -2,7 +2,7 @@
CREATE TABLE `transactions` ( CREATE TABLE `transactions` (
`id` bigint(20) NOT NULL, `id` bigint(20) NOT NULL,
`state_group_id` int(11) NOT NULL, `state_group_id` int(11) NOT NULL,
`transaction_type_id` int(11) NOT NULL, `type_id` int(11) NOT NULL,
`tx_hash` binary(32) NOT NULL, `tx_hash` binary(32) NOT NULL,
`received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `received` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)

View File

@ -122,7 +122,7 @@ export default {
}, },
computed: { computed: {
duration() { duration() {
return this.$moment.duration((this.decay.end - this.decay.start) * 1000)._data return this.$moment.duration(this.decay.end - this.decay.start)._data
}, },
}, },
} }