mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
check for valid recipient community topic before sending outbound cross group transaction
This commit is contained in:
parent
4b59cf2377
commit
567fbbaf66
@ -1,3 +1,5 @@
|
||||
export const LOG4JS_BASE_CATEGORY = 'dlt'
|
||||
// 7 days
|
||||
export const MIN_TOPIC_EXPIRE_MILLISECONDS_FOR_UPDATE = 1000 * 60 * 60 * 24 * 7
|
||||
// 10 minutes
|
||||
export const MIN_TOPIC_EXPIRE_MILLISECONDS_FOR_SEND_MESSAGE = 1000 * 60 * 10
|
||||
@ -28,7 +28,7 @@ import { DeferredTransferTransactionRole } from './DeferredTransferTransaction.r
|
||||
import { RedeemDeferredTransferTransactionRole } from './RedeemDeferredTransferTransaction.role'
|
||||
import { RegisterAddressTransactionRole } from './RegisterAddressTransaction.role'
|
||||
import { TransferTransactionRole } from './TransferTransaction.role'
|
||||
|
||||
import { isTopicStillOpen } from '../../utils/hiero'
|
||||
const logger = getLogger(`${LOG4JS_BASE_CATEGORY}.interactions.sendToHiero.SendToHieroContext`)
|
||||
|
||||
/**
|
||||
@ -46,6 +46,10 @@ export async function SendToHieroContext(
|
||||
const outboundTransaction = builder.buildOutbound()
|
||||
validate(outboundTransaction)
|
||||
|
||||
if (!isTopicStillOpen(role.getRecipientCommunityTopicId())) {
|
||||
throw new Error('recipient topic is not open long enough for sending messages')
|
||||
}
|
||||
|
||||
// send outbound transaction to hiero at first, because we need the transaction id for inbound transaction
|
||||
const outboundHieroTransactionIdString = await sendViaHiero(
|
||||
outboundTransaction,
|
||||
|
||||
16
dlt-connector/src/utils/hiero.ts
Normal file
16
dlt-connector/src/utils/hiero.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { HieroId } from '../schemas/typeGuard.schema'
|
||||
import { HieroClient } from '../client/hiero/HieroClient'
|
||||
import { MIN_TOPIC_EXPIRE_MILLISECONDS_FOR_SEND_MESSAGE } from '../config/const'
|
||||
|
||||
/**
|
||||
* Checks whether the given topic in the Hedera network will remain open
|
||||
* for sending messages for at least `MIN_TOPIC_EXPIRE_MILLISECONDS_FOR_SEND_MESSAGE` milliseconds.
|
||||
*
|
||||
* @param {HieroId} hieroTopicId - The topic ID to check.
|
||||
* @returns {Promise<boolean>} `true` if the topic is still open long enough, otherwise `false`.
|
||||
*/
|
||||
export async function isTopicStillOpen(hieroTopicId: HieroId): Promise<boolean> {
|
||||
const hieroClient = HieroClient.getInstance()
|
||||
const topicInfo = await hieroClient.getTopicInfo(hieroTopicId)
|
||||
return topicInfo.expirationTime.getTime() > new Date().getTime() + MIN_TOPIC_EXPIRE_MILLISECONDS_FOR_SEND_MESSAGE
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user