changes to avoid duplicate records in permissioned-nodes.json

This commit is contained in:
vsmk98 2019-01-24 13:35:46 +08:00
parent 4bb8a364a9
commit 412ba4d73d
1 changed files with 14 additions and 11 deletions

View File

@ -10,6 +10,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sync" "sync"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
@ -238,18 +239,20 @@ func (p *PermissionCtrl) updatePermissionedNodes(enodeId, ipAddrPort, discPort,
newEnodeId := p.formatEnodeId(enodeId, ipAddrPort, discPort, raftPort) newEnodeId := p.formatEnodeId(enodeId, ipAddrPort, discPort, raftPort)
// logic to update the permissioned-nodes.json file based on action // logic to update the permissioned-nodes.json file based on action
if operation == NodeAdd {
nodelist = append(nodelist, newEnodeId)
} else {
index := 0 index := 0
recExists := false recExists := false
for i, enodeId := range nodelist { for i, enodeId := range nodelist {
if (enodeId == newEnodeId){ if strings.EqualFold(enodeId, newEnodeId){
index = i index = i
recExists = true recExists = true
break break
} }
} }
if operation == NodeAdd {
if !recExists {
nodelist = append(nodelist, newEnodeId)
}
} else {
if recExists { if recExists {
nodelist = append(nodelist[:index], nodelist[index+1:]...) nodelist = append(nodelist[:index], nodelist[index+1:]...)
} }