mirror of https://github.com/poanetwork/quorum.git
permission: moved startQuorumService from main.go to permission.go
This commit is contained in:
parent
a5a51d1595
commit
8c33f25f1b
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue