Skip to content

Commit

Permalink
refactor: to data directory
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Dec 24, 2024
1 parent 07e16db commit 6f9b3c6
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 511 deletions.
16 changes: 0 additions & 16 deletions .docker/start_all.sh

This file was deleted.

49 changes: 0 additions & 49 deletions .docker/start_dev.sh

This file was deleted.

41 changes: 0 additions & 41 deletions .docker/start_empty.sh

This file was deleted.

46 changes: 0 additions & 46 deletions .docker/start_fast_catchup.sh

This file was deleted.

31 changes: 0 additions & 31 deletions Dockerfile

This file was deleted.

92 changes: 72 additions & 20 deletions cmd/node/bootstrap.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package node

import (
"context"
"fmt"
"github.com/algorandfoundation/algorun-tui/api"
cmdutils "github.com/algorandfoundation/algorun-tui/cmd/utils"
"github.com/algorandfoundation/algorun-tui/internal/algod"
"github.com/algorandfoundation/algorun-tui/internal/algod/utils"
"github.com/algorandfoundation/algorun-tui/internal/system"
"github.com/algorandfoundation/algorun-tui/ui"
"github.com/algorandfoundation/algorun-tui/ui/app"
"github.com/algorandfoundation/algorun-tui/ui/bootstrap"
"github.com/algorandfoundation/algorun-tui/ui/style"
Expand All @@ -28,6 +34,9 @@ var bootstrapCmd = &cobra.Command{
Long: "Text",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
httpPkg := new(api.HttpPkg)

fmt.Print(style.Purple(style.BANNER))
out, err := glamour.Render(in, "dark")
if err != nil {
Expand Down Expand Up @@ -70,27 +79,70 @@ var bootstrapCmd = &cobra.Command{
if !algod.IsRunning() {
log.Fatal("algod is not running")
}
// Create the client
client, err := algod.GetClient("/var/lib/algorand")
if err != nil {
return err
}

//if msg.Catchup {
// ctx := context.Background()
// httpPkg := new(api.HttpPkg)
// client, err := algod.GetClient(endpoint, token)
//
// // Get the latest catchpoint
// catchpoint, _, err := algod.GetLatestCatchpoint(httpPkg, status.Network)
// if err != nil && err.Error() == api.InvalidNetworkParamMsg {
// log.Fatal("This network does not support fast-catchup.")
// } else {
// log.Info(style.Green.Render("Latest Catchpoint: " + catchpoint))
// }
//
// // Start catchup
// res, _, err := algod.StartCatchup(ctx, client, catchpoint, nil)
// if err != nil {
// log.Fatal(err)
// }
//
//}
if msg.Catchup {
network, err := utils.GetNetworkFromDataDir("/var/lib/algorand")
if err != nil {
return err
}
// Get the latest catchpoint
catchpoint, _, err := algod.GetLatestCatchpoint(httpPkg, network)
if err != nil && err.Error() == api.InvalidNetworkParamMsg {
log.Fatal("This network does not support fast-catchup.")
} else {
log.Info(style.Green.Render("Latest Catchpoint: " + catchpoint))
}

// Start catchup
res, _, err := algod.StartCatchup(ctx, client, catchpoint, nil)
if err != nil {
log.Fatal(err)
}
log.Info(style.Green.Render(res))

}

t := new(system.Clock)
// Fetch the state and handle any creation errors
state, stateResponse, err := algod.NewStateModel(ctx, client, httpPkg)
cmdutils.WithInvalidResponsesExplanations(err, stateResponse, cmd.UsageString())
cobra.CheckErr(err)

// Construct the TUI Model from the State
m, err := ui.NewViewportViewModel(state, client)
cobra.CheckErr(err)

// Construct the TUI Application
p = tea.NewProgram(
m,
tea.WithAltScreen(),
tea.WithFPS(120),
)

// Watch for State Updates on a separate thread
// TODO: refactor into context aware watcher without callbacks
go func() {
state.Watch(func(status *algod.StateModel, err error) {
if err == nil {
p.Send(state)
}
if err != nil {
p.Send(state)
p.Send(err)
}
}, ctx, t)
}()

// Execute the TUI Application
_, err = p.Run()
if err != nil {
log.Fatal(err)
}
return nil
},
}
9 changes: 3 additions & 6 deletions cmd/node/catchup/catchup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import (
)

var (
// endpoint is a string variable used to store the algod API endpoint address for communication with the node.
endpoint string = ""

// token is a string flag used to store the admin token required for authenticating with the Algod API.
token string = ""
// dataDir path to the algorand data folder
dataDir string = ""

// force indicates whether to bypass certain checks or enforcement logic within a function or command execution flow.
force bool = false
Expand All @@ -36,7 +33,7 @@ var (
Use: "catchup",
Short: "Manage Fast-Catchup for your node",
Long: cmdLong,
}, &endpoint, &token)
}, &dataDir)
)

func init() {
Expand Down
19 changes: 2 additions & 17 deletions cmd/node/catchup/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

type Catchpoint struct {
Expand Down Expand Up @@ -54,23 +53,9 @@ var debugCmd = utils.WithAlgodFlags(&cobra.Command{
Long: debugCmdLong,
SilenceUsage: false,
Run: func(cmd *cobra.Command, args []string) {
err := utils.InitConfig()
if err != nil {
log.Fatal(err)
}

endpoint := viper.GetString("algod-endpoint")
token := viper.GetString("algod-token")
if endpoint == "" {
log.Fatal("algod-endpoint is required")
}
if token == "" {
log.Fatal("algod-token is required")
}

ctx := context.Background()
httpPkg := new(api.HttpPkg)
client, err := algod.GetClient(endpoint, token)
client, err := algod.GetClient("/var/lib/algorand")
cobra.CheckErr(err)

status, response, err := algod.NewStatus(ctx, client, httpPkg)
Expand Down Expand Up @@ -103,4 +88,4 @@ var debugCmd = utils.WithAlgodFlags(&cobra.Command{
fmt.Println(style.Bold(string(data)))

},
}, &endpoint, &token)
}, &dataDir)
Loading

0 comments on commit 6f9b3c6

Please sign in to comment.