Skip to content

Commit 8af2a90

Browse files
committedAug 11, 2017
[FAB-4207] Auth handlers - take II - Part II
This commit extends the ChaincodeInput of the auth handlers and plugs in a decorator that enables a user to mutate the chaincode input. It also extends the shim API to be able to extract the decoration from the chaincode input. Change-Id: I87be56e0f0b983c42543b095ed0774057d5d801b Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 82507b1 commit 8af2a90

11 files changed

+110
-74
lines changed
 

‎core/chaincode/chaincode_support_test.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ import (
4141
"github.com/hyperledger/fabric/core/peer"
4242
"github.com/hyperledger/fabric/core/policy"
4343
"github.com/hyperledger/fabric/core/scc"
44+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
4445
plgr "github.com/hyperledger/fabric/protos/ledger/queryresult"
4546
pb "github.com/hyperledger/fabric/protos/peer"
4647
putils "github.com/hyperledger/fabric/protos/utils"
4748
"golang.org/x/net/context"
48-
49-
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
5049
)
5150

5251
var globalBlockNum map[string]uint64
@@ -342,7 +341,7 @@ func initializeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCC
342341
}
343342

344343
chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
345-
ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}}
344+
ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, nil}
346345
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
347346

348347
ctxt, txsim, sprop, prop := startTx(t, chainID, cis)
@@ -392,7 +391,7 @@ func invokeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCComm)
392391
}
393392

394393
chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
395-
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
394+
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
396395
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
397396

398397
ctxt, txsim, sprop, prop := startTx(t, chainID, cis)
@@ -439,7 +438,7 @@ func getQueryStateByRange(t *testing.T, chainID, ccname string, ccSide *mockpeer
439438
}
440439

441440
chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
442-
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
441+
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
443442
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
444443

445444
ctxt, txsim, sprop, prop := startTx(t, chainID, cis)
@@ -486,7 +485,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock
486485
}
487486

488487
chaincodeID := &pb.ChaincodeID{Name: calledCC, Version: "0"}
489-
ci := &pb.ChaincodeInput{[][]byte{[]byte("deploycc")}}
488+
ci := &pb.ChaincodeInput{[][]byte{[]byte("deploycc")}, nil}
490489
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
491490

492491
//first deploy the new cc to LSCC
@@ -500,7 +499,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock
500499

501500
//now do the cc2cc
502501
chaincodeID = &pb.ChaincodeID{Name: ccname, Version: "0"}
503-
ci = &pb.ChaincodeInput{[][]byte{[]byte("invokecc")}}
502+
ci = &pb.ChaincodeInput{[][]byte{[]byte("invokecc")}, nil}
504503
cis = &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
505504

506505
ctxt, txsim, sprop, prop = startTx(t, chainID, cis)
@@ -538,7 +537,7 @@ func getQueryResult(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockC
538537
}
539538

540539
chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
541-
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
540+
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
542541
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
543542

544543
ctxt, txsim, sprop, prop := startTx(t, chainID, cis)
@@ -589,7 +588,7 @@ func getHistory(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCCom
589588
}
590589

591590
chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
592-
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
591+
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
593592
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
594593

595594
ctxt, txsim, sprop, prop := startTx(t, chainID, cis)

‎core/chaincode/exectransaction.go

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ func Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}
4646
return nil, nil, fmt.Errorf("%s", err)
4747
}
4848

49+
cMsg.Decorations = cccid.ProposalDecorations
50+
4951
var ccMsg *pb.ChaincodeMessage
5052
ccMsg, err = createCCMessage(cctyp, cccid.TxID, cMsg)
5153
if err != nil {

‎core/chaincode/shim/chaincode.go

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ type ChaincodeStub struct {
6767
creator []byte
6868
transient map[string][]byte
6969
binding []byte
70+
71+
decorations map[string][]byte
7072
}
7173

7274
// Peer address derived from command line or env var
@@ -334,6 +336,7 @@ func (stub *ChaincodeStub) init(handler *Handler, txid string, input *pb.Chainco
334336
stub.args = input.Args
335337
stub.handler = handler
336338
stub.signedProposal = signedProposal
339+
stub.decorations = input.Decorations
337340

338341
// TODO: sanity check: verify that every call to init with a nil
339342
// signedProposal is a legitimate one, meaning it is an internal call
@@ -366,6 +369,10 @@ func (stub *ChaincodeStub) GetTxID() string {
366369
return stub.TxID
367370
}
368371

372+
func (stub *ChaincodeStub) GetDecorations() map[string][]byte {
373+
return stub.decorations
374+
}
375+
369376
// --------- Security functions ----------
370377
//CHAINCODE SEC INTERFACE FUNCS TOBE IMPLEMENTED BY ANGELO
371378

‎core/chaincode/shim/interfaces.go

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ type ChaincodeStubInterface interface {
179179
// GetBinding returns the transaction binding
180180
GetBinding() ([]byte, error)
181181

182+
// GetDecorations returns additional data (if applicable)
183+
// about the proposal that originated from the peer
184+
GetDecorations() map[string][]byte
185+
182186
// GetSignedProposal returns the SignedProposal object, which contains all
183187
// data elements part of a transaction proposal.
184188
GetSignedProposal() (*pb.SignedProposal, error)

‎core/chaincode/shim/mockstub.go

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ func (stub *MockStub) MockInvoke(uuid string, args [][]byte) pb.Response {
134134
return res
135135
}
136136

137+
func (stub *MockStub) GetDecorations() map[string][]byte {
138+
return nil
139+
}
140+
137141
// Invoke this chaincode, also starts and ends a transaction.
138142
func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response {
139143
stub.args = args

‎core/chaincode/shim/shim_test.go

+18-19
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ import (
2424
"testing"
2525
"time"
2626

27+
"github.com/hyperledger/fabric/common/flogging"
2728
mockpeer "github.com/hyperledger/fabric/common/mocks/peer"
2829
"github.com/hyperledger/fabric/common/util"
2930
lproto "github.com/hyperledger/fabric/protos/ledger/queryresult"
3031
pb "github.com/hyperledger/fabric/protos/peer"
3132
"github.com/hyperledger/fabric/protos/utils"
32-
33-
"github.com/hyperledger/fabric/common/flogging"
3433
"github.com/op/go-logging"
3534
"github.com/spf13/viper"
3635
"github.com/stretchr/testify/assert"
@@ -585,7 +584,7 @@ func TestInvoke(t *testing.T) {
585584

586585
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY, Txid: "1"})
587586

588-
ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}}
587+
ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, nil}
589588
payload := utils.MarshalOrPanic(ci)
590589
respSet := &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{
591590
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}},
@@ -608,7 +607,7 @@ func TestInvoke(t *testing.T) {
608607
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3"}, nil}}}
609608
peerSide.SetResponses(respSet)
610609

611-
ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
610+
ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
612611
payload = utils.MarshalOrPanic(ci)
613612
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3"})
614613

@@ -623,7 +622,7 @@ func TestInvoke(t *testing.T) {
623622
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3a"}, nil}}}
624623
peerSide.SetResponses(respSet)
625624

626-
ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
625+
ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
627626
payload = utils.MarshalOrPanic(ci)
628627
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3a"})
629628

@@ -636,7 +635,7 @@ func TestInvoke(t *testing.T) {
636635
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3b"}, nil}}}
637636
peerSide.SetResponses(respSet)
638637

639-
ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
638+
ci = &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
640639
payload = utils.MarshalOrPanic(ci)
641640
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3b"})
642641

@@ -649,7 +648,7 @@ func TestInvoke(t *testing.T) {
649648
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4"}, nil}}}
650649
peerSide.SetResponses(respSet)
651650

652-
ci = &pb.ChaincodeInput{[][]byte{[]byte("delete"), []byte("A")}}
651+
ci = &pb.ChaincodeInput{[][]byte{[]byte("delete"), []byte("A")}, nil}
653652
payload = utils.MarshalOrPanic(ci)
654653
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "4"})
655654

@@ -662,7 +661,7 @@ func TestInvoke(t *testing.T) {
662661
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "4a"}, nil}}}
663662
peerSide.SetResponses(respSet)
664663

665-
ci = &pb.ChaincodeInput{[][]byte{[]byte("delete"), []byte("A")}}
664+
ci = &pb.ChaincodeInput{[][]byte{[]byte("delete"), []byte("A")}, nil}
666665
payload = utils.MarshalOrPanic(ci)
667666
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "4a"})
668667

@@ -674,7 +673,7 @@ func TestInvoke(t *testing.T) {
674673
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "5"}, nil}}}
675674
peerSide.SetResponses(respSet)
676675

677-
ci = &pb.ChaincodeInput{[][]byte{[]byte("badinvoke")}}
676+
ci = &pb.ChaincodeInput{[][]byte{[]byte("badinvoke")}, nil}
678677
payload = utils.MarshalOrPanic(ci)
679678
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "5"})
680679

@@ -700,7 +699,7 @@ func TestInvoke(t *testing.T) {
700699
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6"}, nil}}}
701700
peerSide.SetResponses(respSet)
702701

703-
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}}
702+
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil}
704703
payload = utils.MarshalOrPanic(ci)
705704
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6"})
706705

@@ -715,7 +714,7 @@ func TestInvoke(t *testing.T) {
715714
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6a"}, nil}}}
716715
peerSide.SetResponses(respSet)
717716

718-
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}}
717+
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil}
719718
payload = utils.MarshalOrPanic(ci)
720719
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6a"})
721720

@@ -732,7 +731,7 @@ func TestInvoke(t *testing.T) {
732731
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6b"}, nil}}}
733732
peerSide.SetResponses(respSet)
734733

735-
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}}
734+
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil}
736735
payload = utils.MarshalOrPanic(ci)
737736
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6b"})
738737

@@ -749,7 +748,7 @@ func TestInvoke(t *testing.T) {
749748
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "6c"}, nil}}}
750749
peerSide.SetResponses(respSet)
751750

752-
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}}
751+
ci = &pb.ChaincodeInput{[][]byte{[]byte("rangeq"), []byte("A"), []byte("B")}, nil}
753752
payload = utils.MarshalOrPanic(ci)
754753
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "6c"})
755754

@@ -771,7 +770,7 @@ func TestInvoke(t *testing.T) {
771770
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "7"}, nil}}}
772771
peerSide.SetResponses(respSet)
773772

774-
ci = &pb.ChaincodeInput{[][]byte{[]byte("historyq"), []byte("A")}}
773+
ci = &pb.ChaincodeInput{[][]byte{[]byte("historyq"), []byte("A")}, nil}
775774
payload = utils.MarshalOrPanic(ci)
776775
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "7"})
777776

@@ -786,7 +785,7 @@ func TestInvoke(t *testing.T) {
786785
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "7a"}, nil}}}
787786
peerSide.SetResponses(respSet)
788787

789-
ci = &pb.ChaincodeInput{[][]byte{[]byte("historyq"), []byte("A")}}
788+
ci = &pb.ChaincodeInput{[][]byte{[]byte("historyq"), []byte("A")}, nil}
790789
payload = utils.MarshalOrPanic(ci)
791790
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "7a"})
792791

@@ -812,7 +811,7 @@ func TestInvoke(t *testing.T) {
812811
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "8"}, nil}}}
813812
peerSide.SetResponses(respSet)
814813

815-
ci = &pb.ChaincodeInput{[][]byte{[]byte("richq"), []byte("A")}}
814+
ci = &pb.ChaincodeInput{[][]byte{[]byte("richq"), []byte("A")}, nil}
816815
payload = utils.MarshalOrPanic(ci)
817816
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "8"})
818817

@@ -826,7 +825,7 @@ func TestInvoke(t *testing.T) {
826825
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "8a"}, nil}}}
827826
peerSide.SetResponses(respSet)
828827

829-
ci = &pb.ChaincodeInput{[][]byte{[]byte("richq"), []byte("A")}}
828+
ci = &pb.ChaincodeInput{[][]byte{[]byte("richq"), []byte("A")}, nil}
830829
payload = utils.MarshalOrPanic(ci)
831830
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "8a"})
832831

@@ -907,7 +906,7 @@ func TestCC2CC(t *testing.T) {
907906

908907
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_READY, Txid: "1"})
909908

910-
ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}}
909+
ci := &pb.ChaincodeInput{[][]byte{[]byte("init"), []byte("A"), []byte("100"), []byte("B"), []byte("200")}, nil}
911910
payload := utils.MarshalOrPanic(ci)
912911
respSet := &mockpeer.MockResponseSet{errorFunc, errorFunc, []*mockpeer.MockResponse{
913912
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_PUT_STATE, Txid: "2"}, &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: "2"}},
@@ -929,7 +928,7 @@ func TestCC2CC(t *testing.T) {
929928
&mockpeer.MockResponse{&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_COMPLETED, Txid: "3"}, nil}}}
930929
peerSide.SetResponses(respSet)
931930

932-
ci = &pb.ChaincodeInput{[][]byte{[]byte("cc2cc"), []byte("othercc"), []byte("arg1"), []byte("arg2")}}
931+
ci = &pb.ChaincodeInput{[][]byte{[]byte("cc2cc"), []byte("othercc"), []byte("arg1"), []byte("arg2")}, nil}
933932
payload = utils.MarshalOrPanic(ci)
934933
peerSide.Send(&pb.ChaincodeMessage{Type: pb.ChaincodeMessage_TRANSACTION, Payload: payload, Txid: "3"})
935934

‎core/common/ccprovider/ccinfocache_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import (
2121
"bytes"
2222
"compress/gzip"
2323
"io/ioutil"
24+
"os"
2425
"path/filepath"
2526
"testing"
2627

27-
"os"
28-
2928
"github.com/golang/protobuf/proto"
3029
"github.com/hyperledger/fabric/core/container/util"
3130
"github.com/hyperledger/fabric/protos/peer"
@@ -221,7 +220,7 @@ func TestNewCCContext(t *testing.T) {
221220
NewCCContext("foo", "foo", "", "", false, nil, nil)
222221
}, "NewCCContext should have paniced if version is empty")
223222

224-
ccctx = &CCContext{"foo", "foo", "1.0", "", false, nil, nil, ""}
223+
ccctx = &CCContext{"foo", "foo", "1.0", "", false, nil, nil, "", nil}
225224
assert.Panics(t, func() {
226225
ccctx.GetCanonicalName()
227226
}, "GetConnonicalName should have paniced if cannonical name is empty")

‎core/common/ccprovider/ccprovider.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package ccprovider
1818

1919
import (
20+
"bytes"
2021
"context"
2122
"fmt"
2223
"io/ioutil"
@@ -25,9 +26,6 @@ import (
2526
"strings"
2627

2728
"github.com/golang/protobuf/proto"
28-
29-
"bytes"
30-
3129
"github.com/hyperledger/fabric/common/flogging"
3230
"github.com/hyperledger/fabric/core/ledger"
3331
pb "github.com/hyperledger/fabric/protos/peer"
@@ -345,6 +343,9 @@ type CCContext struct {
345343

346344
//this is not set but computed (note that this is not exported. use GetCanonicalName)
347345
canonicalName string
346+
347+
// this is additional data passed to the chaincode
348+
ProposalDecorations map[string][]byte
348349
}
349350

350351
//NewCCContext just construct a new struct with whatever args
@@ -358,7 +359,7 @@ func NewCCContext(cid, name, version, txid string, syscc bool, signedProp *pb.Si
358359

359360
canName := name + ":" + version
360361

361-
cccid := &CCContext{cid, name, version, txid, syscc, signedProp, prop, canName}
362+
cccid := &CCContext{cid, name, version, txid, syscc, signedProp, prop, canName, nil}
362363

363364
ccproviderLogger.Debugf("NewCCCC (chain=%s,chaincode=%s,version=%s,txid=%s,syscc=%t,proposal=%p,canname=%s", cid, name, version, txid, syscc, prop, cccid.canonicalName)
364365

‎core/endorser/endorser.go

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"github.com/hyperledger/fabric/core/chaincode/shim"
2222
"github.com/hyperledger/fabric/core/common/ccprovider"
2323
"github.com/hyperledger/fabric/core/common/validation"
24+
"github.com/hyperledger/fabric/core/handlers/decoration"
25+
"github.com/hyperledger/fabric/core/handlers/library"
2426
"github.com/hyperledger/fabric/core/ledger"
2527
"github.com/hyperledger/fabric/core/peer"
2628
"github.com/hyperledger/fabric/core/policy"
@@ -111,6 +113,12 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
111113

112114
cccid := ccprovider.NewCCContext(chainID, cid.Name, version, txid, scc, signedProp, prop)
113115

116+
// decorate the chaincode input
117+
decorator := library.InitRegistry(library.Config{}).Lookup(library.DecoratorKey).(decoration.Decorator)
118+
cis.ChaincodeSpec.Input.Decorations = make(map[string][]byte)
119+
cis.ChaincodeSpec.Input = decorator.Decorate(cis.ChaincodeSpec.Input)
120+
cccid.ProposalDecorations = cis.ChaincodeSpec.Input.Decorations
121+
114122
res, ccevent, err = chaincode.ExecuteChaincode(ctxt, cccid, cis.ChaincodeSpec.Input.Args)
115123

116124
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.