From 8c33f25f1b3c51091eee8da0d1e7d516cb58bba3 Mon Sep 17 00:00:00 2001 From: vsmk98 Date: Fri, 7 Jun 2019 14:51:21 +0800 Subject: [PATCH] permission: moved startQuorumService from main.go to permission.go --- cmd/geth/main.go | 56 +--------------------------------------- permission/permission.go | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 66e561cb3..bf791fdc3 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -18,7 +18,6 @@ package main import ( - "errors" "fmt" "math" "os" @@ -28,14 +27,11 @@ import ( "strings" "time" - "github.com/ethereum/go-ethereum/core/types" - "github.com/elastic/gosigar" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/console" - "github.com/ethereum/go-ethereum/core/quorum" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/internal/debug" @@ -350,7 +346,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { //START - QUORUM permission service go func() { if ctx.GlobalBool(utils.EnableNodePermissionFlag.Name) { - if err := startQuorumPermissionService(ctx, stack); err != nil { + if err := permission.StartQuorumPermissionService(ctx, stack); err != nil { utils.Fatalf("Failed to start permissions service %v", err) } } @@ -383,53 +379,3 @@ func startNode(ctx *cli.Context, stack *node.Node) { } } - -// Starts the permission services. services will come up only when -// geth is brought up in --permissioned mode and permission-config.json is present -func startQuorumPermissionService(ctx *cli.Context, stack *node.Node) error { - - var quorumApis []string - dataDir := ctx.GlobalString(utils.DataDirFlag.Name) - - var permissionConfig types.PermissionConfig - var err error - - if permissionConfig, err = permission.ParsePermissionConifg(dataDir); err != nil { - log.Error("loading of permission-config.json failed", "error", err) - return nil - } - - // start the permissions management service - pc, err := permission.NewQuorumPermissionCtrl(stack, ctx.GlobalBool(utils.EnableNodePermissionFlag.Name), &permissionConfig) - if err != nil { - return err - } - - if err = pc.Start(); err == nil { - quorumApis = []string{"quorumPermission"} - } else { - return err - } - - rpcClient, err := stack.Attach() - if err != nil { - return err - } - stateReader := ethclient.NewClient(rpcClient) - - for _, apiName := range quorumApis { - v := stack.GetRPC(apiName) - if v == nil { - return errors.New("failed to start quorum permission api") - } - qapi := v.(*quorum.QuorumControlsAPI) - - err = qapi.Init(stateReader, stack.GetNodeKey(), apiName, &permissionConfig, pc.Interface()) - if err != nil { - log.Info("Failed to starts API", "apiName", apiName) - } else { - log.Info("API started", "apiName", apiName) - } - } - return nil -} diff --git a/permission/permission.go b/permission/permission.go index 3f26aabb8..7815c6d58 100644 --- a/permission/permission.go +++ b/permission/permission.go @@ -4,7 +4,10 @@ import ( "crypto/ecdsa" "encoding/json" "errors" + "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/core/quorum" "github.com/ethereum/go-ethereum/raft" + "gopkg.in/urfave/cli.v1" "io/ioutil" "math/big" "os" @@ -72,6 +75,56 @@ func (p *PermissionCtrl) Interface() *pbind.PermInterface { return p.permInterf } +// Starts the permission services. services will come up only when +// geth is brought up in --permissioned mode and permission-config.json is present +func StartQuorumPermissionService(ctx *cli.Context, stack *node.Node) error { + + var quorumApis []string + dataDir := ctx.GlobalString(utils.DataDirFlag.Name) + + var permissionConfig types.PermissionConfig + var err error + + if permissionConfig, err = ParsePermissionConifg(dataDir); err != nil { + log.Error("loading of permission-config.json failed", "error", err) + return nil + } + + // start the permissions management service + pc, err := NewQuorumPermissionCtrl(stack, ctx.GlobalBool(utils.EnableNodePermissionFlag.Name), &permissionConfig) + if err != nil { + return err + } + + if err = pc.Start(); err == nil { + quorumApis = []string{"quorumPermission"} + } else { + return err + } + + rpcClient, err := stack.Attach() + if err != nil { + return err + } + stateReader := ethclient.NewClient(rpcClient) + + for _, apiName := range quorumApis { + v := stack.GetRPC(apiName) + if v == nil { + return errors.New("failed to start quorum permission api") + } + qapi := v.(*quorum.QuorumControlsAPI) + + err = qapi.Init(stateReader, stack.GetNodeKey(), apiName, &permissionConfig, pc.Interface()) + if err != nil { + log.Info("Failed to starts API", "apiName", apiName) + } else { + log.Info("API started", "apiName", apiName) + } + } + return nil +} + // converts local permissions data to global permissions config func populateConfig(config PermissionLocalConfig) types.PermissionConfig { var permConfig types.PermissionConfig