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

Function ChaincodeInvokeOrQuery

internal/peer/chaincode/common.go:481–584  ·  view source on GitHub ↗

ChaincodeInvokeOrQuery invokes or queries the chaincode. If successful, the INVOKE form prints the ProposalResponse to STDOUT, and the QUERY form prints the query result on STDOUT. A command-line flag (-r, --raw) determines whether the query result is output as raw bytes, or as a printable string. T

(
	spec *pb.ChaincodeSpec,
	cID string,
	txID string,
	invoke bool,
	signer identity.SignerSerializer,
	certificate tls.Certificate,
	endorserClients []pb.EndorserClient,
	deliverClients []pb.DeliverClient,
	bc common.BroadcastClient,
)

Source from the content-addressed store, hash-verified

479// NOTE - Query will likely go away as all interactions with the endorser are
480// Proposal and ProposalResponses
481func ChaincodeInvokeOrQuery(
482 spec *pb.ChaincodeSpec,
483 cID string,
484 txID string,
485 invoke bool,
486 signer identity.SignerSerializer,
487 certificate tls.Certificate,
488 endorserClients []pb.EndorserClient,
489 deliverClients []pb.DeliverClient,
490 bc common.BroadcastClient,
491) (*pb.ProposalResponse, error) {
492 // Build the ChaincodeInvocationSpec message
493 invocation := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
494
495 creator, err := signer.Serialize()
496 if err != nil {
497 return nil, errors.WithMessage(err, "error serializing identity")
498 }
499
500 funcName := "invoke"
501 if !invoke {
502 funcName = "query"
503 }
504
505 // extract the transient field if it exists
506 var tMap map[string][]byte
507 if transient != "" {
508 if err := json.Unmarshal([]byte(transient), &tMap); err != nil {
509 return nil, errors.Wrap(err, "error parsing transient string")
510 }
511 }
512
513 prop, txid, err := protoutil.CreateChaincodeProposalWithTxIDAndTransient(pcommon.HeaderType_ENDORSER_TRANSACTION, cID, invocation, creator, txID, tMap)
514 if err != nil {
515 return nil, errors.WithMessagef(err, "error creating proposal for %s", funcName)
516 }
517
518 signedProp, err := protoutil.GetSignedProposal(prop, signer)
519 if err != nil {
520 return nil, errors.WithMessagef(err, "error creating signed proposal for %s", funcName)
521 }
522
523 responses, err := processProposals(endorserClients, signedProp)
524 if err != nil {
525 return nil, errors.WithMessagef(err, "error endorsing %s", funcName)
526 }
527
528 if len(responses) == 0 {
529 // this should only happen if some new code has introduced a bug
530 return nil, errors.New("no proposal responses received - this might indicate a bug")
531 }
532 // all responses will be checked when the signed transaction is created.
533 // for now, just set this so we check the first response's status
534 proposalResp := responses[0]
535
536 if invoke {
537 if proposalResp != nil {
538 if proposalResp.Response.Status >= shim.ERRORTHRESHOLD {

Callers 2

chaincodeInvokeOrQueryFunction · 0.85

Calls 12

ConnectMethod · 0.95
WaitMethod · 0.95
GetSignedProposalFunction · 0.92
CreateSignedTxFunction · 0.92
processProposalsFunction · 0.85
NewDeliverGroupFunction · 0.85
WrapMethod · 0.80
SerializeMethod · 0.65
UnmarshalMethod · 0.65
NewMethod · 0.65
SendMethod · 0.65

Tested by 1