Skip to content

Commit 513a105

Browse files
committed
add functions documentation
1 parent 69bca0a commit 513a105

File tree

8 files changed

+44
-10
lines changed

8 files changed

+44
-10
lines changed

node-registrar/client/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ The Node Registrar Client enables communication with the ThreeFold Grid's node r
2828
### Farms
2929

3030
* **Create Farm**: Create new farm on the registrar with uniqe name.
31-
* **update Farm**: update farm configuration (farm\_id, dedicated).
32-
* **Get Farm**: Get a farm using either its farm\_id.
31+
* **update Farm**: Update farm configuration (farm\_id, dedicated).
32+
* **Get Farm**: Get a farm using its farm\_id.
3333

3434
### Node
3535

36-
* **Register Node**: Register physical/virtual nodes with the TFGrid.
36+
* **Register Node**: Register physical/virtual nodes with on TFGrid.
3737
* **Update Node**: Update node configuration (farm\_id, interfaces, resources, location, secure\_boot, virtualized).
3838
* **Get Node**: Fetch registered node details using (node\_id, twin\_id, farm\_id).
3939
* **Update Node Uptime**: Update node Uptime.

node-registrar/client/account.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ import (
1515

1616
var ErrorAccountNotFound = fmt.Errorf("failed to get requested account from node registrar")
1717

18+
// CreateAccount create new account on the registrar with uniqe mnemonic.
1819
func (c *RegistrarClient) CreateAccount(relays []string, rmbEncKey string) (account Account, mnemonic string, err error) {
1920
return c.createAccount(relays, rmbEncKey)
2021
}
2122

22-
func (c *RegistrarClient) GetAccount(id uint64) (account Account, err error) {
23-
return c.getAccount(id)
23+
// GetAccount get an account using either its twinID
24+
func (c *RegistrarClient) GetAccount(twinID uint64) (account Account, err error) {
25+
return c.getAccount(twinID)
2426
}
2527

26-
func (c *RegistrarClient) GetAccountByPK(pk []byte) (account Account, err error) {
27-
return c.getAccountByPK(pk)
28+
// GetAccountByPK get an account using either its its publicKey.
29+
func (c *RegistrarClient) GetAccountByPK(publicKey []byte) (account Account, err error) {
30+
return c.getAccountByPK(publicKey)
2831
}
2932

33+
// UpdateAccount update the account configuration (relays or rmbEncKey).
3034
func (c *RegistrarClient) UpdateAccount(opts ...UpdateAccountOpts) (err error) {
3135
return c.updateAccount(opts)
3236
}
@@ -40,18 +44,21 @@ type (
4044
UpdateAccountOpts func(*accountCfg)
4145
)
4246

47+
// UpdateAccountWithRelays update the account relays
4348
func UpdateAccountWithRelays(relays []string) UpdateAccountOpts {
4449
return func(n *accountCfg) {
4550
n.relays = relays
4651
}
4752
}
4853

54+
// UpdateAccountWithRMBEncKey update the account rmb encryption key
4955
func UpdateAccountWithRMBEncKey(rmbEncKey string) UpdateAccountOpts {
5056
return func(n *accountCfg) {
5157
n.rmbEncKey = rmbEncKey
5258
}
5359
}
5460

61+
// EnsureAccount ensures that an account is created with specific seed/mnemonic.
5562
func (c *RegistrarClient) EnsureAccount(relays []string, rmbEncKey string) (account Account, err error) {
5663
return c.ensureAccount(relays, rmbEncKey)
5764
}
@@ -250,6 +257,7 @@ func (c *RegistrarClient) ensureAccount(relays []string, rmbEncKey string) (acco
250257
return account, err
251258
}
252259

260+
// ensureTwinID ensures that the RegistrarClient is set up properly with a valid public key representing an account on the registrar
253261
func (c *RegistrarClient) ensureTwinID() error {
254262
if c.twinID != 0 {
255263
return nil

node-registrar/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type RegistrarClient struct {
1616
twinID uint64
1717
}
1818

19+
// NewRegistrarClient creates a new client with optional seed or mnemonic
1920
func NewRegistrarClient(baseURL string, mnemonicOrSeed ...string) (cli RegistrarClient, err error) {
2021
client := http.DefaultClient
2122

node-registrar/client/farm.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ import (
1515

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

18+
// CreateFarm create new farm on the registrar with uniqe name.
1819
func (c *RegistrarClient) CreateFarm(farmName, stellarAddr string, dedicated bool) (farmID uint64, err error) {
1920
return c.createFarm(farmName, stellarAddr, dedicated)
2021
}
2122

23+
// UpdateFarm update farm configuration (farmName, stellarAddress, dedicated).
2224
func (c *RegistrarClient) UpdateFarm(farmID uint64, opts ...UpdateFarmOpts) (err error) {
2325
return c.updateFarm(farmID, opts)
2426
}
2527

26-
func (c *RegistrarClient) GetFarm(id uint64) (farm Farm, err error) {
27-
return c.getFarm(id)
28+
// GetFarm get a farm using its farmID
29+
func (c *RegistrarClient) GetFarm(farmID uint64) (farm Farm, err error) {
30+
return c.getFarm(farmID)
2831
}
2932

33+
// ListFarms get a list of farm using ListFarmOpts
3034
func (c *RegistrarClient) ListFarms(opts ...ListFarmOpts) (farms []Farm, err error) {
3135
return c.listFarms(opts...)
3236
}
@@ -46,48 +50,56 @@ type (
4650
UpdateFarmOpts func(*farmCfg)
4751
)
4852

53+
// ListFarmWithName lists farms with farm name
4954
func ListFarmWithName(name string) ListFarmOpts {
5055
return func(n *farmCfg) {
5156
n.farmName = name
5257
}
5358
}
5459

60+
// ListFarmWithFarmID lists farms with farmID
5561
func ListFarmWithFarmID(id uint64) ListFarmOpts {
5662
return func(n *farmCfg) {
5763
n.farmID = id
5864
}
5965
}
6066

67+
// ListFarmWithTwinID lists farms with twinID
6168
func ListFarmWithTwinID(id uint64) ListFarmOpts {
6269
return func(n *farmCfg) {
6370
n.twinID = id
6471
}
6572
}
6673

74+
// ListFarmWithDedicated lists dedicated farms
6775
func ListFarmWithDedicated() ListFarmOpts {
6876
return func(n *farmCfg) {
6977
n.dedicated = true
7078
}
7179
}
7280

81+
// ListFarmWithPage lists farms in a certain page
7382
func ListFarmWithPage(page uint32) ListFarmOpts {
7483
return func(n *farmCfg) {
7584
n.page = page
7685
}
7786
}
7887

88+
// ListFarmWithPage lists size number of farms
7989
func ListFarmWithSize(size uint32) ListFarmOpts {
8090
return func(n *farmCfg) {
8191
n.size = size
8292
}
8393
}
8494

95+
// UpdateFarmWithName update farm name
8596
func UpdateFarmWithName(name string) UpdateFarmOpts {
8697
return func(n *farmCfg) {
8798
n.farmName = name
8899
}
89100
}
90101

102+
// UpdateFarmWithName set farm status to dedicated
91103
func UpdateFarmWithDedicated() UpdateFarmOpts {
92104
return func(n *farmCfg) {
93105
n.dedicated = true
@@ -331,6 +343,7 @@ func parseUpdateFarmOpts(opts []UpdateFarmOpts) map[string]any {
331343
return data
332344
}
333345

346+
// validateStellarAddress ensures that the address is valid stellar address
334347
func validateStellarAddress(stellarAddr string) error {
335348
stellarAddr = strings.TrimSpace(stellarAddr)
336349
if len(stellarAddr) != 56 {

node-registrar/client/mnemonic.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ func (c *RegistrarClient) Mnemonic() string {
1212
return c.mnemonic
1313
}
1414

15+
// parseKeysFromMnemonicOrSeed drives keypair from mnemonic or seed
1516
func parseKeysFromMnemonicOrSeed(mnemonicOrSeed string) (keypair subkey.KeyPair, err error) {
1617
// otherwise drive key pair from seed
1718
keypair, err = subkey.DeriveKeyPair(subkeyEd25519.Scheme{}, mnemonicOrSeed)
1819
if err != nil {
19-
return keypair, errors.Wrapf(err, "failed to derive key pair from seed %s", mnemonicOrSeed)
20+
return keypair, errors.Wrapf(err, "failed to drive key pair from seed %s", mnemonicOrSeed)
2021
}
2122

2223
return keypair, nil
2324
}
2425

26+
// generateNewMnemonic generates new mnemonic and keypair
2527
func generateNewMnemonic() (mnemonic string, keypair subkey.KeyPair, err error) {
2628
// Generate 128-bit entropy (12-word mnemonic)
2729
entropy, err := bip39.NewEntropy(128)

node-registrar/client/node.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
var ErrorNodeNotFound = fmt.Errorf("failed to get requested node from node registrar")
1616

17+
// RegisterNode register physical/virtual nodes with on TFGrid.
1718
func (c *RegistrarClient) RegisterNode(
1819
farmID uint64,
1920
twinID uint64,
@@ -27,22 +28,27 @@ func (c *RegistrarClient) RegisterNode(
2728
return c.registerNode(farmID, twinID, interfaces, location, resources, serialNumber, secureBoot, virtualized)
2829
}
2930

31+
// UpdateNode update node configuration (farmID, interfaces, resources, location, secureBoot, virtualized).
3032
func (c *RegistrarClient) UpdateNode(opts ...UpdateNodeOpts) (err error) {
3133
return c.updateNode(opts)
3234
}
3335

36+
// ReportUptime update node Uptime.
3437
func (c *RegistrarClient) ReportUptime(report UptimeReport) (err error) {
3538
return c.reportUptime(report)
3639
}
3740

41+
// GetNode gets registered node details using nodeID
3842
func (c *RegistrarClient) GetNode(id uint64) (node Node, err error) {
3943
return c.getNode(id)
4044
}
4145

46+
// GetNodeByTwinID gets registered node details using twinID
4247
func (c *RegistrarClient) GetNodeByTwinID(id uint64) (node Node, err error) {
4348
return c.getNodeByTwinID(id)
4449
}
4550

51+
// ListNodes lists registered nodes details using (nodeID, twinID, farmID).
4652
func (c *RegistrarClient) ListNodes(opts ...ListNodeOpts) (nodes []Node, err error) {
4753
return c.listNodes(opts)
4854
}

node-registrar/client/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/pkg/errors"
1010
)
1111

12+
// signRequest signs request with challenge with format timestamp:twinID
1213
func (c *RegistrarClient) signRequest(timestamp int64) (authHeader string, err error) {
1314
challenge := []byte(fmt.Sprintf("%d:%v", timestamp, c.twinID))
1415
signature, err := c.keyPair.Sign(challenge)
@@ -24,6 +25,7 @@ func (c *RegistrarClient) signRequest(timestamp int64) (authHeader string, err e
2425
return
2526
}
2627

28+
// parseResponseError parse json response error
2729
func parseResponseError(body io.Reader) (err error) {
2830
errResp := struct {
2931
Error string `json:"error"`

node-registrar/client/zos_version.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import (
1212
"github.com/pkg/errors"
1313
)
1414

15+
// GetZosVersion gets zos version for specific network
1516
func (c *RegistrarClient) GetZosVersion() (version ZosVersion, err error) {
1617
return c.getZosVersion()
1718
}
1819

20+
// SetZosVersion sets zos version for specific network only valid for network admin
1921
func (c *RegistrarClient) SetZosVersion(v string, safeToUpgrade bool) (err error) {
2022
return c.setZosVersion(v, safeToUpgrade)
2123
}

0 commit comments

Comments
 (0)