Skip to content

Commit f7e790a

Browse files
committed
[FAB-9851] Remove constructor in favor of literal
- Remove constructor in favor of explicit dependency injection from ChaincodeSupport to the handler instance. - Add some documentation comments and group fields in Handler - Change state to int based enum so zero value matches default state of created - Rename getCCRootName to chaincodeName to more accurately reflect what is returned Change-Id: I56aa4245be5d1f465b50842b1e92b9b53eff0303 Signed-off-by: Saad Karim <skarim@us.ibm.com> Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 2ed7112 commit f7e790a

6 files changed

+142
-156
lines changed

core/chaincode/chaincode_suite_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hyperledger/fabric/core/common/ccprovider"
1212
"github.com/hyperledger/fabric/core/container/ccintf"
1313
"github.com/hyperledger/fabric/core/ledger"
14+
pb "github.com/hyperledger/fabric/protos/peer"
1415
. "github.com/onsi/ginkgo"
1516
. "github.com/onsi/gomega"
1617

@@ -79,6 +80,6 @@ type chaincodeStream interface {
7980

8081
// Helpers to access unexported state.
8182

82-
func SetHandlerTxContexts(h *Handler, txContexts *TransactionContexts) {
83-
h.txContexts = txContexts
83+
func SetHandlerChaincodeID(h *Handler, chaincodeID *pb.ChaincodeID) {
84+
h.chaincodeID = chaincodeID
8485
}

core/chaincode/chaincode_support.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,22 @@ func (cs *ChaincodeSupport) Stop(ctx context.Context, cccid *ccprovider.CCContex
128128

129129
// HandleChaincodeStream implements ccintf.HandleChaincodeStream for all vms to call with appropriate stream
130130
func (cs *ChaincodeSupport) HandleChaincodeStream(ctxt context.Context, stream ccintf.ChaincodeStream) error {
131-
return HandleChaincodeStream(cs, ctxt, stream)
131+
deadline, ok := ctxt.Deadline()
132+
chaincodeLogger.Debugf("Current context deadline = %s, ok = %v", deadline, ok)
133+
134+
handler := &Handler{
135+
Executor: cs,
136+
Lifecycle: &Lifecycle{Executor: cs},
137+
Keepalive: cs.Keepalive,
138+
Registry: cs.HandlerRegistry,
139+
ACLProvider: cs.ACLProvider,
140+
TXContexts: NewTransactionContexts(),
141+
ActiveTransactions: NewActiveTransactions(),
142+
143+
sccp: cs.sccp,
144+
}
145+
146+
return handler.ProcessStream(stream)
132147
}
133148

134149
// Register the bidi stream entry point called by chaincode to register with the Peer.
@@ -151,7 +166,7 @@ func createCCMessage(messageType pb.ChaincodeMessage_Type, cid string, txid stri
151166
return ccmsg, nil
152167
}
153168

154-
//Execute - execute proposal, return original response of chaincode
169+
// Execute - execute proposal, return original response of chaincode
155170
func (cs *ChaincodeSupport) Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec ccprovider.ChaincodeSpecGetter) (*pb.Response, *pb.ChaincodeEvent, error) {
156171
var cctyp pb.ChaincodeMessage_Type
157172
switch spec.(type) {

core/chaincode/chaincode_support_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ func TestStartAndWaitLaunchError(t *testing.T) {
10881088
}
10891089

10901090
func TestGetTxContextFromHandler(t *testing.T) {
1091-
h := Handler{txContexts: NewTransactionContexts(), sccp: &scc.Provider{Peer: peer.Default, PeerSupport: peer.DefaultSupport, Registrar: inproccontroller.NewRegistry()}}
1091+
h := Handler{TXContexts: NewTransactionContexts(), sccp: &scc.Provider{Peer: peer.Default, PeerSupport: peer.DefaultSupport, Registrar: inproccontroller.NewRegistry()}}
10921092

10931093
chnl := "test"
10941094
txid := "1"
@@ -1190,7 +1190,7 @@ func genNewPldAndCtxFromLdgr(t *testing.T, ccName string, chnl string, txid stri
11901190
// get a context for this txsim
11911191
ctxt := context.WithValue(context.Background(), TXSimulatorKey, txsim)
11921192
// create a new txContext in the handler to be retrieved by the tested function (ie: getTxContextForInvoke)
1193-
newTxCtxt, err := h.txContexts.Create(ctxt, chnl, txid, nil, nil)
1193+
newTxCtxt, err := h.TXContexts.Create(ctxt, chnl, txid, nil, nil)
11941194
if err != nil {
11951195
t.Fatalf("Error creating TxContext by the handler for cc %s and channel '%s': %s", ccName, chnl, err)
11961196
}
@@ -1300,7 +1300,7 @@ func TestCCFramework(t *testing.T) {
13001300
initializeCC(t, chainID, ccname, ccSide, chaincodeSupport)
13011301

13021302
//chaincode support should not allow dups
1303-
handler := &Handler{ChaincodeID: &pb.ChaincodeID{Name: ccname + ":0"}, sccp: chaincodeSupport.sccp}
1303+
handler := &Handler{chaincodeID: &pb.ChaincodeID{Name: ccname + ":0"}, sccp: chaincodeSupport.sccp}
13041304
if err := chaincodeSupport.HandlerRegistry.Register(handler); err == nil {
13051305
t.Fatalf("expected re-register to fail")
13061306
}

0 commit comments

Comments
 (0)