Skip to content

Latest commit

 

History

History
95 lines (75 loc) · 5.55 KB

File metadata and controls

95 lines (75 loc) · 5.55 KB

OpenJML-Wrapped Chaincode-As-A-Service Test Network Configuration

Table of Contents

USAGE

Prerequisites

Make sure you have docker available (with compose, of course). Note that fablo generates scripts that require the legacy docker-compose to exist in your PATH, so if you are using Compose V2, just place a wrapper binary (script) somewhere in your PATH.

Instructions
  1. Normally, all you need to do is execute $ ./fabric-docker.sh up (or $ ./fabric-docker.sh reset if you have already up’ed once)

    • This should…

      • spin up a small local network with a single peer in a single organization (org1) and a single orderer (in a separate organization),

      • generate all crypto material automatically and transparently (you never need to see it),

      • create a channel named my-channel1,

      • start an external chaincode container called tpcc

      • install the chaincode definition (package) for tpcc,

      • and start some Fablo REST endpoints.

  2. Then you can proceed to try calling the chaincode as described below

If you have made changes to the chaincode, pass the -b or --build flag to fabric-docker.sh up or fabrid-docker.sh reset, otherwise the chaincode image will not be rebuilt.
Example 1. Invoking the chaincode

You should use the REST endpoints according to Fablo REST’s documentation. That is, first generate a token using the credentials admin/adminpw at org1’s REST API, then invoke the chaincode using that token and the appropriate parameterization.

I am using HTTPie and jq, but you can also do this with curl and other command line / GUI tools. Note that the command line outputs have been altered to make them more concise.

First, call the /user/enroll endpoint to get a bearer token (the default credentials are admin/adminpw) and save it in a variable token:

$ token=$(http http://localhost:8801/user/enroll id=admin secret=adminpw | jq .token | tr -d '"')

Then you can invoke the chaincode with the received token to invoke the chaincode, like so:

$ http -v -A bearer -a $token http://localhost:8801/invoke/my-channel1/tpcc method=initEntries args:='[]'
POST /invoke/my-channel1/notes HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Authorization: Bearer ba945b10-0253-11ee-b51b-5b5e65097fa0-admin
Content-Type: application/json

{ "args": [], "method": "initEntries" }

HTTP/1.1 200 OK

{ "response": "" }

MORE DETAILS

💡
When developing the chaincode, you most likely do not need to make modifications to anything described here. Fablo (with our customizations) should hide these details from you.
Subdirectories & Files
  • chaincode-package/: contains (with instructions to regenerate) a tpcc.tgz chaincode package, ready to install on Fabric peers (as external Chaincode-As-A-Service)

  • fabric-config/: has been generated by fablo; you probably do not need to worry about anything here

  • fabric-docker/: has been generated by fablo; some files have been modified to support installing chaincode as an external service[1]

  • fabric-docker.sh: script generated by fablo to manage the test network; refer to $ ./fabric-docker.sh help on how to use the script

Some subdirectories have their own README files where you can learn more.

  1. WHEN to regenerate the chaincode package tpcc.tgz?

    This file only needs to be regenerated if the contents of connection.json or metadata.json change. These files contain data such as the name of the chaincode container, the TCP port it listens on.

  2. HOW to regenerate the chaincode package tpcc.tgz?

    There is a package script that recreates the gzipped tarball. Beware that recreating the package changes the package ID which then has to be updated in several places. The full process is the following:

    1. Make your changes to connection.json and metadata.json

    2. Run package to regenerate tpcc.tgz (from the chaincode-package/ directory!)

    3. Run copy-to-fablo (from the chaincode-package/ directory!) to recalculate the package ID for the new package and copy it to the appropriate directory that is mounted to the containers at runtime; the script prints the package ID on the standard output, MAKE NOTE OF IT!

    4. Replace every occurrence of the previous package ID with the new one. Known locations:

      • docker.compose.yaml: in the chaincode container service (tpcc)

      • commands-generated.sh: present multiple times, make sure to replace each

      • The safest way is to recursively grep for the old package ID, eg by issuing $ grep -RFInC1 thisisthepackageida03d5726c28a155d993f6789701908d88746d0e5f0c9078860a7b4ae18411886 from the root of the repository


1. Namely, the commands-generated.sh file has a custom function for this purpose