Skip to content

Commit

Permalink
Merge "[FAB-1351] New chain config client for Kafka"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Yellick authored and Gerrit Code Review committed Dec 19, 2016
2 parents cf03f20 + 6b1b603 commit 06c336d
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 167 deletions.
61 changes: 0 additions & 61 deletions orderer/sample_clients/broadcast_config/broadcast.go

This file was deleted.

108 changes: 108 additions & 0 deletions orderer/sample_clients/broadcast_config/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"context"
"flag"
"fmt"

"google.golang.org/grpc"

"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
ab "github.com/hyperledger/fabric/protos/orderer"
)

var conf *config.TopLevel

type broadcastClient struct {
ab.AtomicBroadcast_BroadcastClient
}

func (bc *broadcastClient) broadcast(env *cb.Envelope) error {
var err error
var resp *ab.BroadcastResponse

err = bc.Send(env)
if err != nil {
return err
}

resp, err = bc.Recv()
if err != nil {
return err
}

fmt.Println("Status:", resp)
return nil
}

// cmdImpl holds the command and its arguments.
type cmdImpl struct {
name string
args argsImpl
}

// argsImpl holds all the possible arguments for all possible commands.
type argsImpl struct {
consensusType string
creationPolicy string
chainID string
}

func init() {
conf = config.Load()
}

func main() {
cmd := new(cmdImpl)
var srv string

flag.StringVar(&srv, "server", fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort), "The RPC server to connect to.")
flag.StringVar(&cmd.name, "cmd", "newChain", "The action that this client is requesting via the config transaction.")
flag.StringVar(&cmd.args.consensusType, "consensusType", conf.General.OrdererType, "In case of a newChain command, the type of consensus the ordering service is running on.")
flag.StringVar(&cmd.args.creationPolicy, "creationPolicy", "AcceptAllPolicy", "In case of a newChain command, the chain creation policy this request should be validated against.")
flag.StringVar(&cmd.args.chainID, "chainID", "NewChainID", "In case of a newChain command, the chain ID to create.")
flag.Parse()

conn, err := grpc.Dial(srv, grpc.WithInsecure())
defer func() {
_ = conn.Close()
}()
if err != nil {
fmt.Println("Error connecting:", err)
return
}

client, err := ab.NewAtomicBroadcastClient(conn).Broadcast(context.TODO())
if err != nil {
fmt.Println("Error connecting:", err)
return
}

bc := &broadcastClient{client}

switch cmd.name {
case "newChain":
env := newChainRequest(cmd.args.consensusType, cmd.args.creationPolicy, cmd.args.chainID)
fmt.Println("Requesting the creation of chain", cmd.args.chainID)
fmt.Println(bc.broadcast(env))
default:
panic("Invalid command given")
}
}
98 changes: 0 additions & 98 deletions orderer/sample_clients/broadcast_config/main.go

This file was deleted.

11 changes: 3 additions & 8 deletions orderer/sample_clients/broadcast_config/newchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ package main

import (
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
"github.com/hyperledger/fabric/orderer/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
)

var genesisBlock *cb.Block

func init() {
genesisBlock = provisional.New(config.Load()).GenesisBlock()
}

func newChainRequest(creationPolicy, newChainID string) *cb.Envelope {
func newChainRequest(consensusType, creationPolicy, newChainID string) *cb.Envelope {
conf.General.OrdererType = consensusType
genesisBlock := provisional.New(conf).GenesisBlock()
oldGenesisTx := utils.ExtractEnvelopeOrPanic(genesisBlock, 0)
oldGenesisTxPayload := utils.ExtractPayloadOrPanic(oldGenesisTx)
oldConfigEnv := utils.UnmarshalConfigurationEnvelopeOrPanic(oldGenesisTxPayload.Data)
Expand Down

0 comments on commit 06c336d

Please sign in to comment.