github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-supply-chain-master/README.md (about)

     1  
     2  ![Hyperledger Sawtooth](images/sawtooth_logo_light_blue-small.png)
     3  
     4  # Sawtooth Supply Chain
     5  
     6  This is a distributed application to help you trace the provenance and other
     7  contextual information of any asset. It can be used as-is or customized for
     8  different use cases. This distributed application runs on top of Hyperledger
     9  Sawtooth, an enterprise blockchain. To learn more about Hyperledger Sawtooth
    10  please see its
    11  [sawtooth-core repo](https://github.com/hyperledger/sawtooth-core) or its
    12  [published docs](https://sawtooth.hyperledger.org/docs/).
    13  
    14  ## Contents
    15  
    16  - [Components](#components)
    17  - [Usage](#usage)
    18    - [Start Up](#start-up)
    19    - [Running Scripts in the Shell](#running-scripts-in-the-shell)
    20    - [Configuring API Keys and Secrets](#configuring-api-keys-and-secrets)
    21  - [Development](#development)
    22    - [Restarting Components](#restarting-components)
    23    - [Manually Building Generated Files](#manually-building-generated-files)
    24  - [Documentation](#documentation)
    25  - [License](#license)
    26  
    27  ## Components
    28  
    29  Running alongside the core components from Hyperledger Sawtooth, Supply Chain
    30  includes a number of elements customizing the blockchain and user interaction
    31  with it:
    32  
    33  - a **transaction processor** which handles Supply Chain transaction logic
    34  - a **server** which provides an HTTP/JSON API for Supply Chain actions
    35  - a **ledger sync** which syncs blockchain data to a local database
    36  - the **AssetTrack** example client for tracking generic assets
    37  - the **FishNet** example client for tracking fish from catch to table
    38  - a **shell** container with the dependencies to run any commands and scripts
    39  
    40  
    41  ## Usage
    42  
    43  This project utilizes [Docker](https://www.docker.com/what-docker) to simplify
    44  dependencies and deployment. After cloning this repo, follow the instructions
    45  specific to your OS to install and run whatever components are required to use
    46  `docker` and `docker-compose` from your command line. This is only dependency
    47  required to run Supply Chain components.
    48  
    49  ### Start Up
    50  
    51  Once Docker is installed and you've cloned this repo, navigate to the root
    52  project directory and run:
    53  
    54  ```bash
    55  docker-compose up
    56  ```
    57  
    58  This will take awhile the first time it runs, but when complete will be running
    59  all required components in separate containers. Many of the components will be
    60  available through HTTP endpoints, including:
    61  
    62  - The Supply Chain REST API will be at **http://localhost:8020**
    63  - AssetTrack will be at **http://localhost:8021**
    64  - FishNet will be at **http://localhost:8022**
    65  - RethinkDB's admin panel will be available at **http://localhost:8023**
    66  - Sawtooth's blockchain REST API will be available at **http://localhost:8024**
    67  
    68  In bash you can shutdown these components with the key combination: `ctrl-C`.
    69  You can shutdown _and_ remove the containers (destroying their data), with the
    70  command:
    71  
    72  ```bash
    73  docker-compose down
    74  ```
    75  
    76  ### Running Scripts in the Shell
    77  
    78  Running `docker-compose up`, will automatically run all scripts necessary to
    79  use all Supply Chain components. However if you want to run any additional
    80  scripts, such as scripts to automatically update sample blockchain data, a shell
    81  container is provided with all necessary dependencies installed. To enter the
    82  shell, simply open a terminal window and run:
    83  
    84  ```bash
    85  docker exec -it supply-shell bash
    86  ```
    87  
    88  Once inside the shell, you might try running the one of the update scripts to
    89  see live updates populate in an example web app. First navigate to the server
    90  directory:
    91  
    92  ```bash
    93  cd server/
    94  ```
    95  
    96  Then run one of the two provided npm scripts:
    97  
    98  ```bash
    99  npm run update-sample-assets
   100  npm run update-sample-fish
   101  ```
   102  
   103  You can customize how many updates are submitted per minute with the `RATE`
   104  environment variable (default 6), and use `LIMIT` to stop the updates after a
   105  certain number are submitted (default 25):
   106  
   107  ```bash
   108  RATE=3 LIMIT=10 npm run update-sample-assets
   109  ```
   110  
   111  If you just want to exit the shell, you can simply run:
   112  
   113  ```bash
   114  exit
   115  ```
   116  
   117  ### Configuring API Keys and Secrets
   118  
   119  While the Server runs out of the box with sensible defaults, there are a number
   120  of secrets and API keys which will not be secure unless set explicitly. While
   121  this is fine for demo purposes, any actual deployment set the following
   122  properties:
   123  
   124  - **JWT_SECRET**: can be any random string
   125  - **PRIVATE_KEY**: must be 64 random hexadecimal characters
   126  - **MAPS_API_KEY**: provided by [Google Maps](https://developers.google.com/maps/documentation/javascript/get-api-key)
   127  
   128  These properties can be set one of two ways, through an environment variable,
   129  or (preferably) by creating a file named `config.json` file in the `server/`
   130  directory. A file named `config.json.example` is provided which should provide
   131  a template to follow.
   132  
   133  ## Development
   134  
   135  ### Restarting Components
   136  
   137  The default Docker containers use the `volumes` command to link directly to the
   138  source code on your host machine. As a result any changes you make will
   139  immediately be reflected in Supply Chain components without having to rebuild
   140  them. However, typically you _will_ have to restart a component before it can
   141  take advantage of any changes. Rather than restarting every container, you can
   142  restart a single component from separate terminal using the container name. For
   143  example:
   144  
   145  ```bash
   146  docker restart supply-server
   147  ```
   148  
   149  The available container names include:
   150  - supply-shell
   151  - supply-processor
   152  - supply-server
   153  - supply-asset-client
   154  - supply-fish-client
   155  - supply-rethink
   156  - supply-validator
   157  - supply-settings-tp
   158  - supply-rest-api
   159  
   160  ### Manually Building Generated Files
   161  
   162  The example clients are based on static files generated by build scripts. Any
   163  time changes are made to their source code they will need to be rebuilt. This
   164  is done automatically on `up`, but if you make changes to these files and wish
   165  to rebuild the generated files immediately, you can do so from within the
   166  Supply Chain Shell:
   167  
   168  ```bash
   169  docker exec -it supply-shell bash
   170  ```
   171  
   172  Once in the shell, you can generate the necessary JS files by navigating to a
   173  client's directory and running its build script:
   174  
   175  ```bash
   176  cd asset_client/
   177  npm run build
   178  ```
   179  
   180  ```bash
   181  cd fish_client/
   182  npm run build
   183  ```
   184  
   185  Unlike other components, the clients do _not_ typically need to be restarted in
   186  order to reflect changes, just rebuild the static files and refresh your
   187  browser (the browser cache may have to be emptied).
   188  
   189  #### Building Protobuf Files
   190  
   191  Files in the `protos/` directory are used to generate classes for all of the
   192  other components. If any changes are made in this directory, these classes will
   193  need to be rebuilt for all components. While this can be done manually, the
   194  necessary commands are included in `docker-compose.yaml`, so simply stop all
   195  containers with `ctrl-C` and then `docker-compose up` again.
   196  
   197  ## Documentation
   198  
   199  The latest documentation for Sawtooth Supply Chain is available within this
   200  repo in the [docs](docs) subdirectory.
   201  
   202  ## License
   203  
   204  Hyperledger Sawtooth software is licensed under the
   205  [Apache License Version 2.0](LICENSE) software license.
   206  
   207  Hyperledger Sawtooth Supply Chain documentation in the [docs](docs)
   208  subdirectory is licensed under a Creative Commons Attribution 4.0 International
   209  License.  You may obtain a copy of the license at:
   210  http://creativecommons.org/licenses/by/4.0/.
   211  
   212  ![Open Source Award Badge](images/rookies16-small.png)