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/transfers money from an account, based on public key.
A customer can:
- deposit money into his/her bank account.
- withdraw money from his/her bank account.
- check the balance in the account.
- transfer money from one bank account to another
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.
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/
NOTE The preferred OS environment is Ubuntu 16.04.3 LTS x64. If you have windows please install Docker Toolbox for Windows or Docker for windows, based on your OS version.
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:
#Create a wallet
sawtooth keygen jack #This creates the public/private keys for Jill, a pre-requisite for all commands following
simplewallet deposit 100 jack #This adds 100 units to Jack's account
simplewallet withdraw 50 jack #Withdraws 50 units from Jack's account
simplewallet balance jack #Displays the balance left in Jack's account
#Create 2nd wallet
sawtooth keygen jill #This creates the public/private keys for Jill, a pre-requisite for all commands following
simplewallet deposit 100 jill #This adds 100 units to Jill's account
simplewallet balance jill #Displays the balance left in Jill's account
simplewallet transfer 25 jack jill #Transfer 25 units money from Jack to Jill
simplewallet balance jack #Displays the balance left in Jack's account
simplewallet balance jill #Displays the balance left in Jill'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
Currently, we're looking for contributions and PRs for following:
- TPs using JS, GO, .NET, Python sawtooth SDKs
- Client apps in JS, GO, .NET, C++, JAVA
More ways you can contribute:
- Bugs or issues: Report problems or defects found when working with simplewallet
- Core features and enhancements: Provide expanded capabilities or optimizations
- Documentation: Improve existing documentation or create new information
- Tests: Add functional, performance, or scalability tests
This example and Hyperledger Sawtooth software are licensed under the Apache License Version 2.0 software license.