Skip to content

Commit

Permalink
Merge "[FAB-4207] Auth handlers - take II - Part II"
Browse files Browse the repository at this point in the history
  • Loading branch information
Srinivasan Muralidharan authored and Gerrit Code Review committed Aug 12, 2017
2 parents 20b61a9 + 8af2a90 commit 7a3ccc0
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 74 deletions.
17 changes: 8 additions & 9 deletions core/chaincode/chaincode_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ import (
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/policy"
"github.com/hyperledger/fabric/core/scc"
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
plgr "github.com/hyperledger/fabric/protos/ledger/queryresult"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"
"golang.org/x/net/context"

mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
)

var globalBlockNum map[string]uint64
Expand Down Expand Up @@ -346,7 +345,7 @@ func initializeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCC
}

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

txid := util.GenerateUUID()
Expand Down Expand Up @@ -397,7 +396,7 @@ func invokeCC(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCComm)
}

chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
txid := util.GenerateUUID()
ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid)
Expand Down Expand Up @@ -444,7 +443,7 @@ func getQueryStateByRange(t *testing.T, chainID, ccname string, ccSide *mockpeer
}

chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
txid := util.GenerateUUID()
ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid)
Expand Down Expand Up @@ -491,7 +490,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock
}

chaincodeID := &pb.ChaincodeID{Name: calledCC, Version: "0"}
ci := &pb.ChaincodeInput{[][]byte{[]byte("deploycc")}}
ci := &pb.ChaincodeInput{[][]byte{[]byte("deploycc")}, nil}
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
txid := util.GenerateUUID()
//first deploy the new cc to LSCC
Expand All @@ -505,7 +504,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock

//now do the cc2cc
chaincodeID = &pb.ChaincodeID{Name: ccname, Version: "0"}
ci = &pb.ChaincodeInput{[][]byte{[]byte("invokecc")}}
ci = &pb.ChaincodeInput{[][]byte{[]byte("invokecc")}, nil}
cis = &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
txid = util.GenerateUUID()
ctxt, txsim, sprop, prop = startTx(t, chainID, cis, txid)
Expand Down Expand Up @@ -543,7 +542,7 @@ func getQueryResult(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockC
}

chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
txid := util.GenerateUUID()
ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid)
Expand Down Expand Up @@ -594,7 +593,7 @@ func getHistory(t *testing.T, chainID, ccname string, ccSide *mockpeer.MockCCCom
}

chaincodeID := &pb.ChaincodeID{Name: ccname, Version: "0"}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}}
ci := &pb.ChaincodeInput{[][]byte{[]byte("invoke"), []byte("A"), []byte("B"), []byte("10")}, nil}
cis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value["GOLANG"]), ChaincodeId: chaincodeID, Input: ci}}
txid := util.GenerateUUID()
ctxt, txsim, sprop, prop := startTx(t, chainID, cis, txid)
Expand Down
2 changes: 2 additions & 0 deletions core/chaincode/exectransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}
return nil, nil, fmt.Errorf("%s", err)
}

cMsg.Decorations = cccid.ProposalDecorations

var ccMsg *pb.ChaincodeMessage
ccMsg, err = createCCMessage(cctyp, cccid.TxID, cMsg)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions core/chaincode/shim/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type ChaincodeStub struct {
creator []byte
transient map[string][]byte
binding []byte

decorations map[string][]byte
}

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

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

func (stub *ChaincodeStub) GetDecorations() map[string][]byte {
return stub.decorations
}

// --------- Security functions ----------
//CHAINCODE SEC INTERFACE FUNCS TOBE IMPLEMENTED BY ANGELO

Expand Down
4 changes: 4 additions & 0 deletions core/chaincode/shim/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ type ChaincodeStubInterface interface {
// GetBinding returns the transaction binding
GetBinding() ([]byte, error)

// GetDecorations returns additional data (if applicable)
// about the proposal that originated from the peer
GetDecorations() map[string][]byte

// GetSignedProposal returns the SignedProposal object, which contains all
// data elements part of a transaction proposal.
GetSignedProposal() (*pb.SignedProposal, error)
Expand Down
4 changes: 4 additions & 0 deletions core/chaincode/shim/mockstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (stub *MockStub) MockInvoke(uuid string, args [][]byte) pb.Response {
return res
}

func (stub *MockStub) GetDecorations() map[string][]byte {
return nil
}

// Invoke this chaincode, also starts and ends a transaction.
func (stub *MockStub) MockInvokeWithSignedProposal(uuid string, args [][]byte, sp *pb.SignedProposal) pb.Response {
stub.args = args
Expand Down
37 changes: 18 additions & 19 deletions core/chaincode/shim/shim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/common/flogging"
mockpeer "github.com/hyperledger/fabric/common/mocks/peer"
"github.com/hyperledger/fabric/common/util"
lproto "github.com/hyperledger/fabric/protos/ledger/queryresult"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"

"github.com/hyperledger/fabric/common/flogging"
"github.com/op/go-logging"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -585,7 +584,7 @@ func TestInvoke(t *testing.T) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down
5 changes: 2 additions & 3 deletions core/common/ccprovider/ccinfocache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import (
"bytes"
"compress/gzip"
"io/ioutil"
"os"
"path/filepath"
"testing"

"os"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/container/util"
"github.com/hyperledger/fabric/protos/peer"
Expand Down Expand Up @@ -221,7 +220,7 @@ func TestNewCCContext(t *testing.T) {
NewCCContext("foo", "foo", "", "", false, nil, nil)
}, "NewCCContext should have paniced if version is empty")

ccctx = &CCContext{"foo", "foo", "1.0", "", false, nil, nil, ""}
ccctx = &CCContext{"foo", "foo", "1.0", "", false, nil, nil, "", nil}
assert.Panics(t, func() {
ccctx.GetCanonicalName()
}, "GetConnonicalName should have paniced if cannonical name is empty")
Expand Down
9 changes: 5 additions & 4 deletions core/common/ccprovider/ccprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package ccprovider

import (
"bytes"
"context"
"fmt"
"io/ioutil"
Expand All @@ -25,9 +26,6 @@ import (
"strings"

"github.com/golang/protobuf/proto"

"bytes"

"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/core/ledger"
pb "github.com/hyperledger/fabric/protos/peer"
Expand Down Expand Up @@ -345,6 +343,9 @@ type CCContext struct {

//this is not set but computed (note that this is not exported. use GetCanonicalName)
canonicalName string

// this is additional data passed to the chaincode
ProposalDecorations map[string][]byte
}

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

canName := name + ":" + version

cccid := &CCContext{cid, name, version, txid, syscc, signedProp, prop, canName}
cccid := &CCContext{cid, name, version, txid, syscc, signedProp, prop, canName, nil}

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)

Expand Down
8 changes: 8 additions & 0 deletions core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/common/validation"
"github.com/hyperledger/fabric/core/handlers/decoration"
"github.com/hyperledger/fabric/core/handlers/library"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/policy"
Expand Down Expand Up @@ -111,6 +113,12 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s

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

// decorate the chaincode input
decorator := library.InitRegistry(library.Config{}).Lookup(library.DecoratorKey).(decoration.Decorator)
cis.ChaincodeSpec.Input.Decorations = make(map[string][]byte)
cis.ChaincodeSpec.Input = decorator.Decorate(cis.ChaincodeSpec.Input)
cccid.ProposalDecorations = cis.ChaincodeSpec.Input.Decorations

res, ccevent, err = chaincode.ExecuteChaincode(ctxt, cccid, cis.ChaincodeSpec.Input.Args)

if err != nil {
Expand Down
Loading

0 comments on commit 7a3ccc0

Please sign in to comment.