H 531: Hyperledger IROHA (15 pts)

What you need

Purpose

To practice using Hyperledger, IBM's blockchain. We'll use the simplest product, IROHA.

Background

Hyperledger is a general-purpose framework that can be used to construct blockchain solutions for many business cases. Here's an explanation from the excellent whitepaper, An Introduction to Hyperledger
"Hyperledger serves as a 'greenhouse' that brings together users, developers, and vendors from many different sectors and market spaces. All these participants have one thing in common: All are interested in learning about, developing, and using enterprise blockchains.
Here are the main components currently available for Hyperledger:

Installing Docker

Execute these commands:
sudo apt update
sudo apt install git apt-transport-https ca-certificates curl gnupg2 software-properties-common -y 
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce -y
sudo systemctl status docker
You see docker's status is "active (running)" as shown below.

Press Q to exit the status page.

Creating a Docker Network

Iroha uses two containers: one for the blockchain, and one for a PostgreSQL server.

We need to create a virtual network so they can communicate with one another.

Execute this command:

sudo docker network create iroha-network
The command succeeds and returns a long hexadecimal number.

Starting a PostgreSQL Container

Now we'll download and run a Postgres container, connected to the virtual network we created above.

Execute this command:

sudo docker run --name some-postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-p 5432:5432 \
--network=iroha-network \
-d postgres:9.5 \
-c 'max_prepared_transactions=100'
Docker downloads a container and runs it, as shown below.

Execute this command:

sudo ss -nltp
Docker-proxy is now listening on port 5432, as shown below.

Creating a Blockstore

This persistent volume will be used to store blocks for the chain.

Execute this command:

sudo docker volume create blockstore
The command succeeds, with the message "blockstore".

Downloading Example Configuration Files

Execute this command:
git clone -b main https://github.com/hyperledger/iroha --depth=1
The code downloads, as shown below.

Starting the Iroha Container

Execute this command:
sudo docker run --name iroha \
-d \
-p 50051:50051 \
-v $(pwd)/iroha/example:/opt/iroha_data \
-v blockstore:/tmp/block_store \
--network=iroha-network \
-e KEY='node0' \
hyperledger/iroha:latest
Docker pulls down another image, as shown below.

Launching the CLI

The blockchain is now running. We'll use a simple CLI to operate it.

Execute this command:

sudo docker exec -it iroha /bin/bash
You see a bash prompt inside the iroha Docker container.

Execute this command to connect with the "admin" account in the "test" domain:

iroha-cli -account_name admin@test
You see a menu with three options, as shown below.

Creating the First Transaction: Creating an Asset

Make these selections, one at a time, to create a new asset named "coolcoin". Type the bold text:
1. New transaction (tx)
9. Create Asset (crt_ast)
Asset name: coolcoin
Domain Id: test
Asset precision: 2
The command is formed, as shown below.

Submitting the Transaction

Make these selections, one at a time, to create a new asset. Type the bold text:
4. Send to Iroha peer (send)
Peer address (0.0.0.0): localhost
Peer port (50051): Press Enter
The transaction is accepted, as shown below.

Creating a Query

Let's check to see if the transaction succeeded.

Make these selections, one at a time:

2. New query (qry)
3. Get information about asset (get_ast_info)
Requested Asset Id: coolcoin#test
1. Send to Iroha peer (send)
Peer address (0.0.0.0): localhost
Peer port (50051): Press Enter
Four lines of information are returned, showing that the asset has been created, as shown below.

Issuing Some Coolcoins

Make these selections, one at a time, to issue 1000 coolcoins.

Type the bold text:

1. New transaction (tx)
16. Add Asset Quantity (add_ast_qty)
Asset Id: coolcoin#test
Amount to add, e.g 123.456: 1000.00
4. Send to Iroha peer (send)
Peer address (localhost): Press Enter
Peer port (50051): Press Enter
The transaction is accepted, as shown below.

Querying the "admin" Account's Assets

Let's check to see if the transaction succeeded. If it did, the coins should be in the "admin" account.

Make these selections, one at a time:

2. New query (qry)
8. Get Account's Assets (get_acc_ast)
Requested account Id: admin@test
Requested Asset Id: coolcoin#test
1. Send to Iroha peer (send)
Peer address (localhost): Press Enter
Peer port (50051): Press Enter
The account has a balance of 1000, as shown below.

Transferring Coins to the "test" Account

The coins are now in the "admin" account. Let's transfer 100 of them to the "test" account.

Make these selections, one at a time, to create a new asset. Type the bold text:

1. New transaction (tx)
4. Transfer Assets (tran_ast)
SrcAccount Id: admin@test
DestAccount Id: test@test
Asset Id: coolcoin#test
Amount to transfer, e.g 123.456: 100.00
4. Send to Iroha peer (send)
Peer address (localhost): Press Enter
Peer port (50051): Press Enter
The transaction is accepted, as shown below.

Querying the "test" Account's Assets

Let's check to see if the transaction succeeded. If it did, the coins should be in the "admin" account.

Make these selections, one at a time:

2. New query (qry)
8. Get Account's Assets (get_acc_ast)
Requested account Id: test@test
Requested Asset Id: coolcoin#test
1. Send to Iroha peer (send)
Peer address (localhost): Press Enter
Peer port (50051): Press Enter
The account has a balance of 100, as shown below.

Attempting to Overdraw Coins

The "admin" account only has 900 coins left. Let's try to transfer 1000 coins to the "test" account.

Make these selections, one at a time, to create a new asset. Type the bold text:

1. New transaction (tx)
4. Transfer Assets (tran_ast)
SrcAccount Id: admin@test
DestAccount Id: test@test
Asset Id: coolcoin#test
Amount to transfer, e.g 123.456: 1000.00
4. Send to Iroha peer (send)
Peer address (localhost): Press Enter
Peer port (50051): Press Enter
The transaction is accepted, as shown below.

Notice the long transaction hash value, below the "Congratulation" line. Copy it to the Clipboard--you'll need it later.

If you are using Google Cloud, highlight it to copy it--don't press Ctrl+C.

Viewing Transaction Status

Let's check to see if the transaction succeeded.

Make these selections, one at a time:

3. New transaction status request (st)
1. Get status of transaction (get_tx_info)
Requested tx hash: Paste in your hash value
1. Send to Iroha peer (send)
Peer address (0.0.0.0): localhost
Peer port (50051): Press Enter
The transaction was rejected, as shown below.

Viewing Roles

Make these selections, one at a time:
2. New query (qry)
6. Get all current roles in the system (get_roles)
1. Send to Iroha peer (send)
Peer address (localhost): Press Enter
Peer port (50051): Press Enter
There are three roles, as shown below.

H 531.1: Role (15 pts)

Find the third role, which is govered by a green rectangle in the image above.

That's the flag.

Exiting from Docker

Enter these commands to exit.

Ctrl+Z.

exit
exit

Sources

How To Install and Use Docker on Debian 10
Hyperledger Iroha Quick Start Guide

Posted 6-10-2020
Updated 9-20-2021