(cmd *cobra.Command, invoke bool, cf *ChaincodeCmdFactory)
| 83 | } |
| 84 | |
| 85 | func 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 | } |
no test coverage detected