mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
fix order of builder commands, debug logs
This commit is contained in:
parent
be48f6aaa2
commit
4dde30ea4b
@ -4,8 +4,10 @@ import {
|
||||
GradidoTransaction,
|
||||
HieroAccountId,
|
||||
InMemoryBlockchain,
|
||||
InMemoryBlockchainProvider,
|
||||
LedgerAnchor,
|
||||
Profiler,
|
||||
TransactionEntry,
|
||||
} from 'gradido-blockchain-js'
|
||||
import { NotEnoughGradidoBalanceError } from './errors'
|
||||
|
||||
@ -38,6 +40,9 @@ export function addToBlockchain(
|
||||
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)
|
||||
throw new Error(`Transaction ${transaction.toJson(true)} not added: ${error}, last transaction was: ${lastTransaction?.getConfirmedTransaction()?.toJson(true)}`)
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
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 { CONFIG } from '../../config'
|
||||
import { deriveFromSeed } from '../../data/deriveKeyPair'
|
||||
@ -33,7 +33,7 @@ async function bootstrapCommunities(context: Context): Promise<Map<string, Commu
|
||||
} else {
|
||||
communityNames.add(alias)
|
||||
}
|
||||
const blockchain = InMemoryBlockchainProvider.getInstance().findBlockchain(alias)
|
||||
const blockchain = InMemoryBlockchainProvider.getInstance().getBlockchain(alias)
|
||||
if (!blockchain) {
|
||||
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()
|
||||
builder
|
||||
.setCreatedAt(creationDate)
|
||||
.setSenderCommunity(alias)
|
||||
.setCommunityRoot(
|
||||
communityKeyPair.getPublicKey(),
|
||||
gmwKeyPair.getPublicKey(),
|
||||
aufKeyPair.getPublicKey(),
|
||||
)
|
||||
.setSenderCommunity(alias)
|
||||
)
|
||||
.sign(communityKeyPair)
|
||||
|
||||
const communityContext: CommunityContext = {
|
||||
|
||||
@ -93,6 +93,7 @@ export class CreationsSyncRole extends AbstractSyncRole<CreationTransactionDb> {
|
||||
): GradidoTransactionBuilder {
|
||||
return this.transactionBuilder
|
||||
.setCreatedAt(item.confirmedAt)
|
||||
.setRecipientCommunity(communityContext.communityId)
|
||||
.addMemo(
|
||||
new EncryptedMemo(
|
||||
item.memo,
|
||||
@ -104,7 +105,6 @@ export class CreationsSyncRole extends AbstractSyncRole<CreationTransactionDb> {
|
||||
new TransferAmount(recipientKeyPair.getPublicKey(), item.amount, communityContext.communityId),
|
||||
item.contributionDate,
|
||||
)
|
||||
.setRecipientCommunity(communityContext.communityId)
|
||||
.sign(signerKeyPair)
|
||||
}
|
||||
|
||||
|
||||
@ -89,6 +89,7 @@ export class DeletedTransactionLinksSyncRole extends AbstractSyncRole<DeletedTra
|
||||
): GradidoTransactionBuilder {
|
||||
return this.transactionBuilder
|
||||
.setCreatedAt(item.deletedAt)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.setRedeemDeferredTransfer(
|
||||
linkFundingTransactionNr,
|
||||
new GradidoTransfer(
|
||||
@ -96,7 +97,6 @@ export class DeletedTransactionLinksSyncRole extends AbstractSyncRole<DeletedTra
|
||||
linkFundingPublicKey,
|
||||
),
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.sign(senderKeyPair)
|
||||
}
|
||||
|
||||
|
||||
@ -97,11 +97,11 @@ export class LocalTransactionsSyncRole extends AbstractSyncRole<TransactionDb> {
|
||||
new AuthenticatedEncryption(recipientKeyPair),
|
||||
),
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.setTransactionTransfer(
|
||||
new TransferAmount(senderKeyPair.getPublicKey(), item.amount, communityContext.communityId),
|
||||
recipientKeyPair.getPublicKey(),
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.sign(senderKeyPair)
|
||||
}
|
||||
|
||||
|
||||
@ -103,6 +103,7 @@ export class RedeemTransactionLinksSyncRole extends AbstractSyncRole<RedeemedTra
|
||||
new AuthenticatedEncryption(recipientKeyPair),
|
||||
),
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.setRedeemDeferredTransfer(
|
||||
linkFundingTransactionNr,
|
||||
new GradidoTransfer(
|
||||
@ -110,7 +111,6 @@ export class RedeemTransactionLinksSyncRole extends AbstractSyncRole<RedeemedTra
|
||||
recipientKeyPair.getPublicKey(),
|
||||
),
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.sign(senderKeyPair)
|
||||
}
|
||||
|
||||
|
||||
@ -93,12 +93,12 @@ export class RemoteTransactionsSyncRole extends AbstractSyncRole<TransactionDb>
|
||||
new AuthenticatedEncryption(recipientKeyPair),
|
||||
),
|
||||
)
|
||||
.setSenderCommunity(senderCommunityId)
|
||||
.setRecipientCommunity(recipientCommunityId)
|
||||
.setTransactionTransfer(
|
||||
new TransferAmount(senderKeyPair.getPublicKey(), item.amount, senderCommunityId),
|
||||
recipientKeyPair.getPublicKey(),
|
||||
)
|
||||
.setSenderCommunity(senderCommunityId)
|
||||
.setRecipientCommunity(recipientCommunityId)
|
||||
)
|
||||
.sign(senderKeyPair)
|
||||
}
|
||||
|
||||
@ -165,6 +165,9 @@ export class RemoteTransactionsSyncRole extends AbstractSyncRole<TransactionDb>
|
||||
recipientCommunityContext.communityId
|
||||
)
|
||||
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 {
|
||||
addToBlockchain(
|
||||
@ -181,6 +184,8 @@ export class RemoteTransactionsSyncRole extends AbstractSyncRole<TransactionDb>
|
||||
}
|
||||
transactionBuilder.setParentLedgerAnchor(ledgerAnchor)
|
||||
const inboundTransaction = transactionBuilder.buildInbound()
|
||||
console.log(inboundTransaction.toJson(true))
|
||||
console.log("inbound coin color: %d", inboundTransaction.getTransactionBody()?.getTransferAmount().getCoinCommunityIdIndex())
|
||||
try {
|
||||
addToBlockchain(
|
||||
inboundTransaction,
|
||||
|
||||
@ -87,14 +87,14 @@ export class TransactionLinkFundingsSyncRole extends AbstractSyncRole<Transactio
|
||||
new AuthenticatedEncryption(recipientKeyPair),
|
||||
),
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.setDeferredTransfer(
|
||||
new GradidoTransfer(
|
||||
new TransferAmount(senderKeyPair.getPublicKey(), blockedAmount, communityContext.communityId),
|
||||
recipientKeyPair.getPublicKey(),
|
||||
),
|
||||
duration,
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
)
|
||||
.sign(senderKeyPair)
|
||||
}
|
||||
|
||||
|
||||
@ -72,13 +72,13 @@ export class UsersSyncRole extends AbstractSyncRole<UserDb> {
|
||||
): GradidoTransactionBuilder {
|
||||
return this.transactionBuilder
|
||||
.setCreatedAt(item.createdAt)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.setRegisterAddress(
|
||||
userKeyPair.getPublicKey(),
|
||||
AddressType_COMMUNITY_HUMAN,
|
||||
new Uuidv4Hash(item.gradidoId).getAsMemoryBlock(),
|
||||
accountKeyPair.getPublicKey(),
|
||||
)
|
||||
.setSenderCommunity(communityContext.communityId)
|
||||
.sign(communityKeyPair)
|
||||
.sign(accountKeyPair)
|
||||
.sign(userKeyPair)
|
||||
|
||||
@ -24,7 +24,7 @@ export async function syncDbWithBlockchainContext(context: Context, batchSize: n
|
||||
new RedeemTransactionLinksSyncRole(context),
|
||||
new ContributionLinkTransactionSyncRole(context),
|
||||
new DeletedTransactionLinksSyncRole(context),
|
||||
// new RemoteTransactionsSyncRole(context),
|
||||
new RemoteTransactionsSyncRole(context),
|
||||
]
|
||||
let transactionsCount = 0
|
||||
let transactionsCountSinceLastLog = 0
|
||||
|
||||
@ -102,6 +102,5 @@ describe('basic.schema', () => {
|
||||
)
|
||||
expect(confirmedTransaction.getId()).toBe(7)
|
||||
expect(confirmedTransaction.getConfirmedAt().getSeconds()).toBe(1609464130)
|
||||
expect(confirmedTransaction.getVersionNumber()).toBe('3.5')
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user