本文整理匯總了Golang中github.com/hyperledger/fabric/protos.NewChaincodeExecute函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewChaincodeExecute函數的具體用法?Golang NewChaincodeExecute怎麽用?Golang NewChaincodeExecute使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewChaincodeExecute函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: invoke
// Invoke or query a chaincode.
func invoke(ctx context.Context, spec *pb.ChaincodeSpec, typ pb.Transaction_Type) (*pb.ChaincodeEvent, string, []byte, error) {
chaincodeInvocationSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: spec}
// Now create the Transactions message and send to Peer.
uuid := util.GenerateUUID()
var transaction *pb.Transaction
var err error
transaction, err = pb.NewChaincodeExecute(chaincodeInvocationSpec, uuid, typ)
if err != nil {
return nil, uuid, nil, fmt.Errorf("Error invoking chaincode: %s ", err)
}
var retval []byte
var execErr error
var ccevt *pb.ChaincodeEvent
if typ == pb.Transaction_CHAINCODE_QUERY {
retval, ccevt, execErr = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
} else {
ledger, _ := ledger.GetLedger()
ledger.BeginTxBatch("1")
retval, ccevt, execErr = chaincode.Execute(ctx, chaincode.GetChain(chaincode.DefaultChain), transaction)
if err != nil {
return nil, uuid, nil, fmt.Errorf("Error invoking chaincode: %s ", err)
}
ledger.CommitTxBatch("1", []*pb.Transaction{transaction}, nil, nil)
}
return ccevt, uuid, retval, execErr
}
示例2: createExecTx
func (d *Devops) createExecTx(spec *pb.ChaincodeInvocationSpec, attributes []string, uuid string, invokeTx bool, sec crypto.Client) (*pb.Transaction, error) {
var tx *pb.Transaction
var err error
//TODO What should we do with the attributes
if nil != sec {
if devopsLogger.IsEnabledFor(logging.DEBUG) {
devopsLogger.Debugf("Creating secure invocation transaction %s", uuid)
}
if invokeTx {
tx, err = sec.NewChaincodeExecute(spec, uuid, attributes...)
} else {
tx, err = sec.NewChaincodeQuery(spec, uuid, attributes...)
}
if nil != err {
return nil, err
}
} else {
if devopsLogger.IsEnabledFor(logging.DEBUG) {
devopsLogger.Debugf("Creating invocation transaction (%s)", uuid)
}
var t pb.Transaction_Type
if invokeTx {
t = pb.Transaction_CHAINCODE_INVOKE
} else {
t = pb.Transaction_CHAINCODE_QUERY
}
tx, err = pb.NewChaincodeExecute(spec, uuid, t)
if nil != err {
return nil, err
}
}
return tx, nil
}
示例3: createTransaction
func createTransaction(invokeTx bool, spec *pb.ChaincodeInvocationSpec, uuid string) (*pb.Transaction, error) {
var tx *pb.Transaction
var err error
var sec crypto.Client
if nil != sec {
sec, err = crypto.InitClient(spec.ChaincodeSpec.SecureContext, nil)
defer crypto.CloseClient(sec)
if nil != err {
return nil, err
}
if invokeTx {
tx, err = sec.NewChaincodeExecute(spec, uuid)
} else {
tx, err = sec.NewChaincodeQuery(spec, uuid)
}
if nil != err {
return nil, err
}
} else {
var t pb.Transaction_Type
if invokeTx {
t = pb.Transaction_CHAINCODE_INVOKE
} else {
t = pb.Transaction_CHAINCODE_QUERY
}
tx, err = pb.NewChaincodeExecute(spec, uuid, t)
if nil != err {
return nil, err
}
}
return tx, nil
}
示例4: createQueryTx
func (client *clientImpl) createQueryTx(chaincodeInvocation *obc.ChaincodeInvocationSpec, uuid string, nonce []byte, tCert tCert, attrs ...string) (*obc.Transaction, error) {
// Create a new transaction
tx, err := obc.NewChaincodeExecute(chaincodeInvocation, uuid, obc.Transaction_CHAINCODE_QUERY)
if err != nil {
client.Errorf("Failed creating new transaction [%s].", err.Error())
return nil, err
}
// Copy metadata from ChaincodeSpec
tx.Metadata, err = getMetadata(chaincodeInvocation.GetChaincodeSpec(), tCert, attrs...)
if err != nil {
client.Errorf("Failed creating new transaction [%s].", err.Error())
return nil, err
}
if nonce == nil {
tx.Nonce, err = primitives.GetRandomNonce()
if err != nil {
client.Errorf("Failed creating nonce [%s].", err.Error())
return nil, err
}
} else {
// TODO: check that it is a well formed nonce
tx.Nonce = nonce
}
// Handle confidentiality
if chaincodeInvocation.ChaincodeSpec.ConfidentialityLevel == obc.ConfidentialityLevel_CONFIDENTIAL {
// 1. set confidentiality level and nonce
tx.ConfidentialityLevel = obc.ConfidentialityLevel_CONFIDENTIAL
// 2. set confidentiality protocol version
tx.ConfidentialityProtocolVersion = client.conf.GetConfidentialityProtocolVersion()
// 3. encrypt tx
err = client.encryptTx(tx)
if err != nil {
client.Errorf("Failed encrypting payload [%s].", err.Error())
return nil, err
}
}
return tx, nil
}
示例5: createConfidentialECertHQueryTransaction
func createConfidentialECertHQueryTransaction(t *testing.T) (*obc.Transaction, *obc.Transaction, error) {
uuid := util.GenerateUUID()
cis := &obc.ChaincodeInvocationSpec{
ChaincodeSpec: &obc.ChaincodeSpec{
Type: obc.ChaincodeSpec_GOLANG,
ChaincodeID: &obc.ChaincodeID{Path: "Contract001"},
CtorMsg: nil,
ConfidentialityLevel: obc.ConfidentialityLevel_CONFIDENTIAL,
},
}
otx, err := obc.NewChaincodeExecute(cis, uuid, obc.Transaction_CHAINCODE_QUERY)
if err != nil {
return nil, nil, err
}
handler, err := invoker.GetEnrollmentCertificateHandler()
if err != nil {
return nil, nil, err
}
txHandler, err := handler.GetTransactionHandler()
if err != nil {
return nil, nil, err
}
tx, err := txHandler.NewChaincodeQuery(cis, uuid)
// Check binding consistency
binding, _ := txHandler.GetBinding()
if !reflect.DeepEqual(binding, primitives.Hash(append(handler.GetCertificate(), tx.Nonce...))) {
t.Fatal("Binding is malformed!")
}
// Check confidentiality level
if tx.ConfidentialityLevel != cis.ChaincodeSpec.ConfidentialityLevel {
t.Fatal("Failed setting confidentiality level")
}
// Check metadata
if !reflect.DeepEqual(cis.ChaincodeSpec.Metadata, tx.Metadata) {
t.Fatal("Failed copying metadata")
}
return otx, tx, err
}
示例6: createPublicQueryTransaction
func createPublicQueryTransaction(t *testing.T) (*obc.Transaction, *obc.Transaction, error) {
uuid := util.GenerateUUID()
cis := &obc.ChaincodeInvocationSpec{
ChaincodeSpec: &obc.ChaincodeSpec{
Type: obc.ChaincodeSpec_GOLANG,
ChaincodeID: &obc.ChaincodeID{Path: "Contract001"},
CtorMsg: nil,
ConfidentialityLevel: obc.ConfidentialityLevel_PUBLIC,
},
}
otx, err := obc.NewChaincodeExecute(cis, uuid, obc.Transaction_CHAINCODE_QUERY)
if err != nil {
return nil, nil, err
}
tx, err := invoker.NewChaincodeQuery(cis, uuid)
return otx, tx, err
}