|
1 | 1 | package billing |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "fmt" |
5 | 6 |
|
6 | 7 | "github.com/Layr-Labs/eigenx-cli/pkg/commands/utils" |
7 | 8 | "github.com/Layr-Labs/eigenx-cli/pkg/common" |
8 | 9 | "github.com/Layr-Labs/eigenx-cli/pkg/common/output" |
| 10 | + ethcommon "github.com/ethereum/go-ethereum/common" |
9 | 11 | "github.com/urfave/cli/v2" |
10 | 12 | ) |
11 | 13 |
|
@@ -88,15 +90,19 @@ var CancelCommand = &cli.Command{ |
88 | 90 | caller := info.Caller |
89 | 91 | logger.Info("Suspending apps on %s...", env) |
90 | 92 |
|
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) |
93 | 95 | 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) |
95 | 97 | } |
96 | 98 |
|
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) |
100 | 106 | if err != nil { |
101 | 107 | return fmt.Errorf("failed to suspend apps on %s: %w", env, err) |
102 | 108 | } |
@@ -127,3 +133,23 @@ var CancelCommand = &cli.Command{ |
127 | 133 | return nil |
128 | 134 | }, |
129 | 135 | } |
| 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 | +} |
0 commit comments