Skip to content

Commit 611e2e1

Browse files
committed
full suspension support
1 parent 81abec6 commit 611e2e1

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

pkg/commands/app/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func logsAction(cCtx *cli.Context) error {
203203
case common.AppStatusStopping:
204204
logger.Info("%s is currently stopping. Logs may be limited.", formattedApp)
205205
return nil
206-
case common.AppStatusStopped, common.AppStatusTerminating, common.AppStatusTerminated:
206+
case common.AppStatusStopped, common.AppStatusTerminating, common.AppStatusTerminated, common.AppStatusSuspended:
207207
logger.Info("%s is %s. Logs are not available.", formattedApp, strings.ToLower(status))
208208
return nil
209209
case common.AppStatusFailed:

pkg/commands/billing/cancel.go

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package billing
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/Layr-Labs/eigenx-cli/pkg/commands/utils"
78
"github.com/Layr-Labs/eigenx-cli/pkg/common"
89
"github.com/Layr-Labs/eigenx-cli/pkg/common/output"
10+
ethcommon "github.com/ethereum/go-ethereum/common"
911
"github.com/urfave/cli/v2"
1012
)
1113

@@ -88,15 +90,19 @@ var CancelCommand = &cli.Command{
8890
caller := info.Caller
8991
logger.Info("Suspending apps on %s...", env)
9092

91-
// Get all apps for this developer on this network
92-
apps, _, err := caller.GetAppsByCreator(ctx, developerAddr, 0, 1_000)
93+
// Get only active apps for this developer on this network
94+
activeApps, err := getActiveAppsByCreator(ctx, caller, developerAddr)
9395
if err != nil {
94-
return fmt.Errorf("failed to get apps for %s: %w", env, err)
96+
return fmt.Errorf("failed to get active apps for %s: %w", env, err)
9597
}
9698

97-
// Call suspend with all apps
98-
// Note: The contract will filter to only active apps (STARTED/STOPPED)
99-
err = caller.Suspend(ctx, developerAddr, apps)
99+
if len(activeApps) == 0 {
100+
logger.Info("No active apps to suspend on %s", env)
101+
continue
102+
}
103+
104+
// Suspend only active apps
105+
err = caller.Suspend(ctx, developerAddr, activeApps)
100106
if err != nil {
101107
return fmt.Errorf("failed to suspend apps on %s: %w", env, err)
102108
}
@@ -127,3 +133,23 @@ var CancelCommand = &cli.Command{
127133
return nil
128134
},
129135
}
136+
137+
// getActiveAppsByCreator retrieves only the active apps (STARTED/STOPPED) for a creator
138+
func getActiveAppsByCreator(ctx context.Context, caller *common.ContractCaller, creator ethcommon.Address) ([]ethcommon.Address, error) {
139+
// Get all apps for this creator on this network
140+
allApps, appConfigs, err := caller.GetAppsByCreator(ctx, creator, 0, 1_000)
141+
if err != nil {
142+
return nil, fmt.Errorf("failed to get apps by creator: %w", err)
143+
}
144+
145+
// Filter to only active apps (STARTED/STOPPED)
146+
var activeApps []ethcommon.Address
147+
for i, app := range allApps {
148+
config := appConfigs[i]
149+
status := common.AppStatus(config.Status)
150+
if status == common.ContractAppStatusStarted || status == common.ContractAppStatusStopped {
151+
activeApps = append(activeApps, app)
152+
}
153+
}
154+
return activeApps, nil
155+
}

pkg/commands/utils/contract_utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ func contractStatusToString(status uint8) string {
315315
return "Running"
316316
case common.ContractAppStatusStopped:
317317
return "Stopped"
318+
case common.ContractAppStatusSuspended:
319+
return "Suspended"
318320
case common.ContractAppStatusTerminated:
319321
return "Terminated"
320322
default:

pkg/commands/utils/interactive.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func GetAppIDInteractive(cCtx *cli.Context, argIndex int, action string) (ethcom
250250
case "view":
251251
return true
252252
case "start":
253-
return status == common.ContractAppStatusStopped || exitedApps[addr.Hex()]
253+
return status == common.ContractAppStatusStopped || status == common.ContractAppStatusSuspended || exitedApps[addr.Hex()]
254254
case "stop":
255255
return status == common.ContractAppStatusStarted || exitedApps[addr.Hex()]
256256
default:
@@ -751,10 +751,12 @@ func getStatusPriority(status common.AppStatus, isExited bool) int {
751751
return 2 // Exited apps come second
752752
case common.ContractAppStatusStopped:
753753
return 3
754-
case common.ContractAppStatusTerminated:
754+
case common.ContractAppStatusSuspended:
755755
return 4
756-
default:
756+
case common.ContractAppStatusTerminated:
757757
return 5
758+
default:
759+
return 6
758760
}
759761
}
760762

@@ -765,6 +767,8 @@ func getStatusString(status common.AppStatus) string {
765767
return "Running"
766768
case common.ContractAppStatusStopped:
767769
return "Stopped"
770+
case common.ContractAppStatusSuspended:
771+
return "Suspended"
768772
case common.ContractAppStatusTerminated:
769773
return "Terminated"
770774
default:

pkg/common/contract_caller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (cc *ContractCaller) GetMaxActiveAppsPerUser(ctx context.Context, user comm
290290
}
291291

292292
// GetAppsByCreator retrieves a paginated list of apps created by the specified address
293-
func (cc *ContractCaller) GetAppsByCreator(ctx context.Context, creator common.Address, offset uint64, limit uint64) ([]common.Address, any, error) {
293+
func (cc *ContractCaller) GetAppsByCreator(ctx context.Context, creator common.Address, offset uint64, limit uint64) ([]common.Address, []appcontrollerV1.IAppControllerAppConfig, error) {
294294
appController, err := appcontrollerV1.NewAppController(cc.environmentConfig.AppControllerAddress, cc.ethclient)
295295
if err != nil {
296296
return nil, nil, fmt.Errorf("failed to create app controller: %w", err)

0 commit comments

Comments
 (0)