@@ -121,7 +121,7 @@ access(all) fun main(transactionID: UInt64): FlowTransactionScheduler.Transactio
121121 return nil , fmt .Errorf ("failed to execute script: %w" , err )
122122 }
123123
124- txData , err := parseTransactionData (value )
124+ txData , err := ParseTransactionData (value )
125125 if err != nil {
126126 return nil , fmt .Errorf ("failed to parse transaction data: %w" , err )
127127 }
@@ -136,92 +136,23 @@ access(all) fun main(transactionID: UInt64): FlowTransactionScheduler.Transactio
136136 successMsg := branding .GreenStyle .Render ("Transaction data retrieved successfully" )
137137 logger .Info (fmt .Sprintf ("%s %s" , successIcon , successMsg ))
138138
139- return txData , nil
140- }
141-
142- // parseTransactionData parses the cadence.Value returned from the script
143- func parseTransactionData (value cadence.Value ) (* getResult , error ) {
144- // Check if result is nil (optional return)
145- optional , ok := value .(cadence.Optional )
146- if ! ok {
147- return nil , fmt .Errorf ("expected optional value, got %T" , value )
148- }
149-
150- if optional .Value == nil {
151- return nil , nil // Transaction not found
152- }
153-
154- structValue , ok := optional .Value .(cadence.Struct )
155- if ! ok {
156- return nil , fmt .Errorf ("expected struct value, got %T" , optional .Value )
157- }
158-
159- fields := cadence .FieldsMappedByName (structValue )
160-
161- result := & getResult {}
162-
163- if id , ok := fields ["id" ].(cadence.UInt64 ); ok {
164- result .id = uint64 (id )
165- }
166-
167- if priority , ok := fields ["priority" ].(cadence.Enum ); ok {
168- priorityFields := cadence .FieldsMappedByName (priority )
169- if rawValue , ok := priorityFields ["rawValue" ].(cadence.UInt8 ); ok {
170- result .priority = uint8 (rawValue )
171- }
172- }
173-
174- if effort , ok := fields ["executionEffort" ].(cadence.UInt64 ); ok {
175- result .executionEffort = uint64 (effort )
176- }
177-
178- if status , ok := fields ["status" ].(cadence.Enum ); ok {
179- statusFields := cadence .FieldsMappedByName (status )
180- if rawValue , ok := statusFields ["rawValue" ].(cadence.UInt8 ); ok {
181- result .status = uint8 (rawValue )
182- }
183- }
184-
185- if fees , ok := fields ["fees" ].(cadence.UFix64 ); ok {
186- result .fees = fees .String ()
187- }
188-
189- if timestamp , ok := fields ["scheduledTimestamp" ].(cadence.UFix64 ); ok {
190- result .scheduledTimestamp = timestamp .String ()
191- }
192-
193- if handlerType , ok := fields ["handlerTypeIdentifier" ].(cadence.String ); ok {
194- result .handlerTypeIdentifier = string (handlerType )
195- }
196-
197- if handlerAddr , ok := fields ["handlerAddress" ].(cadence.Address ); ok {
198- result .handlerAddress = handlerAddr .String ()
199- }
200-
201- return result , nil
139+ return & getResult {data : txData }, nil
202140}
203141
204142type getResult struct {
205- id uint64
206- priority uint8
207- executionEffort uint64
208- status uint8
209- fees string
210- scheduledTimestamp string
211- handlerTypeIdentifier string
212- handlerAddress string
143+ data * TransactionData
213144}
214145
215146func (r * getResult ) JSON () any {
216147 return map [string ]any {
217- "id" : r .id ,
218- "priority" : r .priority ,
219- "execution_effort" : r .executionEffort ,
220- "status" : r .status ,
221- "fees" : r .fees ,
222- "scheduled_timestamp" : r .scheduledTimestamp ,
223- "handler_type_identifier" : r .handlerTypeIdentifier ,
224- "handler_address" : r .handlerAddress ,
148+ "id" : r .data . ID ,
149+ "priority" : r .data . Priority ,
150+ "execution_effort" : r .data . ExecutionEffort ,
151+ "status" : r .data . Status ,
152+ "fees" : r .data . Fees ,
153+ "scheduled_timestamp" : r .data . ScheduledTimestamp ,
154+ "handler_type_identifier" : r .data . HandlerTypeIdentifier ,
155+ "handler_address" : r .data . HandlerAddress ,
225156 }
226157}
227158
@@ -230,82 +161,48 @@ func (r *getResult) String() string {
230161
231162 // ID
232163 idLabel := branding .GrayStyle .Render (" ID:" )
233- idValue := branding .PurpleStyle .Render (fmt .Sprintf ("%d" , r .id ))
164+ idValue := branding .PurpleStyle .Render (fmt .Sprintf ("%d" , r .data . ID ))
234165 output += fmt .Sprintf ("%s %s\n " , idLabel , idValue )
235166
236167 // Status
237168 statusLabel := branding .GrayStyle .Render (" Status:" )
238- statusValue := branding .GreenStyle .Render (getStatusString (r .status ))
169+ statusValue := branding .GreenStyle .Render (GetStatusString (r .data . Status ))
239170 output += fmt .Sprintf ("%s %s\n " , statusLabel , statusValue )
240171
241172 // Priority
242173 priorityLabel := branding .GrayStyle .Render (" Priority:" )
243- priorityValue := branding .PurpleStyle .Render (getPriorityString (r .priority ))
174+ priorityValue := branding .PurpleStyle .Render (GetPriorityString (r .data . Priority ))
244175 output += fmt .Sprintf ("%s %s\n " , priorityLabel , priorityValue )
245176
246177 // Execution Effort
247178 effortLabel := branding .GrayStyle .Render (" Execution Effort:" )
248- effortValue := branding .PurpleStyle .Render (fmt .Sprintf ("%d" , r .executionEffort ))
179+ effortValue := branding .PurpleStyle .Render (fmt .Sprintf ("%d" , r .data . ExecutionEffort ))
249180 output += fmt .Sprintf ("%s %s\n " , effortLabel , effortValue )
250181
251182 // Fees
252183 feesLabel := branding .GrayStyle .Render (" Fees:" )
253- feesValue := branding .PurpleStyle .Render (fmt .Sprintf ("%s FLOW" , r .fees ))
184+ feesValue := branding .PurpleStyle .Render (fmt .Sprintf ("%s FLOW" , r .data . Fees ))
254185 output += fmt .Sprintf ("%s %s\n " , feesLabel , feesValue )
255186
256187 // Scheduled Timestamp
257188 timestampLabel := branding .GrayStyle .Render (" Scheduled Timestamp:" )
258- timestampValue := branding .PurpleStyle .Render (r .scheduledTimestamp )
189+ timestampValue := branding .PurpleStyle .Render (r .data . ScheduledTimestamp )
259190 output += fmt .Sprintf ("%s %s\n " , timestampLabel , timestampValue )
260191
261192 // Handler Type
262193 handlerTypeLabel := branding .GrayStyle .Render (" Handler Type:" )
263- handlerTypeValue := branding .PurpleStyle .Render (r .handlerTypeIdentifier )
194+ handlerTypeValue := branding .PurpleStyle .Render (r .data . HandlerTypeIdentifier )
264195 output += fmt .Sprintf ("%s %s\n " , handlerTypeLabel , handlerTypeValue )
265196
266197 // Handler Address
267198 handlerAddrLabel := branding .GrayStyle .Render (" Handler Address:" )
268- handlerAddrValue := branding .PurpleStyle .Render (r .handlerAddress )
199+ handlerAddrValue := branding .PurpleStyle .Render (r .data . HandlerAddress )
269200 output += fmt .Sprintf ("%s %s\n " , handlerAddrLabel , handlerAddrValue )
270201
271202 return output
272203}
273204
274205func (r * getResult ) Oneliner () string {
275- statusStr := getStatusString (r .status )
276- return fmt .Sprintf ("Transaction %d - Status: %s" , r .id , statusStr )
277- }
278-
279- // getStatusString converts status code to readable string
280- func getStatusString (status uint8 ) string {
281- switch status {
282- case 0 :
283- return "Pending"
284- case 1 :
285- return "Scheduled"
286- case 2 :
287- return "Executing"
288- case 3 :
289- return "Executed"
290- case 4 :
291- return "Failed"
292- case 5 :
293- return "Cancelled"
294- default :
295- return fmt .Sprintf ("Unknown(%d)" , status )
296- }
297- }
298-
299- // getPriorityString converts priority code to readable string
300- func getPriorityString (priority uint8 ) string {
301- switch priority {
302- case 0 :
303- return "Low"
304- case 1 :
305- return "Medium"
306- case 2 :
307- return "High"
308- default :
309- return fmt .Sprintf ("Unknown(%d)" , priority )
310- }
206+ statusStr := GetStatusString (r .data .Status )
207+ return fmt .Sprintf ("Transaction %d - Status: %s" , r .data .ID , statusStr )
311208}
0 commit comments