fix order of builder commands, debug logs

This commit is contained in:
einhornimmond 2026-02-13 08:38:20 +01:00
parent be48f6aaa2
commit 4dde30ea4b
11 changed files with 25 additions and 16 deletions

View File

@ -4,8 +4,10 @@ import {
GradidoTransaction, GradidoTransaction,
HieroAccountId, HieroAccountId,
InMemoryBlockchain, InMemoryBlockchain,
InMemoryBlockchainProvider,
LedgerAnchor, LedgerAnchor,
Profiler, Profiler,
TransactionEntry,
} from 'gradido-blockchain-js' } from 'gradido-blockchain-js'
import { NotEnoughGradidoBalanceError } from './errors' import { NotEnoughGradidoBalanceError } from './errors'
@ -38,6 +40,9 @@ export function addToBlockchain(
throw new NotEnoughGradidoBalanceError(needed, exist) throw new NotEnoughGradidoBalanceError(needed, exist)
} }
} }
// const wekingheim = InMemoryBlockchainProvider.getInstance().getBlockchain('wekingheim')
// const lastTransactionw = wekingheim?.findOne(Filter.LAST_TRANSACTION)
const lastTransaction = blockchain.findOne(Filter.LAST_TRANSACTION) const lastTransaction = blockchain.findOne(Filter.LAST_TRANSACTION)
throw new Error(`Transaction ${transaction.toJson(true)} not added: ${error}, last transaction was: ${lastTransaction?.getConfirmedTransaction()?.toJson(true)}`) throw new Error(`Transaction ${transaction.toJson(true)} not added: ${error}, last transaction was: ${lastTransaction?.getConfirmedTransaction()?.toJson(true)}`)
} }

View File

@ -1,5 +1,5 @@
import { randomBytes } from 'node:crypto' import { randomBytes } from 'node:crypto'
import { Abstract, AccountBalances, GradidoTransactionBuilder, InMemoryBlockchain, InMemoryBlockchainProvider, LedgerAnchor } from 'gradido-blockchain-js' import { AccountBalances, GradidoTransactionBuilder, InMemoryBlockchainProvider, LedgerAnchor } from 'gradido-blockchain-js'
import * as v from 'valibot' import * as v from 'valibot'
import { CONFIG } from '../../config' import { CONFIG } from '../../config'
import { deriveFromSeed } from '../../data/deriveKeyPair' import { deriveFromSeed } from '../../data/deriveKeyPair'
@ -33,7 +33,7 @@ async function bootstrapCommunities(context: Context): Promise<Map<string, Commu
} else { } else {
communityNames.add(alias) communityNames.add(alias)
} }
const blockchain = InMemoryBlockchainProvider.getInstance().findBlockchain(alias) const blockchain = InMemoryBlockchainProvider.getInstance().getBlockchain(alias)
if (!blockchain) { if (!blockchain) {
throw new Error(`Couldn't create Blockchain for community ${alias}`) throw new Error(`Couldn't create Blockchain for community ${alias}`)
} }
@ -59,12 +59,12 @@ async function bootstrapCommunities(context: Context): Promise<Map<string, Commu
const builder = new GradidoTransactionBuilder() const builder = new GradidoTransactionBuilder()
builder builder
.setCreatedAt(creationDate) .setCreatedAt(creationDate)
.setSenderCommunity(alias)
.setCommunityRoot( .setCommunityRoot(
communityKeyPair.getPublicKey(), communityKeyPair.getPublicKey(),
gmwKeyPair.getPublicKey(), gmwKeyPair.getPublicKey(),
aufKeyPair.getPublicKey(), aufKeyPair.getPublicKey(),
) )
.setSenderCommunity(alias)
.sign(communityKeyPair) .sign(communityKeyPair)
const communityContext: CommunityContext = { const communityContext: CommunityContext = {

View File

@ -93,6 +93,7 @@ export class CreationsSyncRole extends AbstractSyncRole<CreationTransactionDb> {
): GradidoTransactionBuilder { ): GradidoTransactionBuilder {
return this.transactionBuilder return this.transactionBuilder
.setCreatedAt(item.confirmedAt) .setCreatedAt(item.confirmedAt)
.setRecipientCommunity(communityContext.communityId)
.addMemo( .addMemo(
new EncryptedMemo( new EncryptedMemo(
item.memo, item.memo,
@ -104,7 +105,6 @@ export class CreationsSyncRole extends AbstractSyncRole<CreationTransactionDb> {
new TransferAmount(recipientKeyPair.getPublicKey(), item.amount, communityContext.communityId), new TransferAmount(recipientKeyPair.getPublicKey(), item.amount, communityContext.communityId),
item.contributionDate, item.contributionDate,
) )
.setRecipientCommunity(communityContext.communityId)
.sign(signerKeyPair) .sign(signerKeyPair)
} }

View File

@ -89,6 +89,7 @@ export class DeletedTransactionLinksSyncRole extends AbstractSyncRole<DeletedTra
): GradidoTransactionBuilder { ): GradidoTransactionBuilder {
return this.transactionBuilder return this.transactionBuilder
.setCreatedAt(item.deletedAt) .setCreatedAt(item.deletedAt)
.setSenderCommunity(communityContext.communityId)
.setRedeemDeferredTransfer( .setRedeemDeferredTransfer(
linkFundingTransactionNr, linkFundingTransactionNr,
new GradidoTransfer( new GradidoTransfer(
@ -96,7 +97,6 @@ export class DeletedTransactionLinksSyncRole extends AbstractSyncRole<DeletedTra
linkFundingPublicKey, linkFundingPublicKey,
), ),
) )
.setSenderCommunity(communityContext.communityId)
.sign(senderKeyPair) .sign(senderKeyPair)
} }

View File

@ -97,11 +97,11 @@ export class LocalTransactionsSyncRole extends AbstractSyncRole<TransactionDb> {
new AuthenticatedEncryption(recipientKeyPair), new AuthenticatedEncryption(recipientKeyPair),
), ),
) )
.setSenderCommunity(communityContext.communityId)
.setTransactionTransfer( .setTransactionTransfer(
new TransferAmount(senderKeyPair.getPublicKey(), item.amount, communityContext.communityId), new TransferAmount(senderKeyPair.getPublicKey(), item.amount, communityContext.communityId),
recipientKeyPair.getPublicKey(), recipientKeyPair.getPublicKey(),
) )
.setSenderCommunity(communityContext.communityId)
.sign(senderKeyPair) .sign(senderKeyPair)
} }

View File

@ -103,6 +103,7 @@ export class RedeemTransactionLinksSyncRole extends AbstractSyncRole<RedeemedTra
new AuthenticatedEncryption(recipientKeyPair), new AuthenticatedEncryption(recipientKeyPair),
), ),
) )
.setSenderCommunity(communityContext.communityId)
.setRedeemDeferredTransfer( .setRedeemDeferredTransfer(
linkFundingTransactionNr, linkFundingTransactionNr,
new GradidoTransfer( new GradidoTransfer(
@ -110,7 +111,6 @@ export class RedeemTransactionLinksSyncRole extends AbstractSyncRole<RedeemedTra
recipientKeyPair.getPublicKey(), recipientKeyPair.getPublicKey(),
), ),
) )
.setSenderCommunity(communityContext.communityId)
.sign(senderKeyPair) .sign(senderKeyPair)
} }

View File

@ -93,12 +93,12 @@ export class RemoteTransactionsSyncRole extends AbstractSyncRole<TransactionDb>
new AuthenticatedEncryption(recipientKeyPair), new AuthenticatedEncryption(recipientKeyPair),
), ),
) )
.setSenderCommunity(senderCommunityId)
.setRecipientCommunity(recipientCommunityId)
.setTransactionTransfer( .setTransactionTransfer(
new TransferAmount(senderKeyPair.getPublicKey(), item.amount, senderCommunityId), new TransferAmount(senderKeyPair.getPublicKey(), item.amount, senderCommunityId),
recipientKeyPair.getPublicKey(), recipientKeyPair.getPublicKey(),
) )
.setSenderCommunity(senderCommunityId)
.setRecipientCommunity(recipientCommunityId)
.sign(senderKeyPair) .sign(senderKeyPair)
} }
@ -165,6 +165,9 @@ export class RemoteTransactionsSyncRole extends AbstractSyncRole<TransactionDb>
recipientCommunityContext.communityId recipientCommunityContext.communityId
) )
const outboundTransaction = transactionBuilder.buildOutbound() const outboundTransaction = transactionBuilder.buildOutbound()
console.log(ledgerAnchor.toJson(true))
console.log(outboundTransaction.toJson(true))
console.log("outbound coin color: %d", outboundTransaction.getTransactionBody()?.getTransferAmount().getCoinCommunityIdIndex())
try { try {
addToBlockchain( addToBlockchain(
@ -181,6 +184,8 @@ export class RemoteTransactionsSyncRole extends AbstractSyncRole<TransactionDb>
} }
transactionBuilder.setParentLedgerAnchor(ledgerAnchor) transactionBuilder.setParentLedgerAnchor(ledgerAnchor)
const inboundTransaction = transactionBuilder.buildInbound() const inboundTransaction = transactionBuilder.buildInbound()
console.log(inboundTransaction.toJson(true))
console.log("inbound coin color: %d", inboundTransaction.getTransactionBody()?.getTransferAmount().getCoinCommunityIdIndex())
try { try {
addToBlockchain( addToBlockchain(
inboundTransaction, inboundTransaction,

View File

@ -87,14 +87,14 @@ export class TransactionLinkFundingsSyncRole extends AbstractSyncRole<Transactio
new AuthenticatedEncryption(recipientKeyPair), new AuthenticatedEncryption(recipientKeyPair),
), ),
) )
.setSenderCommunity(communityContext.communityId)
.setDeferredTransfer( .setDeferredTransfer(
new GradidoTransfer( new GradidoTransfer(
new TransferAmount(senderKeyPair.getPublicKey(), blockedAmount, communityContext.communityId), new TransferAmount(senderKeyPair.getPublicKey(), blockedAmount, communityContext.communityId),
recipientKeyPair.getPublicKey(), recipientKeyPair.getPublicKey(),
), ),
duration, duration,
) )
.setSenderCommunity(communityContext.communityId)
.sign(senderKeyPair) .sign(senderKeyPair)
} }

View File

@ -72,13 +72,13 @@ export class UsersSyncRole extends AbstractSyncRole<UserDb> {
): GradidoTransactionBuilder { ): GradidoTransactionBuilder {
return this.transactionBuilder return this.transactionBuilder
.setCreatedAt(item.createdAt) .setCreatedAt(item.createdAt)
.setSenderCommunity(communityContext.communityId)
.setRegisterAddress( .setRegisterAddress(
userKeyPair.getPublicKey(), userKeyPair.getPublicKey(),
AddressType_COMMUNITY_HUMAN, AddressType_COMMUNITY_HUMAN,
new Uuidv4Hash(item.gradidoId).getAsMemoryBlock(), new Uuidv4Hash(item.gradidoId).getAsMemoryBlock(),
accountKeyPair.getPublicKey(), accountKeyPair.getPublicKey(),
) )
.setSenderCommunity(communityContext.communityId)
.sign(communityKeyPair) .sign(communityKeyPair)
.sign(accountKeyPair) .sign(accountKeyPair)
.sign(userKeyPair) .sign(userKeyPair)

View File

@ -24,7 +24,7 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n
new RedeemTransactionLinksSyncRole(context), new RedeemTransactionLinksSyncRole(context),
new ContributionLinkTransactionSyncRole(context), new ContributionLinkTransactionSyncRole(context),
new DeletedTransactionLinksSyncRole(context), new DeletedTransactionLinksSyncRole(context),
// new RemoteTransactionsSyncRole(context), new RemoteTransactionsSyncRole(context),
] ]
let transactionsCount = 0 let transactionsCount = 0
let transactionsCountSinceLastLog = 0 let transactionsCountSinceLastLog = 0

View File

@ -102,6 +102,5 @@ describe('basic.schema', () => {
) )
expect(confirmedTransaction.getId()).toBe(7) expect(confirmedTransaction.getId()).toBe(7)
expect(confirmedTransaction.getConfirmedAt().getSeconds()).toBe(1609464130) expect(confirmedTransaction.getConfirmedAt().getSeconds()).toBe(1609464130)
expect(confirmedTransaction.getVersionNumber()).toBe('3.5')
}) })
}) })