Skip to content

Commit

Permalink
Refactor scripts, update zero.block, add config sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsa authored and lebdron committed Oct 2, 2017
1 parent a072171 commit c9bc2cd
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 60 deletions.
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
tx.json
rx.json
config.json
4 changes: 2 additions & 2 deletions example/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"block_store_path" : "/tmp/block_store/",
"torii_port" : 50051,
"pg_opt" : "host=iroha1001_postgres_1 port=5432 user=iroha password=helloworld",
"redis_host" : "iroha1001_redis_1",
"pg_opt" : "host=localhost port=5432 user=postgres password=mysecretpassword",
"redis_host" : "localhost",
"redis_port" : 6379
}
7 changes: 7 additions & 0 deletions example/config.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"block_store_path" : "/tmp/block_store/",
"torii_port" : 50051,
"pg_opt" : "host=localhost port=5432 user=postgres password=mysecretpassword",
"redis_host" : "localhost",
"redis_port" : 6379
}
53 changes: 53 additions & 0 deletions example/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# to print name of the command or query and wait enter to be pushed
function print_and_read() {
echo "=== $1 ==="
read
}

# update tx counter and created ts of tx
function update_tx() {
created_ts=$(./current_millis)
((tx_counter+=1))

< $(basename $1) \
sed -e "s/\"created_ts\".*/\"created_ts\": $created_ts,/" \
-e "s/\"tx_counter\".*/\"tx_counter\": $tx_counter,/" >tx.json
}

# update tx counter and created ts of query
function update_query() {
created_ts=$(./current_millis)
((tx_counter+=1))

< $(basename $1) \
sed -e "s/\"created_ts\".*/\"created_ts\": $created_ts,/" \
-e "s/\"tx_counter\".*/\"tx_counter\": $tx_counter,/" >rx.json
}

# update and send tx
function send() {
update_tx $1
$IROHA_CLI --grpc --json_transaction tx.json
}

# update and recv result of the query
function recv() {
update_query $1
$IROHA_CLI --grpc --json_query rx.json
}

# print and send command
function run_send() {
print_and_read $1
send $2
echo
}

# print and run query
function run_recv() {
print_and_read $1
recv $2
echo
}
72 changes: 23 additions & 49 deletions example/hakodate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,75 +74,49 @@
#
#------------------------------------------------------------------------

source functions.sh

#IROHA_NODE=iroha_node_1
#IROHA_HOME=/opt/iroha/build/bin
if [[ -z "${IROHA_CLI}" ]];
then IROHA_CLI=/opt/iroha/build/bin/iroha-cli
fi
#IROHA_CLI=/opt/iroha/build/bin/iroha-cli
#IROHA_SEND="--grpc --json_transaction"
#IROHA_RECV="--grpc --json_query"

tx_counter=0

#CURDIR=$(basename $(pwd))

function send() {
echo "=== $1 ==="
read

created_ts=$(./current_millis)
((tx_counter+=1))

< $(basename $2) \
sed -e "s/\"created_ts\".*/\"created_ts\": $created_ts,/" \
-e "s/\"tx_counter\".*/\"tx_counter\": $tx_counter,/" >tx.json

/opt/iroha/build/bin/iroha-cli --grpc --json_transaction tx.json
echo
}

function recv() {
echo "=== $1 ==="
read

created_ts=$(./current_millis)
((tx_counter+=1))

< $(basename $2) \
sed -e "s/\"created_ts\".*/\"created_ts\": $created_ts,/" \
-e "s/\"tx_counter\".*/\"tx_counter\": $tx_counter,/" >rx.json

/opt/iroha/build/bin/iroha-cli --grpc --json_query rx.json
echo
}

## # Generate New Key-pair by iroha-cli
## docker exec -t iroha_node_1 /usr/local/iroha/bin/iroha-cli --new_account --name alice --pass_phrase hell0wor1d

send "CreateDomain" CreateDomain.json
run_send "CreateDomain" CreateDomain.json

send "CreateAsset" CreateAsset.json
run_send "CreateAsset" CreateAsset.json

recv "GetAccount (alice)" GetAccount-alice.json
send "CreateAccount (alice)" CreateAccount-alice.json
recv "GetAccount (alice)" GetAccount-alice.json
run_recv "GetAccount (alice)" GetAccount-alice.json
run_send "CreateAccount (alice)" CreateAccount-alice.json
run_recv "GetAccount (alice)" GetAccount-alice.json

send "CreateAccount (bob)" CreateAccount-bob.json
recv "GetAccount (bob)" GetAccount-bob.json
run_send "CreateAccount (bob)" CreateAccount-bob.json
run_recv "GetAccount (bob)" GetAccount-bob.json

send "AddSignatory (bob)" AddSignatory-bob.json
recv "GetSignatories (bob)" GetSignatories.json
run_send "AddSignatory (bob)" AddSignatory-bob.json
run_recv "GetSignatories (bob)" GetSignatories.json

send "AddAssetQuantity (alice)" AddAssetQuantity-alice.json
recv "GetAccountAssets (alice)" GetAccountAssets-alice.json
run_send "AddAssetQuantity (alice)" AddAssetQuantity-alice.json
run_recv "GetAccountAssets (alice)" GetAccountAssets-alice.json

send "AddAssetQuantity (bob)" AddAssetQuantity-bob.json
recv "GetAccountAssets (bob)" GetAccountAssets-bob.json
run_send "AddAssetQuantity (bob)" AddAssetQuantity-bob.json
run_recv "GetAccountAssets (bob)" GetAccountAssets-bob.json

send "TransferAsset" TransferAsset.json
recv "GetAccountAssets (alice)" GetAccountAssets-alice.json
recv "GetAccountAssets (bob)" GetAccountAssets-bob.json
run_send "TransferAsset" TransferAsset.json
run_recv "GetAccountAssets (alice)" GetAccountAssets-alice.json
run_recv "GetAccountAssets (bob)" GetAccountAssets-bob.json

recv "GetAccountTransactions (bob)" GetAccountTransactions.json
run_recv "GetAccountTransactions (bob)" GetAccountTransactions.json

recv "GetAccountAssetTransactions (alice)" GetAccountAssetTransactions-alice.json
run_recv "GetAccountAssetTransactions (alice)" GetAccountAssetTransactions-alice.json

exit 0
23 changes: 15 additions & 8 deletions example/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#!/bin/bash
../build/bin/iroha-cli --grpc --json_transaction CreateDomain.json
../build/bin/iroha-cli --grpc --json_transaction CreateAsset.json
../build/bin/iroha-cli --grpc --json_transaction CreateAccount-alice.json
../build/bin/iroha-cli --grpc --json_transaction CreateAccount-bob.json
../build/bin/iroha-cli --grpc --json_transaction AddSignatory-bob.json
../build/bin/iroha-cli --grpc --json_transaction AddAssetQuantity-alice.json
../build/bin/iroha-cli --grpc --json_transaction AddAssetQuantity-bob.json
../build/bin/iroha-cli --grpc --json_transaction TransferAsset.json

source functions.sh

if [[ -z "${IROHA_CLI}" ]];
then IROHA_CLI=/opt/iroha/build/bin/iroha-cli
fi

send CreateDomain.json
send CreateAsset.json
send CreateAccount-alice.json
send CreateAccount-bob.json
send AddSignatory-bob.json
send AddAssetQuantity-alice.json
send AddAssetQuantity-bob.json
send TransferAsset.json
2 changes: 1 addition & 1 deletion example/zero.block
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"commands": [
{
"command_type": "AddPeer",
"address": "0.0.0.0:10001",
"address": "0.0.0.0:10000",
"peer_key": "0000000000000000000000000000000000000000000000000000000000000000"
}
]
Expand Down

0 comments on commit c9bc2cd

Please sign in to comment.