It is wrapper on fabric-sdk-go with different API to interact with.
It consists of 3 clients:
- Configuration client used for creating, joining channels, installing, instantiating chaincodes.
- User client used for invoking and querying transactions.
- Channel client. It is similar to user client but for one chaincode only.
go get -u github.com/halfest/fabric-client
There is difference in packing chaincode during it's installation between fabric-sdk-go and fabric peer cli. Former does not pack dependencies alongside with chaincode, so function
// Generates a deployment payload for GOLANG as a series of src/$pkg entries in .tar.gz format
func (goPlatform *Platform) GetDeploymentPayload(path string) ([]byte, error) {
from fabric peer cli was used.
import (
fabclient "github.com/halfest/fabric-client"
"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
)
logging.SetLevel("fabclient", logging.DEBUG)
fabricClient, err := fabclient.CreateFabricClient("config file for fabric-sdk-go", "orderer host")
// Must version is also available
configurationClient, err := fabricClient.CreateConfigurationClient("userName", "orgTitle")
// or without reuse of fabric client
configurationClient, err := fabclient.CreateConfigurationClient("config file for fabric-sdk-go", "orderer host", "userName", "orgTitle")
// Must versions is also available
err = configurationClient.CreateChannel("channelID", "pathToChannelTx")
// Must version is also available
err = configurationClient.JoinChannel("channelID")
// Must version is also available
err = configurationClient.InstallChaincode("chaincodeID", "chaincodePath", "chaincodeVersion")
// Must version is also available
err = configurationClient.InstanciateChaincode("channelID", "chaincodeID", "chaincodePath", "chaincodeVersion", [][]byte{[]byte("instantiate"), []byte("args")}, "chaincodePolicy")
// Must version is also available
userClient, err := fabricClient.CreateUserClient("userName", "orgTitle", "channelID")
// or without reuse of fabric client
userClient, err := fabclient.CreateUserClient("config file for fabric-sdk-go", "orderer host", "userName", "orgTitle", "channelID")
// Must versions is also available
response, err = userClient.Invoke("chaincodeID", "chaincodeMethod", [][]byte{[]byte("method"), []byte("args")})
// Must version is also available
response, err = userClient.Query("chaincodeID", "chaincodeMethod", [][]byte{[]byte("method"), []byte("args")})
// Must version is also available
response, err = userClient.QueryInt("chaincodeID", "chaincodeMethod", [][]byte{[]byte("method"), []byte("args")})
// Must version is also available
chaincodeClient, err := fabricClient.CreateChaincodeClient("channelID", "chaincodeID", "userName", "orgTitle")
// or without reuse of fabric client
chaincodeClient, err := fabclient.CreateChaincodeClient("config file for fabric-sdk-go", "orderer host", "channelID", "chaincodeID", "userName", "orgTitle")
// Must versions is also available
Chaincode client has the same methods as the user client but does not require chaincodeID
parameter