Skip to content

Commit

Permalink
[FAB-9649] Peer CLI invoke wait for event with txid
Browse files Browse the repository at this point in the history
This CR adds the ability to connect the CLI to the
deliver filtered service and wait for an event
containing the txid for a given chaincode invocation.

Change-Id: I8d0694e621467a544fb4c8cda7b880096e677f25
Signed-off-by: Will Lahti <[email protected]>
  • Loading branch information
wlahti committed May 16, 2018
1 parent 94ac268 commit 37b0db9
Show file tree
Hide file tree
Showing 14 changed files with 1,293 additions and 44 deletions.
32 changes: 32 additions & 0 deletions peer/chaincode/api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package api

import (
"context"

pcommon "github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
"google.golang.org/grpc"
)

//go:generate counterfeiter -o ../mock/deliverclient.go -fake-name DeliverClient . DeliverClient

// DeliverClient defines the interface for a peer's deliver service
type DeliverClient interface {
Deliver(ctx context.Context, opts ...grpc.CallOption) (Deliver, error)
DeliverFiltered(ctx context.Context, opts ...grpc.CallOption) (Deliver, error)
}

//go:generate counterfeiter -o ../mock/deliver.go -fake-name Deliver . Deliver

// Deliver defines the interface for delivering blocks
type Deliver interface {
Send(*pcommon.Envelope) error
Recv() (*pb.DeliverResponse, error)
CloseSend() error
}
9 changes: 8 additions & 1 deletion peer/chaincode/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package chaincode

import (
"fmt"
"time"

"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/peer/common"
Expand Down Expand Up @@ -65,6 +66,8 @@ var (
peerAddresses []string
tlsRootCertFiles []string
connectionProfile string
waitForEvent bool
waitForEventTimeout time.Duration
)

var chaincodeCmd = &cobra.Command{
Expand Down Expand Up @@ -116,6 +119,10 @@ func resetFlags() {
fmt.Sprint("If TLS is enabled, the paths to the TLS root cert files of the peers to connect to. The order and number of certs specified should match the --peerAddresses flag"))
flags.StringVarP(&connectionProfile, "connectionProfile", "", common.UndefinedParamValue,
fmt.Sprint("Connection profile that provides the necessary connection information for the network. Note: currently only supported for providing peer connection information"))
flags.BoolVar(&waitForEvent, "waitForEvent", false,
fmt.Sprint("Whether to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully"))
flags.DurationVar(&waitForEventTimeout, "waitForEventTimeout", 30*time.Second,
fmt.Sprint("Time to wait for the event from each peer's deliver filtered service signifying that the 'invoke' transaction has been committed successfully"))
}

func attachFlags(cmd *cobra.Command, names []string) {
Expand All @@ -124,7 +131,7 @@ func attachFlags(cmd *cobra.Command, names []string) {
if flag := flags.Lookup(name); flag != nil {
cmdFlags.AddFlag(flag)
} else {
logger.Fatalf("Could not find flag '%s' to attach to commond '%s'", name, cmd.Name())
logger.Fatalf("Could not find flag '%s' to attach to command '%s'", name, cmd.Name())
}
}
}
Loading

0 comments on commit 37b0db9

Please sign in to comment.