Установка Exonum на VirtualBox

Disclaimer:

Exonum на VirtualBox в образе CentOS 7.5 работает по разному в Docker (корректно) и скомпилированный вручную (вылезают ошибки в JS). При этом версии Node.JS и Linux Kernel совпадают. Дальнейшее расследование будет проводиться по необходимости.

Схема:

Короткий путь:

Образ

VirtualBox image на 17.10.2018  (требует 20 Gb на диске + сам образ 6 Gb)

\\Billing.ru\dfs\incoming\ASushkov\VirtualBox

CentOS 7.5 + Exonum + make v2.ova

User: nwm

Pass: nwm

Запуск Docker:

docker run -p 8000-8008:8000-8008 serhiioryshych/exonum-cryptocurrency-advanced-example

Доступ:  http://192.168.56.1:8008

Запуск ручной сборки

cd exonum/examples/cryptocurrency-advanced/backend

exonum-cryptocurrency-advanced run --node-config example/node_1_cfg.toml --db-path example/db1 --public-api-address 0.0.0.0:8200
cd exonum/examples/cryptocurrency-advanced/frontend
npm start -- --port=5555 --api-root=http://127.0.0.1:8200

Доступ: http://192.168.56.1:5555

Скриншоты и API

см. Appendix

Длинный путь:

Документы и исходники

GitHub: https://github.com/exonum/

Exonum Doc включая установку: https://exonum.com/doc/

Install examples: https://github.com/exonum/exonum/blob/master/examples/cryptocurrency-advanced/README.md

VirtualBox

Устанавливаем:

  • CentOS 7.5
  • Add Extentions
  • uname -a
    Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Установка Exonum из Docker образа

sudo yum install docker

docker –version

systemctl start docker

docker run -p 8000-8008:8000-8008 serhiioryshych/exonum-cryptocurrency-advanced-example

Доступ:

http://192.168.56.1:8008

Установка Exonum из исходников

В образе CentOS 7.5 от Nexign уже установлено:

sudo yum install git gcc gcc-c++

Sodium – крипто библиотека 

Скачиваем отсюда:

https://download.libsodium.org/libsodium/releases/

Например так:

wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.16.tar.gz

Устанавливаем:

tar -xf libsodium-1.0.16.tar.gz

cd libsodium-1.0.16.tar.gz

./configure && make && make check && sudo make install

RocksDB

Подготовка

cd ~

git clone https://github.com/gflags/gflags.git

cd gflags
git checkout v2.0
./configure && make && sudo make install

sudo yum install snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel

Ставим саму RocksDB

cd ~

git clone https://github.com/facebook/rocksdb.git
cd rocksdb/
make shared_lib

или это: 

make static_lib
 

Правим окружение:

export ROCKSDB_LIB_DIR=/home/nwm/rocksdb

export LIBRARY_PATH=$LIBRARY_PATH:/home/nwm/rocksdb

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/nwm/rocksdb:/usr/local/lib

export CPATH=$CPATH:/usr/local/include

export SNAPPY_LIB_DIR=/usr/local/lib

Rust Toolchain

устанавливаем 

curl https://sh.rustup.rs -sSf | sh

пути сразу 

source $HOME/.cargo/env

проверяем 

rustc --version

Добавить в PATH:

$HOME/.cargo/bin

source .bash_profile

Compiling Exonum

Install OpenSSL

sudo yum install openssl

sudo yum install openssl-devel

Сам Exonum

cd ~

git clone https://github.com/exonum/exonum.git

cd exonum

cargo test –manifest-path exonum/Cargo.toml

Компилим пример: cryptocurrency-advanced

Из каталога с Exonum переходим в backend:

cd examples/cryptocurrency-advanced/backend

Или компилим пример:

cargo install

Или если уже были скомпилированы в другом месте, то

cargo install --force

Или если уже был установлен:

cargo build

Для ЧЕТЫРЕХ нод

Далее в этом же каталоге же запускаем генерацию конфигураций

Грохаем все Exonum: sudo ss -tupl | pgrep -f exonum | xargs kill

mkdir example

exonum-cryptocurrency-advanced generate-template example/common.toml –validators-count 4

exonum-cryptocurrency-advanced generate-config example/common.toml  example/pub_1.toml example/sec_1.toml --peer-address 127.0.0.1:6331
exonum-cryptocurrency-advanced generate-config example/common.toml  example/pub_2.toml example/sec_2.toml --peer-address 127.0.0.1:6332
exonum-cryptocurrency-advanced generate-config example/common.toml  example/pub_3.toml example/sec_3.toml --peer-address 127.0.0.1:6333
exonum-cryptocurrency-advanced generate-config example/common.toml  example/pub_4.toml example/sec_4.toml --peer-address 127.0.0.1:6334
exonum-cryptocurrency-advanced finalize --public-api-address 0.0.0.0:8200 --private-api-address 0.0.0.0:8091 example/sec_1.toml example/node_1_cfg.toml --public-configs example/pub_1.toml example/pub_2.toml example/pub_3.toml example/pub_4.toml
exonum-cryptocurrency-advanced finalize --public-api-address 0.0.0.0:8201 --private-api-address 0.0.0.0:8092 example/sec_2.toml example/node_2_cfg.toml --public-configs example/pub_1.toml example/pub_2.toml example/pub_3.toml example/pub_4.toml
exonum-cryptocurrency-advanced finalize --public-api-address 0.0.0.0:8202 --private-api-address 0.0.0.0:8093 example/sec_3.toml example/node_3_cfg.toml --public-configs example/pub_1.toml example/pub_2.toml example/pub_3.toml example/pub_4.toml
exonum-cryptocurrency-advanced finalize --public-api-address 0.0.0.0:8203 --private-api-address 0.0.0.0:8094 example/sec_4.toml example/node_4_cfg.toml --public-configs example/pub_1.toml example/pub_2.toml example/pub_3.toml example/pub_4.toml
Далее в этом же каталоге же запускаем блокчейн:
cd examples/cryptocurrency-advanced/backend
nohup exonum-cryptocurrency-advanced run --node-config example/node_1_cfg.toml --db-path example/db1 --public-api-address 0.0.0.0:8200 &
nohup exonum-cryptocurrency-advanced run --node-config example/node_2_cfg.toml --db-path example/db2 --public-api-address 0.0.0.0:8201 &
nohup exonum-cryptocurrency-advanced run --node-config example/node_3_cfg.toml --db-path example/db3 --public-api-address 0.0.0.0:8202 &
nohup exonum-cryptocurrency-advanced run --node-config example/node_4_cfg.toml --db-path example/db4 --public-api-address 0.0.0.0:8203 &

Для ОДНОЙ ноды

mkdir example

exonum-cryptocurrency-advanced generate-template example/common.toml –validators-count 1

exonum-cryptocurrency-advanced generate-config example/common.toml  example/pub_1.toml example/sec_1.toml --peer-address 127.0.0.1:6331
exonum-cryptocurrency-advanced finalize --public-api-address 0.0.0.0:8200 --private-api-address 0.0.0.0:8091 example/sec_1.toml example/node_1_cfg.toml --public-configs example/pub_1.toml
nohup exonum-cryptocurrency-advanced run --node-config example/node_1_cfg.toml --db-path example/db1 --public-api-address 0.0.0.0:8200 &

Frontend

Устанавливаем Node.js and npm on CentOS 7

https://nodejs.org/en/download/package-manager/

On RHEL, CentOS or Fedora, for Node.js v8 LTS:

curl –silent –location https://rpm.nodesource.com/setup_8.x | sudo bash –

sudo yum -y install nodejs

Из каталога с Exonum переходим в пример frontend:

cd examples/cryptocurrency-advanced/frontend

Смотрим версию Node:

node -e “console.log(‘Running Node.js ‘ + process.version)”

Устанавливаем нужную версию:

nvm install 8.11.3

npm install
npm run build

Отключаем firewall:

systemctl stop firewalld
systemctl disable firewalld

Запускаем:

npm start -- --port=5555 --api-root=http://127.0.0.1:8200

Доступ:

Изнутри:

http://localhost:5555

Или снаружи:

http://192.168.56.1:5555

Appendix

При входе на IP примера заводим кошелек test_user:

При нажатии на кнопку Register запоминаем Secret key, например:

8e08fa13466581a30958198b1d6e729e53943eaeaf203570e3b3ec879c1cbc70dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d82

И Public key:

dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d82

В ответ получаем hash транзакции

{
“tx_hash”: “b10ca1bdee4b4958ca7adbfef81a44a5ce795bc0ed32b19c849c187ed4eb1437”
}

запоминаем hash. Далее можно получать информацию используя API.

Кошелек можно завести и с помощью API, но для этого надо уметь работать с крипто API:

API Create wallet

посылаем POST

http://192.168.56.1:5555/api/services/cryptocurrency/v1/wallets/transaction

с корректно сформированным телом:

{

“protocol_version”: 0,
“service_id”: 128,
“message_id”: 2,
“body”: {
“pub_key”: “dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d82”,
“name”: “test_user”
},
“signature”: “e75ab828636c3496e00f033621081117a2dc840e1f84cb44bbbf1705001360988ce34008746c66a6b4a680293fafd894dc100224ee989c6652eedae4a937a30d”
}

API get transaction information

http://192.168.56.1:5555/api/explorer/v1/transactions?hash=b10ca1bdee4b4958ca7adbfef81a44a5ce795bc0ed32b19c849c187ed4eb1437

Responce:

{
“type”: “committed”,
“content”: {
“debug”: {
“name”: “test_user”
},
“message”: “dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d820000800002000800000009000000746573745f7573657204125a331a647e224aaab7b7ee8a7f087011343d03de6f36c6622ef45cc1a1376d65bd4fa5aa9b64efcd6863754d0f21526bc17539c568c08cddd515a2913a0e”
},
“location”: {
“block_height”: “382577”,
“position_in_block”: “0”
},
“location_proof”: {
“val”: “b10ca1bdee4b4958ca7adbfef81a44a5ce795bc0ed32b19c849c187ed4eb1437”
},
“status”: {
“type”: “success”
}
}

API get Blockchain config

http://192.168.56.1:5555/api/services/configuration/v1/configs/actual

Responce:

{
“hash”: “c12bdd8b288b3a99db51b9ee4cdde0dfe4b6d3019c27fe3b33e4d1eabe3899d9”,
“config”: {
“previous_cfg_hash”: “0000000000000000000000000000000000000000000000000000000000000000”,
“actual_from”: 0,
“validator_keys”: [
{
“consensus_key”: “015ac0497a8fa3376a53c4e1b2e7acac906b7bdef5c901576b3d4bc0ac6bfbca”,
“service_key”: “087741fe75991ed8fead744610c6d12952f70d425a2452938f0d188adfd3bb00”
}
],
“consensus”: {
“first_round_timeout”: 3000,
“status_timeout”: 5000,
“peers_timeout”: 10000,
“txs_block_limit”: 1000,
“max_message_len”: 1048576,
“min_propose_timeout”: 10,
“max_propose_timeout”: 200,
“propose_timeout_threshold”: 500
},
“services”: {
“configuration”: {
“majority_count”: null
},
“cryptocurrency”: null
}
},
“propose”: null,
“votes”: null
}

API get wallet info

http://192.168.56.1:5555/api/services/cryptocurrency/v1/wallets/info?pub_key=dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d82

Responce:

{
“block_proof”: {
“block”: {
“height”: “386666”,
“prev_hash”: “c81a41822c9c0eedd9690538897a5c544a0cf7e7d90b1c16217957772b4206f1”,
“proposer_id”: 0,
“state_hash”: “486e24f7407ab70b23ab763b6b24846c7f12612fdd0495d111d330aa7c8b06d4”,
“tx_count”: 0,
“tx_hash”: “0000000000000000000000000000000000000000000000000000000000000000”
},
“precommits”: [
{
“payload”: {
“block_hash”: “f01fe8e96a052016c3414d9d078b1553fb62e132ccdf25b5bf8e8aea64f9f232”,
“height”: “386666”,
“propose_hash”: “4192d67b9cb5a99cf3c1b2df702a4191d0563e9a20ac3b2dc0d27f553fb8021d”,
“round”: 1,
“time”: {
“nanos”: 458982097,
“secs”: “1539761739”
},
“validator”: 0
},
“message”: “015ac0497a8fa3376a53c4e1b2e7acac906b7bdef5c901576b3d4bc0ac6bfbca010000006ae6050000000000010000004192d67b9cb5a99cf3c1b2df702a4191d0563e9a20ac3b2dc0d27f553fb8021df01fe8e96a052016c3414d9d078b1553fb62e132ccdf25b5bf8e8aea64f9f2324be6c65b00000000d1825b1bde1d71045a30fad82506a323fbcb76fd1643fdb7c64ff45c65c23b9012ba73e343ffb9372fd2f13201686dee782c0100852bd0a7bc7734b27e55ffd7be823102”
}
]
},
“wallet_proof”: {
“to_table”: {
“entries”: [
{
“key”: “50c8ba3a6170f0a2fb6736ece8a603576ef6309a35e810911599bc6211b554a9”,
“value”: “aa0914c9d1b6fb32440b638b097b53d40f3a219f374068ae78739b8ceac1aa11”
}
],
“proof”: [
{
“path”: “0000101010101110110000001010110110011000000001100011001110110111000101011001101100100100000010011111001000011101110010101110111001111111101111101110100011111110000111011111101111110011011010100100110101110010101000101110101000100110011100100010101101100001”,
“hash”: “0000000000000000000000000000000000000000000000000000000000000000”
},
{
“path”: “11”,
“hash”: “80fa8fb547d3239db57a8d6938f367f441564c6209995f00f4669301f2be883b”
}
]
},
“to_wallet”: {
“entries”: [
{
“key”: “dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d82”,
“value”: {
“balance”: “100”,
“history_hash”: “b10ca1bdee4b4958ca7adbfef81a44a5ce795bc0ed32b19c849c187ed4eb1437”,
“history_len”: “1”,
“name”: “test_user”,
“pub_key”: “dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d82”
}
}
],
“proof”: [
{
“path”: “00”,
“hash”: “e5943d10cc29dfb660ba6a94a66e74a0d8a925b53d5ff82bacd037c38ebffcab”
},
{
“path”: “010”,
“hash”: “c5757783188f6588674041333cfb8039d68199cfc78f72603a50f75603b39a31”
},
{
“path”: “01100”,
“hash”: “9d2ae26c27e51428cff43407c06f132316c523755fde516f841ad529086551e0”
},
{
“path”: “1”,
“hash”: “8c7cde3df7d436232f9d6d5557d733a38733e7945632e26b34bc2ff7e1a10dd1”
}
]
}
},
“wallet_history”: {
“proof”: {
“val”: “b10ca1bdee4b4958ca7adbfef81a44a5ce795bc0ed32b19c849c187ed4eb1437”
},
“transactions”: [
{
“CreateWallet”: {
“name”: “test_user”
}
}
]
}
}

API Add Money wallet

посылаем POST

http://192.168.56.1:5555/api/services/cryptocurrency/v1/wallets/transaction

с корректно сформированным телом:

{

“protocol_version”: 0,
“service_id”: 128,
“message_id”: 1,
“body”: {
“pub_key”: “dea18489e18e342ccbb994633aebb7397df6c7aebe380581e2a74264a70c9d82”,

“amount”: “100”

“seed”: “13786703415428081604”
},
“signature”: “e75ab828636c3496e00f033621081117a2dc840e1f84cb44bbbf1705001360988ce34008746c66a6b4a680293fafd894dc100224ee989c6652eedae4a937a30d”
}

Responce:

hash транзакции: 8527662d56ffdf92b63740350fce9e217a06bfb0063ad060ee16ceb3b9c54816

По ней также можно получить информацию:

http://192.168.56.1:5555/api/explorer/v1/transactions?hash=8527662d56ffdf92b63740350fce9e217a06bfb0063ad060ee16ceb3b9c54816

Responce:

{
“type”: “committed”,
“content”: {
“body”: {
“amount”: “100”,
“pub_key”: “8b30d707b8ee3d1266532afb12ef3e3e49d3edf5dcb3ceff7511fb8e64c23050”,
“seed”: “13786703415428081604”
},
“message_id”: 1,
“protocol_version”: 0,
“service_id”: 128,
“signature”: “76b80304392c86d80afe4d0aee93083bf8f9b43bb04207a875cc00b0b2621f599368c4a29ab7555fe45a9047e9bc3d09c6c93e0bcfad0a2ca9a958b786b53e05”
},
“location”: {
“block_height”: “319275”,
“position_in_block”: “0”
},
“location_proof”: {
“val”: “8527662d56ffdf92b63740350fce9e217a06bfb0063ad060ee16ceb3b9c54816”
},
“status”: {
“type”: “success”
}
}

API Transfer Money

посылаем POST

http://192.168.56.1:5555/api/services/cryptocurrency/v1/wallets/transaction

с корректно сформированным телом и PublicID того парня:

{

“protocol_version”: 0,
“service_id”: 128,
“message_id”: 0,
“body”: {

“amount”: “50”

“from”: “92c1be1d17c2d2178553b24ace0e6e285f4b0725a271e58732cbfba0c4fa8086”

“to”: “eb4b7537bea382602274c1ad26cbfcd461636368a450b913cc68011a9fd7bc3a”

“seed”: “13786703415428081604”
},
“signature”: “e75ab828636c3496e00f033621081117a2dc840e1f84cb44bbbf1705001360988ce34008746c66a6b4a680293fafd894dc100224ee989c6652eedae4a937a30d”
}

Responce:

hash