feat: Add Go implementation of full-stack-asset-transfer-guide smart contract (#1376) - #1391
feat: Add Go implementation of full-stack-asset-transfer-guide smart contract (#1376)#1391nXtCyberNet wants to merge 12 commits into
Conversation
60894c9 to
2d376f1
Compare
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
…-transfer-go Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
f4133c1 to
b17085b
Compare
bestbeforetoday
left a comment
There was a problem hiding this comment.
Thank you for the work you have put into this and apologies for not reviewing sooner.
The vars YAML and Docker related files are for the cloud deployment portions. The Go version of the contract is not (yet) hooked into them so they are not necessary. However, I don't object to them being there as reference.
See inline comments where things need to be changed.
The biggest gap in this change is that it is not integrated into the workshop workflow or documentation at all. At a minimum it needs to be included in the automated test of the appdev flow. See the test-appdev target in the justfile and the tests/10-appdev-e2e.sh that it calls.
I would probably rename tests/10-appdev-e2e.sh to something like tests/10-appdev-typescript-e2e.sh and add a similar tests/10-appdev-go-e2e.sh. The justfile could have test-appdev-typescript and test-appdev-go targets. These can then be invoked by the automated build defined in .github/workflows/test-fsat.yaml.
| contractapi.Contract | ||
| } | ||
|
|
||
| func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface, id string, color string, size int, owner string, appraisedValue int) error { |
There was a problem hiding this comment.
This has the wrong number of parameters. It needs to match the TypeScript implementation, which takes a single parameter (in addition to the context) of type Asset.
|
|
||
| // UpdateAsset updates color, size, and appraised value of an existing asset. | ||
| // The asset owner cannot be changed here; use TransferAsset instead. | ||
| func (s *SmartContract) UpdateAsset(ctx contractapi.TransactionContextInterface, id string, color string, size int, appraisedValue int) error { |
There was a problem hiding this comment.
This has the wrong number of parameters. It needs to match the TypeScript implementation, which takes a single parameter (in addition to the context) of type Asset.
| log.Panicf("Error creating asset-transfer chaincode: %v", err) | ||
| } | ||
|
|
||
| if err := assetChaincode.Start(); err != nil { |
There was a problem hiding this comment.
The workshop uses chaincode as an external service to allow the smart contract to be started/stopped and modified without redeployment to Fabric. What you have here should work without modification but certain environment variables need to be set correctly:
CORE_CHAINCODE_ID_NAMEset to the value of theCHAINCODE_IDenvironment variable that is defined by the org env context scripts.CORE_CHAINCODE_SERVER_ADDRESSset to the value of theCHAINCODE_SERVER_ADDRESSenvironment that is defined by the org env context scripts.
Essentially the chaincode containing the asset transfer smart contract is run from the asset-transfer-go directory as:
CORE_CHAINCODE_ID_NAME=${CHAINCODE_ID} \
CORE_CHAINCODE_SERVER_ADDRESS=${CHAINCODE_SERVER_ADDRESS} \
go run ./srcThis needs to be documented somewhere.
| "typescript-eslint": "^8.56.1", | ||
| "vitest": "^4.0.18" |
There was a problem hiding this comment.
This should not have been changed. Vitest is not used.
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
- Add doc comment to test-appdev-go recipe (prevents ambiguous context-line merge that caused 'recipe redefined' error in CI merge commit) - Add debugcc-go recipe targeting contracts/asset-transfer-go so the Go e2e test installs the Go chaincode rather than the TypeScript one - Update tests/10-appdev-go-e2e.sh to call 'just debugcc-go' instead of 'just debugcc', and fix missing trailing newline (POSIX violation) - Update .github/workflows/test-fsat.yaml: rename appdev job to appdev-typescript (calls just test-appdev-typescript) and add a new appdev-go job (calls just test-appdev-go) — the old 'just test-appdev' recipe no longer exists and would cause CI to fail Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
da7e16e to
d2b9a00
Compare
Signed-off-by: Rohan Dev <86916212+nXtCyberNet@users.noreply.github.com>
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
GitHub Actions silently ignores the entire workflow file when two jobs
share the same ID. The appdev-go job was defined twice:
- first at line 34 (old, using checkout@v6, no Go setup)
- again at line 43 (newer, using checkout@v7, referencing a
non-existent applications/trader-go/go.mod path)
Fix: keep a single appdev-go job that:
- uses actions/checkout@v7 (consistent with all other jobs)
- sets up Go via actions/setup-go@v5 reading the go.mod from the
actual chaincode location (contracts/asset-transfer-go/go.mod)
- runs just test-appdev-go in full-stack-asset-transfer-guide
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
The justfile had two definitions of test-appdev-go: - line 115 → tests/10-appdev-go-e2e.sh (stale, used TypeScript client) - line 119 → tests/10-appdev-e2e-go.sh (newer, used Go trader-go client) just errors on any duplicate recipe, causing ALL recipes (including test-ansible, test-chaincode etc.) to fail immediately. Changes: - Remove stale tests/10-appdev-go-e2e.sh (was using trader-typescript) - Remove the first duplicate test-appdev-go recipe from justfile - Fix tests/10-appdev-e2e-go.sh to use debugcc-go + Go chaincode server (go run ./src) instead of debugcc + TypeScript chaincode server Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
|
Hi @bestbeforetoday, could I get a review? As far as I understand, the CI failures were due to flakiness. |
Title: feat: add Go smart contract for full-stack-asset-transfer-guide
Closes: #1376
Summary
This PR adds a Go implementation of the full-stack-asset-transfer-guide smart contract, equivalent to the existing TypeScript contract in
asset-transfer-typescript. It allows developers who prefer Go to follow the guide without switching languages.Changes
Added a new directory
asset-transfer-gocontaining the Go chaincode implementation.Implemented asset lifecycle operations:
Additional components:
main.goentry point to bootstrap the chaincodego.mod/go.sumwith required Fabric dependenciesDockerfileanddocker-entrypoint.shfor Chaincode-as-a-Service (CaaS) deploymentasset-transfer-chaincode-vars.ymlfor compatibility with workshop automationTesting
Tested locally in WSL Ubuntu against a live Microfab network.
weft chaincode package caasand the Fabric lifecycle (install → approve → commit)trader-goclient onmychannel(org1MSP)CreateAsset,UpdateAsset,TransferAsset)All 7 client commands (
getAllAssets,transact,create,read,delete,transfer,listen) executed successfully.Notes
Uses standard Fabric Go chaincode patterns via
github.com/hyperledger/fabric-contract-api-go.The asset data model mirrors the TypeScript implementation with minor adjustments for Go conventions.