@@ -7,12 +7,14 @@ import {
77 CustomRoyaltyFee ,
88 FeeAssessmentMethod ,
99 Transaction ,
10+ TokenInfo ,
1011} from "@hiero-ledger/sdk" ;
1112import Long from "long" ;
1213
1314import { DEFAULT_GRPC_DEADLINE } from "../../utils/constants/config" ;
1415
1516import { applyCommonTransactionParams } from "../../params/common-tx-params" ;
17+ import { TokenInfoQueryResponse } from "../../response/token" ;
1618
1719export const executeTokenManagementTransaction = async (
1820 transaction : Transaction ,
@@ -144,3 +146,103 @@ export const createCustomFees = (customFees: Array<Record<string, any>>) => {
144146
145147 return customFeeList ;
146148} ;
149+
150+ // Helper function to map TokenInfo to TokenInfoQueryResponse
151+ export const mapTokenInfoResponse = (
152+ info : TokenInfo ,
153+ ) : TokenInfoQueryResponse => {
154+ // Helper function to convert pause status
155+ const getPauseStatusString = ( pauseStatus : boolean | null ) : string => {
156+ if ( pauseStatus === null ) {
157+ return "NOT_APPLICABLE" ;
158+ }
159+ return pauseStatus ? "PAUSED" : "UNPAUSED" ;
160+ } ;
161+
162+ // Helper function to serialize custom fees
163+ const serializeCustomFees = ( customFees : CustomFee [ ] ) : any [ ] => {
164+ return customFees . map ( ( fee ) => {
165+ if ( fee instanceof CustomFixedFee ) {
166+ return {
167+ feeCollectorAccountId :
168+ fee . feeCollectorAccountId ?. toString ( ) ,
169+ allCollectorsAreExempt : fee . allCollectorsAreExempt ,
170+ fixedFee : {
171+ amount : fee . amount ?. toString ( ) ,
172+ denominatingTokenId :
173+ fee . denominatingTokenId ?. toString ( ) || null ,
174+ } ,
175+ } ;
176+ } else if ( fee instanceof CustomFractionalFee ) {
177+ return {
178+ feeCollectorAccountId :
179+ fee . feeCollectorAccountId ?. toString ( ) ,
180+ allCollectorsAreExempt : fee . allCollectorsAreExempt ,
181+ fractionalFee : {
182+ numerator : fee . numerator . toString ( ) ,
183+ denominator : fee . denominator . toString ( ) ,
184+ minimumAmount : fee . min ?. toString ( ) || "0" ,
185+ maximumAmount : fee . max ?. toString ( ) || "0" ,
186+ assessmentMethod :
187+ fee . assessmentMethod ?. toString ( ) . toLowerCase ( ) ||
188+ "inclusive" ,
189+ } ,
190+ } ;
191+ } else if ( fee instanceof CustomRoyaltyFee ) {
192+ const result : any = {
193+ feeCollectorAccountId :
194+ fee . feeCollectorAccountId ?. toString ( ) ,
195+ allCollectorsAreExempt : fee . allCollectorsAreExempt ,
196+ royaltyFee : {
197+ numerator : fee . numerator . toString ( ) ,
198+ denominator : fee . denominator . toString ( ) ,
199+ fallbackFee : fee . fallbackFee
200+ ? {
201+ amount : fee . fallbackFee . amount ?. toString ( ) ,
202+ denominatingTokenId :
203+ fee . fallbackFee . denominatingTokenId ?. toString ( ) ||
204+ null ,
205+ }
206+ : null ,
207+ } ,
208+ } ;
209+ return result ;
210+ }
211+ return fee ;
212+ } ) ;
213+ } ;
214+
215+ return {
216+ tokenId : info . tokenId ?. toString ( ) ,
217+ name : info . name ,
218+ symbol : info . symbol ,
219+ decimals : info . decimals ,
220+ totalSupply : info . totalSupply ?. toString ( ) ,
221+ treasuryAccountId : info . treasuryAccountId ?. toString ( ) ,
222+ adminKey : info . adminKey ?. toString ( ) ,
223+ kycKey : info . kycKey ?. toString ( ) ,
224+ freezeKey : info . freezeKey ?. toString ( ) ,
225+ pauseKey : info . pauseKey ?. toString ( ) ,
226+ wipeKey : info . wipeKey ?. toString ( ) ,
227+ supplyKey : info . supplyKey ?. toString ( ) ,
228+ feeScheduleKey : info . feeScheduleKey ?. toString ( ) ,
229+ metadataKey : info . metadataKey ?. toString ( ) ,
230+ defaultFreezeStatus : info . defaultFreezeStatus ,
231+ defaultKycStatus : info . defaultKycStatus ,
232+ pauseStatus : getPauseStatusString ( info . pauseStatus ) ,
233+ isDeleted : info . isDeleted ,
234+ autoRenewAccountId : info . autoRenewAccountId ?. toString ( ) ,
235+ autoRenewPeriod : info . autoRenewPeriod ?. seconds . toString ( ) ,
236+ expirationTime : info . expirationTime ?. seconds . toString ( ) ,
237+ tokenMemo : info . tokenMemo ,
238+ customFees : serializeCustomFees ( info . customFees ) ,
239+ tokenType : info . tokenType ?. toString ( ) ,
240+ supplyType : info . supplyType ?. toString ( ) ,
241+ maxSupply : info . maxSupply ?. toString ( ) ,
242+ metadata :
243+ info . metadata && info . metadata . length > 0
244+ ? Buffer . from ( info . metadata ) . toString ( "hex" )
245+ : "" ,
246+ ledgerId : info . ledgerId ?. toString ( ) ,
247+ } ;
248+ } ;
0 commit comments