本文整理汇总了Golang中github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub.InvokeChaincode方法的典型用法代码示例。如果您正苦于以下问题:Golang ChaincodeStub.InvokeChaincode方法的具体用法?Golang ChaincodeStub.InvokeChaincode怎么用?Golang ChaincodeStub.InvokeChaincode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openblockchain/obc-peer/openchain/chaincode/shim.ChaincodeStub
的用法示例。
在下文中一共展示了ChaincodeStub.InvokeChaincode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: create_log
//==============================================================================================================================
// create_log - Invokes the function of event_code chaincode with the name 'chaincodeName' to log an
// event.
//==============================================================================================================================
func (t *Chaincode) create_log(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
chaincode_name := "398f2e9a632d17bfc54f259f581818448a1f7b654901ce1648a66c36f0003b2ece440382e585d6b7dac8ee010f2b4fae29bda3135cf76d9c3895cacec1ffbeb4"
chaincode_function := "create_log"
chaincode_arguments := args
_, err := stub.InvokeChaincode(chaincode_name, chaincode_function, chaincode_arguments)
if err != nil {
return nil, errors.New("Failed to invoke vehicle_log_code")
}
return nil, nil
}
示例2: invoke
// Transaction invokes another chaincode and changes event state
func (t *SimpleChaincode) invoke(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
var event string // Event entity
var eventVal int // State of event
var err error
if len(args) != 2 {
return nil, errors.New("Incorrect number of arguments. Expecting 2")
}
event = args[0]
eventVal, err = strconv.Atoi(args[1])
if err != nil {
return nil, errors.New("Expected integer value for event state change")
}
if eventVal != 1 {
fmt.Printf("Unexpected event. Doing nothing\n")
return nil, nil
}
// Get the chaincode to call from the ledger
chainCodeToCall, err := t.getChaincodeToCall(stub)
if err != nil {
return nil, err
}
f := "invoke"
invokeArgs := []string{"a", "b", "10"}
response, err := stub.InvokeChaincode(chainCodeToCall, f, invokeArgs)
if err != nil {
errStr := fmt.Sprintf("Failed to invoke chaincode. Got error: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
fmt.Printf("Invoke chaincode successful. Got response %s", string(response))
// Write the event state back to the ledger
err = stub.PutState(event, []byte(strconv.Itoa(eventVal)))
if err != nil {
return nil, err
}
return nil, nil
}
示例3: invoke
// Transaction invokes another chaincode and changes event state
func (t *SimpleChaincode) invoke(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
var event string // Event entity
var eventVal int // State of event
var err error
if len(args) != 2 {
return nil, errors.New("Incorrect number of arguments. Expecting 2")
}
event = args[0]
eventVal, err = strconv.Atoi(args[1])
if err != nil {
return nil, errors.New("Expected integer value for event state change")
}
if eventVal != 1 {
fmt.Printf("Unexpected event. Doing nothing\n")
return nil, nil
}
// Invoke chaincode_example02 - assuming its URL and vesion are known
// Better coding will pass the chaincodeID's URL and version as arguments to this function (or to another function that stores it in the ledger state)
chaincodeUrl := "github.com/openblockchain/obc-peer/openchain/example/chaincode/chaincode_example02"
chaincodeVersion := "0.0.1"
f := "invoke"
invokeArgs := []string{"a", "b", "10"}
response, err := stub.InvokeChaincode(chaincodeUrl, chaincodeVersion, f, invokeArgs)
if err != nil {
errStr := fmt.Sprintf("Failed to invoke chaincode. Got error: %s", err.Error())
fmt.Printf(errStr)
return nil, errors.New(errStr)
}
fmt.Printf("Invoke chaincode successful. Got response %s", string(response))
// Write the event state back to the ledger
err = stub.PutState(event, []byte(strconv.Itoa(eventVal)))
if err != nil {
return nil, err
}
return nil, nil
}