-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-1351] New chain config client for Kafka
https://jira.hyperledger.org/browse/FAB-1351 As things stand right now, the configuration transaction posted by the broadcast_config sample client only works for solo. This is because the genesis block for the Kafka orderer contains extra keys. This changeset: 1. Introduces an extra flag that allows us to specify the consenter type, and then, by using the provisional bootstrapper, it creates the appropriate configuration transaction. 2. Refactors/simplifies the client to bring it more in line with the rest of the sample_clients in the `orderer` package and make future maintenance easier. Change-Id: I61ce5dfb36a11ab58d41a65267768cf0948263dc Signed-off-by: Kostas Christidis <kostas@christidis.io>
- Loading branch information
1 parent
89f9a10
commit 6b1b603
Showing
4 changed files
with
111 additions
and
167 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters