fabric-samples/chaincode/fabcar/go
Mark S. Lewis 63cc77bdc3
Avoid usage of deprecated ioutil Go package (#843)
* Refactor Go files
1. replace deprecated ioutil functions (ioutil is deprecated since Go 1.16)
2. fix variable names that collide with imported package name
3. fix typos

Also update Go version specified by Go modules to ensure a Go version is used in which ioutil is deprecated and replacement functions are available in os and io packages.

Signed-off-by: Tommy TIAN <xtianae@connect.ust.hk>
Co-authored-by: Mark S. Lewis <mark_lewis@uk.ibm.com>

* Specify go 1.18 instead of go 1.19 in go.mod files

Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>

Signed-off-by: Tommy TIAN <xtianae@connect.ust.hk>
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
Co-authored-by: Tommy TIAN <xtianae@connect.ust.hk>
2022-10-25 07:04:39 -04:00
..
.dockerignore Update go chaincode samples 2022-10-18 15:28:20 -04:00
.gitignore Update go chaincode samples 2022-10-18 15:28:20 -04:00
chaincode.env.example Update go chaincode samples 2022-10-18 15:28:20 -04:00
Dockerfile Update go chaincode samples 2022-10-18 15:28:20 -04:00
fabcar.go modify query number in fabcar for golang 2020-06-19 13:09:45 -04:00
go.mod Avoid usage of deprecated ioutil Go package (#843) 2022-10-25 07:04:39 -04:00
go.sum Update go chaincode samples 2022-10-18 15:28:20 -04:00
metadata.json Update go chaincode samples 2022-10-18 15:28:20 -04:00
README.md Update go chaincode samples 2022-10-18 15:28:20 -04:00

FabCar as an external service

See the "Chaincode as an external service" documentation for running chaincode as an external service. This includes details of the external builder and launcher scripts which will peers in your Fabric network will require.

The FabCar chaincode requires two environment variables to run, CHAINCODE_SERVER_ADDRESS and CORE_CHAINCODE_ID_NAME, which are described in the chaincode.env.example file. Copy this file to chaincode.env before continuing.

Note: each organization in a Fabric network will need to follow the instructions below to host their own instance of the FabCar external service.

Packaging and installing

Make sure the value of CHAINCODE_SERVER_ADDRESS in chaincode.env is correct for the FabCar external service you will be running.

The peer needs a connection.json configuration file so that it can connect to the external FabCar service. Use the CHAINCODE_SERVER_ADDRESS value in chaincode.env to create the connection.json file with the following command (requires jq):

env $(cat chaincode.env | grep -v "#" | xargs) jq -n '{"address":env.CHAINCODE_SERVER_ADDRESS,"dial_timeout": "10s","tls_required": false}' > connection.json

Add this file to a code.tar.gz archive ready for adding to a FabCar external service package:

tar cfz code.tar.gz connection.json

Package the FabCar external service using the supplied metadata.json file:

tar cfz fabcar-pkg.tgz metadata.json code.tar.gz

Install the fabcar-pkg.tgz chaincode as usual, for example:

peer lifecycle chaincode install ./fabcar-pkg.tgz

Running the FabCar external service

To run the service in a container, build a FabCar docker image:

docker build -t hyperledger/fabcar-sample .

Edit the chaincode.env file to configure the CHAINCODE_ID variable before starting a FabCar container using the following command:

docker run -it --rm --name fabcar.org1.example.com --hostname fabcar.org1.example.com --env-file chaincode.env --network=net_test hyperledger/fabcar-sample

Starting the FabCar external service

Complete the remaining lifecycle steps to start the FabCar chaincode!