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 4 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.
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.