本文整理匯總了Golang中github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStub.InvokeChaincode方法的典型用法代碼示例。如果您正苦於以下問題:Golang ChaincodeStub.InvokeChaincode方法的具體用法?Golang ChaincodeStub.InvokeChaincode怎麽用?Golang ChaincodeStub.InvokeChaincode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hyperledger/fabric/core/chaincode/shim.ChaincodeStub
的用法示例。
在下文中一共展示了ChaincodeStub.InvokeChaincode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: add_number
//==============================================================================================================================
// Invoke Functions
//==============================================================================================================================
// add_number - Invokes the numbers chaincode and calls the function add_number, chaincode name currently hardcoded
//
//==============================================================================================================================
func (t *SimpleChaincode) add_number(stub *shim.ChaincodeStub, args []string) ([]byte, error) {
_, err := stub.InvokeChaincode("970000a712cf185274f39566276b18591c125ab41ee2674b3ccfeeed3e95a21b7129a4b97598e7807a362b345609caa8985f28f68e3a1614e0f12dcd99d3a589", "add_number", args)
if err != nil {
return nil, errors.New("Unable to invoke chaincode")
}
return nil, nil
}
示例2: Invoke
// Invoke invokes another chaincode - chaincode_example02, upon receipt of an event and changes event state
func (t *SimpleChaincode) Invoke(stub *shim.ChaincodeStub, function string, 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: iq
//helper
func (p *PassthruChaincode) iq(invoke bool, stub *shim.ChaincodeStub, function string, args []string) ([]byte, error) {
if function == "" {
return nil, errors.New("Chaincode ID not provided")
}
chaincodeID := function
var f string
var cargs []string
if len(args) > 0 {
f = args[0]
cargs = args[1:]
}
if invoke {
return stub.InvokeChaincode(chaincodeID, f, cargs)
}
return stub.QueryChaincode(chaincodeID, f, cargs)
}