Skip to content

Commit

Permalink
feat: add catchpoint rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Dec 16, 2024
1 parent 694564c commit 05be82f
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 0 deletions.
189 changes: 189 additions & 0 deletions api/lf.go

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

1 change: 1 addition & 0 deletions generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ output-options:
- GetBlock
- AccountInformation
- GetGenesis
- StartCatchup
63 changes: 63 additions & 0 deletions internal/catchpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package internal

import (
"context"
"errors"
"github.com/algorandfoundation/algorun-tui/api"
"io"
"strings"
)

type CatchPointUrl string

const (
FNet CatchPointUrl = "https://fnet-catchpoints.algorand.green/latest"
BetaNet CatchPointUrl = "https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/betanet/latest.catchpoint"
TestNet CatchPointUrl = "https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/testnet/latest.catchpoint"
MainNet CatchPointUrl = "https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/mainnet/latest.catchpoint"
)

func PostCatchpoint(ctx context.Context, client api.ClientWithResponsesInterface, catchpoint string, params *api.StartCatchupParams) (string, error) {
res, err := client.StartCatchupWithResponse(ctx, catchpoint, params)
if err != nil {
return "", err
}
if res.StatusCode() != 200 {
return "", errors.New(res.Status())
}

return res.JSON200.CatchupMessage, nil
}

func GetLatestCatchpoint(ctx context.Context, http HttpPkgInterface, network string) (string, error) {
var catchpoint string
var url CatchPointUrl
switch network {
case "fnet":
url = FNet
case "betanet":
url = BetaNet
case "testnet":
url = TestNet
case "mainnet":
url = MainNet
}

res, err := http.Get(string(url))
if err != nil {
return catchpoint, err
}
defer res.Body.Close()

if res.StatusCode != 200 {
return catchpoint, errors.New(res.Status)
}

var body []byte
body, err = io.ReadAll(res.Body)
if err != nil {
return catchpoint, err
}

return strings.Replace(string(body), "\n", "", -1), nil
}
14 changes: 14 additions & 0 deletions internal/catchpoint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package internal

import (
"context"
"testing"
)

func Test_GetLatestCatchpoint(t *testing.T) {
catchpoint, err := GetLatestCatchpoint(context.Background(), new(HttpPkg), "mainnet")
if err != nil {
t.Error(err)
}
t.Log(catchpoint)
}

0 comments on commit 05be82f

Please sign in to comment.