MCPcopy
hub / github.com/hyperledger/fabric / chaincodeInvokeOrQuery

Function chaincodeInvokeOrQuery

internal/peer/chaincode/common.go:85–146  ·  view source on GitHub ↗
(cmd *cobra.Command, invoke bool, cf *ChaincodeCmdFactory)

Source from the content-addressed store, hash-verified

83}
84
85func chaincodeInvokeOrQuery(cmd *cobra.Command, invoke bool, cf *ChaincodeCmdFactory) (err error) {
86 spec, err := getChaincodeSpec(cmd)
87 if err != nil {
88 return err
89 }
90
91 // call with empty txid to ensure production code generates a txid.
92 // otherwise, tests can explicitly set their own txid
93 txID := ""
94
95 proposalResp, err := ChaincodeInvokeOrQuery(
96 spec,
97 channelID,
98 txID,
99 invoke,
100 cf.Signer,
101 cf.Certificate,
102 cf.EndorserClients,
103 cf.DeliverClients,
104 cf.BroadcastClient,
105 )
106 if err != nil {
107 return errors.Errorf("%s - proposal response: %v", err, proposalResp)
108 }
109
110 if invoke {
111 logger.Debugf("ESCC invoke result: %v", proposalResp)
112 pRespPayload, err := protoutil.UnmarshalProposalResponsePayload(proposalResp.Payload)
113 if err != nil {
114 return errors.WithMessage(err, "error while unmarshalling proposal response payload")
115 }
116 ca, err := protoutil.UnmarshalChaincodeAction(pRespPayload.Extension)
117 if err != nil {
118 return errors.WithMessage(err, "error while unmarshalling chaincode action")
119 }
120 if proposalResp.Endorsement == nil {
121 return errors.Errorf("endorsement failure during invoke. response: %v", proposalResp.Response)
122 }
123 logger.Infof("Chaincode invoke successful. result: %v", ca.Response)
124 } else {
125 if proposalResp == nil {
126 return errors.New("error during query: received nil proposal response")
127 }
128 if proposalResp.Endorsement == nil {
129 return errors.Errorf("endorsement failure during query. response: %v", proposalResp.Response)
130 }
131
132 if chaincodeQueryRaw && chaincodeQueryHex {
133 return fmt.Errorf("options --raw (-r) and --hex (-x) are not compatible")
134 }
135 if chaincodeQueryRaw {
136 fmt.Println(proposalResp.Response.Payload)
137 return nil
138 }
139 if chaincodeQueryHex {
140 fmt.Printf("%x\n", proposalResp.Response.Payload)
141 return nil
142 }

Callers 2

chaincodeQueryFunction · 0.85
chaincodeInvokeFunction · 0.85

Calls 8

UnmarshalChaincodeActionFunction · 0.92
getChaincodeSpecFunction · 0.85
ChaincodeInvokeOrQueryFunction · 0.85
DebugfMethod · 0.80
ErrorfMethod · 0.65
InfofMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected