Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Example application for Cloud Foundry that exposes a RESTful API to invoke or query Hyperledger Fabric chaincode via the SAP Cloud SDK Hyperledger Fabric Blockchain module.

Notifications You must be signed in to change notification settings

SAP-archive/cloud-blockchain-fabric-gateway-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Important Notice

This public repository is read-only and no longer maintained. For the latest sample code repositories, visit the SAP Samples organization.

REUSE status

Cloud Blockchain Fabric Gateway Example

Description

The Hyperledger Fabric gateway example application for SAP Cloud Platform provides a convenient REST-API to interact with Hyperledger Fabric chaincode. Therefore, it uses the Hyperledger Fabric client component of the SAP Cloud SDK.

Alternatives

Instead of using a REST-gateway we highly recommend using the official Hyperledger Fabric SDKs directly to invoke or query chaincode. This avoids the need of a runtime component and thus increases performance and failure safety. See Hyperledger Fabric Gateway SDK for Java and Hyperledger Fabric Gateway SDK for Node.js. To easily instantiate those SDKs via a user-provided service on Cloud Foundry use the Hyperledger Fabric client component in the SAP Cloud SDK. This SAP Cloud SDK component and the official Hyperledger Fabric Gateway SDK for Java are also used in this example application to reduce the code to a minimum.

Requirements

In order to use this example application, a Hyperledger Fabric network or service instance is required. Additionally, the application should be run in a Cloud Foundry environment on SAP Cloud Platform, or the Cloud Foundry environment variable VCAP_SERVICES must be set manually.

Download and Installation

This example application is intended to be used on a per-channel basis, not per chaincode. In order for the application to successfully connect to the Hyperledger Fabric network and the specific channel, it requires certain credentials. These credentials consist of a username (can be freely chosen), the user's organization (mspid) and the public and private key of the user. For most purposes this should be a technical user that has the permissions to execute chaincode on the channel (read and write). Moreover, the credentials contain a common connection profile that provides all necessary information for the application to connect to the Hyperledger Fabric network. The connection profile, the user certificate and the private key are Base64 encoded so they can be stored in a JSON object. Last but not least, it also includes the name of the channel that has the instantiated chaincodes.

# Edit and insert your own credentials!
{
    "type": "hyperledger-fabric",
    "mspid": "Org1MSP",
    "username": "admin",
    "channelname": "mychannel",
    "connectionprofile": "LS0tCm5hbWU6IGZhYnJpYy1uZXR3b3JrLW9yZzEKdmVyc2lvbjogMS4wLjAKY2xpZW50OgogIG9yZ2FuaXphdGlvbjogT3JnMQpvcmdhbml6YXRpb25zOgogIE9yZzE6CiAgICBtc3BpZDogT3JnMU1TUAogICAgY3J5cHRvUGF0aDogLgogICAgcGVlcnM6CiAgICAtIHBlZXIwLm9yZzEuZXhhbXBsZS5jb206NzA1MQogICAgLSBwZWVyMS5vcmcxLmV4YW1wbGUuY29tOjgwNTEKY2hhbm5lbHM6CiAgbXljaGFubmVsOgogICAgb3JkZXJlcnM6CiAgICAgICAgLSBvcmRlcmVyLmV4YW1wbGUuY29tCiAgICBwZWVyczoKICAgICAgcGVlcjAub3JnMS5leGFtcGxlLmNvbTo3MDUxOgogICAgICAgIGVuZG9yc2luZ1BlZXI6IHRydWUKICAgICAgICBjaGFpbmNvZGVRdWVyeTogdHJ1ZQogICAgICAgIGxlZGdlclF1ZXJ5OiB0cnVlCiAgICAgICAgZXZlbnRTb3VyY2U6IHRydWUKICAgICAgICBkaXNjb3ZlcjogZmFsc2UKICAgICAgcGVlcjEub3JnMS5leGFtcGxlLmNvbTo4MDUxOgogICAgICAgIGVuZG9yc2luZ1BlZXI6IHRydWUKICAgICAgICBjaGFpbmNvZGVRdWVyeTogdHJ1ZQogICAgICAgIGxlZGdlclF1ZXJ5OiB0cnVlCiAgICAgICAgZXZlbnRTb3VyY2U6IHRydWUKICAgICAgICBkaXNjb3ZlcjogZmFsc2UKcGVlcnM6CiAgcGVlcjAub3JnMS5leGFtcGxlLmNvbTo3MDUxOgogICAgdXJsOiBncnBjczovL2xvY2FsaG9zdDo3MDUxCiAgICB0bHNDQUNlcnRzOgogICAgICBwZW06IHwKICAgICAgICAtLS0tLUJFR0lOIENFUlRJRklDQVRFLS0tLS0KICAgICAgICBNSUlDVnpDQ0FmNmdBd0lCQWdJUkFLa3FWb0Q4UXh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WpBQU1Dc0dBMVVkCkl3UWtNQ0tBSUZnQS95cEpjaG8rWUUrZmhiWjJMQ3VWcWNrTTBjc1Z0dEZyTlRweHlyTkVNQW9HQ0NxR1NNNDkKQkFNQ0EwZ0FNRVVDSVFDeVBjbXNnS0RaZVU0d3pGK1dxbWF1eHFVek8wM2JzNWxjckVoWFd4OThTZ0lnU2pHNgplSmU1RGVLc0xPR0ttbGYrNTVVc1M1V2FVcnRlblBFeVVGSE9lUTA9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K",
    "privatekey": "LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JR0hBZ0VBTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEJHMHdhd0lCQVFRZ1FrZXpsaVhjb0lNa0htOVgKcStFcWhZcG1FTzdsQXpDZE1xc0NUL0J4NW1TaFJBTkNBQVNTRnB3bWtQa2hxd29CdUFxeXpJOHhhTXA3Q3Z5TwpPWm9uemxUUTY5NHQyT2w5N2ZTQVd1UytaRERVa0xPdFQ0ZkxhM1A1S2ZDeEsyRkVVczlMaWk5cwotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg=="
}

The above credentials must be provided via a Cloud Foundry user-provided service. To deploy this user-provided service to your Cloud Foundry space log in to Cloud Foundry via the Cloud Foundry CLI:

cf login

After selecting your organization and space run:

# Edit and insert your own credentials!
cf cups gateway-example-credentials -p '{
    "type": "hyperledger-fabric",
    "mspid": "Org1MSP",
    "username": "admin",
    "channelname": "mychannel",
    "connectionprofile": "LS0tCm5hbWU6IGZhYnJpYy1uZXR3b3JrLW9yZzEKdmVyc2lvbjogMS4wLjAKY2xpZW50OgogIG9yZ2FuaXphdGlvbjogT3JnMQpvcmdhbml6YXRpb25zOgogIE9yZzE6CiAgICBtc3BpZDogT3JnMU1TUAogICAgY3J5cHRvUGF0aDogLgogICAgcGVlcnM6CiAgICAtIHBlZXIwLm9yZzEuZXhhbXBsZS5jb206NzA1MQogICAgL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DQVRFLS0tLS0K",
    "privatekey": "LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JR0hBZ0VBTUJNR0J5cUdTTTQ5QWdFR0NDcUdTTTQ5QXdFSEJHMHdhd0lCQVFRZ1FrZXpsaVhjb0lNa0htOVgKcStFcWhZcG1FTzdsQXpDZE1xc0NUL0J4NW1TaFJBTkNBQVNTRnB3bWtQa2hxd29CdUFxeXpJOHhhTXA3Q3Z5TwpPWm9uemxUUTY5NHQyT2w5N2ZTQVd1UytaRERVa0xPdFQ0ZkxhM1A1S2ZDeEsyRkVVczlMaWk5cwotLS0tLUVORCBQUklWQVRFIEtFWS0tLS0tCg=="
}'

Or edit and use the cups.sh file:

./cups.sh

After deploying the user-provided service you are ready to deploy the application itself. Therefore, build the application using maven by running the following command in the application folder:

mvn clean package

To deploy the application make sure you have selected the same organization and space via the Cloud Foundry CLI and the run:

cf push

Usage

The REST-API provides the endpoints /{chaincode_name}/query and /{chaincode_name}/invoke. Both endpoints expect the same request body. Example request:

curl -X POST \
  https://com-sap-icn-gateway-example.cfapps.sap.hana.ondemand.com/crud/invoke \
  -H 'Content-Type: application/json' \
  -d '{
    "function": "write",
    "arguments": ["data"]
}'

function specifies the name of the function in the chaincode (string) and arguments can be an array of string arguments for the chaincode function.

Scaling

Since the application is stateless and completely relies only on the data of the user-provided service, the application can be scaled easily. If the application is under high load or traffic it should be scaled horizontally by adding more instances to the Cloud Foundry application. This can be done via the command:

cf scale com-sap-icn-gateway-example -i 5

After applying these changes, all incoming traffic is automatically load-balanced between all instances of the Cloud Foundry application.

Limitations

This gateway example application does not support private data.

Known Issues

There are no known issues at this time.

How to obtain support

This project is provided "as-is" without support.

License

Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.

About

Example application for Cloud Foundry that exposes a RESTful API to invoke or query Hyperledger Fabric chaincode via the SAP Cloud SDK Hyperledger Fabric Blockchain module.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published