Azure / Hyperledger-Fabric-on-Azure-Kubernetes-Service

We are excited to support Hyperledger Fabric(HLF) Blockchain version 1.4.4 on Azure Kubernetes Service through a solution that helps to deploy blockchain network of your choice with minimal Azure and HLF knowledge. You are only charged for the underlying infrastructure resources consumed, such as AKS cluster, storage, and networking.
Apache License 2.0
35 stars 23 forks source link

How to get connection.json #27

Closed palles77 closed 3 years ago

palles77 commented 3 years ago

Hi

I followed the tutorial provided by Mr Pat Altimore https://github.com/MicrosoftDocs/azure-docs/issues/58191#issuecomment-665300539 I successfully established a chaincode and channel with 3 orderers and 1 peer. However I am facing an issue where I am trying to connect to my Azure Hyperledger AKS Service, but I am not able to compose a connection.json file which would allow me to perfrom TypeScript connnections. Such connections should be able to execute transactions and invoke queries. A typical connection.json looks as follows:

{ "name": "first-network", "version": "1.1", "channels": { "channel": { "orderers": [ "orderer0" ], "peers": [ "peer0-org1" ], "connection": { "timeout": { "peer": { "endorser": "6000", "eventHub": "6000", "eventReg": "6000" } } } } }, "organizations": { "org1": { "mspid": "org1", "adminPrivateKey": { "path": "/usr/src/hlf/crypto-config/peerOrganizations/org1/users/Admin@org1/msp/keystore/pvt-cert.pem" }, "peers": ["peer0-org1"], "signedCert": { "path": "/usr/src/hlf/crypto-config/peerOrganizations/org1/users/Admin@org1/msp/signcerts/Admin@org1-cert.pem" } } }, "orderers": { "orderer0": { "url": "grpcs://orderer0:7050", "grpcOptions": { "ssl-target-name-override": "orderer0" }, "tlsCACerts": { "path": "/usr/src/hlf/crypto-config/ordererOrganizations/orderer/orderers/orderer0/msp/tlscacerts/tlsca.orderer-cert.pem" } } }, "peers": { "peer0-org1": { "url": "grpcs://peer0-org1:7051", "tlsCACerts": { "path": "/usr/src/hlf/crypto-config/peerOrganizations/org1/peers/peer0-org1/tls/ca.crt" }, "grpcOptions": { "ssl-target-name-override": "peer0-org1" } } } }

This sample file comes from my local deployment of Hyperledger Fabric using Docker.

When working with the tutorial from Mr Pat Altimore I am able to retrieve two files (placed in ~/azhlfTool/stores/connectionprofiles). The first file lppeer.json represents connection to peer nodes (I replaced any URLS and certifications with dummy data): { "certificateAuthorities": { "lppeerCA": { "caName": "ca.lppeer", "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE----------END CERTIFICATE-----\n" }, "url": "https://ca.00000000000000000000.northeurope.aksapp.io:443" } }, "client": { "connection": { "timeout": { "orderer": "300", "peer": { "endorser": "300" } } }, "organization": "lppeer" }, "name": "lppeer", "organizations": { "lppeer": { "certificateAuthorities": [ "lppeerCA" ], "mspid": "lppeer", "peers": [ "peer1.lppeer" ] } }, "peers": { "peer1.lppeer": { "grpcOptions": { "hostnameOverride": "peer1.00000000000000000000.northeurope.aksapp.io", "ssl-target-name-override": "peer1.00000000000000000000.northeurope.aksapp.io" }, "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE----------END CERTIFICATE-----\n" }, "url": "grpcs://peer1.00000000000000000000.northeurope.aksapp.io:443" } }, "version": "1.0.0", "wallet": "lppeer" }

The second file lporderer.json represents connection to orderer nodes (I replaced any URLS and certifications with dummy data): { "certificateAuthorities": { "lpordererCA": { "caName": "ca.lporderer", "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE-----\-----END CERTIFICATE-----\n" }, "url": "https://ca.00000000000000000000.westeurope.aksapp.io:443" } }, "client": { "connection": { "timeout": { "orderer": "300", "peer": { "endorser": "300" } } }, "organization": "lporderer" }, "name": "lporderer", "organizations": { "lporderer": { "certificateAuthorities": [ "lpordererCA" ], "mspid": "lporderer", "orderers": [ "orderer1.lporderer", "orderer2.lporderer", "orderer3.lporderer" ] } }, "orderers": { "orderer1.lporderer": { "grpcOptions": { "hostnameOverride": "orderer1.00000000000000000000.westeurope.aksapp.io", "ssl-target-name-override": "orderer1.00000000000000000000.westeurope.aksapp.io" }, "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE----------END CERTIFICATE-----\n" }, "url": "grpcs://orderer1.00000000000000000000.westeurope.aksapp.io:443" }, "orderer2.lporderer": { "grpcOptions": { "hostnameOverride": "orderer2.00000000000000000000.westeurope.aksapp.io", "ssl-target-name-override": "orderer2.00000000000000000000.westeurope.aksapp.io" }, "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE-----n-----END CERTIFICATE-----\n" }, "url": "grpcs://orderer2.00000000000000000000.westeurope.aksapp.io:443" }, "orderer3.lporderer": { "grpcOptions": { "hostnameOverride": "orderer3.00000000000000000000.westeurope.aksapp.io", "ssl-target-name-override": "orderer3.00000000000000000000.westeurope.aksapp.io" }, "tlsCACerts": { "pem": "-----BEGIN CERTIFICATE----------END CERTIFICATE-----\n" }, "url": "grpcs://orderer3.00000000000000000000.westeurope.aksapp.io:443" } }, "version": "1.0.0", "wallet": "lporderer" }

Are there any set of commands that I could use when running interactive CLI shell from azure website which would return a connection.json that could be used in conjunction with TypeScript's 'fabric-network' package?

Any help would be greatly appreciated.

Cheers, Les

chintanr97 commented 3 years ago

Hi @palles77,

The files you fetched using azhlfTool client application is the common connection profile for the respective organization. It can be used along with the Fabric Node SDK code to talk to the network - for submitting transactions. The azhlfTool sample app also achieves the same using the same connection profiles. The open-source code for azhlfTool can be found here.

Please let me know if you face any further issues!

Regards, Chintan Rajvir

palles77 commented 3 years ago

Hi Chintan

Could you tell me how I can debug the azhlf tool using Visual Studio Code? I tried setting up my launch.json file to something like below:

{ "version": "0.2.0", "configurations": [ { "type": "bash", "request": "launch", "name": "Launch remote chaincode debugger", "program": "azhlf", "cwd": "${workspaceFolder}", "env": { "CORE_CHAINCODE_ID_NAME": "transactioncc1:v0" }, "args": [ "chaincode invoke -o lppeer -u admin.lppeer -n chaincode -c lpchannel -f \"registerTransaction\" -a \"4\" \"PAYERABNID1\" \"PAYERUSERID1\" \"15000.00\" \"1500.00\" \"AUD\" \"2020/11/12 12:50 PM\" \"CHECKSUM\" \"BUYERABNID2\"" ], "outFiles": [ "${workspaceFolder}/build/*" ], "sourceMaps": true, "outputCapture": "std" } ] }

when running from the /home/lechu/azhlf directory?

I am trying to replicate what I basically did earlier, using command like below:

lechu@lechu-vm:~/azhlfTool$ ./azhlf chaincode query -o lppeer -u admin.lppeer -n chaincode -c lpchannel -f "getTransactionById" -a "3" --endorsingPeers "peer1

and the result is correct: Chaincode chaincode successfully invoked on channel lpchannel. Got empty response.

If I query the channel lechu@lechu-vm:~/azhlfTool$ ./azhlf chaincode query -o lppeer -u admin.lppeer -n chaincode -c lpchannel -f "getTransactionById" -a "3" --endorsingPeers "peer1"

I get the proper response: peer1 gave response from chaincode: {"amount":15000,"buyerAbn":"BUYERABNID2","checksum":"CHECKSUM","currency":"AUD","date":"2020/11/12 12:50 PM","gstValue":1500,"sellerAbn":"PAYERABNID1","sellerId":"PAYERUSERID1","transactionId":"3"}

My goal is to debug how the TypeScript code written for azhlf proxy is retrieving connection strings and how it ultimately accesses the HLF instance on Azure. I want to extract this bit of code and use it in my Docker container where I send transactions to HLF and retrieve them easily.

Any help would be appreciated.

Cheers, Leslaw

chintanr97 commented 3 years ago

Hi @palles77,

The azhlfTool client application is written in Typescript and makes of Fabric Node SDK modules like fabric-network and fabric-client to talk to the HLF network on AKS. Currently the tool uses Fabric Node SDK v1.4.9. You can deep dive into the implementation of the tool as the code is open-source and only relies of Fabric Node SDK.

Understanding, the different classes in commandHandlers directory and in common directory of the azhlfTool project will help you achieve that.

For debugging in the VS Code, you can clone the entire repository or download the zip and extract the azhlfTool folder from it.

Regards, Chintan Rajvir

palles77 commented 3 years ago

I solved the problem with the following launch.json file:

{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch remote chaincode debugger", "program": "out/cli.js", "cwd": "${workspaceFolder}", "env": { "CORE_CHAINCODE_ID_NAME": "transactioncc1:v0" }, "args": [ "chaincode", "invoke", "-o", "lppeer", "-u", "admin.lppeer", "-n", "channel", "-c", "lpchannel", "-f", "registerTransaction", "-a", "5", "PAYERABNID1", "PAYERUSERID1", "15000.00", "1500.00", "AUD", "2020/11/12 12:50 PM", "CHECKSUM", "BUYERABNID2" ], "outFiles": [ "${workspaceFolder}/build/*" ], "sourceMaps": true, "outputCapture": "std" } ] }

chintanr97 commented 3 years ago

Thankyou @palles77! Closing the thread for now. Please feel free to re-open if any further help is needed!