github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/test/tools/LTE/chainmgmt/tx_envelope_gen.go (about) 1 /* 2 Copyright IBM Corp. 2017 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package chainmgmt 18 19 import ( 20 mockmsp "github.com/hyperledger/fabric/common/mocks/msp" 21 "github.com/hyperledger/fabric/msp" 22 "github.com/hyperledger/fabric/protos/common" 23 pb "github.com/hyperledger/fabric/protos/peer" 24 putils "github.com/hyperledger/fabric/protos/utils" 25 ) 26 27 const ( 28 dummyChainID = "myChain" 29 dummyCCName = "myChaincode" 30 useDummyProposal = true 31 ) 32 33 var ( 34 dummyCCID = &pb.ChaincodeID{Name: dummyCCName, Version: "v1"} 35 dummyProposal *pb.Proposal 36 mspLcl msp.MSP 37 signer msp.SigningIdentity 38 serializedSigner []byte 39 ) 40 41 func init() { 42 mspLcl = mockmsp.NewNoopMsp() 43 signer, _ = mspLcl.GetDefaultSigningIdentity() 44 serializedSigner, _ = signer.Serialize() 45 46 dummyProposal, _, _ = putils.CreateChaincodeProposal( 47 common.HeaderType_ENDORSER_TRANSACTION, dummyChainID, 48 &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: dummyCCID}}, 49 serializedSigner) 50 } 51 52 func createTxEnv(simulationResults []byte) (*common.Envelope, error) { 53 var prop *pb.Proposal 54 var err error 55 if useDummyProposal { 56 prop = dummyProposal 57 } else { 58 prop, _, err = putils.CreateChaincodeProposal( 59 common.HeaderType_ENDORSER_TRANSACTION, 60 dummyChainID, 61 &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{ChaincodeId: dummyCCID}}, 62 serializedSigner) 63 if err != nil { 64 return nil, err 65 } 66 } 67 presp, err := putils.CreateProposalResponse(prop.Header, prop.Payload, nil, simulationResults, nil, dummyCCID, nil, signer) 68 if err != nil { 69 return nil, err 70 } 71 72 env, err := putils.CreateSignedTx(prop, signer, presp) 73 if err != nil { 74 return nil, err 75 } 76 return env, nil 77 }