permission: refactor dir structure for contract

This commit is contained in:
amalraj.manigmail.com 2019-05-08 18:08:08 +08:00
parent 3aad59fc58
commit 468478be78
22 changed files with 16 additions and 8 deletions

View File

@ -20,9 +20,9 @@ import (
"bufio" "bufio"
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/controls/permission"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/permission"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
@ -210,7 +210,7 @@ func RegisterPermissionService(ctx *cli.Context, stack *node.Node) {
var permissionConfig types.PermissionConfig var permissionConfig types.PermissionConfig
var err error var err error
if permissionConfig, err = permission.ParsePermissionConifg(dataDir); err != nil { if permissionConfig, err = permission.ParsePermissionConifg(dataDir); err != nil {
utils.Fatalf("loading of permission-config.json failed", "error") utils.Fatalf("loading of permission-config.json failed", "error", err)
} }
// start the permissions management service // start the permissions management service

View File

@ -284,6 +284,7 @@ func geth(ctx *cli.Context) error {
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the // it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// miner. // miner.
func startNode(ctx *cli.Context, stack *node.Node) { func startNode(ctx *cli.Context, stack *node.Node) {
log.Info("AJ-start node1")
log.DoEmitCheckpoints = ctx.GlobalBool(utils.EmitCheckpointsFlag.Name) log.DoEmitCheckpoints = ctx.GlobalBool(utils.EmitCheckpointsFlag.Name)
debug.Memsize.Add("node", stack) debug.Memsize.Add("node", stack)

View File

@ -64,6 +64,8 @@ func Fatalf(format string, args ...interface{}) {
} }
func StartNode(stack *node.Node) { func StartNode(stack *node.Node) {
log.Info("AJ-start node2")
if err := stack.Start(); err != nil { if err := stack.Start(); err != nil {
Fatalf("Error starting protocol stack: %v", err) Fatalf("Error starting protocol stack: %v", err)
} }

View File

@ -150,6 +150,8 @@ func (n *Node) Register(constructor ServiceConstructor) error {
// Start create a live P2P node and starts running it. // Start create a live P2P node and starts running it.
func (n *Node) Start() error { func (n *Node) Start() error {
log.Info("AJ-start node3")
n.lock.Lock() n.lock.Lock()
defer n.lock.Unlock() defer n.lock.Unlock()
@ -183,7 +185,8 @@ func (n *Node) Start() error {
// Otherwise copy and specialize the P2P configuration // Otherwise copy and specialize the P2P configuration
services := make(map[reflect.Type]Service) services := make(map[reflect.Type]Service)
for _, constructor := range n.serviceFuncs {
for ct, constructor := range n.serviceFuncs {
// Create a new context for the particular service // Create a new context for the particular service
ctx := &ServiceContext{ ctx := &ServiceContext{
config: n.config, config: n.config,
@ -194,12 +197,16 @@ func (n *Node) Start() error {
for kind, s := range services { // copy needed for threaded access for kind, s := range services { // copy needed for threaded access
ctx.services[kind] = s ctx.services[kind] = s
} }
log.Info("AJ-construct service1", "ct", ct, "Cons", constructor)
// Construct and save the service // Construct and save the service
service, err := constructor(ctx) service, err := constructor(ctx)
log.Info("AJ-construct service2", "service", service)
if err != nil { if err != nil {
return err return err
} }
kind := reflect.TypeOf(service) kind := reflect.TypeOf(service)
log.Info("AJ-construct service3", "ct", ct, "kind", kind)
if _, exists := services[kind]; exists { if _, exists := services[kind]; exists {
return &DuplicateServiceError{Kind: kind} return &DuplicateServiceError{Kind: kind}
} }
@ -215,6 +222,7 @@ func (n *Node) Start() error {
// Start each of the services // Start each of the services
started := []reflect.Type{} started := []reflect.Type{}
for kind, service := range services { for kind, service := range services {
log.Info("AJ-start service ", "kind", kind, "srv", service)
// Start the next service, stopping all previous upon failure // Start the next service, stopping all previous upon failure
if err := service.Start(running); err != nil { if err := service.Start(running); err != nil {
for _, kind := range started { for _, kind := range started {

View File

@ -109,10 +109,6 @@ func populateConfig(config PermissionLocalConfig) types.PermissionConfig {
func ParsePermissionConifg(dir string) (types.PermissionConfig, error) { func ParsePermissionConifg(dir string) (types.PermissionConfig, error) {
fileName := "permission-config.json" fileName := "permission-config.json"
fullPath := filepath.Join(dir, fileName) fullPath := filepath.Join(dir, fileName)
if _, err := os.Stat(fullPath); err != nil {
log.Warn("permission-config.json file is missing", err)
return types.PermissionConfig{}, err
}
blob, err := ioutil.ReadFile(fullPath) blob, err := ioutil.ReadFile(fullPath)
@ -152,7 +148,7 @@ func waitForSync(e *eth.Ethereum) {
func NewQuorumPermissionCtrl(stack *node.Node, permissionedMode, isRaft bool, pconfig *types.PermissionConfig) (*PermissionCtrl, error) { func NewQuorumPermissionCtrl(stack *node.Node, permissionedMode, isRaft bool, pconfig *types.PermissionConfig) (*PermissionCtrl, error) {
// Create a new ethclient to for interfacing with the contract // Create a new ethclient to for interfacing with the contract
clnt, e, err := controls.CreateEthClient(stack) clnt, e, err := controls.CreateEthClient(stack)
waitForSync(e) //waitForSync(e)
if err != nil { if err != nil {
log.Error("Unable to create ethereum client for permissions check", "err", err) log.Error("Unable to create ethereum client for permissions check", "err", err)
return nil, err return nil, err
@ -203,6 +199,7 @@ func NewQuorumPermissionCtrl(stack *node.Node, permissionedMode, isRaft bool, pc
// Starts the node permissioning and event monitoring for permissions // Starts the node permissioning and event monitoring for permissions
// smart contracts // smart contracts
func (p *PermissionCtrl) Start(srvr *p2p.Server) error { func (p *PermissionCtrl) Start(srvr *p2p.Server) error {
log.Info("permission service started...")
// Permissions initialization // Permissions initialization
if err := p.init(); err != nil { if err := p.init(); err != nil {
log.Error("Permissions init failed", "err", err) log.Error("Permissions init failed", "err", err)