@hashgraphonline/standards-sdk 0.0.97 → 0.0.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/hcs-10/base-client.d.ts +3 -14
- package/dist/es/hcs-10/base-client.d.ts.map +1 -1
- package/dist/es/hcs-10/connections-manager.d.ts +0 -51
- package/dist/es/hcs-10/connections-manager.d.ts.map +1 -1
- package/dist/es/hcs-10/sdk.d.ts +1 -38
- package/dist/es/hcs-10/sdk.d.ts.map +1 -1
- package/dist/es/hcs-10/types.d.ts +3 -9
- package/dist/es/hcs-10/types.d.ts.map +1 -1
- package/dist/es/inscribe/inscriber.d.ts +0 -2
- package/dist/es/inscribe/inscriber.d.ts.map +1 -1
- package/dist/es/services/index.d.ts +0 -1
- package/dist/es/services/index.d.ts.map +1 -1
- package/dist/es/services/mirror-node.d.ts +1 -17
- package/dist/es/services/mirror-node.d.ts.map +1 -1
- package/dist/es/services/types.d.ts +0 -24
- package/dist/es/services/types.d.ts.map +1 -1
- package/dist/es/standards-sdk.es.js +5 -8
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/es/standards-sdk.es10.js +0 -66
- package/dist/es/standards-sdk.es10.js.map +1 -1
- package/dist/es/standards-sdk.es100.js +13 -4
- package/dist/es/standards-sdk.es100.js.map +1 -1
- package/dist/es/standards-sdk.es101.js +13 -4
- package/dist/es/standards-sdk.es101.js.map +1 -1
- package/dist/es/standards-sdk.es102.js +31 -15
- package/dist/es/standards-sdk.es102.js.map +1 -1
- package/dist/es/standards-sdk.es103.js +14 -4
- package/dist/es/standards-sdk.es103.js.map +1 -1
- package/dist/es/standards-sdk.es104.js +4 -39
- package/dist/es/standards-sdk.es104.js.map +1 -1
- package/dist/es/standards-sdk.es105.js +4 -40
- package/dist/es/standards-sdk.es105.js.map +1 -1
- package/dist/es/standards-sdk.es106.js +15 -36
- package/dist/es/standards-sdk.es106.js.map +1 -1
- package/dist/es/standards-sdk.es107.js +5 -78
- package/dist/es/standards-sdk.es107.js.map +1 -1
- package/dist/es/standards-sdk.es108.js +39 -4
- package/dist/es/standards-sdk.es108.js.map +1 -1
- package/dist/es/standards-sdk.es109.js +38 -32
- package/dist/es/standards-sdk.es109.js.map +1 -1
- package/dist/es/standards-sdk.es110.js +35 -31
- package/dist/es/standards-sdk.es110.js.map +1 -1
- package/dist/es/standards-sdk.es111.js +78 -9
- package/dist/es/standards-sdk.es111.js.map +1 -1
- package/dist/es/standards-sdk.es112.js +3 -34
- package/dist/es/standards-sdk.es112.js.map +1 -1
- package/dist/es/standards-sdk.es113.js +2 -3
- package/dist/es/standards-sdk.es113.js.map +1 -1
- package/dist/es/standards-sdk.es114.js +2 -2
- package/dist/es/standards-sdk.es114.js.map +1 -1
- package/dist/es/standards-sdk.es115.js +34 -2
- package/dist/es/standards-sdk.es115.js.map +1 -1
- package/dist/es/standards-sdk.es116.js +29 -97
- package/dist/es/standards-sdk.es116.js.map +1 -1
- package/dist/es/standards-sdk.es117.js +9 -2
- package/dist/es/standards-sdk.es117.js.map +1 -1
- package/dist/es/standards-sdk.es118.js +34 -16
- package/dist/es/standards-sdk.es118.js.map +1 -1
- package/dist/es/standards-sdk.es13.js +5 -5
- package/dist/es/standards-sdk.es15.js +1 -1
- package/dist/es/standards-sdk.es16.js +1 -1
- package/dist/es/standards-sdk.es18.js +2 -2
- package/dist/es/standards-sdk.es19.js +386 -393
- package/dist/es/standards-sdk.es19.js.map +1 -1
- package/dist/es/standards-sdk.es20.js +315 -386
- package/dist/es/standards-sdk.es20.js.map +1 -1
- package/dist/es/standards-sdk.es21.js +128 -357
- package/dist/es/standards-sdk.es21.js.map +1 -1
- package/dist/es/standards-sdk.es22.js +7 -155
- package/dist/es/standards-sdk.es22.js.map +1 -1
- package/dist/es/standards-sdk.es23.js +1041 -7
- package/dist/es/standards-sdk.es23.js.map +1 -1
- package/dist/es/standards-sdk.es24.js +1692 -966
- package/dist/es/standards-sdk.es24.js.map +1 -1
- package/dist/es/standards-sdk.es25.js +3 -1769
- package/dist/es/standards-sdk.es25.js.map +1 -1
- package/dist/es/standards-sdk.es26.js +3843 -6866
- package/dist/es/standards-sdk.es26.js.map +1 -1
- package/dist/es/standards-sdk.es27.js +7190 -3
- package/dist/es/standards-sdk.es27.js.map +1 -1
- package/dist/es/standards-sdk.es28.js +2 -9
- package/dist/es/standards-sdk.es28.js.map +1 -1
- package/dist/es/standards-sdk.es29.js +36 -2
- package/dist/es/standards-sdk.es29.js.map +1 -1
- package/dist/es/standards-sdk.es30.js +48 -5
- package/dist/es/standards-sdk.es30.js.map +1 -1
- package/dist/es/standards-sdk.es31.js +5 -36
- package/dist/es/standards-sdk.es31.js.map +1 -1
- package/dist/es/standards-sdk.es32.js +100 -47
- package/dist/es/standards-sdk.es32.js.map +1 -1
- package/dist/es/standards-sdk.es33.js +2 -10
- package/dist/es/standards-sdk.es33.js.map +1 -1
- package/dist/es/standards-sdk.es34.js +15 -4166
- package/dist/es/standards-sdk.es34.js.map +1 -1
- package/dist/es/standards-sdk.es35.js +409 -2
- package/dist/es/standards-sdk.es35.js.map +1 -1
- package/dist/es/standards-sdk.es36.js +2 -364
- package/dist/es/standards-sdk.es36.js.map +1 -1
- package/dist/es/standards-sdk.es37.js +2282 -6
- package/dist/es/standards-sdk.es37.js.map +1 -1
- package/dist/es/standards-sdk.es38.js +152 -167
- package/dist/es/standards-sdk.es38.js.map +1 -1
- package/dist/es/standards-sdk.es39.js +188 -74
- package/dist/es/standards-sdk.es39.js.map +1 -1
- package/dist/es/standards-sdk.es4.js +1 -1
- package/dist/es/standards-sdk.es40.js +423 -99
- package/dist/es/standards-sdk.es40.js.map +1 -1
- package/dist/es/standards-sdk.es41.js +20 -47
- package/dist/es/standards-sdk.es41.js.map +1 -1
- package/dist/es/standards-sdk.es42.js +138 -9
- package/dist/es/standards-sdk.es42.js.map +1 -1
- package/dist/es/standards-sdk.es43.js +13 -92
- package/dist/es/standards-sdk.es43.js.map +1 -1
- package/dist/es/standards-sdk.es44.js +28 -3
- package/dist/es/standards-sdk.es44.js.map +1 -1
- package/dist/es/standards-sdk.es45.js +29 -2
- package/dist/es/standards-sdk.es45.js.map +1 -1
- package/dist/es/standards-sdk.es46.js +15 -107
- package/dist/es/standards-sdk.es46.js.map +1 -1
- package/dist/es/standards-sdk.es47.js +41 -71
- package/dist/es/standards-sdk.es47.js.map +1 -1
- package/dist/es/standards-sdk.es48.js +17 -5
- package/dist/es/standards-sdk.es48.js.map +1 -1
- package/dist/es/standards-sdk.es49.js +60 -4
- package/dist/es/standards-sdk.es49.js.map +1 -1
- package/dist/es/standards-sdk.es5.js +9 -32
- package/dist/es/standards-sdk.es5.js.map +1 -1
- package/dist/es/standards-sdk.es50.js +1259 -191
- package/dist/es/standards-sdk.es50.js.map +1 -1
- package/dist/es/standards-sdk.es51.js +142 -52
- package/dist/es/standards-sdk.es51.js.map +1 -1
- package/dist/es/standards-sdk.es52.js +91 -69
- package/dist/es/standards-sdk.es52.js.map +1 -1
- package/dist/es/standards-sdk.es53.js +79 -414
- package/dist/es/standards-sdk.es53.js.map +1 -1
- package/dist/es/standards-sdk.es54.js +32 -2
- package/dist/es/standards-sdk.es54.js.map +1 -1
- package/dist/es/standards-sdk.es55.js +5 -119
- package/dist/es/standards-sdk.es55.js.map +1 -1
- package/dist/es/standards-sdk.es56.js +147 -183
- package/dist/es/standards-sdk.es56.js.map +1 -1
- package/dist/es/standards-sdk.es57.js +18 -433
- package/dist/es/standards-sdk.es57.js.map +1 -1
- package/dist/es/standards-sdk.es58.js +788 -20
- package/dist/es/standards-sdk.es58.js.map +1 -1
- package/dist/es/standards-sdk.es59.js +161 -126
- package/dist/es/standards-sdk.es59.js.map +1 -1
- package/dist/es/standards-sdk.es60.js +138 -13
- package/dist/es/standards-sdk.es60.js.map +1 -1
- package/dist/es/standards-sdk.es61.js +13 -21
- package/dist/es/standards-sdk.es61.js.map +1 -1
- package/dist/es/standards-sdk.es62.js +25 -27
- package/dist/es/standards-sdk.es62.js.map +1 -1
- package/dist/es/standards-sdk.es63.js +24 -19
- package/dist/es/standards-sdk.es63.js.map +1 -1
- package/dist/es/standards-sdk.es64.js +36 -42
- package/dist/es/standards-sdk.es64.js.map +1 -1
- package/dist/es/standards-sdk.es65.js +3 -18
- package/dist/es/standards-sdk.es65.js.map +1 -1
- package/dist/es/standards-sdk.es66.js +3 -60
- package/dist/es/standards-sdk.es66.js.map +1 -1
- package/dist/es/standards-sdk.es67.js +7060 -1213
- package/dist/es/standards-sdk.es67.js.map +1 -1
- package/dist/es/standards-sdk.es68.js +402 -131
- package/dist/es/standards-sdk.es68.js.map +1 -1
- package/dist/es/standards-sdk.es69.js +2 -91
- package/dist/es/standards-sdk.es69.js.map +1 -1
- package/dist/es/standards-sdk.es7.js +5 -106
- package/dist/es/standards-sdk.es7.js.map +1 -1
- package/dist/es/standards-sdk.es70.js +113 -77
- package/dist/es/standards-sdk.es70.js.map +1 -1
- package/dist/es/standards-sdk.es71.js +360 -28
- package/dist/es/standards-sdk.es71.js.map +1 -1
- package/dist/es/standards-sdk.es72.js +5 -5
- package/dist/es/standards-sdk.es72.js.map +1 -1
- package/dist/es/standards-sdk.es73.js +167 -147
- package/dist/es/standards-sdk.es73.js.map +1 -1
- package/dist/es/standards-sdk.es74.js +80 -22
- package/dist/es/standards-sdk.es74.js.map +1 -1
- package/dist/es/standards-sdk.es75.js +102 -781
- package/dist/es/standards-sdk.es75.js.map +1 -1
- package/dist/es/standards-sdk.es76.js +44 -166
- package/dist/es/standards-sdk.es76.js.map +1 -1
- package/dist/es/standards-sdk.es77.js +9 -142
- package/dist/es/standards-sdk.es77.js.map +1 -1
- package/dist/es/standards-sdk.es78.js +97 -3
- package/dist/es/standards-sdk.es78.js.map +1 -1
- package/dist/es/standards-sdk.es79.js +3 -163
- package/dist/es/standards-sdk.es79.js.map +1 -1
- package/dist/es/standards-sdk.es8.js +4 -4
- package/dist/es/standards-sdk.es80.js +2 -32
- package/dist/es/standards-sdk.es80.js.map +1 -1
- package/dist/es/standards-sdk.es81.js +103 -53
- package/dist/es/standards-sdk.es81.js.map +1 -1
- package/dist/es/standards-sdk.es82.js +69 -45
- package/dist/es/standards-sdk.es82.js.map +1 -1
- package/dist/es/standards-sdk.es83.js +5 -9
- package/dist/es/standards-sdk.es83.js.map +1 -1
- package/dist/es/standards-sdk.es84.js +4 -64
- package/dist/es/standards-sdk.es84.js.map +1 -1
- package/dist/es/standards-sdk.es85.js +221 -6
- package/dist/es/standards-sdk.es85.js.map +1 -1
- package/dist/es/standards-sdk.es86.js +56 -13
- package/dist/es/standards-sdk.es86.js.map +1 -1
- package/dist/es/standards-sdk.es87.js +68 -6
- package/dist/es/standards-sdk.es87.js.map +1 -1
- package/dist/es/standards-sdk.es88.js +31 -44
- package/dist/es/standards-sdk.es88.js.map +1 -1
- package/dist/es/standards-sdk.es89.js +63 -2
- package/dist/es/standards-sdk.es89.js.map +1 -1
- package/dist/es/standards-sdk.es9.js +1 -1
- package/dist/es/standards-sdk.es90.js +47 -133
- package/dist/es/standards-sdk.es90.js.map +1 -1
- package/dist/es/standards-sdk.es91.js +10 -172
- package/dist/es/standards-sdk.es91.js.map +1 -1
- package/dist/es/standards-sdk.es92.js +61 -17
- package/dist/es/standards-sdk.es92.js.map +1 -1
- package/dist/es/standards-sdk.es93.js +6 -27
- package/dist/es/standards-sdk.es93.js.map +1 -1
- package/dist/es/standards-sdk.es94.js +14 -25
- package/dist/es/standards-sdk.es94.js.map +1 -1
- package/dist/es/standards-sdk.es95.js +7 -38
- package/dist/es/standards-sdk.es95.js.map +1 -1
- package/dist/es/standards-sdk.es96.js +44 -12
- package/dist/es/standards-sdk.es96.js.map +1 -1
- package/dist/es/standards-sdk.es97.js +2 -13
- package/dist/es/standards-sdk.es97.js.map +1 -1
- package/dist/es/standards-sdk.es98.js +134 -30
- package/dist/es/standards-sdk.es98.js.map +1 -1
- package/dist/es/standards-sdk.es99.js +171 -14
- package/dist/es/standards-sdk.es99.js.map +1 -1
- package/dist/es/utils/index.d.ts +0 -1
- package/dist/es/utils/index.d.ts.map +1 -1
- package/dist/umd/hcs-10/base-client.d.ts +3 -14
- package/dist/umd/hcs-10/base-client.d.ts.map +1 -1
- package/dist/umd/hcs-10/connections-manager.d.ts +0 -51
- package/dist/umd/hcs-10/connections-manager.d.ts.map +1 -1
- package/dist/umd/hcs-10/sdk.d.ts +1 -38
- package/dist/umd/hcs-10/sdk.d.ts.map +1 -1
- package/dist/umd/hcs-10/types.d.ts +3 -9
- package/dist/umd/hcs-10/types.d.ts.map +1 -1
- package/dist/umd/inscribe/inscriber.d.ts +0 -2
- package/dist/umd/inscribe/inscriber.d.ts.map +1 -1
- package/dist/umd/services/index.d.ts +0 -1
- package/dist/umd/services/index.d.ts.map +1 -1
- package/dist/umd/services/mirror-node.d.ts +1 -17
- package/dist/umd/services/mirror-node.d.ts.map +1 -1
- package/dist/umd/services/types.d.ts +0 -24
- package/dist/umd/services/types.d.ts.map +1 -1
- package/dist/umd/standards-sdk.umd.js +22 -22
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/dist/umd/utils/index.d.ts +0 -1
- package/dist/umd/utils/index.d.ts.map +1 -1
- package/package.json +8 -12
- package/dist/es/standards-sdk.es119.js +0 -412
- package/dist/es/standards-sdk.es119.js.map +0 -1
- package/dist/es/standards-sdk.es120.js +0 -2285
- package/dist/es/standards-sdk.es120.js.map +0 -1
- package/dist/es/standards-sdk.es121.js +0 -7139
- package/dist/es/standards-sdk.es121.js.map +0 -1
- package/dist/es/standards-sdk.es122.js +0 -13
- package/dist/es/standards-sdk.es122.js.map +0 -1
- package/dist/es/standards-sdk.es123.js +0 -14
- package/dist/es/standards-sdk.es123.js.map +0 -1
- package/dist/es/standards-sdk.es124.js +0 -21
- package/dist/es/standards-sdk.es124.js.map +0 -1
- package/dist/es/standards-sdk.es125.js +0 -9
- package/dist/es/standards-sdk.es125.js.map +0 -1
- package/dist/es/standards-sdk.es126.js +0 -12
- package/dist/es/standards-sdk.es126.js.map +0 -1
- package/dist/es/utils/transaction-parser.d.ts +0 -103
- package/dist/es/utils/transaction-parser.d.ts.map +0 -1
- package/dist/umd/utils/transaction-parser.d.ts +0 -103
- package/dist/umd/utils/transaction-parser.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-sdk.es20.js","sources":["../../src/inscribe/inscriber.ts"],"sourcesContent":["import { InscriptionSDK } from '@kiloscribe/inscription-sdk';\nimport {\n InscriptionOptions,\n InscriptionResult,\n RetrievedInscriptionResult,\n HederaClientConfig,\n} from './types';\nimport type { DAppSigner } from '@hashgraph/hedera-wallet-connect';\nimport { Logger } from '../utils/logger';\nimport { ProgressCallback, ProgressReporter } from '../utils/progress-reporter';\n\nexport type InscriptionInput =\n | { type: 'url'; url: string }\n | { type: 'file'; path: string }\n | {\n type: 'buffer';\n buffer: ArrayBuffer | Buffer;\n fileName: string;\n mimeType?: string;\n };\n\nexport type InscriptionResponse =\n | { confirmed: false; result: InscriptionResult; sdk: InscriptionSDK }\n | {\n confirmed: true;\n result: InscriptionResult;\n inscription: RetrievedInscriptionResult;\n sdk: InscriptionSDK;\n };\n\nexport async function inscribe(\n input: InscriptionInput,\n clientConfig: HederaClientConfig,\n options: InscriptionOptions,\n existingSDK?: InscriptionSDK\n): Promise<InscriptionResponse> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options.logging,\n });\n\n logger.info('Starting inscription process', {\n type: input.type,\n mode: options.mode || 'file',\n ...(input.type === 'url' ? { url: input.url } : {}),\n ...(input.type === 'file' ? { path: input.path } : {}),\n ...(input.type === 'buffer'\n ? { fileName: input.fileName, bufferSize: input.buffer.byteLength }\n : {}),\n });\n\n try {\n if (options.mode === 'hashinal' && options.metadata) {\n validateHashinalMetadata(options.metadata, logger);\n }\n\n let sdk: InscriptionSDK;\n\n if (existingSDK) {\n logger.debug('Using existing InscriptionSDK instance');\n sdk = existingSDK;\n } else if (options.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: clientConfig.network || 'mainnet',\n });\n } else {\n logger.debug('Initializing InscriptionSDK with server auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'server',\n accountId: clientConfig.accountId,\n privateKey: clientConfig.privateKey,\n network: clientConfig.network || 'mainnet',\n });\n }\n\n const baseRequest = {\n holderId: clientConfig.accountId,\n metadata: options.metadata || {},\n tags: options.tags || [],\n mode: options.mode || 'file',\n chunkSize: options.chunkSize,\n };\n\n let request: any;\n switch (input.type) {\n case 'url':\n request = {\n ...baseRequest,\n file: {\n type: 'url',\n url: input.url,\n },\n };\n break;\n\n case 'file':\n request = {\n ...baseRequest,\n file: {\n type: 'path',\n path: input.path,\n },\n };\n break;\n\n case 'buffer':\n request = {\n ...baseRequest,\n file: {\n type: 'base64',\n base64: Buffer.from(input.buffer).toString('base64'),\n fileName: input.fileName,\n mimeType: input.mimeType,\n },\n };\n break;\n }\n\n if (options.mode === 'hashinal') {\n request.metadataObject = options.metadata;\n request.creator = options.metadata?.creator || clientConfig.accountId;\n request.description = options.metadata?.description;\n\n if (options.jsonFileURL) {\n request.jsonFileURL = options.jsonFileURL;\n }\n }\n\n logger.debug('Preparing to inscribe content', {\n type: input.type,\n mode: options.mode || 'file',\n holderId: clientConfig.accountId,\n });\n\n const result = await sdk.inscribeAndExecute(request, clientConfig);\n logger.info('Starting to inscribe.', {\n type: input.type,\n mode: options.mode || 'file',\n transactionId: result.jobId,\n });\n\n if (options.waitForConfirmation) {\n logger.debug('Waiting for inscription confirmation', {\n transactionId: result.jobId,\n maxAttempts: options.waitMaxAttempts,\n intervalMs: options.waitIntervalMs,\n });\n\n const inscription = await waitForInscriptionConfirmation(\n sdk,\n result.jobId,\n options.waitMaxAttempts,\n options.waitIntervalMs,\n options.progressCallback\n );\n\n logger.info('Inscription confirmation received', {\n transactionId: result.jobId,\n });\n\n return {\n confirmed: true,\n result,\n inscription,\n sdk,\n };\n }\n\n return {\n confirmed: false,\n result,\n sdk,\n };\n } catch (error) {\n logger.error('Error during inscription process', error);\n throw error;\n }\n}\n\nexport async function inscribeWithSigner(\n input: InscriptionInput,\n signer: DAppSigner,\n options: InscriptionOptions,\n existingSDK?: InscriptionSDK\n): Promise<InscriptionResponse> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options.logging,\n });\n\n logger.info('Starting inscription process with signer', {\n type: input.type,\n mode: options.mode || 'file',\n ...(input.type === 'url' ? { url: input.url } : {}),\n ...(input.type === 'file' ? { path: input.path } : {}),\n ...(input.type === 'buffer'\n ? { fileName: input.fileName, bufferSize: input.buffer.byteLength }\n : {}),\n });\n\n try {\n if (options.mode === 'hashinal' && options.metadata) {\n validateHashinalMetadata(options.metadata, logger);\n }\n\n const accountId = signer.getAccountId().toString();\n logger.debug('Using account ID from signer', { accountId });\n\n let sdk: InscriptionSDK;\n\n if (existingSDK) {\n logger.debug('Using existing InscriptionSDK instance');\n sdk = existingSDK;\n } else if (options.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: options.network || 'mainnet',\n });\n } else {\n logger.debug('Initializing InscriptionSDK with client auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'client',\n accountId,\n signer: signer,\n network: options.network || 'mainnet',\n });\n }\n\n const baseRequest = {\n holderId: accountId,\n metadata: options.metadata || {},\n tags: options.tags || [],\n mode: options.mode || 'file',\n chunkSize: options.chunkSize,\n };\n\n let request: any;\n switch (input.type) {\n case 'url':\n request = {\n ...baseRequest,\n file: {\n type: 'url',\n url: input.url,\n },\n };\n break;\n\n case 'file':\n request = {\n ...baseRequest,\n file: {\n type: 'path',\n path: input.path,\n },\n };\n break;\n\n case 'buffer':\n request = {\n ...baseRequest,\n file: {\n type: 'base64',\n base64: Buffer.from(input.buffer).toString('base64'),\n fileName: input.fileName,\n mimeType: input.mimeType,\n },\n };\n break;\n }\n\n if (options.mode === 'hashinal') {\n request.metadataObject = options.metadata;\n request.creator = options.metadata?.creator || accountId;\n request.description = options.metadata?.description;\n\n if (options.jsonFileURL) {\n request.jsonFileURL = options.jsonFileURL;\n }\n }\n\n logger.debug('Preparing to inscribe content with signer', {\n type: input.type,\n mode: options.mode || 'file',\n holderId: accountId,\n });\n\n const result = await sdk.inscribe(\n {\n ...request,\n holderId: accountId,\n },\n signer\n );\n logger.info('Inscription started', {\n type: input.type,\n mode: options.mode || 'file',\n transactionId: result.jobId,\n });\n\n if (options.waitForConfirmation) {\n logger.debug('Waiting for inscription confirmation', {\n transactionId: result.jobId,\n maxAttempts: options.waitMaxAttempts,\n intervalMs: options.waitIntervalMs,\n });\n\n const inscription = await waitForInscriptionConfirmation(\n sdk,\n result.jobId,\n options.waitMaxAttempts,\n options.waitIntervalMs,\n options.progressCallback\n );\n\n logger.info('Inscription confirmation received', {\n transactionId: result.jobId,\n });\n\n return {\n confirmed: true,\n result,\n inscription,\n sdk,\n };\n }\n\n return {\n confirmed: false,\n result,\n sdk,\n };\n } catch (error) {\n logger.error('Error during inscription process', error);\n throw error;\n }\n}\n\nexport async function retrieveInscription(\n transactionId: string,\n options: InscriptionOptions & { accountId?: string; privateKey?: string }\n): Promise<RetrievedInscriptionResult> {\n const logger = Logger.getInstance({\n module: 'Inscriber',\n ...options?.logging || {},\n });\n\n const formattedTransactionId = transactionId.includes('@')\n ? `${transactionId.split('@')[0]}-${transactionId\n .split('@')[1]\n .replace(/\\./g, '-')}`\n : transactionId;\n\n logger.info('Retrieving inscription', {\n originalTransactionId: transactionId,\n formattedTransactionId,\n });\n\n try {\n let sdk: InscriptionSDK;\n\n if (options?.apiKey) {\n logger.debug('Initializing InscriptionSDK with API key');\n sdk = new InscriptionSDK({\n apiKey: options.apiKey,\n network: options.network || 'mainnet',\n });\n } else if (options?.accountId && options?.privateKey) {\n logger.debug('Initializing InscriptionSDK with server auth');\n sdk = await InscriptionSDK.createWithAuth({\n type: 'server',\n accountId: options.accountId,\n privateKey: options.privateKey,\n network: options.network || 'mainnet',\n });\n } else {\n const error = new Error(\n 'Either API key or account ID and private key are required for retrieving inscriptions'\n );\n logger.error('Missing authentication credentials', {\n hasApiKey: Boolean(options?.apiKey),\n hasAccountId: Boolean(options?.accountId),\n hasPrivateKey: Boolean(options?.privateKey),\n });\n throw error;\n }\n\n logger.debug('Initialized SDK for inscription retrieval', {\n formattedTransactionId,\n network: options.network || 'mainnet',\n });\n\n const result = await sdk.retrieveInscription(formattedTransactionId);\n logger.info('Successfully retrieved inscription', {\n formattedTransactionId,\n });\n\n return result;\n } catch (error) {\n logger.error('Error retrieving inscription', {\n formattedTransactionId,\n error,\n });\n throw error;\n }\n}\n\nfunction validateHashinalMetadata(metadata: any, logger: any): void {\n const requiredFields = ['name', 'creator', 'description', 'type'];\n const missingFields = requiredFields.filter((field) => !metadata[field]);\n\n if (missingFields.length > 0) {\n const error = new Error(\n `Missing required Hashinal metadata fields: ${missingFields.join(', ')}`\n );\n logger.error('Hashinal metadata validation failed', { missingFields });\n throw error;\n }\n\n logger.debug('Hashinal metadata validation passed', {\n name: metadata.name,\n creator: metadata.creator,\n description: metadata.description,\n type: metadata.type,\n hasAttributes: !!metadata.attributes,\n hasProperties: !!metadata.properties,\n });\n}\n\nexport async function waitForInscriptionConfirmation(\n sdk: InscriptionSDK,\n transactionId: string,\n maxAttempts: number = 30,\n intervalMs: number = 4000,\n progressCallback?: ProgressCallback\n): Promise<RetrievedInscriptionResult> {\n const logger = Logger.getInstance({ module: 'Inscriber' });\n const progressReporter = new ProgressReporter({\n module: 'Inscriber',\n logger,\n callback: progressCallback,\n });\n\n try {\n logger.debug('Waiting for inscription confirmation', {\n transactionId,\n maxAttempts,\n intervalMs,\n });\n\n progressReporter.preparing('Preparing for inscription confirmation', 5, {\n transactionId,\n maxAttempts,\n intervalMs,\n });\n\n try {\n const waitMethod = sdk.waitForInscription.bind(sdk) as (\n txId: string,\n maxAttempts: number,\n intervalMs: number,\n checkCompletion: boolean,\n progressCallback?: Function\n ) => Promise<RetrievedInscriptionResult>;\n\n const wrappedCallback = (data: any) => {\n const stage = data.stage || 'confirming';\n const message = data.message || 'Processing inscription';\n const percent = data.progressPercent || 50;\n\n progressReporter.report({\n stage: stage,\n message: message,\n progressPercent: percent,\n details: {},\n });\n };\n\n return await waitMethod(\n transactionId,\n maxAttempts,\n intervalMs,\n true,\n wrappedCallback\n );\n } catch (e) {\n console.log(e);\n // Fall back to standard method if progress callback fails\n logger.debug('Falling back to standard waitForInscription method', {\n error: e,\n });\n progressReporter.verifying('Verifying inscription status', 50, {\n error: e,\n });\n\n return await sdk.waitForInscription(\n transactionId,\n maxAttempts,\n intervalMs,\n true\n );\n }\n } catch (error) {\n logger.error('Error waiting for inscription confirmation', {\n transactionId,\n maxAttempts,\n intervalMs,\n error,\n });\n\n progressReporter.failed('Inscription confirmation failed', {\n transactionId,\n error,\n });\n\n throw error;\n }\n}\n"],"names":[],"mappings":";;;;AA8BA,eAAsB,SACpB,OACA,cACA,SACA,aAC8B;AACxB,QAAA,SAAS,OAAO,YAAY;AAAA,IAChC,QAAQ;AAAA,IACR,GAAG,QAAQ;AAAA,EAAA,CACZ;AAED,SAAO,KAAK,gCAAgC;AAAA,IAC1C,MAAM,MAAM;AAAA,IACZ,MAAM,QAAQ,QAAQ;AAAA,IACtB,GAAI,MAAM,SAAS,QAAQ,EAAE,KAAK,MAAM,IAAI,IAAI,CAAC;AAAA,IACjD,GAAI,MAAM,SAAS,SAAS,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;AAAA,IACpD,GAAI,MAAM,SAAS,WACf,EAAE,UAAU,MAAM,UAAU,YAAY,MAAM,OAAO,WAAA,IACrD,CAAA;AAAA,EAAC,CACN;AAEG,MAAA;AACF,QAAI,QAAQ,SAAS,cAAc,QAAQ,UAAU;AAC1B,+BAAA,QAAQ,UAAU,MAAM;AAAA,IAAA;AAG/C,QAAA;AAEJ,QAAI,aAAa;AACf,aAAO,MAAM,wCAAwC;AAC/C,YAAA;AAAA,IAAA,WACG,QAAQ,QAAQ;AACzB,aAAO,MA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AS;AACtB,cAAA,UAAU,KAAK,WAAW;AAC1B,cAAA,UAAU,KAAK,mBAAmB;AAExC,yBAAiB,OAAO;AAAA,UACtB;AAAA,UACA;AAAA,UACA,iBAAiB;AAAA,UACjB,SAAS,CAAA;AAAA,QAAC,CACX;AAAA,MACH;AAEA,aAAO,MAAM;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,aACO,GAAG;AACV,cAAQ,IAAI,CAAC;AAEb,aAAO,MAAM,sDAAsD;AAAA,QACjE,OAAO;AAAA,MAAA,CACR;AACgB,uBAAA,UAAU,gCAAgC,IAAI;AAAA,QAC7D,OAAO;AAAA,MAAA,CACR;AAED,aAAO,MAAM,IAAI;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IAAA;AAAA,WAEK,OAAO;AACd,WAAO,MAAM,8CAA8C;AAAA,MACzD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAED,qBAAiB,OAAO,mCAAmC;AAAA,MACzD;AAAA,MACA;AAAA,IAAA,CACD;AAEK,UAAA;AAAA,EAAA;AAEV;"}
|
|
1
|
+
{"version":3,"file":"standards-sdk.es20.js","sources":["../../src/services/mirror-node.ts"],"sourcesContent":["import { PublicKey, Timestamp } from '@hashgraph/sdk';\nimport axios from 'axios';\nimport { Logger } from '../utils/logger';\nimport { HCSMessage } from '../hcs-10/base-client';\nimport { proto } from '@hashgraph/proto';\nimport {\n AccountResponse,\n CustomFees,\n HBARPrice,\n TokenInfoResponse,\n TopicMessagesResponse,\n TopicResponse,\n} from './types';\nimport { NetworkType } from '../utils/types';\nexport class HederaMirrorNode {\n private network: NetworkType;\n private baseUrl: string;\n private logger: Logger;\n private isServerEnvironment: boolean;\n\n constructor(network: NetworkType, logger: Logger) {\n this.network = network;\n this.baseUrl = this.getMirrorNodeUrl();\n this.logger = logger;\n this.isServerEnvironment = typeof window === 'undefined';\n }\n\n private getMirrorNodeUrl(): string {\n return this.network === 'mainnet'\n ? 'https://mainnet-public.mirrornode.hedera.com'\n : 'https://testnet.mirrornode.hedera.com';\n }\n\n getBaseUrl(): string {\n return this.baseUrl;\n }\n\n /**\n * Retrieves the public key for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve the public key for.\n * @returns A promise that resolves to the public key for the given account.\n * @throws An error if the account ID is invalid or the public key cannot be retrieved.\n */\n async getPublicKey(accountId: string): Promise<PublicKey> {\n this.logger.info(`Getting public key for account ${accountId}`);\n\n const accountInfo = await this.requestAccount(accountId);\n\n try {\n if (!accountInfo || !accountInfo.key) {\n throw new Error(\n `Failed to retrieve public key for account ID: ${accountId}`\n );\n }\n\n return PublicKey.fromString(accountInfo.key.key);\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error fetching public key from Mirror Node: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Retrieves the memo for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve the memo for.\n * @returns A promise that resolves to the memo for the given account.\n * @throws An error if the account ID is invalid or the memo cannot be retrieved.\n */\n async getAccountMemo(accountId: string): Promise<string | null> {\n const maxRetries = 3;\n\n for (let attempt = 0; attempt < maxRetries; attempt++) {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n\n const response = await axios.get(accountInfoUrl);\n const accountInfo = response.data;\n\n if (accountInfo && accountInfo.memo) {\n return accountInfo.memo;\n }\n\n this.logger.error(`No memo found for account ${accountId}`);\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error getting account memo (attempt ${attempt + 1}): ${error.message}`;\n this.logger.error(logMessage);\n\n if (attempt < maxRetries - 1) {\n await new Promise((resolve) => setTimeout(resolve, 2000));\n }\n }\n }\n\n return null;\n }\n\n /**\n * Retrieves topic information for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve information for.\n * @returns A promise that resolves to the topic information.\n * @throws An error if the topic ID is invalid or the information cannot be retrieved.\n */\n async getTopicInfo(topicId: string): Promise<TopicResponse> {\n try {\n const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;\n const response = await axios.get(topicInfoUrl);\n return response.data;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error retrieving topic information: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Retrieves custom fees for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve custom fees for.\n * @returns A promise that resolves to the custom fees for the given topic.\n * @throws An error if the topic ID is invalid or the custom fees cannot be retrieved.\n */\n async getTopicFees(topicId: string): Promise<CustomFees | null> {\n try {\n const topicInfo = await this.getTopicInfo(topicId);\n return topicInfo.custom_fees;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error retrieving topic fees: ${error.message}`;\n this.logger.error(logMessage);\n return null;\n }\n }\n\n /**\n * Retrieves the current HBAR price from the mirror node.\n * @param date The date to retrieve the HBAR price for.\n * @returns A promise that resolves to the HBAR price for the given date.\n * @throws An error if the date is invalid or the price cannot be retrieved.\n */\n async getHBARPrice(date: Date): Promise<number | null> {\n try {\n const timestamp = Timestamp.fromDate(date).toString();\n\n const request = await fetch(\n `https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`\n );\n const response = (await request.json()) as HBARPrice;\n\n const usdPrice =\n Number(response?.current_rate?.cent_equivalent) /\n Number(response?.current_rate?.hbar_equivalent) /\n 100;\n\n return usdPrice;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error retrieving HBAR price: ${error.message}`;\n this.logger.error(logMessage);\n return null;\n }\n }\n\n /**\n * Retrieves token information for a given token ID from the mirror node.\n * @param tokenId The ID of the token to retrieve information for.\n * @returns A promise that resolves to the token information.\n * @throws An error if the token ID is invalid or the information cannot be retrieved.\n */\n async getTokenInfo(tokenId: string): Promise<TokenInfoResponse | null> {\n this.logger.debug(`Fetching token info for ${tokenId}`);\n try {\n const tokenInfoUrl = `${this.baseUrl}/api/v1/tokens/${tokenId}`;\n const response = await axios.get<TokenInfoResponse>(tokenInfoUrl);\n if (response.data) {\n this.logger.trace(`Token info found for ${tokenId}:`, response.data);\n return response.data;\n }\n this.logger.warn(`No token info found for ${tokenId}`);\n return null;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error fetching token info for ${tokenId}: ${error.message}`;\n this.logger.error(logMessage);\n\n return null;\n }\n }\n\n /**\n * Retrieves messages for a given topic ID from the mirror node.\n * @param topicId The ID of the topic to retrieve messages for.\n * @returns A promise that resolves to the messages for the given topic.\n * @throws An error if the topic ID is invalid or the messages cannot be retrieved.\n */\n async getTopicMessages(topicId: string): Promise<HCSMessage[]> {\n this.logger.trace(`Querying messages for topic ${topicId}`);\n\n let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;\n const messages: HCSMessage[] = [];\n\n while (nextUrl) {\n try {\n const response = await axios.get<TopicMessagesResponse>(nextUrl);\n const data = response.data;\n\n if (data.messages && data.messages.length > 0) {\n for (const message of data.messages) {\n try {\n if (!message.message) {\n continue;\n }\n\n let messageContent: string;\n try {\n if (this.isServerEnvironment) {\n messageContent = Buffer.from(\n message.message,\n 'base64'\n ).toString('utf-8');\n } else {\n messageContent = new TextDecoder().decode(\n Uint8Array.from(atob(message.message), (c) =>\n c.charCodeAt(0)\n )\n );\n }\n } catch (error) {\n const logMessage = `Error decoding message: ${error}`;\n this.logger.error(logMessage);\n continue;\n }\n\n let messageJson;\n try {\n messageJson = JSON.parse(messageContent);\n } catch (error) {\n const logMessage = `Invalid JSON message content: ${messageContent}`;\n this.logger.error(logMessage);\n return;\n }\n\n messageJson.sequence_number = message.sequence_number;\n messages.push({\n ...messageJson,\n consensus_timestamp: message.consensus_timestamp,\n sequence_number: message.sequence_number,\n created: new Date(Number(message.consensus_timestamp) * 1000),\n });\n } catch (error: any) {\n const logMessage = `Error processing message: ${error.message}`;\n this.logger.error(logMessage);\n }\n }\n }\n\n nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : '';\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error querying topic messages: ${error.message} on ${topicId}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n return messages;\n }\n\n /**\n * Requests account information for a given account ID from the mirror node.\n * @param accountId The ID of the account to retrieve information for.\n * @returns A promise that resolves to the account information.\n * @throws An error if the account ID is invalid or the information cannot be retrieved.\n */\n async requestAccount(accountId: string): Promise<AccountResponse> {\n try {\n const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;\n const response = await axios.get(accountInfoUrl);\n if (!response.data) {\n throw new Error(\n `Failed to make request to mirror node for account: ${accountId}`\n );\n }\n return response.data;\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Failed to fetch account: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Checks if a user has access to a given key list.\n * @param keyBytes The key list to check access for.\n * @param userPublicKey The public key of the user to check access for.\n * @returns A promise that resolves to true if the user has access, false otherwise.\n */\n async checkKeyListAccess(\n keyBytes: Buffer,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n try {\n const key = proto.Key.decode(keyBytes);\n return this.evaluateKeyAccess(key, userPublicKey);\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error decoding protobuf key: ${error.message}`;\n this.logger.error(logMessage);\n throw new Error(logMessage);\n }\n }\n\n /**\n * Evaluates the access of a given key to a user's public key.\n * @param key The key to evaluate access for.\n * @param userPublicKey The public key of the user to evaluate access for.\n * @returns A promise that resolves to true if the key has access, false otherwise.\n */\n private async evaluateKeyAccess(\n key: proto.IKey,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n if (key.ed25519) {\n return this.compareEd25519Key(key.ed25519, userPublicKey);\n }\n\n if (key.keyList) {\n return this.evaluateKeyList(key.keyList, userPublicKey);\n }\n\n if (key.thresholdKey && key.thresholdKey.keys) {\n return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);\n }\n\n return false;\n }\n\n /**\n * Evaluates the access of a given key list to a user's public key.\n * @param keyList The key list to evaluate access for.\n * @param userPublicKey The public key of the user to evaluate access for.\n * @returns A promise that resolves to true if the key list has access, false otherwise.\n */\n private async evaluateKeyList(\n keyList: proto.IKeyList,\n userPublicKey: PublicKey\n ): Promise<boolean> {\n const keys = keyList.keys || [];\n\n for (const listKey of keys) {\n if (!listKey) continue;\n\n if (listKey.ed25519) {\n if (this.compareEd25519Key(listKey.ed25519, userPublicKey)) {\n return true;\n }\n } else if (listKey.keyList || listKey.thresholdKey) {\n try {\n const nestedKeyBytes = proto.Key.encode({\n ...(listKey.keyList ? { keyList: listKey.keyList } : {}),\n ...(listKey.thresholdKey\n ? { thresholdKey: listKey.thresholdKey }\n : {}),\n }).finish();\n\n const hasNestedAccess = await this.checkKeyListAccess(\n Buffer.from(nestedKeyBytes),\n userPublicKey\n );\n\n if (hasNestedAccess) {\n return true;\n }\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error in nested key: ${error.message}`;\n this.logger.debug(logMessage);\n }\n }\n }\n\n return false;\n }\n\n /**\n * Compares an Ed25519 key with a user's public key.\n * @param keyData The Ed25519 key data to compare.\n * @param userPublicKey The public key of the user to compare with.\n * @returns A boolean indicating whether the key matches the user's public key.\n */\n private compareEd25519Key(\n keyData: Uint8Array,\n userPublicKey: PublicKey\n ): boolean {\n try {\n const decodedKey = PublicKey.fromBytes(Buffer.from(keyData));\n return decodedKey.toString() === userPublicKey.toString();\n } catch (e: any) {\n const error = e as Error;\n const logMessage = `Error comparing Ed25519 key: ${error.message}`;\n this.logger.debug(logMessage);\n return false;\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAcO,MAAM,iBAAiB;AAAA,EAM5B,YAAY,SAAsB,QAAgB;AAChD,SAAK,UAAU;AACV,SAAA,UAAU,KAAK,iBAAiB;AACrC,SAAK,SAAS;AACT,SAAA,sB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,SAAS,QAAQ,QAAA,IAAY,CAAC;AAAA,YACtD,GAAI,QAAQ,eACR,EAAE,cAAc,QAAQ,aAAA,IACxB,CAAA;AAAA,UACL,CAAA,EAAE,OAAO;AAEJ,gBAAA,kBAAkB,MAAM,KAAK;AAAA,YACjC,OAAO,KAAK,cAAc;AAAA,YAC1B;AAAA,UACF;AAEA,cAAI,iBAAiB;AACZ,mBAAA;AAAA,UAAA;AAAA,iBAEF,GAAQ;AACf,gBAAM,QAAQ;AACR,gBAAA,aAAa,wBAAwB,MAAM,OAAO;AACnD,eAAA,OAAO,MAAM,UAAU;AAAA,QAAA;AAAA,MAC9B;AAAA,IACF;AAGK,WAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASD,kBACN,SACA,eACS;AACL,QAAA;AACF,YAAM,aAAa,UAAU,UAAU,OAAO,KAAK,OAAO,CAAC;AAC3D,aAAO,WAAW,eAAe,cAAc,SAAS;AAAA,aACjD,GAAQ;AACf,YAAM,QAAQ;AACR,YAAA,aAAa,gCAAgC,MAAM,OAAO;AAC3D,WAAA,OAAO,MAAM,UAAU;AACrB,aAAA;AAAA,IAAA;AAAA,EACT;AAEJ;"}
|
|
@@ -1,387 +1,158 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.
|
|
9
|
-
this.baseUrl = this.getMirrorNodeUrl();
|
|
10
|
-
this.logger = logger;
|
|
11
|
-
this.isServerEnvironment = typeof window === "undefined";
|
|
12
|
-
}
|
|
13
|
-
getMirrorNodeUrl() {
|
|
14
|
-
return this.network === "mainnet" ? "https://mainnet-public.mirrornode.hedera.com" : "https://testnet.mirrornode.hedera.com";
|
|
15
|
-
}
|
|
16
|
-
getBaseUrl() {
|
|
17
|
-
return this.baseUrl;
|
|
1
|
+
import { CustomFeeType } from "./standards-sdk.es22.js";
|
|
2
|
+
import { HederaMirrorNode } from "./standards-sdk.es20.js";
|
|
3
|
+
class FeeConfigBuilder {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.customFees = [];
|
|
6
|
+
this.logger = options.logger;
|
|
7
|
+
this.mirrorNode = new HederaMirrorNode(options.network, options.logger);
|
|
8
|
+
this.defaultCollectorAccountId = options.defaultCollectorAccountId || "";
|
|
18
9
|
}
|
|
19
10
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
11
|
+
* Static factory method to create a FeeConfigBuilder with a single HBAR fee.
|
|
12
|
+
* @param hbarAmount Amount in HBAR.
|
|
13
|
+
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
|
|
14
|
+
* @param network Network type ('mainnet' or 'testnet').
|
|
15
|
+
* @param logger Logger instance.
|
|
16
|
+
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
17
|
+
* @returns A configured FeeConfigBuilder instance.
|
|
24
18
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return PublicKey.fromString(accountInfo.key.key);
|
|
35
|
-
} catch (e) {
|
|
36
|
-
const error = e;
|
|
37
|
-
const logMessage = `Error fetching public key from Mirror Node: ${error.message}`;
|
|
38
|
-
this.logger.error(logMessage);
|
|
39
|
-
throw new Error(logMessage);
|
|
40
|
-
}
|
|
19
|
+
static forHbar(hbarAmount, collectorAccountId, network, logger, exemptAccounts = []) {
|
|
20
|
+
const builder = new FeeConfigBuilder({
|
|
21
|
+
network,
|
|
22
|
+
logger,
|
|
23
|
+
defaultCollectorAccountId: collectorAccountId
|
|
24
|
+
});
|
|
25
|
+
return builder.addHbarFee(hbarAmount, collectorAccountId, exemptAccounts);
|
|
41
26
|
}
|
|
42
27
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
* @
|
|
28
|
+
* Static factory method to create a FeeConfigBuilder with a single token fee.
|
|
29
|
+
* Automatically fetches token decimals if not provided.
|
|
30
|
+
* @param tokenAmount Amount of tokens.
|
|
31
|
+
* @param feeTokenId Token ID for the fee.
|
|
32
|
+
* @param collectorAccountId Optional account ID to collect the fee. If omitted or undefined, defaults to the agent's own account ID during topic creation.
|
|
33
|
+
* @param network Network type ('mainnet' or 'testnet').
|
|
34
|
+
* @param logger Logger instance.
|
|
35
|
+
* @param exemptAccounts Optional array of account IDs exempt from this fee.
|
|
36
|
+
* @param decimals Optional decimals for the token (fetched if omitted).
|
|
37
|
+
* @returns A Promise resolving to a configured FeeConfigBuilder instance.
|
|
47
38
|
*/
|
|
48
|
-
async
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} catch (e) {
|
|
63
|
-
const error = e;
|
|
64
|
-
const logMessage = `Error getting account memo (attempt ${attempt + 1}): ${error.message}`;
|
|
65
|
-
this.logger.error(logMessage);
|
|
66
|
-
if (attempt < maxRetries - 1) {
|
|
67
|
-
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Retrieves topic information for a given topic ID from the mirror node.
|
|
75
|
-
* @param topicId The ID of the topic to retrieve information for.
|
|
76
|
-
* @returns A promise that resolves to the topic information.
|
|
77
|
-
* @throws An error if the topic ID is invalid or the information cannot be retrieved.
|
|
78
|
-
*/
|
|
79
|
-
async getTopicInfo(topicId) {
|
|
80
|
-
try {
|
|
81
|
-
const topicInfoUrl = `${this.baseUrl}/api/v1/topics/${topicId}`;
|
|
82
|
-
const response = await axios.get(topicInfoUrl);
|
|
83
|
-
return response.data;
|
|
84
|
-
} catch (e) {
|
|
85
|
-
const error = e;
|
|
86
|
-
const logMessage = `Error retrieving topic information: ${error.message}`;
|
|
87
|
-
this.logger.error(logMessage);
|
|
88
|
-
throw new Error(logMessage);
|
|
89
|
-
}
|
|
39
|
+
static async forToken(tokenAmount, feeTokenId, collectorAccountId, network, logger, exemptAccounts = [], decimals) {
|
|
40
|
+
const builder = new FeeConfigBuilder({
|
|
41
|
+
network,
|
|
42
|
+
logger,
|
|
43
|
+
defaultCollectorAccountId: collectorAccountId
|
|
44
|
+
});
|
|
45
|
+
await builder.addTokenFee(
|
|
46
|
+
tokenAmount,
|
|
47
|
+
feeTokenId,
|
|
48
|
+
collectorAccountId,
|
|
49
|
+
decimals,
|
|
50
|
+
exemptAccounts
|
|
51
|
+
);
|
|
52
|
+
return builder;
|
|
90
53
|
}
|
|
91
54
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
95
|
-
* @
|
|
55
|
+
* Adds an HBAR fee configuration to the builder.
|
|
56
|
+
* Allows chaining multiple fee additions.
|
|
57
|
+
* @param hbarAmount The amount in HBAR (e.g., 0.5).
|
|
58
|
+
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
|
|
59
|
+
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* HBAR fee.
|
|
60
|
+
* @returns This FeeConfigBuilder instance for chaining.
|
|
96
61
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
62
|
+
addHbarFee(hbarAmount, collectorAccountId, exemptAccountIds = []) {
|
|
63
|
+
if (hbarAmount <= 0) {
|
|
64
|
+
throw new Error("HBAR amount must be greater than zero");
|
|
65
|
+
}
|
|
66
|
+
this.customFees.push({
|
|
67
|
+
feeAmount: {
|
|
68
|
+
amount: hbarAmount * 1e8,
|
|
69
|
+
decimals: 0
|
|
70
|
+
},
|
|
71
|
+
feeCollectorAccountId: collectorAccountId || "",
|
|
72
|
+
feeTokenId: void 0,
|
|
73
|
+
exemptAccounts: [...exemptAccountIds],
|
|
74
|
+
type: CustomFeeType.FIXED_FEE
|
|
75
|
+
});
|
|
76
|
+
return this;
|
|
107
77
|
}
|
|
108
78
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @
|
|
79
|
+
* Adds a token fee configuration to the builder.
|
|
80
|
+
* Allows chaining multiple fee additions.
|
|
81
|
+
* Fetches token decimals automatically if not provided.
|
|
82
|
+
* @param tokenAmount The amount of the specified token.
|
|
83
|
+
* @param feeTokenId The ID of the token to charge the fee in.
|
|
84
|
+
* @param collectorAccountId Optional. The account ID to collect this fee. If omitted, defaults to the agent's own account ID during topic creation.
|
|
85
|
+
* @param decimals Optional. The number of decimals for the token. If omitted, it will be fetched from the mirror node.
|
|
86
|
+
* @param exemptAccountIds Optional. Accounts specifically exempt from *this* token fee.
|
|
87
|
+
* @returns A Promise resolving to this FeeConfigBuilder instance for chaining.
|
|
113
88
|
*/
|
|
114
|
-
async
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const request = await fetch(
|
|
118
|
-
`https://mainnet-public.mirrornode.hedera.com/api/v1/network/exchangerate?timestamp=${timestamp}`
|
|
119
|
-
);
|
|
120
|
-
const response = await request.json();
|
|
121
|
-
const usdPrice = Number(response?.current_rate?.cent_equivalent) / Number(response?.current_rate?.hbar_equivalent) / 100;
|
|
122
|
-
return usdPrice;
|
|
123
|
-
} catch (e) {
|
|
124
|
-
const error = e;
|
|
125
|
-
const logMessage = `Error retrieving HBAR price: ${error.message}`;
|
|
126
|
-
this.logger.error(logMessage);
|
|
127
|
-
return null;
|
|
89
|
+
async addTokenFee(tokenAmount, feeTokenId, collectorAccountId, decimals, exemptAccountIds = []) {
|
|
90
|
+
if (tokenAmount <= 0) {
|
|
91
|
+
throw new Error("Token amount must be greater than zero");
|
|
128
92
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* Retrieves token information for a given token ID from the mirror node.
|
|
132
|
-
* @param tokenId The ID of the token to retrieve information for.
|
|
133
|
-
* @returns A promise that resolves to the token information.
|
|
134
|
-
* @throws An error if the token ID is invalid or the information cannot be retrieved.
|
|
135
|
-
*/
|
|
136
|
-
async getTokenInfo(tokenId) {
|
|
137
|
-
this.logger.debug(`Fetching token info for ${tokenId}`);
|
|
138
|
-
try {
|
|
139
|
-
const tokenInfoUrl = `${this.baseUrl}/api/v1/tokens/${tokenId}`;
|
|
140
|
-
const response = await axios.get(tokenInfoUrl);
|
|
141
|
-
if (response.data) {
|
|
142
|
-
this.logger.trace(`Token info found for ${tokenId}:`, response.data);
|
|
143
|
-
return response.data;
|
|
144
|
-
}
|
|
145
|
-
this.logger.warn(`No token info found for ${tokenId}`);
|
|
146
|
-
return null;
|
|
147
|
-
} catch (e) {
|
|
148
|
-
const error = e;
|
|
149
|
-
const logMessage = `Error fetching token info for ${tokenId}: ${error.message}`;
|
|
150
|
-
this.logger.error(logMessage);
|
|
151
|
-
return null;
|
|
93
|
+
if (!feeTokenId) {
|
|
94
|
+
throw new Error("Fee token ID is required when adding a token fee");
|
|
152
95
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* Retrieves messages for a given topic ID from the mirror node.
|
|
156
|
-
* @param topicId The ID of the topic to retrieve messages for.
|
|
157
|
-
* @returns A promise that resolves to the messages for the given topic.
|
|
158
|
-
* @throws An error if the topic ID is invalid or the messages cannot be retrieved.
|
|
159
|
-
*/
|
|
160
|
-
async getTopicMessages(topicId) {
|
|
161
|
-
this.logger.trace(`Querying messages for topic ${topicId}`);
|
|
162
|
-
let nextUrl = `${this.baseUrl}/api/v1/topics/${topicId}/messages`;
|
|
163
|
-
const messages = [];
|
|
164
|
-
while (nextUrl) {
|
|
96
|
+
let finalDecimals = decimals;
|
|
97
|
+
if (finalDecimals === void 0) {
|
|
165
98
|
try {
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!message.message) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
let messageContent;
|
|
175
|
-
try {
|
|
176
|
-
if (this.isServerEnvironment) {
|
|
177
|
-
messageContent = Buffer.from(
|
|
178
|
-
message.message,
|
|
179
|
-
"base64"
|
|
180
|
-
).toString("utf-8");
|
|
181
|
-
} else {
|
|
182
|
-
messageContent = new TextDecoder().decode(
|
|
183
|
-
Uint8Array.from(
|
|
184
|
-
atob(message.message),
|
|
185
|
-
(c) => c.charCodeAt(0)
|
|
186
|
-
)
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
} catch (error) {
|
|
190
|
-
const logMessage = `Error decoding message: ${error}`;
|
|
191
|
-
this.logger.error(logMessage);
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
let messageJson;
|
|
195
|
-
try {
|
|
196
|
-
messageJson = JSON.parse(messageContent);
|
|
197
|
-
} catch (error) {
|
|
198
|
-
const logMessage = `Invalid JSON message content: ${messageContent}`;
|
|
199
|
-
this.logger.error(logMessage);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
messageJson.sequence_number = message.sequence_number;
|
|
203
|
-
messages.push({
|
|
204
|
-
...messageJson,
|
|
205
|
-
consensus_timestamp: message.consensus_timestamp,
|
|
206
|
-
sequence_number: message.sequence_number,
|
|
207
|
-
created: new Date(Number(message.consensus_timestamp) * 1e3)
|
|
208
|
-
});
|
|
209
|
-
} catch (error) {
|
|
210
|
-
const logMessage = `Error processing message: ${error.message}`;
|
|
211
|
-
this.logger.error(logMessage);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
nextUrl = data.links?.next ? `${this.baseUrl}${data.links.next}` : "";
|
|
216
|
-
} catch (e) {
|
|
217
|
-
const error = e;
|
|
218
|
-
const logMessage = `Error querying topic messages: ${error.message} on ${topicId}`;
|
|
219
|
-
this.logger.error(logMessage);
|
|
220
|
-
throw new Error(logMessage);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return messages;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Requests account information for a given account ID from the mirror node.
|
|
227
|
-
* @param accountId The ID of the account to retrieve information for.
|
|
228
|
-
* @returns A promise that resolves to the account information.
|
|
229
|
-
* @throws An error if the account ID is invalid or the information cannot be retrieved.
|
|
230
|
-
*/
|
|
231
|
-
async requestAccount(accountId) {
|
|
232
|
-
try {
|
|
233
|
-
const accountInfoUrl = `${this.baseUrl}/api/v1/accounts/${accountId}`;
|
|
234
|
-
const response = await axios.get(accountInfoUrl);
|
|
235
|
-
if (!response.data) {
|
|
236
|
-
throw new Error(
|
|
237
|
-
`Failed to make request to mirror node for account: ${accountId}`
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
return response.data;
|
|
241
|
-
} catch (e) {
|
|
242
|
-
const error = e;
|
|
243
|
-
const logMessage = `Failed to fetch account: ${error.message}`;
|
|
244
|
-
this.logger.error(logMessage);
|
|
245
|
-
throw new Error(logMessage);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Checks if a user has access to a given key list.
|
|
250
|
-
* @param keyBytes The key list to check access for.
|
|
251
|
-
* @param userPublicKey The public key of the user to check access for.
|
|
252
|
-
* @returns A promise that resolves to true if the user has access, false otherwise.
|
|
253
|
-
*/
|
|
254
|
-
async checkKeyListAccess(keyBytes, userPublicKey) {
|
|
255
|
-
try {
|
|
256
|
-
const key = proto.Key.decode(keyBytes);
|
|
257
|
-
return this.evaluateKeyAccess(key, userPublicKey);
|
|
258
|
-
} catch (e) {
|
|
259
|
-
const error = e;
|
|
260
|
-
const logMessage = `Error decoding protobuf key: ${error.message}`;
|
|
261
|
-
this.logger.error(logMessage);
|
|
262
|
-
throw new Error(logMessage);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Evaluates the access of a given key to a user's public key.
|
|
267
|
-
* @param key The key to evaluate access for.
|
|
268
|
-
* @param userPublicKey The public key of the user to evaluate access for.
|
|
269
|
-
* @returns A promise that resolves to true if the key has access, false otherwise.
|
|
270
|
-
*/
|
|
271
|
-
async evaluateKeyAccess(key, userPublicKey) {
|
|
272
|
-
if (key.ed25519) {
|
|
273
|
-
return this.compareEd25519Key(key.ed25519, userPublicKey);
|
|
274
|
-
}
|
|
275
|
-
if (key.keyList) {
|
|
276
|
-
return this.evaluateKeyList(key.keyList, userPublicKey);
|
|
277
|
-
}
|
|
278
|
-
if (key.thresholdKey && key.thresholdKey.keys) {
|
|
279
|
-
return this.evaluateKeyList(key.thresholdKey.keys, userPublicKey);
|
|
280
|
-
}
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Evaluates the access of a given key list to a user's public key.
|
|
285
|
-
* @param keyList The key list to evaluate access for.
|
|
286
|
-
* @param userPublicKey The public key of the user to evaluate access for.
|
|
287
|
-
* @returns A promise that resolves to true if the key list has access, false otherwise.
|
|
288
|
-
*/
|
|
289
|
-
async evaluateKeyList(keyList, userPublicKey) {
|
|
290
|
-
const keys = keyList.keys || [];
|
|
291
|
-
for (const listKey of keys) {
|
|
292
|
-
if (!listKey) continue;
|
|
293
|
-
if (listKey.ed25519) {
|
|
294
|
-
if (this.compareEd25519Key(listKey.ed25519, userPublicKey)) {
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
} else if (listKey.keyList || listKey.thresholdKey) {
|
|
298
|
-
try {
|
|
299
|
-
const nestedKeyBytes = proto.Key.encode({
|
|
300
|
-
...listKey.keyList ? { keyList: listKey.keyList } : {},
|
|
301
|
-
...listKey.thresholdKey ? { thresholdKey: listKey.thresholdKey } : {}
|
|
302
|
-
}).finish();
|
|
303
|
-
const hasNestedAccess = await this.checkKeyListAccess(
|
|
304
|
-
Buffer.from(nestedKeyBytes),
|
|
305
|
-
userPublicKey
|
|
99
|
+
const tokenInfo = await this.mirrorNode.getTokenInfo(feeTokenId);
|
|
100
|
+
if (tokenInfo?.decimals) {
|
|
101
|
+
finalDecimals = parseInt(tokenInfo.decimals, 10);
|
|
102
|
+
this.logger.info(
|
|
103
|
+
`Fetched decimals for ${feeTokenId}: ${finalDecimals}`
|
|
306
104
|
);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const logMessage = `Error in nested key: ${error.message}`;
|
|
313
|
-
this.logger.debug(logMessage);
|
|
105
|
+
} else {
|
|
106
|
+
this.logger.warn(
|
|
107
|
+
`Could not fetch decimals for ${feeTokenId}, defaulting to 0.`
|
|
108
|
+
);
|
|
109
|
+
finalDecimals = 0;
|
|
314
110
|
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
this.logger.error(
|
|
113
|
+
`Error fetching decimals for ${feeTokenId}, defaulting to 0: ${error}`
|
|
114
|
+
);
|
|
115
|
+
finalDecimals = 0;
|
|
315
116
|
}
|
|
316
117
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return decodedKey.toString() === userPublicKey.toString();
|
|
329
|
-
} catch (e) {
|
|
330
|
-
const error = e;
|
|
331
|
-
const logMessage = `Error comparing Ed25519 key: ${error.message}`;
|
|
332
|
-
this.logger.debug(logMessage);
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
118
|
+
this.customFees.push({
|
|
119
|
+
feeAmount: {
|
|
120
|
+
amount: tokenAmount * 10 ** finalDecimals,
|
|
121
|
+
decimals: finalDecimals
|
|
122
|
+
},
|
|
123
|
+
feeCollectorAccountId: collectorAccountId || "",
|
|
124
|
+
feeTokenId,
|
|
125
|
+
exemptAccounts: [...exemptAccountIds],
|
|
126
|
+
type: CustomFeeType.FIXED_FEE
|
|
127
|
+
});
|
|
128
|
+
return this;
|
|
335
129
|
}
|
|
336
130
|
/**
|
|
337
|
-
*
|
|
338
|
-
* @
|
|
339
|
-
* @
|
|
131
|
+
* Builds the final TopicFeeConfig object.
|
|
132
|
+
* @returns The TopicFeeConfig containing all added custom fees and a consolidated list of unique exempt accounts.
|
|
133
|
+
* @throws Error if no fees have been added.
|
|
134
|
+
* @throws Error if more than 10 fees have been added.
|
|
340
135
|
*/
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
136
|
+
build() {
|
|
137
|
+
if (this.customFees.length === 0) {
|
|
138
|
+
throw new Error(
|
|
139
|
+
"At least one fee must be added using addHbarFee/addTokenFee or created using forHbar/forToken"
|
|
345
140
|
);
|
|
346
|
-
const url = `${this.baseUrl}/api/v1/schedules/${scheduleId}`;
|
|
347
|
-
const response = await axios.get(url);
|
|
348
|
-
if (response.data) {
|
|
349
|
-
return response.data;
|
|
350
|
-
}
|
|
351
|
-
return null;
|
|
352
|
-
} catch (error) {
|
|
353
|
-
this.logger.error(`Error fetching schedule info: ${error.message}`);
|
|
354
|
-
return null;
|
|
355
141
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
* Checks the status of a scheduled transaction
|
|
359
|
-
* @param scheduleId The schedule ID to check
|
|
360
|
-
* @returns Status of the scheduled transaction
|
|
361
|
-
*/
|
|
362
|
-
async getScheduledTransactionStatus(scheduleId) {
|
|
363
|
-
try {
|
|
364
|
-
this.logger.info(
|
|
365
|
-
`Checking status of scheduled transaction ${scheduleId}`
|
|
366
|
-
);
|
|
367
|
-
const scheduleInfo = await this.getScheduleInfo(scheduleId);
|
|
368
|
-
if (!scheduleInfo) {
|
|
369
|
-
throw new Error(`Schedule ${scheduleId} not found`);
|
|
370
|
-
}
|
|
371
|
-
return {
|
|
372
|
-
executed: Boolean(scheduleInfo.executed_timestamp),
|
|
373
|
-
executedDate: scheduleInfo.executed_timestamp ? new Date(Number(scheduleInfo.executed_timestamp) * 1e3) : void 0,
|
|
374
|
-
deleted: scheduleInfo.deleted || false
|
|
375
|
-
};
|
|
376
|
-
} catch (error) {
|
|
377
|
-
this.logger.error(
|
|
378
|
-
`Error checking scheduled transaction status: ${error}`
|
|
379
|
-
);
|
|
380
|
-
throw error;
|
|
142
|
+
if (this.customFees.length > 10) {
|
|
143
|
+
throw new Error("Maximum of 10 custom fees per topic allowed");
|
|
381
144
|
}
|
|
145
|
+
const allExemptAccounts = /* @__PURE__ */ new Set();
|
|
146
|
+
this.customFees.forEach((fee) => {
|
|
147
|
+
fee.exemptAccounts.forEach((account) => allExemptAccounts.add(account));
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
customFees: this.customFees,
|
|
151
|
+
exemptAccounts: Array.from(allExemptAccounts)
|
|
152
|
+
};
|
|
382
153
|
}
|
|
383
154
|
}
|
|
384
155
|
export {
|
|
385
|
-
|
|
156
|
+
FeeConfigBuilder
|
|
386
157
|
};
|
|
387
158
|
//# sourceMappingURL=standards-sdk.es21.js.map
|