Skip to content

Commit 0952d12

Browse files
fix(ccaas): return query payloads and align grpcio 1.83.1
Signed-off-by: kmilo <kmilo.denis.glez@yandex.com>
1 parent 3bf0621 commit 0952d12

7 files changed

Lines changed: 18 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Requirements
1111
------------
1212
- Python 3.10+ (3.11 recommended)
1313
- See `requirements.txt` for runtime dependencies. Key packages:
14-
- `grpcio==1.51.3`
14+
- `grpcio==1.83.1`
1515
- `protobuf>=7.35.1`
1616
- `grpclib==0.4.3`
1717

‎examples/ccaas/asset-transfer-basic/README.md‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ cd /path/to/fabric-chaincode-python
2828
python3 -m venv .venv
2929
source .venv/bin/activate
3030
pip install -r requirements.txt
31-
pip install "grpcio>=1.83.1"
3231
```
3332

3433
### 2. Package the Chaincode
@@ -94,14 +93,18 @@ source .venv/bin/activate
9493
cd /path/to/test-network-nano-bash
9594
. ./peer1admin.sh
9695
PACKAGE_ID=$(peer lifecycle chaincode queryinstalled --output json | \
97-
jq -r '.installed_chaincodes[] | select(.references.mychannel? != null) | \
98-
select(.references.mychannel.chaincodes[]? .name=="basic") | .package_id')
96+
jq -r '
97+
.installed_chaincodes[]
98+
| select(.references.mychannel? != null)
99+
| select(any(.references.mychannel.chaincodes[]?; .name == "basic"))
100+
| .package_id
101+
')
99102

100103
# Start the server
101104
cd /path/to/fabric-chaincode-python
102105
export CHAINCODE_ID="$PACKAGE_ID"
103106
export CHAINCODE_SERVER_ADDRESS=127.0.0.1:9999
104-
python examples/ccaas/asset-transfer-basic/main.py
107+
./.venv/bin/python examples/ccaas/asset-transfer-basic/main.py
105108
```
106109

107110
### 6. Invoke & Query
@@ -183,7 +186,8 @@ Tells Fabric that this is a CCAAS package:
183186
### Server won't start
184187
- Ensure `CHAINCODE_ID` matches the package-id from `peer lifecycle chaincode install`
185188
- Check that `connection.json` address is accessible from the peer
186-
- Verify gRPC is installed: `pip install "grpcio>=1.83.1"`
189+
- Verify dependencies are installed: `pip install -r requirements.txt`
190+
- Verify you're using the project venv: `./.venv/bin/python -c "import grpc; print(grpc.__version__)"`
187191

188192
### Peer can't reach chaincode
189193
- Check firewall rules allowing port 9999

‎examples/ccaas/asset-transfer-basic/main.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ async def invoke(self, stub: ChaincodeStubInterface) -> pb.Response:
7878
return pb.Response(status=ResponseCode.ERROR, message="ReadAsset requires 1 argument")
7979
asset_id = inputs[0]
8080
result = await self.read_asset(stub, asset_id)
81-
return pb.Response(status=ResponseCode.OK, message=result)
81+
if not result:
82+
return pb.Response(status=ResponseCode.ERROR, message=f"Asset {asset_id} does not exist")
83+
return pb.Response(status=ResponseCode.OK, payload=result)
8284

8385
elif action == "DeleteAsset":
8486
if len(inputs) < 1:
@@ -89,7 +91,7 @@ async def invoke(self, stub: ChaincodeStubInterface) -> pb.Response:
8991

9092
elif action == "GetAllAssets":
9193
results = await self.get_all_assets(stub)
92-
return pb.Response(status=ResponseCode.OK, message=results)
94+
return pb.Response(status=ResponseCode.OK, payload=results.encode())
9395

9496
else:
9597
return pb.Response(status=ResponseCode.ERROR, message=f"Unknown function: {action}")

‎examples/ccaas/asset-transfer-sbe/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pip install -r requirements.txt
5555
export CHAINCODE_ID=asset_transfer_sbe_1:<package_hash>
5656
export CHAINCODE_SERVER_ADDRESS=127.0.0.1:9999
5757

58-
cd examples/ccaas/asset-transfer-sbe
5958
python main.py
6059
```
6160

‎examples/ccaas/asset-transfer-sbe/main.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def invoke(self, stub: ChaincodeStubInterface) -> pb.Response:
6161
if len(args) != 1:
6262
return self._error("AssetExists requires 1 argument: assetId")
6363
exists = await self.asset_exists(stub, args[0])
64-
return pb.Response(status=ResponseCode.OK, message=str(exists).lower())
64+
return pb.Response(status=ResponseCode.OK, payload=str(exists).lower().encode())
6565

6666
if fn == "InitLedger":
6767
return await self.init_ledger(stub)
@@ -100,7 +100,7 @@ async def read_asset(self, stub: ChaincodeStubInterface, asset_id: str) -> pb.Re
100100
asset_bytes = await stub.get_state(asset_id)
101101
if not asset_bytes:
102102
return self._error(f"The asset {asset_id} does not exist")
103-
return pb.Response(status=ResponseCode.OK, message=asset_bytes.decode())
103+
return pb.Response(status=ResponseCode.OK, payload=asset_bytes)
104104

105105
async def update_asset(self, stub: ChaincodeStubInterface, asset_id: str, new_value: str) -> pb.Response:
106106
asset_data = await stub.get_state(asset_id)

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "README.md"
1010
license = {text = "Apache License v2.0"}
1111
requires-python = ">=3.10"
1212
dependencies = [
13-
"grpcio>=1.51.3",
13+
"grpcio>=1.83.1",
1414
"grpclib>=0.4.3",
1515
"protobuf>=7.35.1"
1616
]

‎requirements.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
grpcio==1.51.3
1+
grpcio==1.83.1
22
grpclib==0.4.3
33
protobuf>=7.35.1

0 commit comments

Comments
 (0)