check for valid recipient community topic before sending outbound cross group transaction

This commit is contained in:
einhornimmond 2025-10-24 07:49:06 +02:00
parent 4b59cf2377
commit 567fbbaf66
3 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -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,

View 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
}