From 412ba4d73d9e3ad5456ba6a1419f063a3a58549f Mon Sep 17 00:00:00 2001 From: vsmk98 Date: Thu, 24 Jan 2019 13:35:46 +0800 Subject: [PATCH] changes to avoid duplicate records in permissioned-nodes.json --- controls/permission/permission.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/controls/permission/permission.go b/controls/permission/permission.go index f1ed8fb28..23d7e0fd8 100644 --- a/controls/permission/permission.go +++ b/controls/permission/permission.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "sync" + "strings" "github.com/ethereum/go-ethereum/accounts/abi/bind" "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) // logic to update the permissioned-nodes.json file based on action - if operation == NodeAdd { - nodelist = append(nodelist, newEnodeId) - } else { - index := 0 - recExists := false - for i, enodeId := range nodelist { - if (enodeId == newEnodeId){ - index = i - recExists = true - break - } + index := 0 + recExists := false + for i, enodeId := range nodelist { + if strings.EqualFold(enodeId, newEnodeId){ + index = i + recExists = true + break } + } + if operation == NodeAdd { + if !recExists { + nodelist = append(nodelist, newEnodeId) + } + } else { if recExists { nodelist = append(nodelist[:index], nodelist[index+1:]...) }