Skip to content

feat: Add Go implementation of full-stack-asset-transfer-guide smart contract (#1376) - #1391

Open
nXtCyberNet wants to merge 12 commits into
hyperledger:mainfrom
nXtCyberNet:issue/asset-transfer-go
Open

feat: Add Go implementation of full-stack-asset-transfer-guide smart contract (#1376)#1391
nXtCyberNet wants to merge 12 commits into
hyperledger:mainfrom
nXtCyberNet:issue/asset-transfer-go

Conversation

@nXtCyberNet

@nXtCyberNet nXtCyberNet commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

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-go containing the Go chaincode implementation.

Implemented asset lifecycle operations:

  • CreateAsset
  • ReadAsset
  • UpdateAsset
  • DeleteAsset
  • AssetExists
  • TransferAsset
  • GetAllAssets

Additional components:

  • main.go entry point to bootstrap the chaincode
  • go.mod / go.sum with required Fabric dependencies
  • Dockerfile and docker-entrypoint.sh for Chaincode-as-a-Service (CaaS) deployment
  • asset-transfer-chaincode-vars.yml for compatibility with workshop automation

Testing
Tested locally in WSL Ubuntu against a live Microfab network.

  • Deployed chaincode in CaaS mode using weft chaincode package caas and the Fabric lifecycle (install → approve → commit)
  • Executed asset operations through the trader-go client on mychannel (org1MSP)
  • Verified chaincode events (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.

@nXtCyberNet
nXtCyberNet requested a review from a team as a code owner March 11, 2026 06:12
@nXtCyberNet
nXtCyberNet force-pushed the issue/asset-transfer-go branch from 60894c9 to 2d376f1 Compare March 11, 2026 06:16
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>
@nXtCyberNet
nXtCyberNet force-pushed the issue/asset-transfer-go branch from f4133c1 to b17085b Compare March 11, 2026 16:35

@bestbeforetoday bestbeforetoday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_NAME set to the value of the CHAINCODE_ID environment variable that is defined by the org env context scripts.
  • CORE_CHAINCODE_SERVER_ADDRESS set to the value of the CHAINCODE_SERVER_ADDRESS environment 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 ./src

This needs to be documented somewhere.

Comment on lines +60 to +61
"typescript-eslint": "^8.56.1",
"vitest": "^4.0.18"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@nXtCyberNet
nXtCyberNet force-pushed the issue/asset-transfer-go branch from da7e16e to d2b9a00 Compare July 28, 2026 09:17
nXtCyberNet and others added 2 commits July 28, 2026 14:48
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>
@nXtCyberNet

nXtCyberNet commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi @bestbeforetoday, could I get a review? As far as I understand, the CI failures were due to flakiness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go implementation of full-stack-asset-transfer-guide smart contract

2 participants