format code

This commit is contained in:
amalraj.manigmail.com 2018-11-14 18:24:28 +08:00
parent 405204cd23
commit 9628cb5e2b
4 changed files with 26 additions and 24 deletions

View File

@ -362,7 +362,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
func startQuorumPermissionService(ctx *cli.Context, stack *node.Node) { func startQuorumPermissionService(ctx *cli.Context, stack *node.Node) {
// start the permissions management service // start the permissions management service
pc, err := permission.NewQuorumPermissionCtrl(stack, ctx.GlobalBool(utils.EnableNodePermissionFlag.Name),ctx.GlobalBool(utils.RaftModeFlag.Name)) pc, err := permission.NewQuorumPermissionCtrl(stack, ctx.GlobalBool(utils.EnableNodePermissionFlag.Name), ctx.GlobalBool(utils.RaftModeFlag.Name))
if err != nil { if err != nil {
utils.Fatalf("Failed to start Quorum Permission contract service: %v", err) utils.Fatalf("Failed to start Quorum Permission contract service: %v", err)
} }

View File

@ -3,8 +3,8 @@ package permission
import ( import (
"crypto/ecdsa" "crypto/ecdsa"
"encoding/json" "encoding/json"
"fmt"
"errors" "errors"
"fmt"
"io/ioutil" "io/ioutil"
"math/big" "math/big"
"os" "os"
@ -38,14 +38,14 @@ const (
) )
type PermissionCtrl struct { type PermissionCtrl struct {
node *node.Node node *node.Node
ethClnt *ethclient.Client ethClnt *ethclient.Client
eth *eth.Ethereum eth *eth.Ethereum
isRaft bool isRaft bool
permissionedMode bool permissionedMode bool
key *ecdsa.PrivateKey key *ecdsa.PrivateKey
dataDir string dataDir string
pm *pbind.Permissions pm *pbind.Permissions
} }
// Creates the controls structure for permissions // Creates the controls structure for permissions
@ -345,7 +345,7 @@ func (p *PermissionCtrl) populateAcctPermissions() error {
for recExists { for recExists {
recExists = pastEvents.Next() recExists = pastEvents.Next()
if recExists { if recExists {
log.Info("SMK-populateAcctPermissions @344 ", "Account", pastEvents.Event.Address, "access",pastEvents.Event.Access) log.Info("SMK-populateAcctPermissions @344 ", "Account", pastEvents.Event.Address, "access", pastEvents.Event.Access)
types.AddAccountAccess(pastEvents.Event.Address, pastEvents.Event.Access) types.AddAccountAccess(pastEvents.Event.Address, pastEvents.Event.Access)
} }
} }
@ -442,7 +442,7 @@ func (p *PermissionCtrl) populateInitPermission() error {
log.Info("SMK-populateInitPermission @447") log.Info("SMK-populateInitPermission @447")
} }
if !p.permissionedMode{ if !p.permissionedMode {
return errors.New("Node started in non-permissioned mode") return errors.New("Node started in non-permissioned mode")
log.Info("SMK-populateInitPermission @452") log.Info("SMK-populateInitPermission @452")
} }

View File

@ -73,7 +73,7 @@ type txArgs struct {
} }
type nodeStatus struct { type nodeStatus struct {
Name string Name string
Status string Status string
} }
@ -90,7 +90,7 @@ func NewPermissionAPI(tp *core.TxPool, am *accounts.Manager) *PermissionAPI {
// helper function decodes the node status to string // helper function decodes the node status to string
func decodeNodeStatus(nodeStatus uint8) string { func decodeNodeStatus(nodeStatus uint8) string {
var status string var status string
switch nodeStatus{ switch nodeStatus {
case 0: case 0:
status = "Unknown" status = "Unknown"
case 1: case 1:
@ -131,7 +131,7 @@ func (p *PermissionAPI) Init(ethClnt *ethclient.Client, key *ecdsa.PrivateKey) e
return nil return nil
} }
// Returns the list of Nodes and status of each // Returns the list of Nodes and status of each
func (s *PermissionAPI) PermissionNodeList() []nodeStatus { func (s *PermissionAPI) PermissionNodeList() []nodeStatus {
auth := bind.NewKeyedTransactor(s.key) auth := bind.NewKeyedTransactor(s.key)
ps := &pbind.PermissionsSession{ ps := &pbind.PermissionsSession{
@ -153,9 +153,9 @@ func (s *PermissionAPI) PermissionNodeList() []nodeStatus {
// loop for each index and get the node details from the contract // loop for each index and get the node details from the contract
if err == nil { if err == nil {
i := int64(0) i := int64(0)
for nodeCnt.Cmp(big.NewInt(i)) > 0{ for nodeCnt.Cmp(big.NewInt(i)) > 0 {
nodeDtls, _ := ps.GetNodeDetails(big.NewInt(i)) nodeDtls, _ := ps.GetNodeDetails(big.NewInt(i))
nodeStatArr[i].Name = "enode://"+ nodeDtls.EnodeId + "@" +nodeDtls.IpAddrPort nodeStatArr[i].Name = "enode://" + nodeDtls.EnodeId + "@" + nodeDtls.IpAddrPort
nodeStatArr[i].Name += "?discport=" + nodeDtls.DiscPort nodeStatArr[i].Name += "?discport=" + nodeDtls.DiscPort
if len(nodeDtls.RaftPort) > 0 { if len(nodeDtls.RaftPort) > 0 {
nodeStatArr[i].Name += "&raftport" + nodeDtls.RaftPort nodeStatArr[i].Name += "&raftport" + nodeDtls.RaftPort
@ -254,7 +254,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.RemoveVoter(args.voter) tx, err = ps.RemoveVoter(args.voter)
case ProposeNode: case ProposeNode:
if !checkVoterExists(ps){ if !checkVoterExists(ps) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -272,7 +272,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.ProposeNode(enodeID, ipAddrPort, discPort, raftPort) tx, err = ps.ProposeNode(enodeID, ipAddrPort, discPort, raftPort)
case ApproveNode: case ApproveNode:
if !checkIsVoter(ps, args.txa.From){ if !checkIsVoter(ps, args.txa.From) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -284,7 +284,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.ApproveNode(enodeID) tx, err = ps.ApproveNode(enodeID)
case ProposeNodeDeactivation: case ProposeNodeDeactivation:
if !checkVoterExists(ps){ if !checkVoterExists(ps) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -296,7 +296,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.ProposeDeactivation(enodeID) tx, err = ps.ProposeDeactivation(enodeID)
case ApproveNodeDeactivation: case ApproveNodeDeactivation:
if !checkIsVoter(ps, args.txa.From){ if !checkIsVoter(ps, args.txa.From) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -308,7 +308,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.DeactivateNode(enodeID) tx, err = ps.DeactivateNode(enodeID)
case ProposeNodeActivation: case ProposeNodeActivation:
if !checkVoterExists(ps){ if !checkVoterExists(ps) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -320,7 +320,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.ProposeNodeActivation(enodeID) tx, err = ps.ProposeNodeActivation(enodeID)
case ApproveNodeActivation: case ApproveNodeActivation:
if !checkIsVoter(ps, args.txa.From){ if !checkIsVoter(ps, args.txa.From) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -332,7 +332,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.ActivateNode(enodeID) tx, err = ps.ActivateNode(enodeID)
case ProposeNodeBlacklisting: case ProposeNodeBlacklisting:
if !checkVoterExists(ps){ if !checkVoterExists(ps) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -349,7 +349,7 @@ func (s *PermissionAPI) executePermAction(action PermAction, args txArgs) ExecSt
tx, err = ps.ProposeNodeBlacklisting(enodeID, ipAddrPort, discPort, raftPort) tx, err = ps.ProposeNodeBlacklisting(enodeID, ipAddrPort, discPort, raftPort)
case ApproveNodeBlacklisting: case ApproveNodeBlacklisting:
if !checkIsVoter(ps, args.txa.From){ if !checkIsVoter(ps, args.txa.From) {
return voterErr return voterErr
} }
node, err = discover.ParseNode(args.nodeId) node, err = discover.ParseNode(args.nodeId)
@ -428,6 +428,7 @@ func checkIsVoter(ps *pbind.PermissionsSession, acctId common.Address) bool {
} }
return false return false
} }
// newPermSession creates a new permission contract session // newPermSession creates a new permission contract session
func (s *PermissionAPI) newPermSession(w accounts.Wallet, txa ethapi.SendTxArgs) *pbind.PermissionsSession { func (s *PermissionAPI) newPermSession(w accounts.Wallet, txa ethapi.SendTxArgs) *pbind.PermissionsSession {
frmAcct, transactOpts, gasLimit, gasPrice, nonce := s.getTxParams(txa, w) frmAcct, transactOpts, gasLimit, gasPrice, nonce := s.getTxParams(txa, w)

View File

@ -23,6 +23,7 @@ type OrgStruct struct {
OrgId string OrgId string
Keys []string Keys []string
} }
var DefaultAccess = FullAccess var DefaultAccess = FullAccess
const acctMapLimit = 100 const acctMapLimit = 100