From c86e6e7edcb2f935d82508cd46568eebc0cc64e4 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Fri, 16 Aug 2024 12:34:52 +0100 Subject: [PATCH] [WIP] Add developing chaincode tutorial See #127 Signed-off-by: James Taylor --- docs/tutorials/develop-chaincode.md | 56 +++++++++++++++++++++++++++++ mkdocs.yml | 1 + samples/go-contract/ccaas.env | 24 +++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 docs/tutorials/develop-chaincode.md create mode 100644 samples/go-contract/ccaas.env diff --git a/docs/tutorials/develop-chaincode.md b/docs/tutorials/develop-chaincode.md new file mode 100644 index 0000000..82ce33b --- /dev/null +++ b/docs/tutorials/develop-chaincode.md @@ -0,0 +1,56 @@ +# Developing and debuging chaincode + +TODO: Check chaincode/contract api implementations all support automatic switching between client and server mode... +- [Go contracts](https://github.com/hyperledger/fabric-contract-api-go/commit/7c7666d5dd3bdc23ace194784d123697669a3558)✅ +- Java (tbc) +- Node (tbc) + + +Use ccaas.env file? Might be easier to set chaincode ID outside file? + +``` +# CHAINCODE_SERVER_ADDRESS must be set to the host and port where the peer can +# connect to the chaincode server +CHAINCODE_SERVER_ADDRESS= + +# CHAINCODE_ID must be set to the Package ID that is assigned to the chaincode +# on install. The `peer lifecycle chaincode queryinstalled` command can be +# used to get the ID after install if required +CHAINCODE_ID= + +# Optional parameters that will be used for TLS connection between peer node +# and the chaincode. +# TLS is disabled by default, uncomment the following line to enable TLS connection +# CHAINCODE_TLS_DISABLED=false + +# Following variables will be ignored if TLS is not enabled. +# They need to be in PEM format +# CHAINCODE_TLS_KEY=/path/to/private/key/file +# CHAINCODE_TLS_CERT=/path/to/public/cert/file + +# The following variable will be used by the chaincode server to verify the +# connection from the peer node. +# Note that when this is set a single chaincode server cannot be shared +# across organizations unless their root CA is same. +# CHAINCODE_CLIENT_CA_CERT=/path/to/peer/organization/root/ca/cert/file +``` + +Run the chaincode... use docker? What networking would be required to get to peer inside k8s test network? + +``` +docker pull ghcr.io/hyperledger-labs/fabric-builder-k8s/sample-go-contract:latest +docker pull ghcr.io/hyperledger-labs/fabric-builder-k8s/sample-node-contract:latest +docker pull ghcr.io/hyperledger-labs/fabric-builder-k8s/sample-java-contract:latest +``` + +``` +docker run -it --rm --name sample-contract --env-file ccaas.env ghcr.io/hyperledger-labs/fabric-builder-k8s/sample-go-contract +``` + +TBC, that seemed to run the peer!!! + +Maybe don't use docker! :) + +See also: +- https://github.com/hyperledger/fabric-samples/blob/main/full-stack-asset-transfer-guide/docs/SmartContractDev/03-Test-And-Debug-Reference.md + diff --git a/mkdocs.yml b/mkdocs.yml index 6639e00..69be1d9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -107,4 +107,5 @@ nav: - Kubernetes namespace: configuring/kubernetes-namespace.md - Kubernetes service account: configuring/kubernetes-service-account.md - Tutorials: + - Developing and debuging chaincode: tutorials/develop-chaincode.md - Creating a chaincode package: tutorials/package-chaincode.md diff --git a/samples/go-contract/ccaas.env b/samples/go-contract/ccaas.env new file mode 100644 index 0000000..e6ea44a --- /dev/null +++ b/samples/go-contract/ccaas.env @@ -0,0 +1,24 @@ +# CHAINCODE_SERVER_ADDRESS must be set to the host and port where the peer can +# connect to the chaincode server +CHAINCODE_SERVER_ADDRESS=localhost + +# CHAINCODE_ID must be set to the Package ID that is assigned to the chaincode +# on install. The `peer lifecycle chaincode queryinstalled` command can be +# used to get the ID after install if required +CHAINCODE_ID=test + +# Optional parameters that will be used for TLS connection between peer node +# and the chaincode. +# TLS is disabled by default, uncomment the following line to enable TLS connection +# CHAINCODE_TLS_DISABLED=false + +# Following variables will be ignored if TLS is not enabled. +# They need to be in PEM format +# CHAINCODE_TLS_KEY=/path/to/private/key/file +# CHAINCODE_TLS_CERT=/path/to/public/cert/file + +# The following variable will be used by the chaincode server to verify the +# connection from the peer node. +# Note that when this is set a single chaincode server cannot be shared +# across organizations unless their root CA is same. +# CHAINCODE_CLIENT_CA_CERT=/path/to/peer/organization/root/ca/cert/file