A simple sawtooth "simplewallet" transaction family example (processor + client)
This is a minimal example of a sawtooth 1.0 application. This example demonstrates, a common usecase, where a customer deposits/withdraws money from an account, based on private key.
A customer can:
- deposit money into his/her bank account.
- withdraw money from his/her bank account.
- check the balance in the account.
The customer is identified by a customer name and a corresponding public key. The value of the wallet, i.e. the balance, is stored at an address derived from hash of customer's public key and the transaction family namespace. To keep code simple, this example has been written for just one customer, one account.
The application is built in two parts:
-
The client application written in python, written in two parts: _client.py file representing the backend stuff and the _cli.py representing the frontend stuff. The example is built by using the setup.py file located in one directory level up.
-
The Transaction Processor is written in C++11 using c++-sawtooth-sdk. It comes with its CMake files for build.
This example uses docker-compose and docker containers. If you do not have these installed please follow the instructions here: https://docs.docker.com/install/
Start the pre-built docker containers in docker-compose.yaml file, located in sawtooth-simplewallet directory:
cd sawtooth-simplewallet
docker-compose up
At this point all the containers should be running.
To launch the client, you could do this:
docker exec -it simplewallet-client bash
You can locate the right docker client container name using docker ps
.
Sample command usage:
sawtooth keygen jack #This creates the public/private keys, a pre-requisite for all commands following
simplewallet deposit 100 jack #This adds the 100 amount to Jack's state address
simplewallet withdraw 50 jack #Withdraws 50 units from Jack's state address
simplewallet balance jack #Displays the balance left in Jack's account
To build TP code of your preferred language and run the simplewallet example:
docker-compose -f simplewallet-build-tp-<your_prog_language>.yaml up --build
where,
<your_prog_language> should be replaced with either cxx
or java
This example and Hyperledger Sawtooth software are licensed under the Apache License Version 2.0 software license.