// EXP_ExecuteWithBinding executes a transaction with a specific binding/TXHandler func (d *Devops) EXP_ExecuteWithBinding(ctx context.Context, executeWithBinding *pb.ExecuteWithBinding) (*pb.Response, error) { if d.isSecurityEnabled { devopsLogger.Debug("Getting TxHandler for binding") txHandler, err := d.bindingMap.getTxHandlerForBinding(executeWithBinding.Binding) if nil != err { return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte(err.Error())}, nil } ctorbytes, merr := asn1.Marshal(*executeWithBinding.ChaincodeInvocationSpec.ChaincodeSpec.CtorMsg) if merr != nil { return nil, fmt.Errorf("Error marshalling constructor: %s", err) } tid, generr := util.GenerateIDWithAlg("", ctorbytes) if generr != nil { return nil, fmt.Errorf("Error: cannot generate TX ID (executing with binding)") } tx, err := txHandler.NewChaincodeExecute(executeWithBinding.ChaincodeInvocationSpec, tid) if err != nil { return nil, fmt.Errorf("Error creating executing with binding: %s", err) } return d.coord.ExecuteTransaction(tx), nil //return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte("NOT IMPLEMENTED")}, nil //return &pb.Response{Status: pb.Response_SUCCESS, Msg: sigmaOutputBytes}, nil } devopsLogger.Warning("Security NOT enabled") return &pb.Response{Status: pb.Response_FAILURE, Msg: []byte("Security NOT enabled")}, nil }
func (d *Devops) invokeOrQuery(ctx context.Context, chaincodeInvocationSpec *pb.ChaincodeInvocationSpec, attributes []string, invoke bool) (*pb.Response, error) { if chaincodeInvocationSpec.ChaincodeSpec.ChaincodeID.Name == "" { return nil, fmt.Errorf("name not given for invoke/query") } // Now create the Transactions message and send to Peer. var customIDgenAlg = strings.ToLower(chaincodeInvocationSpec.IdGenerationAlg) var id string var generr error if customIDgenAlg != "" { id, generr = util.GenerateIDWithAlg(customIDgenAlg, chaincodeInvocationSpec.ChaincodeSpec.CtorMsg.Args[0]) if generr != nil { return nil, generr } } else { id = util.GenerateUUID() } devopsLogger.Infof("Transaction ID: %v", id) var transaction *pb.Transaction var err error var sec crypto.Client if peer.SecurityEnabled() { if devopsLogger.IsEnabledFor(logging.DEBUG) { devopsLogger.Debugf("Initializing secure devops using context %s", chaincodeInvocationSpec.ChaincodeSpec.SecureContext) } sec, err = crypto.InitClient(chaincodeInvocationSpec.ChaincodeSpec.SecureContext, nil) defer crypto.CloseClient(sec) // remove the security context since we are no longer need it down stream chaincodeInvocationSpec.ChaincodeSpec.SecureContext = "" if nil != err { return nil, err } } transaction, err = d.createExecTx(chaincodeInvocationSpec, attributes, id, invoke, sec) if err != nil { return nil, err } if devopsLogger.IsEnabledFor(logging.DEBUG) { devopsLogger.Debugf("Sending invocation transaction (%s) to validator", transaction.Uuid) } resp := d.coord.ExecuteTransaction(transaction) if resp.Status == pb.Response_FAILURE { err = fmt.Errorf(string(resp.Msg)) } else { if !invoke && nil != sec && viper.GetBool("security.privacy") { if resp.Msg, err = sec.DecryptQueryResult(transaction, resp.Msg); nil != err { devopsLogger.Errorf("Failed decrypting query transaction result %s", string(resp.Msg[:])) //resp = &pb.Response{Status: pb.Response_FAILURE, Msg: []byte(err.Error())} } } } return resp, err }