-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support dynamic loading of dapps
- Loading branch information
Showing
7 changed files
with
212 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
package status | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
cmdcommon "github.com/cartesi/rollups-node/cmd/cartesi-rollups-cli/root/common" | ||
"github.com/cartesi/rollups-node/internal/model" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "status", | ||
Short: "Display and set application status", | ||
Example: examples, | ||
Run: run, | ||
} | ||
|
||
const examples = `# Get application status: | ||
cartesi-rollups-cli app status -a 0x000000000000000000000000000000000` | ||
|
||
var ( | ||
enable bool | ||
disable bool | ||
) | ||
|
||
func init() { | ||
Cmd.Flags().StringVarP( | ||
&cmdcommon.ApplicationAddress, | ||
"address", | ||
"a", | ||
"", | ||
"Application contract address", | ||
) | ||
cobra.CheckErr(Cmd.MarkFlagRequired("address")) | ||
|
||
Cmd.Flags().BoolVarP( | ||
&enable, | ||
"enable", | ||
"e", | ||
false, | ||
"Enable the application", | ||
) | ||
|
||
Cmd.Flags().BoolVarP( | ||
&disable, | ||
"disable", | ||
"d", | ||
false, | ||
"Disable the application", | ||
) | ||
|
||
} | ||
|
||
func run(cmd *cobra.Command, args []string) { | ||
ctx := cmd.Context() | ||
|
||
if cmdcommon.Database == nil { | ||
panic("Database was not initialized") | ||
} | ||
|
||
address := common.HexToAddress(cmdcommon.ApplicationAddress) | ||
application, err := cmdcommon.Database.GetApplication(ctx, address) | ||
cobra.CheckErr(err) | ||
|
||
if (!cmd.Flags().Changed("enable")) && (!cmd.Flags().Changed("disable")) { | ||
fmt.Println(application.Status) | ||
os.Exit(0) | ||
} | ||
|
||
if cmd.Flags().Changed("enable") && cmd.Flags().Changed("disable") { | ||
fmt.Fprintln(os.Stderr, "Cannot enable and disable at the same time") | ||
os.Exit(1) | ||
} | ||
|
||
status := model.ApplicationStatusRunning | ||
if cmd.Flags().Changed("disable") { | ||
status = model.ApplicationStatusNotRunning | ||
} | ||
|
||
err = cmdcommon.Database.UpdateApplicationStatus(ctx, address, status) | ||
cobra.CheckErr(err) | ||
|
||
fmt.Printf("Application status updated to %s\n", status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters