Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions node-registrar/client/farm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import (
"github.com/pkg/errors"
)

const (
// StellarAddressLength is the expected length of a Stellar address
StellarAddressLength = 56
// DefaultPageSize is the default number of results per page
DefaultPageSize = 50
)

var ErrorFarmNotFound = fmt.Errorf("failed to get requested farm from node registrar")

// CreateFarm create new farm on the registrar with uniqe name.
Expand Down Expand Up @@ -267,7 +274,7 @@ func parseListFarmOpts(filter FarmFilter) map[string]any {
}
data["page"] = page

size := uint32(50)
size := uint32(DefaultPageSize)
if filter.Size != nil {
size = *filter.Size
}
Expand Down Expand Up @@ -297,8 +304,8 @@ func parseUpdateFarmOpts(update FarmUpdate) map[string]any {
// validateStellarAddress ensures that the address is valid stellar address
func validateStellarAddress(stellarAddr string) error {
stellarAddr = strings.TrimSpace(stellarAddr)
if len(stellarAddr) != 56 {
return fmt.Errorf("invalid stellar address %s, address length should be 56 characters", stellarAddr)
if len(stellarAddr) != StellarAddressLength {
return fmt.Errorf("invalid stellar address %s, address length should be %d characters", stellarAddr, StellarAddressLength)
}
if stellarAddr[0] != 'G' {
return fmt.Errorf("invalid stellar address %s, address should should start with 'G'", stellarAddr)
Expand Down
2 changes: 1 addition & 1 deletion node-registrar/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func parseListNodeOpts(filter NodeFilter) map[string]any {
}
data["page"] = page

size := uint32(50)
size := uint32(DefaultPageSize)
if filter.Size != nil {
size = *filter.Size
}
Expand Down
4 changes: 3 additions & 1 deletion node-registrar/docs/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Node Registrar client

> **Note:** The constant `PubKeySize = 32` is used for ED25519/SR25519 public key/seed size in all code examples below.

To be able to use the node registrar you can use the following scripts.

## Account Management
Expand All @@ -8,7 +10,7 @@ To be able to use the node registrar you can use the following scripts.

```go
// Generate new seed
seed := make([]byte, 32)
seed := make([]byte, PubKeySize)
_, err := rand.Read(seed)
if err != nil {
panic(err)
Expand Down
4 changes: 4 additions & 0 deletions node-registrar/pkg/db/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (

const ZOS4VersionKey = "zos_4"

var (
ErrVersionAlreadySet = errors.New("version already set")
)

// ListNodes retrieves all nodes from the database with applied filters and pagination
func (db *Database) ListNodes(filter NodeFilter, limit Limit) (nodes []Node, err error) {
query := db.gormDB.Model(&Node{})
Expand Down
Loading
Loading