update for hiero

This commit is contained in:
einhornimmond 2025-09-08 14:34:00 +02:00
parent 18879cf207
commit 832f2f6ce5
8 changed files with 44 additions and 17 deletions

View File

@ -15,6 +15,19 @@
"fileNameSep" : "_",
"numBackups" : 30
},
"dlt.client.HieroClient": {
"type": "dateFile",
"filename": "../logs/dlt-connector/apiversion-%v.log",
"pattern": "yyyy-MM-dd",
"layout":
{
"type": "pattern", "pattern": "%d{ISO8601} %p %c [topicId=%X{topicId}] [%f : %l] - %m"
},
"compress": true,
"keepFileExt" : true,
"fileNameSep" : "_",
"numBackups" : 30
},
"errorFile":
{
"type": "dateFile",
@ -22,7 +35,7 @@
"pattern": "yyyy-MM-dd",
"layout":
{
"type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{url}] [%f : %l] - %m"
"type": "pattern", "pattern": "%d{ISO8601} %p %c [%f : %l] - %m"
},
"compress": true,
"keepFileExt" : true,
@ -40,7 +53,7 @@
"type": "stdout",
"layout":
{
"type": "pattern", "pattern": "%d{ISO8601} %p %c [%X{url}] [%f : %l] - %m"
"type": "pattern", "pattern": "%d{ISO8601} %p %c [%f : %l] - %m"
}
}
},

View File

@ -66,7 +66,7 @@ export class GradidoNodeClient {
}
const response = await this.rpcCall<{ transaction: string }>('gettransaction', parameter)
if (response.isSuccess()) {
this.logger.debug('result: ', response.result.transaction)
// this.logger.debug('result: ', response.result.transaction)
return parse(confirmedTransactionSchema, response.result.transaction)
}
if (response.isError()) {

View File

@ -8,6 +8,7 @@ import { hieroIdSchema, uuidv4Schema } from '../../schemas/typeGuard.schema'
*/
export const communitySchema = v.object({
uuid: uuidv4Schema,
name: v.string('expect string type'),
hieroTopicId: v.nullish(hieroIdSchema),
foreign: v.boolean('expect boolean type'),
creationDate: dateSchema,
@ -21,6 +22,7 @@ export const homeCommunityGraphqlQuery = gql`
query {
homeCommunity {
uuid
name
hieroTopicId
foreign
creationDate
@ -32,6 +34,7 @@ export const setHomeCommunityTopicId = gql`
mutation ($uuid: String!, $hieroTopicId: String){
updateHomeCommunity(uuid: $uuid, hieroTopicId: $hieroTopicId) {
uuid
name
hieroTopicId
foreign
creationDate

View File

@ -2,6 +2,7 @@ import {
AccountBalance,
AccountBalanceQuery,
Client,
Key,
LocalProvider,
PrivateKey,
Timestamp,
@ -58,6 +59,7 @@ export class HieroClient {
topicId: HieroId,
transaction: GradidoTransaction,
): Promise<{ receipt: TransactionReceipt; response: TransactionResponse }> {
this.logger.addContext('topicId', topicId.toString())
const serializedTransaction = transaction.getSerializedTransaction()
if (!serializedTransaction) {
throw new Error('cannot serialize transaction')
@ -84,10 +86,16 @@ export class HieroClient {
}
public async getTopicInfo(topicId: HieroId): Promise<TopicInfoOutput> {
this.logger.addContext('topicId', topicId.toString())
const info = await new TopicInfoQuery()
.setTopicId(TopicId.fromString(topicId))
.execute(this.client)
this.logger.debug(JSON.stringify(info, null, 2))
this.logger.info(`topic is valid until ${info.expirationTime?.toDate()?.toLocaleString()}`)
if (info.topicMemo) {
this.logger.info(`topic memo: ${info.topicMemo}`)
}
this.logger.debug(`topic sequence number: ${info.sequenceNumber.toNumber()}`)
// this.logger.debug(JSON.stringify(info, null, 2))
return parse(topicInfoSchema, {
topicId: topicId.toString(),
sequenceNumber: info.sequenceNumber.toNumber(),
@ -97,16 +105,26 @@ export class HieroClient {
})
}
public async createTopic(): Promise<HieroId> {
let transaction = await new TopicCreateTransaction().freezeWithSigner(this.wallet)
public async createTopic(topicMemo?: string): Promise<HieroId> {
let transaction = new TopicCreateTransaction({
topicMemo,
adminKey: undefined,
submitKey: undefined,
autoRenewPeriod: undefined,
autoRenewAccountId: undefined,
})
transaction = await transaction.freezeWithSigner(this.wallet)
transaction = await transaction.signWithSigner(this.wallet)
const createResponse = await transaction.executeWithSigner(this.wallet)
const createReceipt = await createResponse.getReceiptWithSigner(this.wallet)
this.logger.debug(createReceipt.toString())
this.logger.addContext('topicId', createReceipt.topicId?.toString())
return parse(hieroIdSchema, createReceipt.topicId?.toString())
}
public async updateTopic(topicId: HieroId): Promise<void> {
this.logger.addContext('topicId', topicId.toString())
let transaction = new TopicUpdateTransaction()
transaction.setExpirationTime(new Date(new Date().getTime() + MIN_AUTORENEW_PERIOD * 1000))
transaction.setTopicId(TopicId.fromString(topicId))

View File

@ -7,8 +7,8 @@ dotenv.config()
type ConfigOutput = InferOutput<typeof configSchema>
let config: ConfigOutput
console.info('Config loading...')
try {
console.info('Config loading...')
config = parse(configSchema, process.env)
} catch (error: Error | unknown) {
if (error instanceof ValiError) {

View File

@ -81,7 +81,7 @@ async function homeCommunitySetup({ backend, hiero }: Clients, logger: Logger):
let homeCommunity = await backend.getHomeCommunityDraft()
// on missing topicId, create one
if (!homeCommunity.hieroTopicId) {
const topicId = await hiero.createTopic()
const topicId = await hiero.createTopic(homeCommunity.name)
// update topic on backend server
homeCommunity = await backend.setHomeCommunityTopicId(homeCommunity.uuid, topicId)
} else {

View File

@ -1,9 +1,2 @@
import { MemoryBlock } from 'gradido-blockchain-js'
import * as v from 'valibot'
export const keyGenerationSeedSchema = v.pipe(
v.string('expect string type'),
v.hexadecimal('expect hexadecimal string'),
v.length(64, 'expect seed length minimum 64 characters (32 Bytes)'),
v.transform<string, MemoryBlock>((input: string) => MemoryBlock.fromHex(input)),
)

View File

@ -128,8 +128,8 @@ declare const validHieroTransactionId: unique symbol
export type HieroTransactionId = string & { [validHieroTransactionId]: true }
export const hieroTransactionIdSchema = v.pipe(
v.string('expect hiero transaction id type, for example 0.0.141760-1755138896-607329203'),
v.regex(/^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-[0-9]+$/),
v.string('expect hiero transaction id type, for example 0.0.141760-1755138896-607329203 or 0.0.141760@1755138896.607329203'),
v.regex(/^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+-[0-9]+|@[0-9]+\.[0-9]+)$/),
v.transform<string, HieroTransactionId>((input: string) => input as HieroTransactionId),
)