From 8b03b054080c4b4451ecc1ac307357e476c74e6a Mon Sep 17 00:00:00 2001 From: Jiyun Park Date: Thu, 27 Dec 2018 18:39:11 +0900 Subject: [PATCH 1/7] [LC-102] remove subscribeUseHttps from iconrpcserver_conf.json --- conf/iconrpcserver_conf.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conf/iconrpcserver_conf.json b/conf/iconrpcserver_conf.json index 9dc6fcad2..7144ae8d8 100644 --- a/conf/iconrpcserver_conf.json +++ b/conf/iconrpcserver_conf.json @@ -17,6 +17,5 @@ "port": 9000, "amqpTarget": "127.0.0.1", "amqpKey": "7100", - "gunicornWorkerCount": 1, - "subscribeUseHttps": true + "gunicornWorkerCount": 1 } From 3abe0d648381d380a80a01874588936564480e4f Mon Sep 17 00:00:00 2001 From: Jiyun Park Date: Wed, 9 Jan 2019 17:58:15 +0900 Subject: [PATCH 2/7] update script url and README --- README.md | 6 ++---- run_loopchain.sh | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 686c23d3f..7af0fc0ee 100644 --- a/README.md +++ b/README.md @@ -87,11 +87,9 @@ $ ./run_test.sh ``` $ mkdir -p resources/my_pki -$ cd resources/my_pki -$ openssl ecparam -genkey -name secp256k1 | openssl ec -aes-256-cbc -out my_private.pem # generate private key -$ openssl ec -in my_private.pem -pubout -out my_public.pem # generate public key +$ openssl ecparam -genkey -name secp256k1 | openssl ec -aes-256-cbc -out ./resources/my_pki/my_private.pem # generate private key +$ openssl ec -in ./resources/my_pki/my_private.pem -pubout -out ./resources/my_pki/my_public.pem # generate public key $ export PW_icon_dex={ENTER_MY_PASSWORD} -$ cd ../../ ``` #### Run loopchain as a Citizen Node diff --git a/run_loopchain.sh b/run_loopchain.sh index f2ace1cf1..0abb0eea4 100755 --- a/run_loopchain.sh +++ b/run_loopchain.sh @@ -11,7 +11,7 @@ fi touch $PID_FILE echo "Run loopchain for citizen start!" -./loopchain.py citizen -r https://cicon.net.solidwallet.io -o ./conf/loopchain_conf.json & +./loopchain.py citizen -r https://test-ctz.solidwallet.io -o ./conf/loopchain_conf.json & echo $! > $PID_FILE echo "Run iconservice for citizenstart!" From c029829507f528ea956cdb94380fbb09206aa9b6 Mon Sep 17 00:00:00 2001 From: Jiyun Park Date: Fri, 18 Jan 2019 14:35:24 +0900 Subject: [PATCH 3/7] [LC-102] add script & config for run mainnet/testnet citizen node --- conf/{ => mainnet}/iconrpcserver_conf.json | 2 +- conf/{ => mainnet}/iconservice_conf.json | 10 +++---- conf/{ => mainnet}/loopchain_conf.json | 5 ++-- conf/testnet/iconrpcserver_conf.json | 21 ++++++++++++++ conf/testnet/iconservice_conf.json | 28 +++++++++++++++++++ conf/testnet/loopchain_conf.json | 32 ++++++++++++++++++++++ run_mainnet_citizen.sh | 21 ++++++++++++++ run_loopchain.sh => run_testnet_citizen.sh | 10 +++---- run_test.sh => run_unittest.sh | 0 stop_all.sh => stop_mainnet_citizen.sh | 21 ++++++-------- stop_testnet_citizen.sh | 19 +++++++++++++ 11 files changed, 144 insertions(+), 25 deletions(-) rename conf/{ => mainnet}/iconrpcserver_conf.json (88%) rename conf/{ => mainnet}/iconservice_conf.json (65%) rename conf/{ => mainnet}/loopchain_conf.json (84%) create mode 100644 conf/testnet/iconrpcserver_conf.json create mode 100644 conf/testnet/iconservice_conf.json create mode 100644 conf/testnet/loopchain_conf.json create mode 100755 run_mainnet_citizen.sh rename run_loopchain.sh => run_testnet_citizen.sh (56%) rename run_test.sh => run_unittest.sh (100%) rename stop_all.sh => stop_mainnet_citizen.sh (52%) create mode 100755 stop_testnet_citizen.sh diff --git a/conf/iconrpcserver_conf.json b/conf/mainnet/iconrpcserver_conf.json similarity index 88% rename from conf/iconrpcserver_conf.json rename to conf/mainnet/iconrpcserver_conf.json index 7144ae8d8..67381013d 100644 --- a/conf/iconrpcserver_conf.json +++ b/conf/mainnet/iconrpcserver_conf.json @@ -3,7 +3,7 @@ "logger": "iconrpcserver", "colorLog": true, "level": "warning", - "filePath": "./log/iconrpcserver.log", + "filePath": "./log/mainnet/iconrpcserver.log", "outputType": "console|file", "rotate": { "type": "period|bytes", diff --git a/conf/iconservice_conf.json b/conf/mainnet/iconservice_conf.json similarity index 65% rename from conf/iconservice_conf.json rename to conf/mainnet/iconservice_conf.json index c2cc0a8d8..d4595d082 100644 --- a/conf/iconservice_conf.json +++ b/conf/mainnet/iconservice_conf.json @@ -3,7 +3,7 @@ "logger": "iconservice", "colorLog": true, "level": "warning", - "filePath": "./log/iconservice.log", + "filePath": "./log/mainnet/iconservice.log", "outputType": "console|file", "rotate": { "type": "period|bytes", @@ -13,15 +13,15 @@ "maxBytes": 50000000 } }, - "scoreRootPath": ".storage_test/.score_testnet", - "stateDbRootPath": ".storage_test/.statedb_testnet", + "scoreRootPath": ".storage_mainnet/.score", + "stateDbRootPath": ".storage_mainnet/.statedb", "channel": "icon_dex", "amqpKey": "7100", "amqpTarget": "127.0.0.1", - "builtinScoreOwner": "hx6e1dd0d4432620778b54b2bbc21ac3df961adf89", + "builtinScoreOwner": "hx677133298ed5319607a321a38169031a8867085c", "service": { "fee": true, - "audit": false, + "audit": true, "deployerWhiteList": false, "scorePackageValidator": false } diff --git a/conf/loopchain_conf.json b/conf/mainnet/loopchain_conf.json similarity index 84% rename from conf/loopchain_conf.json rename to conf/mainnet/loopchain_conf.json index 14926b71d..c7c895c0c 100644 --- a/conf/loopchain_conf.json +++ b/conf/mainnet/loopchain_conf.json @@ -22,8 +22,9 @@ "USE_EXTERNAL_REST": true, "PORT_PEER": 7100, "AMQP_KEY": "7100", - "DEFAULT_STORAGE_PATH": ".storage_test/", + "DEFAULT_STORAGE_PATH": ".storage_mainnet/", "ALLOW_MAKE_EMPTY_BLOCK": false, "SUBSCRIBE_USE_HTTPS": true, - "LOOPCHAIN_LOG_LEVEL": "INFO" + "LOOPCHAIN_LOG_LEVEL": "INFO", + "LOG_FILE_LOCATION": "./log/mainnet" } diff --git a/conf/testnet/iconrpcserver_conf.json b/conf/testnet/iconrpcserver_conf.json new file mode 100644 index 000000000..17c07dd34 --- /dev/null +++ b/conf/testnet/iconrpcserver_conf.json @@ -0,0 +1,21 @@ +{ + "log": { + "logger": "iconrpcserver", + "colorLog": true, + "level": "warning", + "filePath": "./log/testnet/iconrpcserver.log", + "outputType": "console|file", + "rotate": { + "type": "period|bytes", + "period": "daily", + "interval": 1, + "backupCount": 10, + "maxBytes": 50000000 + } + }, + "channel": "icon_dex", + "port": 9100, + "amqpTarget": "127.0.0.1", + "amqpKey": "7200", + "gunicornWorkerCount": 1 +} diff --git a/conf/testnet/iconservice_conf.json b/conf/testnet/iconservice_conf.json new file mode 100644 index 000000000..d230bab78 --- /dev/null +++ b/conf/testnet/iconservice_conf.json @@ -0,0 +1,28 @@ +{ + "log": { + "logger": "iconservice", + "colorLog": true, + "level": "warning", + "filePath": "./log/testnet/iconservice.log", + "outputType": "console|file", + "rotate": { + "type": "period|bytes", + "period": "daily", + "interval": 1, + "backupCount": 10, + "maxBytes": 50000000 + } + }, + "scoreRootPath": ".storage_testnet/.score", + "stateDbRootPath": ".storage_testnet/.statedb", + "channel": "icon_dex", + "amqpKey": "7200", + "amqpTarget": "127.0.0.1", + "builtinScoreOwner": "hxba096790caa1804a8828939839a901a5978020a7", + "service": { + "fee": true, + "audit": true, + "deployerWhiteList": false, + "scorePackageValidator": false + } +} diff --git a/conf/testnet/loopchain_conf.json b/conf/testnet/loopchain_conf.json new file mode 100644 index 000000000..0a5a2c336 --- /dev/null +++ b/conf/testnet/loopchain_conf.json @@ -0,0 +1,32 @@ +{ + "LOOPCHAIN_DEFAULT_CHANNEL": "icon_dex", + "CHANNEL_OPTION" : { + "icon_dex": { + "block_versions": { + "0.1a": 0 + }, + "hash_versions": { + "genesis": 0, + "0x2": 1, + "0x3": 1 + }, + "store_valid_transaction_only": true, + "send_tx_type": 2, + "load_cert": false, + "consensus_cert_use": false, + "tx_cert_use": false, + "key_load_type": 0, + "public_path": "./resources/my_pki/my_public.pem", + "private_path": "./resources/my_pki/my_private.pem" + } + }, + "USE_EXTERNAL_SCORE": true, + "USE_EXTERNAL_REST": true, + "PORT_PEER": 7200, + "AMQP_KEY": "7200", + "DEFAULT_STORAGE_PATH": ".storage_testnet/", + "ALLOW_MAKE_EMPTY_BLOCK": false, + "SUBSCRIBE_USE_HTTPS": true, + "LOOPCHAIN_LOG_LEVEL": "INFO", + "LOG_FILE_LOCATION": "./log/testnet" +} diff --git a/run_mainnet_citizen.sh b/run_mainnet_citizen.sh new file mode 100755 index 000000000..8c67c46b3 --- /dev/null +++ b/run_mainnet_citizen.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +export REDIRECT_PROTOCOL=https +PID_FILE="mainnet_citizen.pid" + +if [ -f ${PID_FILE} ]; then + echo "remove ${PID_FILE}" + rm -f ${PID_FILE} +fi + +touch ${PID_FILE} + +echo "Run loopchain for citizen start!" +./loopchain.py citizen -d -r https://int-ctz.solidwallet.io -o ./conf/mainnet/loopchain_conf.json & +echo $! > $PID_FILE + +echo "Run iconservice for citizen start!" +iconservice start -c ./conf/mainnet/iconservice_conf.json & + +echo "Run iconrpcserver for citizen start!" +iconrpcserver start -p 9000 -c conf/mainnet/iconrpcserver_conf.json & diff --git a/run_loopchain.sh b/run_testnet_citizen.sh similarity index 56% rename from run_loopchain.sh rename to run_testnet_citizen.sh index 0abb0eea4..7537968aa 100755 --- a/run_loopchain.sh +++ b/run_testnet_citizen.sh @@ -1,7 +1,7 @@ #!/bin/sh export REDIRECT_PROTOCOL=https -PID_FILE="loopchain.pid" +PID_FILE="testnet_citizen.pid" if [ -f $PID_FILE ]; then echo "remove $PID_FILE" @@ -11,11 +11,11 @@ fi touch $PID_FILE echo "Run loopchain for citizen start!" -./loopchain.py citizen -r https://test-ctz.solidwallet.io -o ./conf/loopchain_conf.json & +./loopchain.py citizen -r https://test-ctz.solidwallet.io -o ./conf/testnet/loopchain_conf.json & echo $! > $PID_FILE -echo "Run iconservice for citizenstart!" -iconservice start -c ./conf/iconservice_conf.json & +echo "Run iconservice for citizen start!" +iconservice start -c ./conf/testnet/iconservice_conf.json & echo "Run iconrpcserver for citizen start!" -iconrpcserver start -p 9000 -c conf/iconrpcserver_conf.json & +iconrpcserver start -p 9100 -c conf/testnet/iconrpcserver_conf.json & diff --git a/run_test.sh b/run_unittest.sh similarity index 100% rename from run_test.sh rename to run_unittest.sh diff --git a/stop_all.sh b/stop_mainnet_citizen.sh similarity index 52% rename from stop_all.sh rename to stop_mainnet_citizen.sh index 1f8b49454..f7d72e15d 100755 --- a/stop_all.sh +++ b/stop_mainnet_citizen.sh @@ -1,22 +1,19 @@ #!/bin/sh -echo "Stop loopchain Processes" - - -echo "Stopping iconservice..." -iconservice stop -c ./conf/iconservice_conf.json - - -echo "Stopping iconrpcserver..." -iconrpcserver stop -p 9000 -c conf/iconrpcserver_conf.json +echo "Stop loopchain Processes" -PID_FILE="loopchain.pid" +PID_FILE="mainnet_citizen.pid" if [ -f ${PID_FILE} ]; then - echo "Kill All python process" + echo "Kill loopchain on mainnet process" PID=`cat ${PID_FILE}` pgrep -P ${PID} | xargs -I ARG kill -9 ARG kill ${PID} - rm -f loopchain.pid + rm -f ${PID_FILE} fi +echo "Stopping iconservice..." +iconservice stop -c ./conf/mainnet/iconservice_conf.json + +echo "Stopping iconrpcserver..." +iconrpcserver stop -p 9100 -c ./conf/mainnet/iconrpcserver_conf.json pkill -f gunicorn diff --git a/stop_testnet_citizen.sh b/stop_testnet_citizen.sh new file mode 100755 index 000000000..ff66d0f7f --- /dev/null +++ b/stop_testnet_citizen.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +echo "Stop loopchain Processes" + +PID_FILE="testnet_citizen.pid" +if [ -f ${PID_FILE} ]; then + echo "Kill loopchain on testnet process" + PID=`cat ${PID_FILE}` + pgrep -P ${PID} | xargs -I ARG kill -9 ARG + kill ${PID} + rm -f ${PID_FILE} +fi + +echo "Stopping iconservice..." +iconservice stop -c ./conf/testnet/iconservice_conf.json + +echo "Stopping iconrpcserver..." +iconrpcserver stop -p 9100 -c ./conf/testnet/iconrpcserver_conf.json +pkill -f gunicorn From 7f76ec9b2b293820474e7fbfc6b6b1fbc7e8ca3a Mon Sep 17 00:00:00 2001 From: Jiyun Park Date: Fri, 18 Jan 2019 14:36:17 +0900 Subject: [PATCH 4/7] [LC-102] fix bug in block height sync with citizen node --- loopchain/peer/block_manager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loopchain/peer/block_manager.py b/loopchain/peer/block_manager.py index face59ced..8c1a1813d 100644 --- a/loopchain/peer/block_manager.py +++ b/loopchain/peer/block_manager.py @@ -624,7 +624,9 @@ def __get_peer_stub_list(self, target_peer_stub=None): response = target_peer_stub.call("Status") util.logger.spam('{/api/v1/status/peer} response: ' + response.text) response.block_height = int(json.loads(response.text)["block_height"]) - response.unconfirmed_block_height = int(json.loads(response.text)["unconfirmed_block_height"]) + response.unconfirmed_block_height = int( + json.loads(response.text).get("unconfirmed_block_height", -1) + ) stub.target = target response.block_height = max(response.block_height, response.unconfirmed_block_height) From b454f8d96ba784f19e7c4531adf758121c4dc62e Mon Sep 17 00:00:00 2001 From: Jiyun Park Date: Fri, 18 Jan 2019 18:24:35 +0900 Subject: [PATCH 5/7] [LC-102] update conf and script for citizen --- README.md | 87 ++++++++++++++++++++++++++------ conf/mainnet/loopchain_conf.json | 1 - conf/testnet/loopchain_conf.json | 3 -- loopchain/configure_default.py | 7 +-- loopchain/launcher.py | 2 +- run_unittest.sh => run_test.sh | 0 run_testnet_citizen.sh | 8 +-- 7 files changed, 81 insertions(+), 27 deletions(-) rename run_unittest.sh => run_test.sh (100%) diff --git a/README.md b/README.md index 7af0fc0ee..4fc1560f6 100644 --- a/README.md +++ b/README.md @@ -23,15 +23,27 @@ $ python -V ``` -#### Install third party tools -automake, pkg-config, libtool, leveldb, rabbitmq, openssl +#### Setting environments (for local OS X) + +* install Xcode command tool +* install brew (if it's not installed) + +```bash +$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +``` + +* Install third party tools + +```bash +$ brew install automake pkg-config libtool leveldb rabbitmq openssl +``` #### Setup RabbitMQ -* increase number of file descriptors +* increase number of RabbitMQ file descriptors ``` -$ ulimit -S -n {value: int} +ulimit -S -n {value: int} ``` - Add the above command to the `rabbitmq-env.conf` file to run the command each time rabbitmq starts. @@ -41,21 +53,22 @@ $ ulimit -S -n {value: int} * start rabbitmq -``` +```bash $ brew services start rabbitmq $ rabbitmqctl list_queues ``` * enable rabbitmq web management -``` +```bash $ rabbitmq-plugins enable rabbitmq_management ``` #### Install requirements If you have generated ssh key for github, you can install with below commands. -``` + +```bash $ pip3 install git+ssh://git@github.com/icon-project/icon-service.git@master $ pip3 install git+ssh://git@github.com/icon-project/icon-commons.git@master $ pip3 install git+ssh://git@github.com/icon-project/icon-rpc-server.git@master @@ -63,7 +76,8 @@ $ pip3 install -r requirements.txt ``` Also, you can install with below commands too. -``` + +```bash $ pip3 install git+https://github.com/icon-project/icon-service.git@master $ pip3 install git+https://github.com/icon-project/icon-commons.git@master $ pip3 install git+https://github.com/icon-project/icon-rpc-server.git@master @@ -71,13 +85,14 @@ $ pip3 install -r requirements.txt ``` #### generate gRPC code -``` + +```bash $ ./generate_code.sh ``` -#### Run Test +#### Run Unittest -``` +```bash $ ./run_test.sh ``` @@ -85,19 +100,61 @@ $ ./run_test.sh #### Generate Key -``` +```bash $ mkdir -p resources/my_pki $ openssl ecparam -genkey -name secp256k1 | openssl ec -aes-256-cbc -out ./resources/my_pki/my_private.pem # generate private key $ openssl ec -in ./resources/my_pki/my_private.pem -pubout -out ./resources/my_pki/my_public.pem # generate public key $ export PW_icon_dex={ENTER_MY_PASSWORD} ``` -#### Run loopchain as a Citizen Node +### Run Citizen Node on ICON Testnet network +This script will enable ICON citizen node on Testnet network, running on port 9100. +Once it's connected to the network, it will start to sync all the blocks on the ICON testnet network. +As we do not support fast sync mode for now, it may take some time to sync all the blocks. The feature will be implemented soon. +```bash +$ ./run_testnet_citizen.sh ``` -$ ./run_loopchain.sh + +#### Test through command line interface for ICON + +* Install t-bears + +T-Bears provides the command line interface to interact with the ICON network. It implements all the JSON-RPC v3 APIs. +For a detailed usage guideline, please see T-Bears tutorial. + +```bash +(venv) $ pip3 install tbears +``` + +* Check block data + + * get lastblock + ```bash + $ tbears lastblock -u http://127.0.0.1:9100/api/v3 + ``` + + * get totalsupply + ```bash + $ tbears totalsupply -u http://127.0.0.1:9100/api/v3 + ``` + +* Stop the testnet citizen node + +```bash +$ ./stop_testnet_citizen.sh +``` + +### Run Citizen Node on ICON Mainnet network +This script will enable ICON citizen node on Mainnet network, running on port 9000. + +```bash +$ ./run_mainnet_citizen.sh ``` + +ICON Testnet Tracker() + #### Stop All ``` @@ -110,4 +167,4 @@ $ ./stop_all.sh ``` $ rm -rf log $ rm -rf .storage_test -``` \ No newline at end of file +``` diff --git a/conf/mainnet/loopchain_conf.json b/conf/mainnet/loopchain_conf.json index c7c895c0c..ed7f9a81c 100644 --- a/conf/mainnet/loopchain_conf.json +++ b/conf/mainnet/loopchain_conf.json @@ -1,5 +1,4 @@ { - "LOOPCHAIN_DEFAULT_CHANNEL": "icon_dex", "CHANNEL_OPTION" : { "icon_dex": { "block_versions": { diff --git a/conf/testnet/loopchain_conf.json b/conf/testnet/loopchain_conf.json index 0a5a2c336..e60174557 100644 --- a/conf/testnet/loopchain_conf.json +++ b/conf/testnet/loopchain_conf.json @@ -1,5 +1,4 @@ { - "LOOPCHAIN_DEFAULT_CHANNEL": "icon_dex", "CHANNEL_OPTION" : { "icon_dex": { "block_versions": { @@ -10,8 +9,6 @@ "0x2": 1, "0x3": 1 }, - "store_valid_transaction_only": true, - "send_tx_type": 2, "load_cert": false, "consensus_cert_use": false, "tx_cert_use": false, diff --git a/loopchain/configure_default.py b/loopchain/configure_default.py index ad44bd8ef..3cd39fb19 100644 --- a/loopchain/configure_default.py +++ b/loopchain/configure_default.py @@ -54,7 +54,7 @@ class LogOutputType(IntFlag): LOG_OUTPUT_TYPE = LogOutputType.console | LogOutputType.file -LOG_FILE_LOCATION = "/var/tmp/" +LOG_FILE_LOCATION = os.path.join(LOOPCHAIN_ROOT_PATH, 'log') LOG_FILE_PREFIX = "loopchain" LOG_FILE_EXTENSION = "log" @@ -202,7 +202,8 @@ class SendTxType(IntEnum): DEFAULT_SCORE_PACKAGE = 'loopchain/default' DEFAULT_SCORE_BRANCH_MASTER = 'master' DEFAULT_SCORE_BRANCH = os.getenv('DEFAULT_SCORE_BRANCH', DEFAULT_SCORE_BRANCH_MASTER) -DEFAULT_SCORE_CONF_PATH = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/iconservice_conf.json') +DEFAULT_SCORE_CONF_PATH = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/testnet/iconservice_conf.json') +DEFAULT_BUILTIN_SCORE_OWNER = "hx6e1dd0d4432620778b54b2bbc21ac3df961adf89" # Devnet # DEFAULT USER / PASSWORD DEFAULT_SCORE_BASE_USER = 'score' @@ -328,7 +329,7 @@ def is_support_node_function(cls, node_function, node_type): # If disconnected state of the peer is maintained, That peer will removed from peer list after this minutes. TIMEOUT_PEER_REMOVE_IN_LIST = 5 # minutes, replace by NO_RESPONSE_COUNT_ALLOW_BY_HEARTBEAT RADIO_STATION_NAME = "RadioStation" -LOOPCHAIN_DEFAULT_CHANNEL = "loopchain_default" # Default Channel Name +LOOPCHAIN_DEFAULT_CHANNEL = "icon_dex" # Default Channel Name LOOPCHAIN_TEST_CHANNEL = "loopchain_test" CHANNEL_MANAGE_DATA_PATH = os.path.join(LOOPCHAIN_ROOT_PATH, 'channel_manage_data.json') # Channel Manage Data Path ENABLE_CHANNEL_AUTH = False # if this option is true, peer only gets channel infos to which it belongs. diff --git a/loopchain/launcher.py b/loopchain/launcher.py index 8afd3c506..4337bc4af 100644 --- a/loopchain/launcher.py +++ b/loopchain/launcher.py @@ -165,7 +165,7 @@ def start_as_score(args): "stateDbRootPath": f".storage/.statedb{amqp_key}_{channel}", "channel": channel, "amqpKey": amqp_key, - "builtinScoreOwner": load_conf.get("builtinScoreOwner"), + "builtinScoreOwner": conf.DEFAULT_BUILTIN_SCORE_OWNER, "service": load_conf.get("service") } diff --git a/run_unittest.sh b/run_test.sh similarity index 100% rename from run_unittest.sh rename to run_test.sh diff --git a/run_testnet_citizen.sh b/run_testnet_citizen.sh index 7537968aa..2f3d04a07 100755 --- a/run_testnet_citizen.sh +++ b/run_testnet_citizen.sh @@ -3,15 +3,15 @@ export REDIRECT_PROTOCOL=https PID_FILE="testnet_citizen.pid" -if [ -f $PID_FILE ]; then - echo "remove $PID_FILE" - rm -f $PID_FILE +if [ -f ${PID_FILE} ]; then + echo "remove ${PID_FILE}" + rm -f ${PID_FILE} fi touch $PID_FILE echo "Run loopchain for citizen start!" -./loopchain.py citizen -r https://test-ctz.solidwallet.io -o ./conf/testnet/loopchain_conf.json & +./loopchain.py citizen -r https://int-test-ctz.solidwallet.io -o ./conf/testnet/loopchain_conf.json & echo $! > $PID_FILE echo "Run iconservice for citizen start!" From e1feedf61c22a3e39c80d22e2f04b9da2fbc11e8 Mon Sep 17 00:00:00 2001 From: Jiyun Park Date: Mon, 21 Jan 2019 12:40:21 +0900 Subject: [PATCH 6/7] [LC-102] add conf json files and apply them in launcher --- VERSION | 1 + conf/develop/iconrpcserver_conf.json | 21 +++++++++++++ conf/develop/iconservice_conf.json | 28 +++++++++++++++++ conf/mainnet/iconrpcserver_conf.json | 4 +-- conf/mainnet/iconservice_conf.json | 2 +- conf/mainnet/loopchain_conf.json | 6 ++-- conf/testnet/iconrpcserver_conf.json | 4 +-- conf/testnet/iconservice_conf.json | 2 +- conf/testnet/loopchain_conf.json | 6 ++-- loopchain/channel/channel_service.py | 3 +- loopchain/configure_default.py | 17 ++++++++-- loopchain/container/container.py | 3 +- loopchain/launcher.py | 40 +++++++++++++++++------- loopchain/peer/peer_service.py | 3 +- loopchain/utils/loggers/configuration.py | 2 +- setup.py | 4 +++ 16 files changed, 117 insertions(+), 29 deletions(-) create mode 100644 VERSION create mode 100644 conf/develop/iconrpcserver_conf.json create mode 100644 conf/develop/iconservice_conf.json diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..e4a973f91 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.24.2 diff --git a/conf/develop/iconrpcserver_conf.json b/conf/develop/iconrpcserver_conf.json new file mode 100644 index 000000000..13aa5b441 --- /dev/null +++ b/conf/develop/iconrpcserver_conf.json @@ -0,0 +1,21 @@ +{ + "log": { + "logger": "iconrpcserver", + "colorLog": true, + "level": "info", + "filePath": "./log/develop/iconrpcserver.log", + "outputType": "console|file", + "rotate": { + "type": "period|bytes", + "period": "daily", + "interval": 1, + "backupCount": 10, + "maxBytes": 50000000 + } + }, + "channel": "icon_dex", + "port": 9000, + "amqpTarget": "127.0.0.1", + "amqpKey": "7100", + "gunicornWorkerCount": 1 +} diff --git a/conf/develop/iconservice_conf.json b/conf/develop/iconservice_conf.json new file mode 100644 index 000000000..c62eb570e --- /dev/null +++ b/conf/develop/iconservice_conf.json @@ -0,0 +1,28 @@ +{ + "log": { + "logger": "iconservice", + "colorLog": true, + "level": "info", + "filePath": "./log/develop/iconservice.log", + "outputType": "console|file", + "rotate": { + "type": "period|bytes", + "period": "daily", + "interval": 1, + "backupCount": 10, + "maxBytes": 50000000 + } + }, + "scoreRootPath": ".storage/.score", + "stateDbRootPath": ".storage/.statedb", + "channel": "icon_dex", + "amqpKey": "7100", + "amqpTarget": "127.0.0.1", + "builtinScoreOwner": "hx6e1dd0d4432620778b54b2bbc21ac3df961adf89", + "service": { + "fee": true, + "audit": false, + "deployerWhiteList": false, + "scorePackageValidator": false + } +} diff --git a/conf/mainnet/iconrpcserver_conf.json b/conf/mainnet/iconrpcserver_conf.json index 67381013d..769f71e9e 100644 --- a/conf/mainnet/iconrpcserver_conf.json +++ b/conf/mainnet/iconrpcserver_conf.json @@ -14,8 +14,8 @@ } }, "channel": "icon_dex", - "port": 9000, + "port": 9100, "amqpTarget": "127.0.0.1", - "amqpKey": "7100", + "amqpKey": "7200", "gunicornWorkerCount": 1 } diff --git a/conf/mainnet/iconservice_conf.json b/conf/mainnet/iconservice_conf.json index d4595d082..ecbb3ea84 100644 --- a/conf/mainnet/iconservice_conf.json +++ b/conf/mainnet/iconservice_conf.json @@ -16,7 +16,7 @@ "scoreRootPath": ".storage_mainnet/.score", "stateDbRootPath": ".storage_mainnet/.statedb", "channel": "icon_dex", - "amqpKey": "7100", + "amqpKey": "7200", "amqpTarget": "127.0.0.1", "builtinScoreOwner": "hx677133298ed5319607a321a38169031a8867085c", "service": { diff --git a/conf/mainnet/loopchain_conf.json b/conf/mainnet/loopchain_conf.json index ed7f9a81c..3298ef4f2 100644 --- a/conf/mainnet/loopchain_conf.json +++ b/conf/mainnet/loopchain_conf.json @@ -18,9 +18,9 @@ } }, "USE_EXTERNAL_SCORE": true, - "USE_EXTERNAL_REST": true, - "PORT_PEER": 7100, - "AMQP_KEY": "7100", + "EXTERNAL_SCORE_RUN_IN_LAUNCHER": true, + "PORT_PEER": 7200, + "AMQP_KEY": "7200", "DEFAULT_STORAGE_PATH": ".storage_mainnet/", "ALLOW_MAKE_EMPTY_BLOCK": false, "SUBSCRIBE_USE_HTTPS": true, diff --git a/conf/testnet/iconrpcserver_conf.json b/conf/testnet/iconrpcserver_conf.json index 17c07dd34..3fa795a6b 100644 --- a/conf/testnet/iconrpcserver_conf.json +++ b/conf/testnet/iconrpcserver_conf.json @@ -14,8 +14,8 @@ } }, "channel": "icon_dex", - "port": 9100, + "port": 9000, "amqpTarget": "127.0.0.1", - "amqpKey": "7200", + "amqpKey": "7100", "gunicornWorkerCount": 1 } diff --git a/conf/testnet/iconservice_conf.json b/conf/testnet/iconservice_conf.json index d230bab78..7e66bac52 100644 --- a/conf/testnet/iconservice_conf.json +++ b/conf/testnet/iconservice_conf.json @@ -16,7 +16,7 @@ "scoreRootPath": ".storage_testnet/.score", "stateDbRootPath": ".storage_testnet/.statedb", "channel": "icon_dex", - "amqpKey": "7200", + "amqpKey": "7100", "amqpTarget": "127.0.0.1", "builtinScoreOwner": "hxba096790caa1804a8828939839a901a5978020a7", "service": { diff --git a/conf/testnet/loopchain_conf.json b/conf/testnet/loopchain_conf.json index e60174557..58e24e314 100644 --- a/conf/testnet/loopchain_conf.json +++ b/conf/testnet/loopchain_conf.json @@ -18,9 +18,9 @@ } }, "USE_EXTERNAL_SCORE": true, - "USE_EXTERNAL_REST": true, - "PORT_PEER": 7200, - "AMQP_KEY": "7200", + "EXTERNAL_SCORE_RUN_IN_LAUNCHER": true, + "PORT_PEER": 7100, + "AMQP_KEY": "7100", "DEFAULT_STORAGE_PATH": ".storage_testnet/", "ALLOW_MAKE_EMPTY_BLOCK": false, "SUBSCRIBE_USE_HTTPS": true, diff --git a/loopchain/channel/channel_service.py b/loopchain/channel/channel_service.py index 19bcae4f4..b231c5f5f 100644 --- a/loopchain/channel/channel_service.py +++ b/loopchain/channel/channel_service.py @@ -347,7 +347,8 @@ async def __run_score_container(self): command_arguments.Type.AMQPTarget, command_arguments.Type.AMQPKey, command_arguments.Type.Develop, - command_arguments.Type.ConfigurationFilePath + command_arguments.Type.ConfigurationFilePath, + command_arguments.Type.RadioStationTarget ) self.__score_container = CommonSubprocess(process_args) diff --git a/loopchain/configure_default.py b/loopchain/configure_default.py index 3cd39fb19..c7c1eecfa 100644 --- a/loopchain/configure_default.py +++ b/loopchain/configure_default.py @@ -202,8 +202,6 @@ class SendTxType(IntEnum): DEFAULT_SCORE_PACKAGE = 'loopchain/default' DEFAULT_SCORE_BRANCH_MASTER = 'master' DEFAULT_SCORE_BRANCH = os.getenv('DEFAULT_SCORE_BRANCH', DEFAULT_SCORE_BRANCH_MASTER) -DEFAULT_SCORE_CONF_PATH = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/testnet/iconservice_conf.json') -DEFAULT_BUILTIN_SCORE_OWNER = "hx6e1dd0d4432620778b54b2bbc21ac3df961adf89" # Devnet # DEFAULT USER / PASSWORD DEFAULT_SCORE_BASE_USER = 'score' @@ -429,3 +427,18 @@ def is_support_node_function(cls, node_function, node_type): # LFT #### #################### ALLOW_MAKE_EMPTY_BLOCK = True + + +#################### +# ICON #### +#################### +URL_CITIZEN_TESTNET = 'https://int-test-ctz.solidwallet.io' +URL_CITIZEN_MAINNET = 'https://int-ctz.solidwallet.io' +CONF_PATH_LOOPCHAIN_TESTNET = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/testnet/loopchain_conf.json') +CONF_PATH_LOOPCHAIN_MAINNET = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/mainnet/loopchain_conf.json') +CONF_PATH_ICONSERVICE_DEV = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/develop/iconservice_conf.json') +CONF_PATH_ICONSERVICE_TESTNET = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/testnet/iconservice_conf.json') +CONF_PATH_ICONSERVICE_MAINNET = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/mainnet/iconservice_conf.json') +CONF_PATH_ICONRPCSERVER_DEV = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/develop/iconrpcserver_conf.json') +CONF_PATH_ICONRPCSERVER_TESTNET = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/testnet/iconrpcserver_conf.json') +CONF_PATH_ICONRPCSERVER_MAINNET = os.path.join(LOOPCHAIN_ROOT_PATH, 'conf/mainnet/iconrpcserver_conf.json') diff --git a/loopchain/container/container.py b/loopchain/container/container.py index e754f7ae2..2e56d17a6 100644 --- a/loopchain/container/container.py +++ b/loopchain/container/container.py @@ -99,7 +99,8 @@ def run(self, conn, event: multiprocessing.Event): command_arguments.Type.AMQPTarget, command_arguments.Type.AMQPKey, command_arguments.Type.Develop, - command_arguments.Type.ConfigurationFilePath + command_arguments.Type.ConfigurationFilePath, + command_arguments.Type.RadioStationTarget ) server = CommonSubprocess(args) api_port = self._port + conf.PORT_DIFF_REST_SERVICE_CONTAINER diff --git a/loopchain/launcher.py b/loopchain/launcher.py index 4337bc4af..0df8a4918 100644 --- a/loopchain/launcher.py +++ b/loopchain/launcher.py @@ -41,6 +41,13 @@ def main(argv): args = parser.parse_args(argv) command_arguments.set_raw_commands(args) + if args.radio_station_target == 'testnet': + args.radio_station_target = conf.URL_CITIZEN_TESTNET + args.configure_file_path = conf.CONF_PATH_LOOPCHAIN_TESTNET + elif args.radio_station_target == 'mainnet': + args.radio_station_target = conf.URL_CITIZEN_MAINNET + args.configure_file_path = conf.CONF_PATH_LOOPCHAIN_MAINNET + if args.configure_file_path: conf.Configure().load_configure_json(args.configure_file_path) @@ -100,20 +107,24 @@ def start_as_rest_server(args): channel = conf.LOOPCHAIN_DEFAULT_CHANNEL amqp_key = args.amqp_key or conf.AMQP_KEY api_port = int(peer_port) + conf.PORT_DIFF_REST_SERVICE_CONTAINER + conf_path = conf.CONF_PATH_ICONRPCSERVER_DEV + + if args.radio_station_target: + if args.radio_station_target == conf.URL_CITIZEN_TESTNET: + conf_path = conf.CONF_PATH_ICONRPCSERVER_TESTNET + elif args.radio_station_target == conf.URL_CITIZEN_MAINNET: + conf_path = conf.CONF_PATH_ICONRPCSERVER_MAINNET from iconrpcserver.default_conf.icon_rpcserver_config import default_rpcserver_config from iconrpcserver.icon_rpcserver_cli import start_process, find_procs_by_params from iconcommons.icon_config import IconConfig from iconcommons.logger import Logger + with open(conf_path) as file: + load_conf = json.load(file) + additional_conf = { - "log": { - "logger": "iconrpcserver", - "colorLog": True, - "level": "info", - "filePath": "./log/iconrpcserver.log", - "outputType": "console|file" - }, + "log": load_conf.get("log"), "channel": channel, "port": api_port, "amqpKey": amqp_key, @@ -148,6 +159,13 @@ def start_as_score(args): score_package = args.score_package or conf.DEFAULT_SCORE_PACKAGE amqp_target = args.amqp_target or conf.AMQP_TARGET amqp_key = args.amqp_key or conf.AMQP_KEY + conf_path = conf.CONF_PATH_ICONSERVICE_DEV + + if args.radio_station_target: + if args.radio_station_target == conf.URL_CITIZEN_TESTNET: + conf_path = conf.CONF_PATH_ICONSERVICE_TESTNET + elif args.radio_station_target == conf.URL_CITIZEN_MAINNET: + conf_path = conf.CONF_PATH_ICONSERVICE_MAINNET if conf.USE_EXTERNAL_SCORE: if conf.EXTERNAL_SCORE_RUN_IN_LAUNCHER: @@ -156,16 +174,16 @@ def start_as_score(args): from iconcommons.icon_config import IconConfig from iconcommons.logger import Logger - with open(conf.DEFAULT_SCORE_CONF_PATH) as file: + with open(conf_path) as file: load_conf = json.load(file) additional_conf = { "log": load_conf.get("log"), - "scoreRootPath": f".storage/.score{amqp_key}_{channel}", - "stateDbRootPath": f".storage/.statedb{amqp_key}_{channel}", + "scoreRootPath": load_conf.get("scoreRootPath") + f"{amqp_key}_{channel}", + "stateDbRootPath": load_conf.get("stateDbRootPath") + f"{amqp_key}_{channel}", "channel": channel, "amqpKey": amqp_key, - "builtinScoreOwner": conf.DEFAULT_BUILTIN_SCORE_OWNER, + "builtinScoreOwner": load_conf.get("builtinScoreOwner"), "service": load_conf.get("service") } diff --git a/loopchain/peer/peer_service.py b/loopchain/peer/peer_service.py index 42802b663..4a2518259 100644 --- a/loopchain/peer/peer_service.py +++ b/loopchain/peer/peer_service.py @@ -376,7 +376,8 @@ async def serve_channels(self): command_arguments.Type.Develop, command_arguments.Type.AMQPTarget, command_arguments.Type.AMQPKey, - command_arguments.Type.ConfigurationFilePath + command_arguments.Type.ConfigurationFilePath, + command_arguments.Type.RadioStationTarget ) service = CommonSubprocess(args) diff --git a/loopchain/utils/loggers/configuration.py b/loopchain/utils/loggers/configuration.py index bb2900f29..32a4642b9 100644 --- a/loopchain/utils/loggers/configuration.py +++ b/loopchain/utils/loggers/configuration.py @@ -181,7 +181,7 @@ def _create_file_handler(self): if not os.path.isdir(self.log_file_location): raise RuntimeError(f"LogFileLocation({self.log_file_location}) is not a directory.") else: - os.mkdir(self.log_file_location) + os.makedirs(self.log_file_location) if self.log_file_rotate_when and self.log_file_rotate_max_bytes: file_handler = SizedTimedRotatingFileHandler( diff --git a/setup.py b/setup.py index d89a59b93..81a4a9984 100644 --- a/setup.py +++ b/setup.py @@ -8,6 +8,10 @@ version = os.environ.get('VERSION') # 1.21.5 +if version is None: + with open(os.path.join('.', 'VERSION')) as version_file: + version = version_file.read().strip() + setup_options = { 'name': 'loopchain', 'version': version, From 816916032c7eca6bdc093155daeeaf9c6a153c5b Mon Sep 17 00:00:00 2001 From: Jiyun Park Date: Mon, 21 Jan 2019 16:05:33 +0900 Subject: [PATCH 7/7] [LC-102] add manual for tbears in README --- README.md | 568 +++++++++++++++++++++++++++++++++++++------- sendtx_testnet.json | 12 + 2 files changed, 498 insertions(+), 82 deletions(-) create mode 100644 sendtx_testnet.json diff --git a/README.md b/README.md index 4fc1560f6..15f597702 100644 --- a/README.md +++ b/README.md @@ -1,170 +1,574 @@ # Loopchain -## Install Requirements + Loopchain is a high-performance Blockchain Consensus & Network engine of ICON project. -#### Make Virtual Env for Python 3.6.5 (recommended version, 3.7 is not supported, possible versions are 3.6.x) + In order to run a loopchain node, you need to install [ICON Service](https://github.com/icon-project/icon-service) that runs a smart contract and interacts with loopchain engine, and [ICON RPC Server](https://github.com/icon-project/icon-rpc-server) that processes HTTP requests from clients. For details, refer to the guide below. - * check your python version +## Installation - ``` - $ python3 -V - ``` +### Requirements - * make virtual env and apply +Loopchain development and execution requires following environments. - ``` - $ virtualenv -p python3 ./venv - $ source ./venv/bin/activate - ``` +* OS: MacOS, Linux + * Windows are not supported yet. - * check virtual env python version +* Python + * Make Virtual Env for Python 3.6.5+ (recommended version, 3.7 is not supported) + * check your python version - ``` - $ python -V - ``` + ```bash + $ python3 -V + ``` + + > If you'd like to easily manage your python version by each projects, we highly recommend to use **pyenv**. + * Install **pyenv** + ``` + $ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash + ``` + + * Append the following commands to `~/.bash_profile`. + ``` + export PATH="/home/centos/.pyenv/bin:$PATH" + eval "$(pyenv init -)" + eval "$(pyenv virtualenv-init -)" + ``` + * Apply for the profile + + ``` + $ source ~/.bash_profile + ``` + * Install **python 3.6.5** + + ``` + $ pyenv install 3.6.5 + $ pyenv shell 3.6.5 + ``` + + * make virtual env and apply + + ``` + $ virtualenv -p python3 ./venv + $ source ./venv/bin/activate + ``` -#### Setting environments (for local OS X) +### Setup on MacOS * install Xcode command tool -* install brew (if it's not installed) +* install brew + + ```bash + (venv) $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + ``` + +* Install third party tools + + ```bash + (venv) $ brew install automake pkg-config libtool leveldb rabbitmq openssl + ``` + +* Setup RabbitMQ + + * increase number of RabbitMQ file descriptors + + > Add the below command to the `rabbitmq-env.conf` file to run the command each time rabbitmq starts. + ``` + ulimit -S -n {value: int} + ``` + > You may find this file (/usr/local/etc/rabbitmq/rabbitmq-env.conf). + > Recommended value is 2048 or more. (Local test case only) + > You may need to adjust this value depending on your infrastructure environment. + + * start rabbitmq + + ```bash + (venv) $ brew services start rabbitmq + (venv) $ rabbitmqctl list_queues + ``` + + * enable rabbitmq web management + + ```bash + (venv) $ rabbitmq-plugins enable rabbitmq_management + ``` + +#### Install requirements + +If you have generated ssh key for github, you can install with below commands. +All libraries are recommended to install the master version of github. ```bash -$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +(venv) $ pip3 install git+ssh://git@github.com/icon-project/icon-service.git@master +(venv) $ pip3 install git+ssh://git@github.com/icon-project/icon-commons.git@master +(venv) $ pip3 install git+ssh://git@github.com/icon-project/icon-rpc-server.git@master +(venv) $ pip3 install -r requirements.txt ``` -* Install third party tools +Also, you can install with below commands as well. ```bash -$ brew install automake pkg-config libtool leveldb rabbitmq openssl +(venv) $ pip3 install git+https://github.com/icon-project/icon-service.git@master +(venv) $ pip3 install git+https://github.com/icon-project/icon-commons.git@master +(venv) $ pip3 install git+https://github.com/icon-project/icon-rpc-server.git@master +(venv) $ pip3 install -r requirements.txt ``` -#### Setup RabbitMQ +#### generate gRPC code +This script generates python gRPC code from protocol buffer which is defined in `loopchain.proto`. + +```bash +(venv) $ ./generate_code.sh +``` -* increase number of RabbitMQ file descriptors +#### Run Unittest +After installation, run the unittest by following command line in order to check whether it operates well or not. +```bash +(venv) $ ./run_test.sh ``` -ulimit -S -n {value: int} + +## Quick Start + +* [Run Citizen Node on ICON Testnet network](#run-citizen-node-on-icon-testnet-network) +* [Run Citizen Node on ICON Mainnet network](#run-citizen-node-on-icon-mainnet-network) + +### Run Citizen Node on ICON Testnet network + +#### Generate Key + +```bash +(venv) $ mkdir -p resources/my_pki +(venv) $ openssl ecparam -genkey -name secp256k1 | openssl ec -aes-256-cbc -out ./resources/my_pki/my_private.pem # generate private key +(venv) $ openssl ec -in ./resources/my_pki/my_private.pem -pubout -out ./resources/my_pki/my_public.pem # generate public key +(venv) $ export PW_icon_dex={ENTER_MY_PASSWORD} +(venv) $ export REDIRECT_PROTOCOL=https ``` -- Add the above command to the `rabbitmq-env.conf` file to run the command each time rabbitmq starts. -- You may find this file (/usr/local/etc/rabbitmq/rabbitmq-env.conf). -- Recommended value is 2048 or more. (Local test case only) -- You may need to adjust this value depending on your infrastructure environment. +This script will enable ICON citizen node on Testnet network, running on port **9000**. +Once it's connected to the network, it will start to sync all the blocks on the ICON testnet network. -* start rabbitmq +```bash +(venv) $ ./loop citizen -r testnet +``` + +If you want to browse and search the blocks and transactions in ICON Testnet, please go to [ICON testnet tracker](https://trackerdev.icon.foundation). + +#### Test through command line interface for ICON + +T-Bears is a suite of development tools for SCORE and provides the command line interface to interact with the ICON network including all the JSON-RPC v3 APIs. +For a detailed usage guideline, please refer to [T-Bears tutorial](https://github.com/icon-project/t-bears). + +* Install t-bears ```bash -$ brew services start rabbitmq -$ rabbitmqctl list_queues +(venv) $ pip3 install tbears ``` -* enable rabbitmq web management +##### Test jsonRPC APIs +In v3, parameters in all api request params require the string '0x' at the front. + +* get lastblock + +This method returns the last block the Citizen node has currently synced. ```bash -$ rabbitmq-plugins enable rabbitmq_management +usage: tbears lastblock [-h] [-u URI] [-c CONFIG] + +// Example +(venv) $ tbears lastblock // Example (default uri: http://localhost:9000/api/v3) + +// result +block info : { + "jsonrpc": "2.0", + "result": { + "version": "0.1a", + "prev_block_hash": "c5dae2634737e28ff4a1987abe1362890f8a6aaea3e7c0086f5e5fe5300361eb", + "merkle_tree_root_hash": "a0c897c5b78860e8500019a3a0788e0498aeec20f3e8e57cc22d9c5096e6ab84", + "time_stamp": 1537335737897461, + "confirmed_transaction_list": [ + { + "stepLimit": "0x1e8480", + "signature": "k+F7dxstj1mXr7AL2hGo8RMgAEW0fc8AEhXMPiZOzBgvZYvcIkyVrUdoTnoTMJK55420+36ZdOBoo/tiM1AGZgE=", + "nid": "0x2", + "from": "hx8f1796338f819e4e0276e7d449227a3bfb7ea2a6", + "to": "cx3ae5c047638df3e3b02120c913dda852ff84d297", + "version": "0x3", + "value": "0xde0b6b3a7640000", + "nonce": "0x1", + "timestamp": "0x57632de7fb4f8", + "txHash": "0xa0c897c5b78860e8500019a3a0788e0498aeec20f3e8e57cc22d9c5096e6ab84" + } + ], + "block_hash": "da8abc0c9bad1d5b868c17b4a3e575ad7b2b8430880e233490fad1811a12277c", + "height": 30000, + "peer_id": "hx98cd0d78e8936b633210b04a6ce10eab655c0881", + "signature": "J4PrnX0jG5sXcdf1bscPvlZPCioDv+pezm1WkEFlOqg8ZHTNZT9LSkCjZFLVbKfObkYRmHDPmGfLgBTPMvZV3wE=" + }, + "id": 1 +} ``` -#### Install requirements +* get blockbyheight -If you have generated ssh key for github, you can install with below commands. +```bash +usage: tbears blockbyheight [-h] [-u URI] [-c CONFIG] height + +// Example +(venv) $ tbears blockbyheight 0x1 + +// result +block info : { + "jsonrpc": "2.0", + "result": { + "version": "0.1a", + "prev_block_hash": "885b8021826f7e741be7f53bb95b48221e9ab263f377e997b2e47a7b8f4a2a8b", + "merkle_tree_root_hash": "cb3a60b8cba5c7647fa7d2eb351be0723b8a733c41c6bfa0e9f4e6f5b89378e7", + "time_stamp": 1519289604305467, + "confirmed_transaction_list": [ + { + "from": "hx5a05b58a25a1e5ea0f1d5715e1f655dffc1fb30a", + "to": "hx7bcf759a16661dbb9356318af31dc6d4803fc969", + "value": "0x845951614014880000000", + "fee": "0x2386f26fc10000", + "timestamp": "1519289604008199", + "tx_hash": "cb3a60b8cba5c7647fa7d2eb351be0723b8a733c41c6bfa0e9f4e6f5b89378e7", + "signature": "HIjTnNCwHwTiSs7Ucj+oXsyc0ZzDDz9jIKWoQouifEYOCkaAWz8swKet/neGBBckLm6GujqDajWZ290Hoq/ROwE=", + "method": "icx_sendTransaction" + } + ], + "block_hash": "d5629fe006104df557570ce2613c8df1901d8f6f322b9f251645c201fa1d1e9e", + "height": 1, + "peer_id": "hx1fe2dfae9a5439bb1d4e193a3b7c6e5df6c6650e", + "signature": "lGQu4IdK/ZPeCB4e2IJc8s0l38uh30OmH/xSXE7+STpMJaphHbFJYtl7U/Y7bgWhJtQri+GJsp25PyNRzioabAE=" + }, + "id": 1 +``` + +* get blockbyhash ```bash -$ pip3 install git+ssh://git@github.com/icon-project/icon-service.git@master -$ pip3 install git+ssh://git@github.com/icon-project/icon-commons.git@master -$ pip3 install git+ssh://git@github.com/icon-project/icon-rpc-server.git@master -$ pip3 install -r requirements.txt +usage: tbears blockbyhash [-h] [-u URI] [-c CONFIG] hash + +// Example + +(venv) $ tbears blockbyhash 0xce00facd0ac3832e1e6e623d8f4b9344782da881e55abb48d1494fde9e465f78 + +// Result is same as above. ``` -Also, you can install with below commands too. +* get totalsupply ```bash -$ pip3 install git+https://github.com/icon-project/icon-service.git@master -$ pip3 install git+https://github.com/icon-project/icon-commons.git@master -$ pip3 install git+https://github.com/icon-project/icon-rpc-server.git@master -$ pip3 install -r requirements.txt +usage: tbears totalsupply [-h] [-u URI] [-c CONFIG] + +// Example +(venv) $ tbears totalsupply + +// Result +Total supply of ICX in hex: 0x2961fff8ca4a62327800000 +Total supply of ICX in decimal: 800460000000000000000000000 ``` -#### generate gRPC code +* Create a Keystore + +Create a keystore file in the given path. Generate a private and public key pair using secp256k1 library. ```bash -$ ./generate_code.sh +usage: tbears keystore [-h] [-p PASSWORD] path + +// Example +(venv) $ tbears keystore ./my_keystore.json + +input your keystore password: (You have to initialize your keystore password) + +Made keystore file successfully ``` -#### Run Unittest +It will create new keystore file like this: + +```json +// my_keystore.json +{ + "address": "hx63499c4efc26c9370f6d68132c116d180d441266", // address for your account + "crypto": { + "cipher": "aes-128-ctr", + "cipherparams": { + "iv": "1a3b55deff9809c702e5da6265efe759", + }, + "ciphertext": "42e4e768cfdedc54446efc7c0b7726326394d4c0b753ef76827ef1bdd3a7d5c9", + "kdf": "scrypt", + "kdfparams": { + "dklen": 32, + "n": 16384, + "r": 1, + "p": 8, + "salt": "fdaff79a618e562a17224dd6c2072025", + }, + "mac": "400cbabc7fcff73ac5a28f64a0d36a5007b1a40e6ac2fe8fd2b771d89fe43385", + }, + "id": "15240a99-1c08-4b44-8cdd-5b9ebe71530f", + "version": 3, + "coinType": "icx" +} +``` + +> For there's no balance at that address, you need to request some testnet icx to your address. The instruction and the link to request testnet icx will be updated soon. + +* get balance + +```bash +usage: tbears balance [-h] [-u URI] [-c CONFIG] address + +// Example +(venv) $ tbears balance hx63499c4efc26c9370f6d68132c116d180d441266 + +// Result +balance in hex: 0xde0b6b3a7640000 +balance in decimal: 1000000000000000000 +``` + +* Send transaction + +Now that you have received a sufficient amount of icx, you can use it to send transactions. + +``` +usage: tbears sendtx [-h] [-u URI] [-k KEYSTORE] [-c CONFIG] json_file + +Request icx_sendTransaction with the specified json file and keystore file. If +keystore file is not given, tbears sends request as it is in the json file. + +positional arguments: + json_file File path containing icx_sendTransaction content + +optional arguments: + -h, --help show this help message and exit + -u URI, --node-uri URI + URI of node (default: http://127.0.0.1:9000/api/v3) + -k KEYSTORE, --key-store KEYSTORE + Keystore file path. Used to generate "from" address and + transaction signature + -c CONFIG, --config CONFIG + Configuration file path. This file defines the default + value for the "uri" (default: ./tbears_cli_config.json) +``` + +We provide the minimal settings for the simple coin transfer in the `sendtx_testnet.json` file. +The address to which icx is sent(`to`) is the address the ICON developers usually use when testing. You can change the address and the value if you want. +```json +// sendtx_testnet.json + +{ + "jsonrpc": "2.0", + "method": "icx_sendTransaction", + "params": { + "version": "0x3", // transaction version + "to": "hx670e692ffd3d5587c36c3a9d8442f6d2a8fcc795", // default address for testing + "value": "0xde0b6b3a7640000", // 1 ICX + "stepLimit": "0x3000000", + "nid": "0x2" // network id for testnet + }, + "id": 1 +} +``` + +Example ```bash -$ ./run_test.sh +(venv) $ tbears sendtx -k my_keystore.json send.json + +input your keystore password: + +Send transaction request successfully. +transaction hash: 0xc8a3e3f77f21f8f1177d829cbc4c0ded6fd064cc8e42ef309dacff5c0a952289 ``` -## Quick Start + For the details, please go to [Command-line Interfaces(CLIs)](https://github.com/icon-project/t-bears#command-line-interfacesclis) chapter in t-bears repository. + +### Run Citizen Node on ICON Mainnet network #### Generate Key ```bash -$ mkdir -p resources/my_pki -$ openssl ecparam -genkey -name secp256k1 | openssl ec -aes-256-cbc -out ./resources/my_pki/my_private.pem # generate private key -$ openssl ec -in ./resources/my_pki/my_private.pem -pubout -out ./resources/my_pki/my_public.pem # generate public key -$ export PW_icon_dex={ENTER_MY_PASSWORD} +(venv) $ mkdir -p resources/my_pki +(venv) $ openssl ecparam -genkey -name secp256k1 | openssl ec -aes-256-cbc -out ./resources/my_pki/my_private.pem # generate private key +(venv) $ openssl ec -in ./resources/my_pki/my_private.pem -pubout -out ./resources/my_pki/my_public.pem # generate public key +(venv) $ export PW_icon_dex={ENTER_MY_PASSWORD} +(venv) $ export REDIRECT_PROTOCOL=https ``` -### Run Citizen Node on ICON Testnet network -This script will enable ICON citizen node on Testnet network, running on port 9100. -Once it's connected to the network, it will start to sync all the blocks on the ICON testnet network. -As we do not support fast sync mode for now, it may take some time to sync all the blocks. The feature will be implemented soon. +This script will enable ICON citizen node on Mainnet network, running on port **9100**. +Once it's connected to the network, it will start to sync all the blocks on the ICON mainnet network. ```bash -$ ./run_testnet_citizen.sh +(venv) $ ./loop citizen -r mainnet ``` +If you want to browse and search the blocks and transactions in ICON Mainnet, please go to [ICON tracker](https://tracker.icon.foundation). + #### Test through command line interface for ICON -* Install t-bears +Since the mainnet citizen runs on port 9100, you need `-u http://127.0.0.1:9100/api/v3` for all command options in tbears that requires uri option. + +##### Test jsonRPC APIs +In v3, parameters in all api request params require the string '0x' at the front. -T-Bears provides the command line interface to interact with the ICON network. It implements all the JSON-RPC v3 APIs. -For a detailed usage guideline, please see T-Bears tutorial. +* get lastblock + +This method returns the last block the Citizen node has currently synced. ```bash -(venv) $ pip3 install tbears +usage: tbears lastblock [-h] [-u URI] [-c CONFIG] + +// Example +(venv) $ tbears lastblock -u http://127.0.0.1:9100/api/v3 // Example (default uri: http://localhost:9000/api/v3) + +// result +block info : { + "jsonrpc": "2.0", + "result": { + "version": "0.1a", + "prev_block_hash": "c5dae2634737e28ff4a1987abe1362890f8a6aaea3e7c0086f5e5fe5300361eb", + "merkle_tree_root_hash": "a0c897c5b78860e8500019a3a0788e0498aeec20f3e8e57cc22d9c5096e6ab84", + "time_stamp": 1537335737897461, + "confirmed_transaction_list": [ + { + "stepLimit": "0x1e8480", + "signature": "k+F7dxstj1mXr7AL2hGo8RMgAEW0fc8AEhXMPiZOzBgvZYvcIkyVrUdoTnoTMJK55420+36ZdOBoo/tiM1AGZgE=", + "nid": "0x2", + "from": "hx8f1796338f819e4e0276e7d449227a3bfb7ea2a6", + "to": "cx3ae5c047638df3e3b02120c913dda852ff84d297", + "version": "0x3", + "value": "0xde0b6b3a7640000", + "nonce": "0x1", + "timestamp": "0x57632de7fb4f8", + "txHash": "0xa0c897c5b78860e8500019a3a0788e0498aeec20f3e8e57cc22d9c5096e6ab84" + } + ], + "block_hash": "da8abc0c9bad1d5b868c17b4a3e575ad7b2b8430880e233490fad1811a12277c", + "height": 30000, + "peer_id": "hx98cd0d78e8936b633210b04a6ce10eab655c0881", + "signature": "J4PrnX0jG5sXcdf1bscPvlZPCioDv+pezm1WkEFlOqg8ZHTNZT9LSkCjZFLVbKfObkYRmHDPmGfLgBTPMvZV3wE=" + }, + "id": 1 +} ``` -* Check block data +* get blockbyheight - * get lastblock - ```bash - $ tbears lastblock -u http://127.0.0.1:9100/api/v3 - ``` - - * get totalsupply - ```bash - $ tbears totalsupply -u http://127.0.0.1:9100/api/v3 - ``` +```bash +usage: tbears blockbyheight [-h] [-u URI] [-c CONFIG] height + +// Example +(venv) $ tbears blockbyheight -u http://127.0.0.1:9100/api/v3 0x1 + +// result +block info : { + "jsonrpc": "2.0", + "result": { + "version": "0.1a", + "prev_block_hash": "885b8021826f7e741be7f53bb95b48221e9ab263f377e997b2e47a7b8f4a2a8b", + "merkle_tree_root_hash": "cb3a60b8cba5c7647fa7d2eb351be0723b8a733c41c6bfa0e9f4e6f5b89378e7", + "time_stamp": 1519289604305467, + "confirmed_transaction_list": [ + { + "from": "hx5a05b58a25a1e5ea0f1d5715e1f655dffc1fb30a", + "to": "hx7bcf759a16661dbb9356318af31dc6d4803fc969", + "value": "0x845951614014880000000", + "fee": "0x2386f26fc10000", + "timestamp": "1519289604008199", + "tx_hash": "cb3a60b8cba5c7647fa7d2eb351be0723b8a733c41c6bfa0e9f4e6f5b89378e7", + "signature": "HIjTnNCwHwTiSs7Ucj+oXsyc0ZzDDz9jIKWoQouifEYOCkaAWz8swKet/neGBBckLm6GujqDajWZ290Hoq/ROwE=", + "method": "icx_sendTransaction" + } + ], + "block_hash": "d5629fe006104df557570ce2613c8df1901d8f6f322b9f251645c201fa1d1e9e", + "height": 1, + "peer_id": "hx1fe2dfae9a5439bb1d4e193a3b7c6e5df6c6650e", + "signature": "lGQu4IdK/ZPeCB4e2IJc8s0l38uh30OmH/xSXE7+STpMJaphHbFJYtl7U/Y7bgWhJtQri+GJsp25PyNRzioabAE=" + }, + "id": 1 +``` -* Stop the testnet citizen node +* get blockbyhash ```bash -$ ./stop_testnet_citizen.sh +usage: tbears blockbyhash [-h] [-u URI] [-c CONFIG] hash + +// Example + +(venv) $ tbears blockbyhash -u http://127.0.0.1:9100/api/v3 0xce00facd0ac3832e1e6e623d8f4b9344782da881e55abb48d1494fde9e465f78 + +// Result is same as above. ``` -### Run Citizen Node on ICON Mainnet network -This script will enable ICON citizen node on Mainnet network, running on port 9000. +* get totalsupply ```bash -$ ./run_mainnet_citizen.sh +usage: tbears totalsupply [-h] [-u URI] [-c CONFIG] + +// Example +(venv) $ tbears totalsupply -u http://127.0.0.1:9100/api/v3 + +// Result +Total supply of ICX in hex: 0x2961fff8ca4a62327800000 +Total supply of ICX in decimal: 800460000000000000000000000 ``` +* Create your account on Mainnet if you don't have one. +For Mainnet, we recommend you to create your account on Official ICONex application. + +1. Go to our website at https://icon.foundation +2. Click ‘Wallet’ button on the top +3. Move to Chrome extension page (https://chrome.google.com/webstore/detail/iconex-beta/flpiciilemghbmfalicajoolhkkenfel?hl=en) +4. Click “Add on +CHROME” button on the upper right corner -ICON Testnet Tracker() +* get balance + +```bash +usage: tbears balance [-h] [-u URI] [-c CONFIG] address -#### Stop All +// Example +(venv) $ tbears balance -u http://127.0.0.1:9100/api/v3 hx63499c4efc26c9370f6d68132c116d180d441266 +// Result +balance in hex: 0xde0b6b3a7640000 +balance in decimal: 1000000000000000000 ``` -# This script does not support all platforms and may need to be modified. (Please refer to the script.) -$ ./stop_all.sh + +* Send transaction + +Now that you have received a sufficient amount of icx, you can use it to send transactions. + +``` +usage: tbears sendtx [-h] [-u URI] [-k KEYSTORE] [-c CONFIG] json_file + +Request icx_sendTransaction with the specified json file and keystore file. If +keystore file is not given, tbears sends request as it is in the json file. + +positional arguments: + json_file File path containing icx_sendTransaction content + +optional arguments: + -h, --help show this help message and exit + -u URI, --node-uri URI + URI of node (default: http://127.0.0.1:9000/api/v3) + -k KEYSTORE, --key-store KEYSTORE + Keystore file path. Used to generate "from" address and + transaction signature + -c CONFIG, --config CONFIG + Configuration file path. This file defines the default + value for the "uri" (default: ./tbears_cli_config.json) ``` +For the details, please go to [Command-line Interfaces(CLIs)](https://github.com/icon-project/t-bears#command-line-interfacesclis) chapter in t-bears repository. + #### Clean Up (delete log / delete DB) ``` -$ rm -rf log -$ rm -rf .storage_test +$ rm -rf log/ +$ rm -rf .storage_test/ .storage_main/ ``` + +## License + +This project follows the Apache 2.0 License. Please refer to [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) for details. diff --git a/sendtx_testnet.json b/sendtx_testnet.json new file mode 100644 index 000000000..9c6c960a6 --- /dev/null +++ b/sendtx_testnet.json @@ -0,0 +1,12 @@ +{ + "jsonrpc": "2.0", + "method": "icx_sendTransaction", + "params": { + "version": "0x3", + "to": "hx670e692ffd3d5587c36c3a9d8442f6d2a8fcc795", + "value": "0xde0b6b3a7640000", + "stepLimit": "0x3000000", + "nid": "0x2" + }, + "id": 1 +} \ No newline at end of file