Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #138 from JackalLabs/marston/terminate
Browse files Browse the repository at this point in the history
add shutdown command
  • Loading branch information
TheMarstonConnell authored Apr 5, 2024
2 parents a7bd36d + 08971b6 commit 505ef3b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions jprov/jprovd/init_provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package main

import (
"bufio"
"fmt"
"os"
"strings"

"github.com/JackalLabs/jackal-provider/jprov/crypto"
"github.com/JackalLabs/jackal-provider/jprov/utils"
Expand All @@ -10,6 +13,28 @@ import (
"github.com/spf13/cobra"
)

func askForConfirmation(s string) bool {
reader := bufio.NewReader(os.Stdin)

for {
fmt.Printf("%s [y/n]: ", s)

response, err := reader.ReadString('\n')
if err != nil {
fmt.Println("failed to read string")
return false
}

response = strings.ToLower(strings.TrimSpace(response))

if response == "y" || response == "yes" {
return true
} else if response == "n" || response == "no" {
return false
}
}
}

func CmdInitProvider() *cobra.Command {
cmd := &cobra.Command{
Use: "init [ip] [totalspace] [keybase-identity]",
Expand Down Expand Up @@ -55,3 +80,47 @@ func CmdInitProvider() *cobra.Command {

return cmd
}

func CmdShutdownProvider() *cobra.Command {
cmd := &cobra.Command{
Use: "terminate",
Short: "Permanently remove provider from network and get deposit back",
Long: "Permanently remove provider from network and get deposit back.",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) (err error) {
if !askForConfirmation("Terminate Provider Permanently?") {
return nil
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
fmt.Println(err)
return err
}

address, err := crypto.GetAddress(clientCtx)
if err != nil {
fmt.Println(err)
return err
}

fmt.Printf("Terminating provider: %s\n", address)
msg := types.NewMsgShutdownProvider(
address,
)
if err := msg.ValidateBasic(); err != nil {
fmt.Println(err)
return err
}
res, err := utils.SendTx(clientCtx, cmd.Flags(), "", msg)
if err != nil {
fmt.Println(err)
return err
}
fmt.Println(res.RawLog)
return err
},
}

return cmd
}
1 change: 1 addition & 0 deletions jprov/jprovd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func NewRootCmd() *cobra.Command {
VersionCmd(),
NetworkCmd(),
BlanketCmd(),
CmdShutdownProvider(),
)

return rootCmd
Expand Down

0 comments on commit 505ef3b

Please sign in to comment.