feat: add chaincode-to-fsc asset transfer POC example#1304
feat: add chaincode-to-fsc asset transfer POC example#1304aaradhychinche-alt wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a minimal “chaincode-to-FSC” tutorial example that demonstrates an asset transfer flow implemented as client-side orchestration (mocked, in-memory backend), intended to help developers map chaincode patterns to FSC-style flows.
Changes:
- Introduces an in-memory mock “protocol” layer for asset state read/write.
- Adds a simple transfer flow with input validation, submit, and verification steps.
- Adds a CLI entrypoint and accompanying tutorial documentation for running the example.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/chaincode-to-fsc/internal/protocol/fabricx.go | In-memory mock ledger/protocol for reading assets and submitting transfers |
| examples/chaincode-to-fsc/internal/model/asset.go | Minimal asset data model |
| examples/chaincode-to-fsc/internal/flow/transfer_asset.go | Transfer flow orchestration (read → validate → submit → verify) |
| examples/chaincode-to-fsc/cmd/token-transfer/main.go | CLI for invoking the transfer flow |
| examples/chaincode-to-fsc/go.mod | Standalone Go module for the example |
| examples/chaincode-to-fsc/READEME.md | Tutorial-style documentation for running the example |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| endorsing transaction | ||
| submitting transaction | ||
| verifying state | ||
| transfer successful: a1 -> bob |
There was a problem hiding this comment.
The documented output doesn't match what the code prints/returns. TransferAsset returns "success: asset %s now owned by %s", but the README shows "transfer successful: a1 -> bob". Please update the README output (or adjust the program output) so users can follow the tutorial without confusion.
| transfer successful: a1 -> bob | |
| success: asset a1 now owned by bob |
| module github.com/hyperledger-labs/fabric-smart-client/examples/chaincode-to-fsc | ||
|
|
||
| go 1.25.7 No newline at end of file |
There was a problem hiding this comment.
This example introduces a nested Go module, but the repo's make tidy target only runs go mod tidy in a few locations and currently won't tidy this module. Consider updating the repo tooling (or adding a note in the README) so future dependency changes here don't get missed.
| var assets = map[string]model.Asset{ | ||
| "a1": { | ||
| ID: "a1", | ||
| Owner: "alice", | ||
| }, | ||
| } |
There was a problem hiding this comment.
assets is a package-level map that is read and written by GetAsset/SubmitTransfer without any synchronization. If this example is invoked concurrently (or exercised under -race), this can trigger data races and even runtime panics on concurrent map access. Consider guarding the map with a sync.RWMutex (or encapsulating state in a struct) and using the lock in both functions.
|
Thank you @aaradhychinche-alt for creating this PR. I've left you a few comments on the corresponding issue. I've changed this PR to draft mode for now - so we can refine it more and more :D |
thankssssss i will look upto the reviews |
|
@mbrandenburger i have updated the pr :-
|
|
@mbrandenburger What should we do next to improve this ? |
|
Hi @aaradhychinche-alt Thank for working on this - a good step forward. You should move forward with this and start porting the Asset Transfer logic into views; setup fsc nodes nodes; think about how to spinnup a fabric-x network (for example, you could use our integration test suite (nwo)). |
|
Hi @marcus Brandenburger I’ve updated the PR with a working chaincode-to-FSC migration PoC. Would appreciate it if you could take a look and share your feedback. |
d8dbfc3 to
cc8a035
Compare
Signed-off-by: Aaradhy Chinche <aaradhychinche@gmail.com>
44f023c to
0903c24
Compare
|
@mbrandenburger what is your review ? |
|
👋 Hey @aaradhychinche-alt! This PR has been inactive for 5 days. Are you still working on this? We will close this in 2 days if we see no further activity. If you're still on it, leave a comment to let us know! If you'd like to step down, comment |
|
Hey @aaradhychinche-alt 👋 thanks for the PR! This comment updates automatically as you push changes -- think of it as your PR's live scoreboard! PR Checks✅ DCO Sign-off -- All commits have valid sign-offs. Nice work! ❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:
You'll need to sign your commits with GPG (e.g. ✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing! ❌ Issue Link -- Almost there! You are not assigned to the following linked issues: #1303. Please ensure you are assigned to all linked issues before opening a PR. You can comment ⏳ All checks must pass before this PR can be reviewed. You've got this! |
i am working on it!! |
mbrandenburger
left a comment
There was a problem hiding this comment.
Thank you @aaradhychinche-alt for this work. Really good progress. I have a few suggestions below.
| | `issuer` | Org1 | Initiator for `InitLedger` and `CreateAsset`. | | ||
| | `endorser` | Org1 | Approver. Holds the chaincode-equivalent validation logic. | | ||
| | `auditor` | Org1 | Witness responder on every state-changing transaction. | |
There was a problem hiding this comment.
I believe we should merge issuer, endorser, auditor into a single node and call it endorser? This would simplify the topology a lot.
There was a problem hiding this comment.
Optionally, we should have a second endorser in a different org to make a stronger policy.
| Prerequisites — match the Fabric-X compatibility matrix at the time of | ||
| writing: | ||
|
|
||
| | Tool | Version | | ||
| | ------------------- | ---------------- | | ||
| | Go | 1.26+ | | ||
| | Docker | 20.x+ | | ||
| | Fabric-X-Orderer | v0.0.21 / v0.0.23 | | ||
| | Fabric-X-Committer | v0.1.7 / v0.1.9 | |
There was a problem hiding this comment.
I suggest to remove this from this tutorial and refer to the FSC documentation.
There was a problem hiding this comment.
Let's also link to the documentation how to setup the dev environment.
| ### 8.1 Why a separate auditor node | ||
|
|
||
| Classical chaincode applications often retrofitted an auditor by | ||
| emitting chaincode events and scraping them off-chain. With FSC the | ||
| auditor becomes a topology-level role — register an FSC node, hand it | ||
| `AuditorView` as a responder, and every state-changing transaction | ||
| automatically pulls the auditor into the endorsement flow. We did this | ||
| to demonstrate the pattern; the example would still work without it. |
There was a problem hiding this comment.
As suggested earlier - I believe the auditor make this tutorial harder to follow.
| - **Second demo (work-in-progress).** A port of | ||
| `asset-transfer-private-data` that exercises the | ||
| hash-on-ledger / body-via-P2P pattern from §9.4. | ||
| - **CC-Tools port (stretch).** Show that the methodology generalises | ||
| beyond hand-written chaincode. | ||
| - **Index-key range scan helper (stretch).** A reusable FSC view that | ||
| implements the index-key pattern from §9.1, so applications get a | ||
| drop-in substitute for `GetStateByRange`. | ||
| - **Blog post.** A 1500–2500-word digest of this README aimed at the | ||
| LFDT community. | ||
| - **Meetup talk.** A 15-minute walkthrough with slides. | ||
|
|
||
| Issues and PRs welcome. The mentorship project that produced this | ||
| example is tracked in | ||
| [LF-Decentralized-Trust-Mentorships/mentorship-program#59](https://github.com/LF-Decentralized-Trust-Mentorships/mentorship-program/issues/59). |
There was a problem hiding this comment.
Let's remove this section.
| This is the long-form companion to [README.md](README.md). The README is | ||
| the tutorial a reviewer reads in 20 minutes; this file is the *textbook* | ||
| that teaches you, line by line, what every piece of this PoC is doing | ||
| and why. If you have never used FSC before, start here. |
There was a problem hiding this comment.
I think the detail in the walkthrough is great but I believe we should focus on a single documentation per tutorial. I suggest to remove the walkthrough. This also help to maintain the tutorial in the future.
| @@ -0,0 +1,80 @@ | |||
| # Chaincode -> FSC Example (Asset Transfer) | |||
There was a problem hiding this comment.
We can remove examples/chaincode-to-fsc as now integration/fabricx/chaincode-to-fsc contains the real tutorial.
|
@mbrandenburger thanks for the response i will look upto changes and apply them now |
Summary
This PR adds a minimal example demonstrating how a classic Fabric chaincode use case (asset transfer) can be implemented using a Fabric Smart Client (FSC)-style flow.
Motivation
This example aims to help developers understand how to move business logic from on-ledger chaincode execution to client-side flow orchestration using FSC.
What’s Included
cmd/token-transfer)internal/flow)internal/protocol)internal/model)Flow
The example demonstrates:
Scope
Notes
examples/Future Work
POC: Porting Fabric Chaincode (Asset Transfer) to Fabric Smart Client Flow (Tutorial Example) #1303