mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
changes for adapting to gradido blockchain changes
This commit is contained in:
parent
2cea5a025f
commit
93e3271705
@ -1,4 +1,5 @@
|
||||
export enum DltTransactionType {
|
||||
UNKNOWN = 0,
|
||||
REGISTER_ADDRESS = 1,
|
||||
CREATION = 2,
|
||||
TRANSFER = 3,
|
||||
|
||||
@ -48,15 +48,6 @@ export class TransactionToDltRole extends AbstractTransactionToDltRole<Transacti
|
||||
const draft = new TransactionDraft()
|
||||
draft.amount = this.self.amount.abs().toString()
|
||||
|
||||
if (
|
||||
!this.self.linkedUserGradidoID ||
|
||||
!this.self.linkedUserCommunityUuid ||
|
||||
!this.self.userCommunityUuid
|
||||
) {
|
||||
throw new LogError(
|
||||
`missing necessary field in transaction: ${this.self.id}, need linkedUserGradidoID, linkedUserCommunityUuid and userCommunityUuid`,
|
||||
)
|
||||
}
|
||||
switch (this.self.typeId as TransactionTypeId) {
|
||||
case TransactionTypeId.CREATION:
|
||||
draft.type = TransactionType.GRADIDO_CREATION
|
||||
@ -68,8 +59,18 @@ export class TransactionToDltRole extends AbstractTransactionToDltRole<Transacti
|
||||
this.type = DltTransactionType.TRANSFER
|
||||
break
|
||||
default:
|
||||
this.type = DltTransactionType.UNKNOWN
|
||||
throw new LogError('wrong role for type', this.self.typeId as TransactionTypeId)
|
||||
}
|
||||
if (
|
||||
!this.self.linkedUserGradidoID ||
|
||||
!this.self.linkedUserCommunityUuid ||
|
||||
!this.self.userCommunityUuid
|
||||
) {
|
||||
throw new LogError(
|
||||
`missing necessary field in transaction: ${this.self.id}, need linkedUserGradidoID, linkedUserCommunityUuid and userCommunityUuid`,
|
||||
)
|
||||
}
|
||||
// it is a redeem of a transaction link?
|
||||
const transactionLink = this.self.transactionLink
|
||||
if (transactionLink) {
|
||||
@ -77,6 +78,7 @@ export class TransactionToDltRole extends AbstractTransactionToDltRole<Transacti
|
||||
this.self.userCommunityUuid,
|
||||
new IdentifierSeed(transactionLink.code),
|
||||
)
|
||||
draft.type = TransactionType.GRADIDO_REDEEM_DEFERRED_TRANSFER
|
||||
this.type = DltTransactionType.REDEEM_DEFERRED_TRANSFER
|
||||
} else {
|
||||
draft.user = new UserIdentifier(
|
||||
|
||||
@ -3,6 +3,7 @@ import { TransactionLink } from '@entity/TransactionLink'
|
||||
import { User } from '@entity/User'
|
||||
|
||||
import { DltConnectorClient } from '@/apis/dltConnector/DltConnectorClient'
|
||||
import { TransactionResult } from '@/apis/dltConnector/model/TransactionResult'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
|
||||
import { AbstractTransactionToDltRole } from './AbstractTransactionToDlt.role'
|
||||
@ -41,10 +42,18 @@ export async function transactionToDlt(dltConnector: DltConnectorClient): Promis
|
||||
}
|
||||
let messageId = ''
|
||||
let error: string | null = null
|
||||
|
||||
const result = await dltConnector.sendTransaction(
|
||||
pendingTransactionRole.convertToGraphqlInput(),
|
||||
)
|
||||
let result: TransactionResult | undefined
|
||||
try {
|
||||
result = await dltConnector.sendTransaction(pendingTransactionRole.convertToGraphqlInput())
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
error = e.message
|
||||
} else if (typeof e === 'string') {
|
||||
error = e
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
if (result?.succeed && result.recipe) {
|
||||
messageId = result.recipe.messageIdHex
|
||||
} else if (result?.error) {
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { CONFIG } from '@/config'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import { TypeORMError } from '@dbTools/typeorm'
|
||||
// eslint-disable-next-line import/named, n/no-extraneous-import
|
||||
import { FetchError } from 'node-fetch'
|
||||
@ -6,7 +8,6 @@ import { FetchError } from 'node-fetch'
|
||||
import { DltConnectorClient } from '@dltConnector/DltConnectorClient'
|
||||
|
||||
import { LogError } from '@/server/LogError'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import {
|
||||
InterruptiveSleepManager,
|
||||
TRANSMIT_TO_IOTA_INTERRUPTIVE_SLEEP_KEY,
|
||||
@ -40,7 +41,9 @@ export async function sendTransactionsToDltConnector(): Promise<void> {
|
||||
await transactionToDlt(dltConnector)
|
||||
await InterruptiveSleepManager.getInstance().sleep(
|
||||
TRANSMIT_TO_IOTA_INTERRUPTIVE_SLEEP_KEY,
|
||||
1000,
|
||||
// TODO: put sleep time into config, because it influence performance,
|
||||
// transactionToDlt call 4 db queries to look for new transactions
|
||||
CONFIG.PRODUCTION ? 100000 : 1000,
|
||||
)
|
||||
} catch (e) {
|
||||
// couldn't connect to dlt-connector? We wait
|
||||
|
||||
@ -7,7 +7,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
ALTER TABLE \`dlt_transactions\`
|
||||
CHANGE \`transaction_id\` \`transaction_id\` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
ADD \`user_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`transaction_id\`,
|
||||
ADD \`transaction_link_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`user_id\`
|
||||
ADD \`transaction_link_id\` INT UNSIGNED NULL DEFAULT NULL AFTER \`user_id\`,
|
||||
ADD \`type_id\` INT UNSIGNED NOT NULL AFTER \`transaction_link_id\`
|
||||
;
|
||||
`)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import {
|
||||
AuthenticatedEncryption,
|
||||
DurationSeconds,
|
||||
EncryptedMemo,
|
||||
GradidoTransactionBuilder,
|
||||
GradidoTransfer,
|
||||
@ -74,11 +75,13 @@ export class DeferredTransferTransactionRole extends AbstractTransactionRole {
|
||||
new GradidoTransfer(
|
||||
new TransferAmount(
|
||||
senderKeyPair.getPublicKey(),
|
||||
GradidoUnit.fromString(this.self.amount),
|
||||
GradidoUnit.fromString(this.self.amount).calculateCompoundInterest(
|
||||
this.self.timeoutDuration,
|
||||
),
|
||||
),
|
||||
recipientKeyPair.getPublicKey(),
|
||||
),
|
||||
this.self.timeoutDuration,
|
||||
new DurationSeconds(this.self.timeoutDuration),
|
||||
)
|
||||
.sign(senderKeyPair)
|
||||
return builder
|
||||
|
||||
@ -75,10 +75,8 @@ export class RedeemDeferredTransferTransactionRole extends AbstractTransactionRo
|
||||
}
|
||||
const recipientKeyPair = await KeyPairCalculation(new KeyPairIdentifier(this.linkedUser))
|
||||
|
||||
// TODO: fix getMemos in gradido-blockchain-js to return correct data
|
||||
builder
|
||||
.setCreatedAt(new Date(this.self.createdAt))
|
||||
.addMemo(deferredTransferBody.getMemos()[0])
|
||||
.setRedeemDeferredTransfer(
|
||||
deferredTransfer.getId(),
|
||||
new GradidoTransfer(
|
||||
@ -89,6 +87,10 @@ export class RedeemDeferredTransferTransactionRole extends AbstractTransactionRo
|
||||
recipientKeyPair.getPublicKey(),
|
||||
),
|
||||
)
|
||||
const memos = deferredTransferBody.getMemos()
|
||||
for (let i = 0; i < memos.size(); i++) {
|
||||
builder.addMemo(memos.get(i))
|
||||
}
|
||||
const senderCommunity = this.self.user.communityUuid
|
||||
const recipientCommunity = this.linkedUser.communityUuid
|
||||
if (senderCommunity !== recipientCommunity) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user