From f27b438bfb0bec5d23fb0d427d698f6139d95c24 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 30 Dec 2025 14:52:08 +0100 Subject: [PATCH] use precise ledger anchor type --- dlt-connector/bun.lock | 1 + .../blockchain.ts | 32 ++----------------- .../db-v2.7.0_to_blockchain-v3.5/bootstrap.ts | 9 ++++-- .../CreationsSync.role.ts | 3 +- .../DeletedTransactionLinksSync.role.ts | 3 +- .../LocalTransactionsSync.role.ts | 3 +- .../RedeemTransactionLinksSync.role.ts | 3 +- .../TransactionLinkFundingsSync.role.ts | 3 +- .../syncDbWithBlockchain/UsersSync.role.ts | 16 ++++++---- 9 files changed, 31 insertions(+), 42 deletions(-) diff --git a/dlt-connector/bun.lock b/dlt-connector/bun.lock index 5337098a9..faaacaeb4 100644 --- a/dlt-connector/bun.lock +++ b/dlt-connector/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "dlt-connector", diff --git a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/blockchain.ts b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/blockchain.ts index d689f22e1..5091a122b 100644 --- a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/blockchain.ts +++ b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/blockchain.ts @@ -4,29 +4,23 @@ import { GradidoTransactionBuilder, HieroAccountId, InMemoryBlockchain, + LedgerAnchor, } from 'gradido-blockchain-js' -import { getLogger } from 'log4js' -import { LOG4JS_BASE_CATEGORY } from '../../config/const' -import { CommunityRootTransactionRole } from '../../interactions/sendToHiero/CommunityRootTransaction.role' -import { Community } from '../../schemas/transaction.schema' import { NotEnoughGradidoBalanceError } from './errors' -const logger = getLogger( - `${LOG4JS_BASE_CATEGORY}.migrations.db-v2.7.0_to_blockchain-v3.6.blockchain`, -) export const defaultHieroAccount = new HieroAccountId(0, 0, 2) export function addToBlockchain( builder: GradidoTransactionBuilder, blockchain: InMemoryBlockchain, - transactionId: number, + ledgerAnchor: LedgerAnchor, accountBalances: AccountBalances, ): boolean { const transaction = builder.build() try { const result = blockchain.createAndAddConfirmedTransactionExtern( transaction, - transactionId, + ledgerAnchor, accountBalances, ) return result @@ -44,23 +38,3 @@ export function addToBlockchain( } } -export async function addCommunityRootTransaction( - blockchain: InMemoryBlockchain, - community: Community, - accountBalances: AccountBalances -): Promise { - const communityRootTransactionRole = new CommunityRootTransactionRole(community) - if ( - addToBlockchain( - await communityRootTransactionRole.getGradidoTransactionBuilder(), - blockchain, - 0, - accountBalances, - ) - ) { - logger.info(`Community Root Transaction added`) - } else { - throw new Error(`Community Root Transaction not added`) - } -} - diff --git a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/bootstrap.ts b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/bootstrap.ts index cd34bd8eb..9bc6f6a57 100644 --- a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/bootstrap.ts +++ b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/bootstrap.ts @@ -1,5 +1,5 @@ import { randomBytes } from 'node:crypto' -import { AccountBalances, GradidoTransactionBuilder, InMemoryBlockchainProvider } from 'gradido-blockchain-js' +import { AccountBalances, GradidoTransactionBuilder, InMemoryBlockchainProvider, LedgerAnchor } from 'gradido-blockchain-js' import * as v from 'valibot' import { CONFIG } from '../../config' import { deriveFromSeed } from '../../data/deriveKeyPair' @@ -80,7 +80,12 @@ async function bootstrapCommunities(context: Context): Promise { addToBlockchain( this.buildTransaction(item, communityContext, recipientKeyPair, signerKeyPair), blockchain, - item.id, + new LedgerAnchor(item.id, LedgerAnchor.Type_LEGACY_GRADIDO_DB_CONTRIBUTION_ID), this.calculateAccountBalances(item, communityContext, recipientPublicKey), ) } catch(e) { diff --git a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/DeletedTransactionLinksSync.role.ts b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/DeletedTransactionLinksSync.role.ts index 0111234b7..e772509f9 100644 --- a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/DeletedTransactionLinksSync.role.ts +++ b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/DeletedTransactionLinksSync.role.ts @@ -12,6 +12,7 @@ import { GradidoTransfer, GradidoUnit, KeyPairEd25519, + LedgerAnchor, MemoryBlockPtr, TransferAmount } from 'gradido-blockchain-js' @@ -149,7 +150,7 @@ export class DeletedTransactionLinksSyncRole extends AbstractSyncRole { addToBlockchain( this.buildTransaction(item, senderKeyPair, recipientKeyPair), blockchain, - item.id, + new LedgerAnchor(item.id, LedgerAnchor.Type_LEGACY_GRADIDO_DB_TRANSACTION_ID), this.calculateBalances(item, communityContext, senderPublicKey, recipientPublicKey), ) } catch(e) { diff --git a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/RedeemTransactionLinksSync.role.ts b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/RedeemTransactionLinksSync.role.ts index 810fed60d..139be9259 100644 --- a/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/RedeemTransactionLinksSync.role.ts +++ b/dlt-connector/src/migrations/db-v2.7.0_to_blockchain-v3.5/interaction/syncDbWithBlockchain/RedeemTransactionLinksSync.role.ts @@ -10,6 +10,7 @@ import { GradidoTransfer, GradidoUnit, KeyPairEd25519, + LedgerAnchor, MemoryBlockPtr, TransferAmount } from 'gradido-blockchain-js' @@ -163,7 +164,7 @@ export class RedeemTransactionLinksSyncRole extends AbstractSyncRole { const result = await this.context.db .select() .from(usersTable) - .where(or( - gt(usersTable.createdAt, toMysqlDateTime(lastIndex.date)), - and( - eq(usersTable.createdAt, toMysqlDateTime(lastIndex.date)), - gt(usersTable.id, lastIndex.id) + .where(and( + eq(usersTable.foreign, 0), + or( + gt(usersTable.createdAt, toMysqlDateTime(lastIndex.date)), + and( + eq(usersTable.createdAt, toMysqlDateTime(lastIndex.date)), + gt(usersTable.id, lastIndex.id) + ) ) )) .orderBy(asc(usersTable.createdAt), asc(usersTable.id)) @@ -94,7 +98,7 @@ export class UsersSyncRole extends AbstractSyncRole { addToBlockchain( this.buildTransaction(item, communityContext.keyPair, accountKeyPair, userKeyPair), communityContext.blockchain, - item.id, + new LedgerAnchor(item.id, LedgerAnchor.Type_LEGACY_GRADIDO_DB_USER_ID), this.calculateAccountBalances(accountPublicKey), ) } catch (e) {