Skip to content

Instantly share code, notes, and snippets.

@dolanor
Created February 20, 2017 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolanor/17161d8cfafb666b667da82aa729e963 to your computer and use it in GitHub Desktop.
Save dolanor/17161d8cfafb666b667da82aa729e963 to your computer and use it in GitHub Desktop.
Query some HyperLedger chaincode from Go
package main
import (
"fmt"
"github.com/hyperledger/fabric/peer/chaincode"
pb "github.com/hyperledger/fabric/protos/peer"
)
func main() {
chainID := "mychannel"
var err error
if err != nil {
panic(err)
}
ccInput := &pb.ChaincodeInput{
Args: [][]byte{
[]byte("a"),
[]byte("b"),
[]byte("100"),
},
}
for _, v := range ccInput.Args {
fmt.Println(string(v))
}
spec := &pb.ChaincodeSpec{
Type: 1,
ChaincodeId: &pb.ChaincodeID{Path: "github.com/hyperledger/fabric/examples/chaincode/go/chaincode02", Name: "hash chaincode", Version: "used in deploy"},
Input: ccInput,
}
cf, err := chaincode.InitCmdFactory()
if err != nil {
panic(err)
}
rsp, err := chaincode.ChaincodeInvokeOrQuery(spec, chainID, false, cf.Signer, cf.EndorserClient, cf.BroadcastClient)
if err != nil {
panic(err)
}
fmt.Printf("rsp = %+v\n", rsp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment