use precise ledger anchor type

This commit is contained in:
einhornimmond 2025-12-30 14:52:08 +01:00
parent 8618b8193a
commit f27b438bfb
9 changed files with 31 additions and 42 deletions

View File

@ -1,5 +1,6 @@
{
"lockfileVersion": 1,
"configVersion": 0,
"workspaces": {
"": {
"name": "dlt-connector",

View File

@ -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<void> {
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`)
}
}

View File

@ -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<Map<string, Commu
const accountBalances = new AccountBalances()
accountBalances.add(communityContext.aufBalance.getAccountBalance())
accountBalances.add(communityContext.gmwBalance.getAccountBalance())
addToBlockchain(builder, blockchain, communityDb.id, accountBalances)
addToBlockchain(
builder,
blockchain,
new LedgerAnchor(communityDb.id, LedgerAnchor.Type_LEGACY_GRADIDO_DB_COMMUNITY_ID),
accountBalances,
)
}
return communities
}

View File

@ -7,6 +7,7 @@ import {
Filter,
GradidoTransactionBuilder,
KeyPairEd25519,
LedgerAnchor,
MemoryBlockPtr,
SearchDirection_DESC,
TransactionType_CREATION,
@ -137,7 +138,7 @@ export class CreationsSyncRole extends AbstractSyncRole<CreationTransactionDb> {
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) {

View File

@ -12,6 +12,7 @@ import {
GradidoTransfer,
GradidoUnit,
KeyPairEd25519,
LedgerAnchor,
MemoryBlockPtr,
TransferAmount
} from 'gradido-blockchain-js'
@ -149,7 +150,7 @@ export class DeletedTransactionLinksSyncRole extends AbstractSyncRole<DeletedTra
linkFundingPublicKey,
),
blockchain,
item.id,
new LedgerAnchor(item.id, LedgerAnchor.Type_LEGACY_GRADIDO_DB_TRANSACTION_LINK_ID),
this.calculateBalances(item, deferredTransfer, senderLastBalance, communityContext, senderPublicKey),
)
} catch(e) {

View File

@ -7,6 +7,7 @@ import {
Filter,
GradidoTransactionBuilder,
KeyPairEd25519,
LedgerAnchor,
MemoryBlockPtr,
SearchDirection_DESC,
TransferAmount
@ -146,7 +147,7 @@ export class LocalTransactionsSyncRole extends AbstractSyncRole<TransactionDb> {
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) {

View File

@ -10,6 +10,7 @@ import {
GradidoTransfer,
GradidoUnit,
KeyPairEd25519,
LedgerAnchor,
MemoryBlockPtr,
TransferAmount
} from 'gradido-blockchain-js'
@ -163,7 +164,7 @@ export class RedeemTransactionLinksSyncRole extends AbstractSyncRole<RedeemedTra
addToBlockchain(
this.buildTransaction(item, transaction.getTransactionNr(), senderKeyPair, recipientKeyPair),
blockchain,
item.id,
new LedgerAnchor(item.id, LedgerAnchor.Type_LEGACY_GRADIDO_DB_TRANSACTION_LINK_ID),
this.calculateBalances(item, deferredTransfer, communityContext, senderPublicKey, recipientPublicKey),
)
} catch(e) {

View File

@ -9,6 +9,7 @@ import {
GradidoTransfer,
GradidoUnit,
KeyPairEd25519,
LedgerAnchor,
MemoryBlockPtr,
TransferAmount
} from 'gradido-blockchain-js'
@ -179,7 +180,7 @@ export class TransactionLinkFundingsSyncRole extends AbstractSyncRole<Transactio
addToBlockchain(
this.buildTransaction(item, blockedAmount, duration, senderKeyPair, recipientKeyPair),
blockchain,
item.id,
new LedgerAnchor(item.id, LedgerAnchor.Type_LEGACY_GRADIDO_DB_TRANSACTION_LINK_ID),
accountBalances,
)
} catch(e) {

View File

@ -6,6 +6,7 @@ import {
GradidoTransactionBuilder,
GradidoUnit,
KeyPairEd25519,
LedgerAnchor,
MemoryBlockPtr
} from 'gradido-blockchain-js'
import * as v from 'valibot'
@ -37,11 +38,14 @@ export class UsersSyncRole extends AbstractSyncRole<UserDb> {
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<UserDb> {
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) {