diff --git a/example/.gitignore b/example/.gitignore index a775609891..33d08b130e 100755 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,2 +1,3 @@ tx.json rx.json +config.json \ No newline at end of file diff --git a/example/config.json b/example/config.json index 1d5d9a216a..54b5890579 100644 --- a/example/config.json +++ b/example/config.json @@ -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 } diff --git a/example/config.sample b/example/config.sample new file mode 100644 index 0000000000..54b5890579 --- /dev/null +++ b/example/config.sample @@ -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 +} diff --git a/example/functions.sh b/example/functions.sh new file mode 100644 index 0000000000..33f70eed61 --- /dev/null +++ b/example/functions.sh @@ -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 +} \ No newline at end of file diff --git a/example/hakodate.sh b/example/hakodate.sh index afe43a03b8..4286ce2c29 100755 --- a/example/hakodate.sh +++ b/example/hakodate.sh @@ -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 diff --git a/example/run.sh b/example/run.sh old mode 100644 new mode 100755 index 3af6e1425a..f408340ec6 --- a/example/run.sh +++ b/example/run.sh @@ -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 \ No newline at end of file + +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 \ No newline at end of file diff --git a/example/zero.block b/example/zero.block index 5fa4b1e5ed..4bee44cc24 100644 --- a/example/zero.block +++ b/example/zero.block @@ -25,7 +25,7 @@ "commands": [ { "command_type": "AddPeer", - "address": "0.0.0.0:10001", + "address": "0.0.0.0:10000", "peer_key": "0000000000000000000000000000000000000000000000000000000000000000" } ]