mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
add workarund for contribution resolver and binarization instead of InMemoryBlockchain for exporting testdata to gradido-blockchain
This commit is contained in:
parent
0ac776fc14
commit
4a72e65460
@ -25,12 +25,14 @@ import { Community, Transaction } from '../../schemas/transaction.schema'
|
||||
import { identifierSeedSchema } from '../../schemas/typeGuard.schema'
|
||||
import { AbstractTransactionRole } from '../../interactions/sendToHiero/AbstractTransaction.role'
|
||||
import * as v from 'valibot'
|
||||
import * as fs from 'node:fs'
|
||||
|
||||
const logger = getLogger(
|
||||
`${LOG4JS_BASE_CATEGORY}.migrations.db-v2.7.0_to_blockchain-v3.6.blockchain`,
|
||||
)
|
||||
export const defaultHieroAccount = new HieroAccountId(0, 0, 2)
|
||||
let transactionAddedToBlockchainSum = 0
|
||||
const sizeBuffer = Buffer.alloc(2)
|
||||
|
||||
function addToBlockchain(
|
||||
builder: GradidoTransactionBuilder,
|
||||
@ -38,7 +40,18 @@ function addToBlockchain(
|
||||
createdAtTimestamp: Timestamp,
|
||||
): boolean {
|
||||
const transaction = builder.build()
|
||||
// TOD: use actual transaction id if exist in dlt_transactions table
|
||||
/* const transactionSerializer = new InteractionSerialize(transaction)
|
||||
const binTransaction = transactionSerializer.run()
|
||||
if (!binTransaction) {
|
||||
logger.error(`Failed to serialize transaction ${transaction.toJson(true)}`)
|
||||
return false
|
||||
}
|
||||
const filePath = `${blockchain.getCommunityId()}.bin`
|
||||
sizeBuffer.writeUInt16LE(binTransaction.size(), 0)
|
||||
fs.appendFileSync(filePath, sizeBuffer)
|
||||
fs.appendFileSync(filePath, binTransaction.data())
|
||||
*/
|
||||
// TODO: use actual transaction id if exist in dlt_transactions table
|
||||
const transactionId = new HieroTransactionId(createdAtTimestamp, defaultHieroAccount)
|
||||
const interactionSerialize = new InteractionSerialize(transactionId)
|
||||
|
||||
@ -51,7 +64,7 @@ function addToBlockchain(
|
||||
return result
|
||||
} catch (error) {
|
||||
logger.error(`Transaction ${transaction.toJson(true)} not added: ${error}`)
|
||||
return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { and, asc, eq, inArray, isNotNull, lt, sql } from 'drizzle-orm'
|
||||
import { and, asc, eq, inArray, isNotNull, lt, ne, sql } from 'drizzle-orm'
|
||||
import { alias } from 'drizzle-orm/mysql-core'
|
||||
import { MySql2Database } from 'drizzle-orm/mysql2'
|
||||
import { GradidoUnit } from 'gradido-blockchain-js'
|
||||
@ -11,6 +11,7 @@ import {
|
||||
eventsTable,
|
||||
transactionLinksTable,
|
||||
transactionsTable,
|
||||
userRolesTable,
|
||||
usersTable,
|
||||
} from './drizzle.schema'
|
||||
import { TransactionTypeId } from './TransactionTypeId'
|
||||
@ -136,6 +137,21 @@ export async function loadTransactions(
|
||||
.limit(1)
|
||||
if (contribution && contribution.length > 0 && contribution[0].contributionLinkId) {
|
||||
linkedUser = contributionLinkModerators.get(contribution[0].contributionLinkId)
|
||||
if (linkedUser?.gradidoId === user.gradidoId) {
|
||||
const adminUser = await db
|
||||
.select({
|
||||
user: usersTable
|
||||
})
|
||||
.from(usersTable)
|
||||
.leftJoin(userRolesTable, and(eq(usersTable.id, userRolesTable.userId), eq(userRolesTable.role, 'admin')))
|
||||
.orderBy(asc(userRolesTable.id))
|
||||
.where(ne(userRolesTable.userId, row.user.id))
|
||||
.limit(1)
|
||||
if (!adminUser || !adminUser.length) {
|
||||
throw new Error(`cannot find replace admin for contribution link`)
|
||||
}
|
||||
linkedUser = v.parse(createdUserDbSchema, adminUser[0].user)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
linkedUser = v.parse(createdUserDbSchema, row.linkedUser)
|
||||
|
||||
@ -25,20 +25,20 @@ export const communitiesTable = mysqlTable(
|
||||
(table) => [unique('uuid_key').on(table.communityUuid)],
|
||||
)
|
||||
|
||||
export const contributionsTable = mysqlTable("contributions", {
|
||||
export const contributionsTable = mysqlTable('contributions', {
|
||||
id: int().autoincrement().notNull(),
|
||||
contributionLinkId: int("contribution_link_id").default(sql`NULL`),
|
||||
confirmedBy: int("confirmed_by").default(sql`NULL`),
|
||||
confirmedAt: datetime("confirmed_at", { mode: 'string'}).default(sql`NULL`),
|
||||
deletedAt: datetime("deleted_at", { mode: 'string'}).default(sql`NULL`),
|
||||
transactionId: int("transaction_id").default(sql`NULL`),
|
||||
contributionLinkId: int('contribution_link_id').default(sql`NULL`),
|
||||
confirmedBy: int('confirmed_by').default(sql`NULL`),
|
||||
confirmedAt: datetime('confirmed_at', { mode: 'string'}).default(sql`NULL`),
|
||||
deletedAt: datetime('deleted_at', { mode: 'string'}).default(sql`NULL`),
|
||||
transactionId: int('transaction_id').default(sql`NULL`),
|
||||
})
|
||||
|
||||
export const eventsTable = mysqlTable("events", {
|
||||
export const eventsTable = mysqlTable('events', {
|
||||
id: int().autoincrement().notNull(),
|
||||
type: varchar({ length: 100 }).notNull(),
|
||||
actingUserId: int("acting_user_id").notNull(),
|
||||
involvedContributionLinkId: int("involved_contribution_link_id").default(sql`NULL`),
|
||||
actingUserId: int('acting_user_id').notNull(),
|
||||
involvedContributionLinkId: int('involved_contribution_link_id').default(sql`NULL`),
|
||||
})
|
||||
|
||||
export const usersTable = mysqlTable(
|
||||
@ -54,6 +54,15 @@ export const usersTable = mysqlTable(
|
||||
(table) => [unique('uuid_key').on(table.gradidoId, table.communityUuid)],
|
||||
)
|
||||
|
||||
export const userRolesTable = mysqlTable('user_roles', {
|
||||
id: int().autoincrement().notNull(),
|
||||
userId: int('user_id').notNull(),
|
||||
role: varchar({ length: 40 }).notNull(),
|
||||
},
|
||||
(table) => [
|
||||
index('user_id').on(table.userId),
|
||||
])
|
||||
|
||||
export const transactionsTable = mysqlTable(
|
||||
'transactions',
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user