Skip to content

Commit 13eafa8

Browse files
author
Yunshi Sun
authored
Merge pull request #52 from renproject/release/v3.0.6
v3.0.6
2 parents e99b315 + 3adc871 commit 13eafa8

6 files changed

Lines changed: 25 additions & 19 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.5
1+
3.0.6

cmd/list.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"fmt"
55
"io/ioutil"
66
"path/filepath"
7+
"sync/atomic"
78

9+
"github.com/fatih/color"
810
"github.com/renproject/darknode-cli/cmd/provider"
911
"github.com/renproject/darknode-cli/util"
1012
"github.com/renproject/phi"
@@ -20,7 +22,7 @@ func listAllNodes(ctx *cli.Context) error {
2022
}
2123

2224
nodes := make([][]string, len(nodesNames))
23-
errs := map[string]error{}
25+
var errs int64
2426
phi.ParForAll(nodesNames, func(i int) {
2527
name := nodesNames[i]
2628
var err error
@@ -49,10 +51,13 @@ func listAllNodes(ctx *cli.Context) error {
4951
return []string{name, id.String(), ip, provider, string(tags), ethAddr.Hex()}, nil
5052
}()
5153
if err != nil {
52-
errs[name] = err
54+
color.Red("[%v] cannot get detail of the darknode, err = %v", name, err)
55+
atomic.AddInt64(&errs, 1)
5356
}
5457
})
55-
if len(errs) == len(nodesNames) {
58+
59+
// Check if we can find any valid nodes.
60+
if atomic.LoadInt64(&errs) == int64(len(nodesNames)) {
5661
return fmt.Errorf("cannot find any node")
5762
}
5863

cmd/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ func checkUpdates(curVer string) {
190190
client := github.NewClient(nil)
191191
release, _, err := client.Repositories.GetLatestRelease(ctx, "renproject", "darknode-cli")
192192
if err != nil {
193-
color.Red("cannot check latest release, err = %v", err)
194193
return
195194
}
196195

darknode/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ func NewConfig(network Network) (Config, error) {
7676
// all versions of darknode configs.
7777
type GeneralConfig struct {
7878
// Private configuration
79-
Keystore keystore.Keystore `json:"keystore"`
80-
ECDSADistKeyShare ECDSADistKeyShare `json:"ecdsaDistKeyShare"`
79+
Keystore keystore.Keystore `json:"keystore"`
8180

8281
// Public configuration
8382
Network Network `json:"network"`

util/node.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func ValidateNodeName(name string) error {
5656
}
5757

5858
// Config returns the config of the node with given name.
59-
func Config(name string) (darknode.GeneralConfig, error){
59+
func Config(name string) (darknode.GeneralConfig, error) {
6060
path := filepath.Join(NodePath(name), "config.json")
6161
return darknode.NewConfigFromJSONFile(path)
6262
}
@@ -118,21 +118,14 @@ func GetNodesByTags(tags string) ([]string, error) {
118118
if err != nil {
119119
return nil, err
120120
}
121-
ts := strings.Split(strings.TrimSpace(tags), ",")
122121
nodes := make([]string, 0)
123122
for _, f := range files {
124-
tagFile := filepath.Join(Directory, "darknodes", f.Name(), "tags.out")
125-
tags, err := ioutil.ReadFile(tagFile)
123+
path := filepath.Join(Directory, "darknodes", f.Name(), "tags.out")
124+
tagFile, err := ioutil.ReadFile(path)
126125
if err != nil {
127126
continue
128127
}
129-
haveAllTags := true
130-
for i := range ts {
131-
if !strings.Contains(string(tags), ts[i]) {
132-
haveAllTags = false
133-
}
134-
}
135-
if !haveAllTags {
128+
if !ValidateTags(string(tagFile), tags) {
136129
continue
137130
}
138131

@@ -145,6 +138,16 @@ func GetNodesByTags(tags string) ([]string, error) {
145138
return nodes, nil
146139
}
147140

141+
func ValidateTags(have, required string) bool {
142+
tagsStr := strings.Split(strings.TrimSpace(required), ",")
143+
for _, tag := range tagsStr {
144+
if !strings.Contains(have, tag) {
145+
return false
146+
}
147+
}
148+
return true
149+
}
150+
148151
func isDeployed(name string) bool {
149152
path := NodePath(name)
150153
script := fmt.Sprintf("cd %v && terraform output ip", path)

util/system.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NodePath(name string) string {
2424

2525
// BackUpConfig copies the config file of the node to the backup folder under
2626
// .darknode directory in case something unexpected happens.
27-
func BackUpConfig(name string) error{
27+
func BackUpConfig(name string) error {
2828
path := NodePath(name)
2929
backupFolder := filepath.Join(Directory, "backup", name)
3030
if err := Run("mkdir", "-p", backupFolder); err != nil {

0 commit comments

Comments
 (0)