Skip to content

Commit

Permalink
chore: polish commands and overviews
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Dec 19, 2024
1 parent 0f66c96 commit b38db59
Show file tree
Hide file tree
Showing 22 changed files with 677 additions and 76 deletions.
9 changes: 8 additions & 1 deletion api/catchpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"errors"
"io"
"net/http"
"strings"
)

Expand All @@ -15,7 +16,10 @@ const (
MainNet CatchPointUrl = "https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/mainnet/latest.catchpoint"
)

const InvalidNetworkParamMsg = "invalid network"

type LatestCatchpointResponse struct {
HTTPResponse *http.Response
ResponseCode int
ResponseStatus string
JSON200 string
Expand All @@ -42,8 +46,11 @@ func GetLatestCatchpointWithResponse(http HttpPkgInterface, network string) (Lat
case "mainnet-v1.0", "mainnet":
url = MainNet
}

if url == "" {
return response, errors.New(InvalidNetworkParamMsg)
}

Check warning on line 51 in api/catchpoint.go

View check run for this annotation

Codecov / codecov/patch

api/catchpoint.go#L50-L51

Added lines #L50 - L51 were not covered by tests
res, err := http.Get(string(url))
response.HTTPResponse = res
if err != nil {
return response, err
}

Check warning on line 56 in api/catchpoint.go

View check run for this annotation

Codecov / codecov/patch

api/catchpoint.go#L55-L56

Added lines #L55 - L56 were not covered by tests
Expand Down
42 changes: 42 additions & 0 deletions api/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package api

import (
"fmt"
"net/http"
)

type GenesisFileKey string

const (
MainnetGenesisKey GenesisFileKey = "mainnet"
TestnetGenesisKey GenesisFileKey = "testnet"
FnetGenesisKey GenesisFileKey = "fnet"
)

type GenesisFileResponse struct {
ResponseCode int
ResponseStatus string
JSON200 string
}

func (r GenesisFileResponse) StatusCode() int {
return r.ResponseCode

Check warning on line 23 in api/genesis.go

View check run for this annotation

Codecov / codecov/patch

api/genesis.go#L22-L23

Added lines #L22 - L23 were not covered by tests
}
func (r GenesisFileResponse) Status() string {
return r.ResponseStatus

Check warning on line 26 in api/genesis.go

View check run for this annotation

Codecov / codecov/patch

api/genesis.go#L25-L26

Added lines #L25 - L26 were not covered by tests
}
func GetGenesis(key GenesisFileKey) {
var url string
if key == FnetGenesisKey {
url = "http://relay-eu-no-1.algorand.green:8184/genesis"
} else {
url = fmt.Sprintf("https://raw.githubusercontent.com/algorand/go-algorand/master/installer/genesis/%s/genesis.json", key)
}
resp, err := http.Get(url)
if err != nil {
panic(err)

Check warning on line 37 in api/genesis.go

View check run for this annotation

Codecov / codecov/patch

api/genesis.go#L28-L37

Added lines #L28 - L37 were not covered by tests
}
defer resp.Body.Close()
fmt.Println(resp.StatusCode)

Check warning on line 40 in api/genesis.go

View check run for this annotation

Codecov / codecov/patch

api/genesis.go#L39-L40

Added lines #L39 - L40 were not covered by tests

}
3 changes: 3 additions & 0 deletions api/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package api
import (
"encoding/json"
"errors"
"net/http"
"strings"
)

const ChannelNotFoundMsg = "channel not found"

type GithubVersionResponse struct {
HTTPResponse *http.Response
ResponseCode int
ResponseStatus string
JSON200 string
Expand All @@ -24,6 +26,7 @@ func (r GithubVersionResponse) Status() string {
func GetGoAlgorandReleaseWithResponse(http HttpPkgInterface, channel string) (*GithubVersionResponse, error) {
var versions GithubVersionResponse
resp, err := http.Get("https://api.github.com/repos/algorand/go-algorand/releases")
versions.HTTPResponse = resp
if resp == nil || err != nil {
return nil, err
}
Expand Down
139 changes: 139 additions & 0 deletions api/lf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions cmd/node/catchup/catchup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package catchup

import (
"github.com/algorandfoundation/algorun-tui/cmd/utils"
"github.com/algorandfoundation/algorun-tui/ui/style"
"github.com/charmbracelet/lipgloss"
"github.com/spf13/cobra"
)

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 = ""

// force indicates whether to bypass certain checks or enforcement logic within a function or command execution flow.
force bool = false

// cmdLong provides a detailed description of the Fast-Catchup feature, explaining its purpose and expected sync durations.
cmdLong = lipgloss.JoinVertical(
lipgloss.Left,
style.Purple(style.BANNER),
"",
style.Bold("Fast-Catchup is a feature that allows your node to catch up to the network faster than normal."),
"",
style.BoldUnderline("Overview:"),
"The entire process should sync a node in minutes rather than hours or days.",
"Actual sync times may vary depending on the number of accounts, number of blocks and the network.",
"",
style.Yellow.Render("Note: Not all networks support Fast-Catchup."),
)

// Cmd represents the root command for managing an Algorand node, including its description and usage instructions.
Cmd = utils.WithAlgodFlags(&cobra.Command{
Use: "catchup",
Short: "Manage Fast-Catchup for your node",
Long: cmdLong,
}, &endpoint, &token)
)

func init() {
Cmd.AddCommand(startCmd)
Cmd.AddCommand(stopCmd)
Cmd.AddCommand(debugCmd)
}
Loading

0 comments on commit b38db59

Please sign in to comment.