@@ -16,7 +16,7 @@ import (
1616)
1717
1818type InstancesDescribeStore struct {
19- WorkflowInstancesHistory []shared.WorkflowInstanceHistory `json:"workflowInstanceHistory"`
19+ WorkflowInstancesHistory []shared.V2WorkflowInstanceHistory `json:"workflowInstanceHistory"`
2020}
2121type InstancesDescribeController struct {
2222 store * InstancesDescribeStore
@@ -51,14 +51,14 @@ func (c *InstancesDescribeController) GetStore() *InstancesDescribeStore {
5151func (c * InstancesDescribeController ) Run (cmd * cobra.Command , args []string ) (fctl.Renderable , error ) {
5252 store := fctl .GetStackStore (cmd .Context ())
5353
54- response , err := store .Client ().Orchestration .V1 .GetInstanceHistory (cmd .Context (), operations.GetInstanceHistoryRequest {
54+ response , err := store .Client ().Orchestration .V2 .GetInstanceHistory (cmd .Context (), operations.V2GetInstanceHistoryRequest {
5555 InstanceID : args [0 ],
5656 })
5757 if err != nil {
5858 return nil , err
5959 }
6060
61- c .store .WorkflowInstancesHistory = response .GetWorkflowInstanceHistoryResponse .Data
61+ c .store .WorkflowInstancesHistory = response .V2GetWorkflowInstanceHistoryResponse .Data
6262
6363 return c , nil
6464}
@@ -74,15 +74,15 @@ func (c *InstancesDescribeController) Render(cmd *cobra.Command, args []string)
7474 return nil
7575}
7676
77- func printHistoryBaseInfo (out io.Writer , name string , ind int , history shared.WorkflowInstanceHistory ) {
77+ func printHistoryBaseInfo (out io.Writer , name string , ind int , history shared.V2WorkflowInstanceHistory ) {
7878 fctl .Section .WithWriter (out ).Printf ("Stage %d : %s\n " , ind , name )
7979 fctl .BasicText .WithWriter (out ).Printfln ("Started at: %s" , history .StartedAt .Format (time .RFC3339 ))
8080 if history .Terminated {
81- fctl .BasicText .WithWriter (out ).Printfln ("Terminated at: %s" , history .StartedAt .Format (time .RFC3339 ))
81+ fctl .BasicText .WithWriter (out ).Printfln ("Terminated at: %s" , history .TerminatedAt .Format (time .RFC3339 ))
8282 }
8383}
8484
85- func stageSourceName (src * shared.StageSendSource ) string {
85+ func stageSourceName (src * shared.V2StageSendSource ) string {
8686 switch {
8787 case src .Wallet != nil :
8888 return fmt .Sprintf ("wallet '%s' (balance: %s)" , src .Wallet .ID , * src .Wallet .Balance )
@@ -95,7 +95,7 @@ func stageSourceName(src *shared.StageSendSource) string {
9595 }
9696}
9797
98- func stageDestinationName (dst * shared.StageSendDestination ) string {
98+ func stageDestinationName (dst * shared.V2StageSendDestination ) string {
9999 switch {
100100 case dst .Wallet != nil :
101101 return fmt .Sprintf ("wallet '%s' (balance: %s)" , dst .Wallet .ID , * dst .Wallet .Balance )
@@ -108,12 +108,12 @@ func stageDestinationName(dst *shared.StageSendDestination) string {
108108 }
109109}
110110
111- func subjectName (src shared.Subject ) string {
111+ func subjectName (src shared.V2Subject ) string {
112112 switch {
113- case src .WalletSubject != nil :
114- return fmt .Sprintf ("wallet %s (balance: %s)" , src .WalletSubject .Identifier , * src .WalletSubject .Balance )
115- case src .LedgerAccountSubject != nil :
116- return fmt .Sprintf ("account %s" , src .LedgerAccountSubject .Identifier )
113+ case src .V2WalletSubject != nil :
114+ return fmt .Sprintf ("wallet %s (balance: %s)" , src .V2WalletSubject .Identifier , * src .V2WalletSubject .Balance )
115+ case src .V2LedgerAccountSubject != nil :
116+ return fmt .Sprintf ("account %s" , src .V2LedgerAccountSubject .Identifier )
117117 default :
118118 return "unknown_subject_type"
119119 }
@@ -131,29 +131,31 @@ func printMetadata(metadata map[string]string) []pterm.BulletListItem {
131131 return ret
132132}
133133
134- func printStage (cmd * cobra.Command , i int , client * formance.Formance , id string , history shared.WorkflowInstanceHistory ) error {
134+ func printStage (cmd * cobra.Command , i int , client * formance.Formance , id string , history shared.V2WorkflowInstanceHistory ) error {
135135 cyanWriter := fctl .BasicTextCyan
136136 defaultWriter := fctl .BasicText
137137
138138 listItems := make ([]pterm.BulletListItem , 0 )
139139
140140 switch history .Input .Type {
141- case shared .StageTypeStageSend :
141+ case shared .V2StageTypeV2StageSend :
142142 printHistoryBaseInfo (cmd .OutOrStdout (), "send" , i , history )
143- cyanWriter .Printfln ("Send %v %s from %s to %s" , history .Input .StageSend .Amount .Amount ,
144- history .Input .StageSend .Amount .Asset , stageSourceName (history .Input .StageSend .Source ),
145- stageDestinationName (history .Input .StageSend .Destination ))
143+ if history .Input .V2StageSend != nil {
144+ cyanWriter .Printfln ("Send %v %s from %s to %s" , history .Input .V2StageSend .Amount .Amount ,
145+ history .Input .V2StageSend .Amount .Asset , stageSourceName (history .Input .V2StageSend .Source ),
146+ stageDestinationName (history .Input .V2StageSend .Destination ))
147+ }
146148 fctl .Println ()
147149
148- stageResponse , err := client .Orchestration .V1 .GetInstanceStageHistory (cmd .Context (), operations.GetInstanceStageHistoryRequest {
150+ stageResponse , err := client .Orchestration .V2 .GetInstanceStageHistory (cmd .Context (), operations.V2GetInstanceStageHistoryRequest {
149151 InstanceID : id ,
150152 Number : int64 (i ),
151153 })
152154 if err != nil {
153155 return err
154156 }
155157
156- for _ , historyStage := range stageResponse .GetWorkflowInstanceHistoryStageResponse .Data {
158+ for _ , historyStage := range stageResponse .V2GetWorkflowInstanceHistoryStageResponse .Data {
157159 switch {
158160 case historyStage .Input .StripeTransfer != nil :
159161 listItems = append (listItems , historyItemTitle ("Send %v %s to Stripe connected account: %s" ,
@@ -162,19 +164,26 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string,
162164 * historyStage .Input .StripeTransfer .Destination ,
163165 ))
164166 case historyStage .Input .CreateTransaction != nil :
165- listItems = append (listItems , historyItemTitle ("Send %v %s from account %s to account %s (ledger %s)" ,
166- historyStage .Input .CreateTransaction .Data .Postings [0 ].Amount ,
167- historyStage .Input .CreateTransaction .Data .Postings [0 ].Asset ,
168- historyStage .Input .CreateTransaction .Data .Postings [0 ].Source ,
169- historyStage .Input .CreateTransaction .Data .Postings [0 ].Destination ,
170- * historyStage .Input .CreateTransaction .Ledger ,
171- ))
167+ if historyStage .Input .CreateTransaction .Data != nil && len (historyStage .Input .CreateTransaction .Data .Postings ) > 0 {
168+ listItems = append (listItems , historyItemTitle ("Send %v %s from account %s to account %s (ledger %s)" ,
169+ historyStage .Input .CreateTransaction .Data .Postings [0 ].Amount ,
170+ historyStage .Input .CreateTransaction .Data .Postings [0 ].Asset ,
171+ historyStage .Input .CreateTransaction .Data .Postings [0 ].Source ,
172+ historyStage .Input .CreateTransaction .Data .Postings [0 ].Destination ,
173+ * historyStage .Input .CreateTransaction .Ledger ,
174+ ))
175+ }
172176 if historyStage .Error == nil && historyStage .LastFailure == nil && historyStage .Terminated {
173- listItems = append (listItems , historyItemDetails ("Created transaction: %d" , historyStage .Output .CreateTransaction .Data .ID ))
174- if historyStage .Input .CreateTransaction .Data .Reference != nil {
175- listItems = append (listItems , historyItemDetails ("Reference: %s" , * historyStage .Output .CreateTransaction .Data .Reference ))
177+ if historyStage .Output .CreateTransaction != nil && len (historyStage .Output .CreateTransaction .Data ) > 0 {
178+ txid := historyStage .Output .CreateTransaction .Data [0 ].Txid
179+ if txid != nil {
180+ listItems = append (listItems , historyItemDetails ("Created transaction: %d" , txid .Int64 ()))
181+ }
176182 }
177- if len (historyStage .Input .CreateTransaction .Data .Metadata ) > 0 {
183+ if historyStage .Input .CreateTransaction != nil && historyStage .Input .CreateTransaction .Data != nil && historyStage .Input .CreateTransaction .Data .Reference != nil {
184+ listItems = append (listItems , historyItemDetails ("Reference: %s" , * historyStage .Input .CreateTransaction .Data .Reference ))
185+ }
186+ if historyStage .Input .CreateTransaction != nil && historyStage .Input .CreateTransaction .Data != nil && len (historyStage .Input .CreateTransaction .Data .Metadata ) > 0 {
178187 listItems = append (listItems , printMetadata (historyStage .Input .CreateTransaction .Data .Metadata )... )
179188 }
180189 }
@@ -221,11 +230,7 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string,
221230 historyStage .Input .GetPayment .ID ))
222231 case historyStage .Input .GetWallet != nil :
223232 listItems = append (listItems , historyItemTitle ("Read wallet '%s'" , historyStage .Input .GetWallet .ID ))
224- case historyStage .Input .RevertTransaction != nil :
225- listItems = append (listItems , historyItemTitle ("Revert transaction %s" , historyStage .Input .RevertTransaction .ID ))
226- if historyStage .Error == nil {
227- listItems = append (listItems , historyItemTitle ("Created transaction: %d" , historyStage .Output .RevertTransaction .Data .ID ))
228- }
233+ // V2 doesn't have RevertTransaction, skip it
229234 case historyStage .Input .VoidHold != nil :
230235 listItems = append (listItems , historyItemTitle ("Cancel debit hold %s" , historyStage .Input .VoidHold .ID ))
231236 case historyStage .Input .ListWallets != nil :
@@ -242,31 +247,37 @@ func printStage(cmd *cobra.Command, i int, client *formance.Formance, id string,
242247 listItems = append (listItems , historyItemError (* historyStage .Error ))
243248 }
244249 }
245- case shared .StageTypeStageDelay :
250+ case shared .V2StageTypeV2StageDelay :
246251 printHistoryBaseInfo (cmd .OutOrStdout (), "delay" , i , history )
247- switch {
248- case history .Input .StageDelay .Duration != nil :
249- listItems = append (listItems , historyItemTitle ("Pause workflow for a delay of %s" , * history .Input .StageDelay .Duration ))
250- case history .Input .StageDelay .Until != nil :
251- listItems = append (listItems , historyItemTitle ("Pause workflow until %s" , * history .Input .StageDelay .Until ))
252+ if history .Input .V2StageDelay != nil {
253+ switch {
254+ case history .Input .V2StageDelay .Duration != nil :
255+ listItems = append (listItems , historyItemTitle ("Pause workflow for a delay of %s" , * history .Input .V2StageDelay .Duration ))
256+ case history .Input .V2StageDelay .Until != nil :
257+ listItems = append (listItems , historyItemTitle ("Pause workflow until %s" , * history .Input .V2StageDelay .Until ))
258+ }
252259 }
253- case shared .StageTypeStageWaitEvent :
260+ case shared .V2StageTypeV2StageWaitEvent :
254261 printHistoryBaseInfo (cmd .OutOrStdout (), "wait_event" , i , history )
255- listItems = append (listItems , historyItemTitle ("Waiting event '%s'" , history .Input .StageWaitEvent .Event ))
262+ if history .Input .V2StageWaitEvent != nil {
263+ listItems = append (listItems , historyItemTitle ("Waiting event '%s'" , history .Input .V2StageWaitEvent .Event ))
264+ }
256265 if history .Error == nil {
257266 if history .Terminated {
258267 listItems = append (listItems , historyItemDetails ("Event received!" ))
259268 } else {
260269 listItems = append (listItems , historyItemDetails ("Still waiting event..." ))
261270 }
262271 }
263- case shared .StageTypeUpdate :
272+ case shared .V2StageTypeV2Update :
264273 printHistoryBaseInfo (cmd .OutOrStdout (), "update" , i , history )
265- switch {
266- case history .Input .Update .Account != nil :
267- account := history .Input .Update .Account
268- listItems = append (listItems , historyItemTitle ("Update account '%s' of ledger '%s'" , account .ID , account .Ledger ))
269- listItems = append (listItems , printMetadata (account .Metadata )... )
274+ if history .Input .V2Update != nil {
275+ switch {
276+ case history .Input .V2Update .Account != nil :
277+ account := history .Input .V2Update .Account
278+ listItems = append (listItems , historyItemTitle ("Update account '%s' of ledger '%s'" , account .ID , account .Ledger ))
279+ listItems = append (listItems , printMetadata (account .Metadata )... )
280+ }
270281 }
271282 default :
272283 // Display error?
0 commit comments