GithubHelp home page GithubHelp logo

askmish / sawtooth-simplewallet Goto Github PK

View Code? Open in Web Editor NEW
66.0 12.0 66.0 154 KB

A simple sawtooth "simplewallet" transaction family (processor + client)

License: Apache License 2.0

CMake 0.98% Shell 1.97% C++ 11.22% Python 22.54% Java 7.50% JavaScript 16.04% CSS 1.08% Dockerfile 10.30% Rust 12.95% Go 8.72% Handlebars 6.70%
simplewallet sawtooth wallet-account hyperledger-sawtooth processor-client transaction-family

sawtooth-simplewallet's Introduction

sawtooth-simplewallet

A simple sawtooth "simplewallet" transaction family example (processor + client)

Introduction

This is a minimal example of a sawtooth 1.2 application. This example demonstrates, a common usecase, where a customer deposits/withdraws/transfers money from a wallet account.

A customer can:

  1. deposit money into his/her wallet account
  2. withdraw money from his/her wallet account
  3. check the balance in the wallet account
  4. transfer money from his/her wallet account to another

The customer is identified by a customer name and a corresponding public key. The wallet account balance, is stored at an address, derived from SHA 512 hash of customer's public key and the simplewallet transaction family namespace.

Components

The application is built in two parts:

  1. 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.

  2. The Transaction Processor is written in C++11 using c++-sawtooth-sdk. It comes with its CMake files for build. The Transaction Processor is also available in Java and Python.

Pre-requisites

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. Although, other linux distributions which support Docker should work. If you have Windows please install Docker Toolbox for Windows or Docker for Windows, based on your OS version.

NOTE: The minimum version of Docker Engine necessary is 17.03.0-ce. Linux distributions often ship with older versions of Docker.

Here's a gist detailing steps on installing docker and docker-compose.

Working with proxies

For linux:

Follow the instructions in sawtooth-core/BUILD.md

For pre-Windows 10 versions (using Docker Toolbox for Windows):

Start the virtualbox host with:

   docker-machine rm default
   docker-machine create -d virtualbox --engine-env HTTP_PROXY=<your_http_proxy> --engine-env HTTPS_PROXY=<your_https_proxy> --engine-env NO_PROXY=<your_no_proxy> default

When you start Kitematic it will initially show an error, but just click "Use Virtualbox".

For Windows 10 (using Docker for Windows):

Right click on the Docker icon in the notification area, select Settings. Then click Proxies. Select "Manual proxy configuration" and enter the following then click Apply.

    Web Server (HTTP):         <your_http_proxy>
    Secure Web Server (HTTPS): <your_https_proxy>
    Bypass for these hosts:    <your_no_proxy>,localhost,127.0.0.1

Usage

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 Jack, a pre-requisite for the following commands

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 the following commands

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

Building containers

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, java, or py

Building and running on OS (without Docker)

To run sawtooth-simplewallet without Docker, we'll have to use a Ubuntu 16.04 OS installation and compile simplewallet from sources. Below is a sample procedure for python TP/client:

  1. Install sawtooth on Ubuntu 16.04 LTS x64 machine and setup genesis block. Refer sawtooth app developer's guide here

    • Start the validator, rest-api and settings-tp in separate, new consoles:

      sudo -u sawtooth sawtooth-validator -vv
      sudo -u sawtooth sawtooth-rest-api -vvv
      sudo -u sawtooth settings-tp -vv
  2. In a new console, clone the simplewallet repo:

    git clone https://github.com/askmish/sawtooth-simplewallet.git

  3. cd sawtooth-simplewallet

  4. Modify two files:

    • Create a new branch to start making changes git checkout -b nodocker
    • Edit file pyclient/wallet/simplewallet_cli.py and change rest-api:8008 to localhost:8008
    • Edit file pyprocessor/processor/simplewallet_tp.py and change validator:4004 to localhost:4004
  5. Setup the simplewallet-tp.

  6. Setup the client. Open a new console.

    • Follow the pyclient/Dockerfile
    • Install all the dependencies in the first RUN line in the pyclient/Dockerfile
    • Run the simplewallet client with ./pyclient/simplewallet command. Refer Usage section above, for examples.

NOTE If you prefer using the simplewallet client without directory prefix, you could add the pyclient directory to your PATH environment variable, as shown below:

export PATH = $PATH:<absolute-path-to-your-cloned-sawtooth-simplewallet-dir>/pyclient"

Video Presentation

A video presentation on YouTube uses this application as an example. It is "Hyperledger Sawtooth Application Development using 'SimpleWallet'". It is at https://youtu.be/4VUaZkwJdCc

Javascript Client

The client is also written in Javascript using node.js. The app.js is the main javascript file from where the main function call occurs. Handlebars are used for templating, client related CSS and JavaScript code is written in public folder and server related files are written in router/ folder. Running the default docker-compose.yaml file or the simplewallet-build-client-js.yaml launches the client, which is accessible at localhost:3000.

How to use the simplewallet UI:

  1. Build and start the Docker containers:

docker-compose -f simplewallet-build-client-js.yaml up

  1. Open bash shell in simplewallet-client-js container:

docker exec -it simplewallet-client-js bash

  1. Create user accounts for jack and jill:

sawtooth keygen jack && sawtooth keygen jill

  1. Open two new browser tabs and go to http://localhost:3000 on each tab

  2. Login in one tab as jack and in other as jill

  3. Start with an initial deposit for each user - jack and jill via the Deposit tab in the UI homepage

Contributing

Currently, we're looking for contributions and PRs for following:

  • TP using .NET sawtooth SDK
  • Client apps in GO, .NET, C++, and 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

License

This example and Hyperledger Sawtooth software are licensed under the Apache License Version 2.0 software license.

sawtooth-simplewallet's People

Contributors

arsulegai avatar askmish avatar danintel avatar dependabot[bot] avatar jakepanter avatar manojgop avatar prp20 avatar ram-srini avatar rranjan3 avatar shonjs avatar sofiter avatar varalakshmika avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sawtooth-simplewallet's Issues

Wallet with Javascript SDK running a PBFT consensus

Dear! I have installed your repository and also watched your video. I need simulate currency transactions using the PBFT algorithm and the Javascript SDK. This is for an academic thesis, but I am finding serious problems since I am not used with docker and containers. Would be possible any help related to your repo?

Cannot create protobuf/protobuf_bundle.json: Directory nonexistent npm ERR! code ELIFECYCLE npm ERR! errno 2

Things I have done :

Installed latest Node(8.11.3)& npm version.
Started JavaScript essential thing using docker-compose up (used javascript .yaml file).

Things giving error:

Want to setup Javascript transaction processor so moved to dir jsprocessor.

Trying to install all node modules using $ npm install, but giving error shown in image. I think it is relate to node js.

Reinstalled Node & NPM, Externally installed npm module that producing error but no effect.

What am I doing wrong?
nder

Add instructions to run jsclient

Some basic instructions for running jsclient would be helpful.
I didn't find anything in README.md or the jsclient files.

Even better would be a container with jsclient and any processor (Python or C++).

Issue in running docker-compose.yaml

Hi,
When I give the following command:
docker-compose -f docker-compose.yaml up
I get this error:

validator is up-to-date
sawtooth-simplewallet_settings-tp_1 is up-to-date
simplewallet-processor is up-to-date
rest-api is up-to-date
Recreating simplewallet-client ... error

ERROR: for simplewallet-client  Cannot start service simplewallet-client: failed to create endpoint simplewallet-client on network sawtooth-simplewallet_default: Windows does not support host IP addresses in NAT settings

ERROR: for simplewallet-client  Cannot start service simplewallet-client: failed to create endpoint simplewallet-client on network sawtooth-simplewallet_default: Windows does not support host IP addresses in NAT settings
ERROR: Encountered errors while bringing up the project.

Please help. What should I do?

Transfer to new client not working

Hey,
I've set up 3 clients for an instance, client A, client B, client C. If the client A did some transaction deposited 10000 and transfer 1000 to client C which doesn't have any transactions, the balance for client C shown as undefined.
If client B have made a few transactions and the balance for client B is 1000 then if client A transfer it is credited to client B account.

Error on building yaml file

Some days ago the code was functioning well, but recently I get this error on compiling the simplewallet-build-tp.py file:

curl: (6) Could not resolve host: p80.pool.sks-keyservers.net
gpg: no valid OpenPGP data found.

The command '/bin/sh -c apt-get update && apt-get install -y -q curl gnupg && curl -sSL 'http://p80.pool.sks-keyservers.net/pks/lookup?op=get&search=0x8AA7AF1F1091A5FD' | apt-key add - && echo 'deb [arch=amd64] http://repo.sawtooth.me/ubuntu/chime/stable bionic universe' >> /etc/apt/sources.list && apt-get update' returned a non-zero code: 2
ERROR: Service 'simplewallet-client' failed to build : Build failed

simplewallet balance jack, Not working with the following error.

root@d533a2567fd4:/project/simplewallet/pyclient# simplewallet balance jack #Displays the balance left in Jack's account
[19:48:16 INFO connectionpool] Starting new HTTP connection (1): rest-api
[19:48:16 DEBUG connectionpool] "GET /state/7e266409c158f073860c0938ce27c3eea1354b73d3313da10e46c6a828eac674bef285 HTTP/1.1" 404 134
Traceback (most recent call last):
File "/project/simplewallet/pyclient/wallet/simplewallet_client.py", line 148, in _send_to_restapi
result.status_code, result.reason))
Exception: Error 404: Not Found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/project/simplewallet/pyclient/wallet/simplewallet_cli.py", line 257, in main_wrapper
main()
File "/project/simplewallet/pyclient/wallet/simplewallet_cli.py", line 243, in main
do_balance(args)
File "/project/simplewallet/pyclient/wallet/simplewallet_cli.py", line 208, in do_balance
data = client.balance()
File "/project/simplewallet/pyclient/wallet/simplewallet_client.py", line 117, in balance
"state/{}".format(self._address))
File "/project/simplewallet/pyclient/wallet/simplewallet_client.py", line 155, in _send_to_restapi
raise Exception(err)
Exception: Error 404: Not Found

It will die if i transfer to user(who he dont run simplewallet deposit first)(bug)

This is my step:

  1. sawtooth keygen a
  2. sawtooth keygen b
  3. simplewallet deposit 100 a
  4. simplewallet transfer 25 a b

(just not deposit any value to b)

And then,the docker logs will scroll a lot of info cyclically,the info like this:


simplewallet-processor    | Got: transfer and 25
simplewallet-processor    | Got beneficiary: 03605ad5fbb2c9106e71dddb5e1492aaffbf29358cd41b8c02bd061869c873a940
simplewallet-processor    | 479056 [0x7fee26c74780] DEBUG simplewallet null - SimpleWalletApplicator::doTransfer Key: 022116461963790d88e315c0fc81e3f8f2ae74aac5eff42fb888edb69405d34df4 Address: 7e266467df98ca12dc7b4d797a3c13e07718e2066b353a50f73072c4c2f7d3a4fdaaa1
simplewallet-processor    | 479056 [0x7fee26c74780] DEBUG simplewallet null - SimpleWalletApplicator::doTransfer Beneficiary Key: 03605ad5fbb2c9106e71dddb5e1492aaffbf29358cd41b8c02bd061869c873a940 Address: 7e26649edfba4e018ac9c59a0462e8d8565ec4b1db295597da83b7d9819705d090bbe8
simplewallet-processor    | 479057 [0x7fee225c4700] DEBUG sawtooth.MessageDispatcher null - ReceiveMessage MessageType: 8
simplewallet-processor    | 479058 [0x7fee225c4700] DEBUG sawtooth.MessageDispatcher null - ReceiveMessage MessageType: 8
simplewallet-processor    | 479058 [0x7fee26c74780] ERROR sawtooth.TransactionProcessor null - applicator->Apply unknown error

And if i exec the command simplewallet balance b it will display 404 Not Found.
Like this:

simplewallet balance y
[12:01:14 INFO    connectionpool] Starting new HTTP connection (1): rest-api
[12:01:14 DEBUG   connectionpool] "GET /state/7e26649edfba4e018ac9c59a0462e8d8565ec4b1db295597da83b7d9819705d090bbe8 HTTP/1.1" 404 134
Error: Error 404: Not Found

I think its solution is:
If i try transfer it will check first if this user had balance(it just can be 0).
Another i think it can initialize user 's balance to 0 if i 'keygen'

Thank you~

Loops on the go processor

When we transfer money to an account that doesn't have balance the processor goes into a loop. I've tried to change the error handling to

return &processor.InvalidTransactionError{Msg: "Didn't find the wallet key associated with user key " + self.getUserTo()}

But still i get a loop, any ideas?

Upgrade simplewallet to use Sawtooth 1.1

The changes are needed to the docker-compose .yaml files to use the 1.1 containers (instead of 1.0) and to add a devmode-engine-rust container.

The diffs should be very similar to the changes I made to cookiejar. Here's the diffs:
danintel/sawtooth-cookiejar@9f0b69c

The sawtooth-validator command line needs this new argument: --bind consensus:tcp://eth0:5050

The repository needs updating from 1.0 to "bumper" (1.1) and adding [arch=amd64] Something like:
"deb [arch=amd64] http://repo.sawtooth.me/ubuntu/bumper/stable xenial universe"

The dev-mode engine addition to the .yaml files should be something like:

+  devmode-engine:
+    image: hyperledger/sawtooth-devmode-engine-rust:1.1
+    ports:
+      - '5050:5050'
+    container_name: sawtooth-devmode-engine-rust-default
+    depends_on:
+      - validator
+    entrypoint: devmode-engine-rust --connect tcp://validator:5050

unable to get chain head from block store

This is the error i am facing i have done native installation. I am hitting the Javascript application
The validator has no genesis block, and so cannot be queried. Wait for genesis to be completed and resubmit. If you are running the validator, ensure it was set up properly.

Transfer 0 error

I tried the following command "simplewallet transfer 0 <user 1> <user 2>" and there was something like an infinite loop. This was the error that was displayed.

simplewallet-processor | SimpleWalletApplicator::Apply
simplewallet-processor | Got: transfer and 0
simplewallet-processor | Got beneficiary: 023e1bde5961655a5c3a51daab5e5820556fadd722932d7dd3eee38ecbc0ab2f94
simplewallet-processor | 124360 [0x7faca6499780] DEBUG simplewallet null - SimpleWalletApplicator::doTransfer Key: 020ec936c18ed8d96272e8c62f5269db1122656ca0e9a894d37c8005a5a7c632f5 Address: 7e26646cb200282575bc2638258e663febd8ffcf543f0690bd2dc8da494d4bd2e6bac3
simplewallet-processor | 124361 [0x7faca6499780] DEBUG simplewallet null - SimpleWalletApplicator::doTransfer Beneficiary Key: 023e1bde5961655a5c3a51daab5e5820556fadd722932d7dd3eee38ecbc0ab2f94 Address: 7e2664e728c0be707e30c78292c546be8be02442d70e6e0597c5e2b0ec77505b221589
simplewallet-processor | 124363 [0x7faca1de9700] DEBUG sawtooth.MessageDispatcher null - ReceiveMessage MessageType: 8
simplewallet-processor | 124364 [0x7faca6499780] ERROR sawtooth.TransactionProcessor null - applicator->Apply unknown error
simplewallet-processor | 124365 [0x7faca1de9700] DEBUG sawtooth.MessageDispatcher null - ReceiveMessage MessageType: 5

simplewallet-processor container exists without any error

simplewallet-processor container exists without any error

here's the log of docker container:

-- The CXX compiler identification is GNU 5.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /project/simplewallet/cxxprocessor/build
Scanning dependencies of target simplewallet-tp
[ 50%] Building CXX object CMakeFiles/simplewallet-tp.dir/simplewallet-tp.cpp.o
[100%] Linking CXX executable bin/simplewallet-tp
[100%] Built target simplewallet-tp
-- Configuring done
-- Generating done
-- Build files have been written to: /project/simplewallet/cxxprocessor/build
[100%] Built target simplewallet-tp

List transactions

Nice work guys, but is there any way i can list the transactions for a wallet? thanks

Login not working on js client UI

When clicking the login button after giving the username, in the js client UI, it doesn't go to the home page.
Refreshes and stays on the same page.
(Browser - firefox 63.0.3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.