diff --git a/README.md b/README.md index 4f5817f..e156e14 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,33 @@ -# bitcore-btcp +# bitcore-install - v0.0.1 -To build and install Bitcoin Private, [bitcore-node-btcp](https://github.com/BTCPrivate/bitcore-node-btcp) and its dependencies, and the bitcoind + [insight-api-btcp](https://github.com/BTCPrivate/insight-api-btcp) + [insight-ui-btcp](https://github.com/BTCPrivate/insight-ui-btcp) services: +### Vendor backend samples for BTCP (Javascript, Bitcore) -`./btcp-explorer.sh` +Run any one of these in a fresh Ubuntu VM to get started: -To run: +#### `btcp_store_demo.sh` +- Creates a bitcore fullnode configured for `store-demo`, as well as block explorer + api +- **Public AMI:** BTCP-Store (ami-62e3881a) + +#### `btcp_explorer_demo.sh` +- Creates a bitcore fullnode configured for block explorer + api (`insight-ui-btcp` and `insight-api-btcp`) + +#### `btcp_fetch_wallet.sh` +- Acquires `btcpd` and `btcp-cli` by either downloading the [latest indexing-enabled binaries](https://github.com/BTCPrivate/BitcoinPrivate/releases/tag/v1.0.11-d3905b0), or by fetching the [source on the explorer-btcp branch](https://github.com/BTCPrivate/BitcoinPrivate/tree/explorer-btcp) and building + + +# Related Repos + +- [store-demo](https://github.com/BTCPrivate/store-demo) +- [address-watch](https://github.com/BTCPrivate/address-watch) +- [bitcore-node-btcp](https://github.com/BTCPrivate/bitcore-node-btcp) +- [bitcore-lib-btcp](https://github.com/BTCPrivate/bitcore-lib-btcp) +- [bitcore-p2p-btcp](https://github.com/BTCP-community/bitcore-p2p-btcp) +- [bitcore-message-btcp](https://github.com/BTCPrivate/bitcore-message-btcp) +- [bitcore-build-btcp](https://github.com/BTCPrivate/bitcore-build-btcp) +- [insight-ui-btcp](https://github.com/BTCPrivate/insight-ui-btcp) +- [insight-api-btcp](https://github.com/BTCPrivate/insight-api-btcp) + +- [Bitcoin Private Daemon + CLI](https://github.com/BTCPrivate/BitcoinPrivate/tree/explorer-btcp) + +Runs with bitcore-node-btcp (fork of bitcore-node v4) on bitcore v3.1. Original work: [str4d/insight-api-zcash](https://github.com/str4d/insight-api-zcash). -`./start.sh` diff --git a/btcp_basic_node.sh b/btcp_explorer_demo.sh similarity index 100% rename from btcp_basic_node.sh rename to btcp_explorer_demo.sh diff --git a/btcp_store_demo.sh b/btcp_store_demo.sh index e703160..e8ed109 100755 --- a/btcp_store_demo.sh +++ b/btcp_store_demo.sh @@ -1,9 +1,9 @@ #!/bin/bash -# BTCP Bitcore API + Explorer + Store / AddressWatch Demo - # !!! EC2 - Make sure port 8001 is in your security group +# !!! Run this in a fresh environment. + install_ubuntu() { # Get Ubuntu Dependencies @@ -19,12 +19,11 @@ sudo apt-get -y install libzmq3-dev } - make_swapfile() { -# You must have enough memory for the installation to succeed. +# You must have enough memory for the BTCP build to succeed. -PREV=$PWD +local PREV=$PWD cd / sudo dd if=/dev/zero of=swapfile bs=1M count=3000 sudo mkswap swapfile @@ -35,10 +34,35 @@ cd $PREV } +prompt_swapfile() { + +echo "" +echo "Can we make you a 3gb swapfile? EC2 Micro needs it because it takes a lot of memory to build BTCP." +echo "" +read -r -p "[y/N] " response +case "$response" in + [yY][eE][sS]|[yY]) + make_swapfile + ;; + *) + echo "Not creating swapfile." + ;; +esac + +} + clone_and_build_btcp() { # Clone latest Bitcoin Private source, and checkout explorer-btcp -git clone -b explorer-btcp https://github.com/BTCPrivate/BitcoinPrivate +if [ ! -e ~/BitcoinPrivate ] +then + git clone -b explorer-btcp https://github.com/BTCPrivate/BitcoinPrivate +fi + +# Freshen up +#git checkout explorer-btcp +#git checkout -- . +#git pull # Fetch BTCP/Zcash ceremony params ./BitcoinPrivate/btcputil/fetch-params.sh @@ -46,32 +70,88 @@ git clone -b explorer-btcp https://github.com/BTCPrivate/BitcoinPrivate # Build Bitcoin Private ./BitcoinPrivate/btcputil/build.sh -j$(nproc) -#Make hidden .btcprivate dir because the daemon has not ran and created the folder yet +} + +init_btcprivate_dotdir() { + +# Make .btcprivate dir (btcpd hasn't been run) if [ ! -e ~/.btcprivate/ ] then - echo "Bitcoin Private Data Dir(.btcprivate) does not exist in the current user home directory, creating folder..." mkdir ~/.btcprivate fi -#Then download the blockchain.tar.gz and extract to speed up the initial syncing when first starting -echo "Bitcoin Private Data Dir(.btcprivate) does exist in the current user home directory. Downloading and Extracting files" -cd ~/.btcprivate -wget https://storage.googleapis.com/btcpblockchain/blockchain.tar.gz -tar -zxvf blockchain.tar.gz -echo "Downloading and extracting of blockchain files completed" - -# Make initial, empty btcprivate.conf if needed +# Make empty btcprivate.conf if needed; otherwise use existing if [ ! -e ~/.btcprivate/btcprivate.conf ] then - touch ~/.btcprivate/btcprivate.conf + +local RPCPASSWORD=$(head -c 32 /dev/urandom | base64) +touch ~/.btcprivate/btcprivate.conf +cat << EOF > ~/.btcprivate/btcprivate.conf +#gen=1 +#reindex=1 +#showmetrics=0 +#rpcport=7932 +rpcuser=bitcoin +rpcpassword=$RPCPASSWORD +server=1 +whitelist=127.0.0.1 +txindex=1 +addressindex=1 +timestampindex=1 +spentindex=1 +zmqpubrawtx=tcp://127.0.0.1:28332 +zmqpubhashblock=tcp://127.0.0.1:28332 +rpcallowip=127.0.0.1 +uacomment=bitcore +addnode=dnsseed.btcprivate.org +EOF + fi +cd ~/.btcprivate +# Download + decompress blockchain.tar.gz (blocks/, chainstate/) to quickly sync past block 300,000 +fetch_btcp_blockchain + +} + +fetch_zcash_params() { + +wget -qO- https://raw.githubusercontent.com/BTCPrivate/BitcoinPrivate/master/btcputil/fetch-params.sh | bash + +} + +fetch_btcp_blockchain() { + +cd ~/.btcprivate + +local FILE="blockchain-explorer.tar.gz" +wget https://storage.googleapis.com/btcpblockchain/$FILE +tar -zxvf $FILE +echo "Downloading and extracting blockchain files - Done." +rm -rf $FILE + +} + +fetch_btcp_binaries() { + +mkdir -p ~/BitcoinPrivate/src +cd ~/BitcoinPrivate/src + +local RELEASE="1.0.11" +local COMMIT="d3905b0" +local FILE="btcp-${RELEASE}-explorer-${COMMIT}-linux.tar.gz" +wget https://github.com/BTCPrivate/BitcoinPrivate/releases/download/v${RELEASE}-${COMMIT}/${FILE} +tar -zxvf $FILE +echo "Downloading and extracting BTCP files - Done." +rm -rf $FILE } install_nvm_npm() { +cd ~ + # Install npm sudo apt-get -y install npm @@ -81,7 +161,7 @@ wget -qO- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | b # Set up nvm export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion # Install node v4 nvm install v4 @@ -90,7 +170,7 @@ nvm alias default v4 } -# MongoDB dependency for bitcore-wallet-service: +# MongoDB dependency for bitcore: install_mongodb() { @@ -105,9 +185,10 @@ sudo mkdir -p /data/db } - install_bitcore() { +cd ~ + # Install Bitcore (Headless) npm install BTCPrivate/bitcore-node-btcp @@ -116,9 +197,9 @@ npm install BTCPrivate/bitcore-node-btcp cd btcp-explorer # Install Insight API / UI (Explorer) (Headless) -../node_modules/bitcore-node-btcp/bin/bitcore-node install BTCPrivate/insight-api-btcp BTCPrivate/insight-ui-btcp BTCPrivate/store-demo -# (BTCPrivate/address-watch) (BTCPrivate/bitcore-wallet-service (untested)) +../node_modules/bitcore-node-btcp/bin/bitcore-node install BTCPrivate/insight-api-btcp BTCPrivate/insight-ui-btcp BTCPrivate/store-demo # BTCPrivate/address-watch, BTCPrivate/bitcore-wallet-service (untested) +local BITCORE_SERVICE_APP="store-demo" #address-watch, bitcore-wallet-service # Create config file for Bitcore cat << EOF > bitcore-node.json @@ -129,7 +210,7 @@ cat << EOF > bitcore-node.json "bitcoind", "insight-api-btcp", "insight-ui-btcp", - "store-demo", + "$BITCORE_SERVICE_APP", "web" ], "servicesConfig": { @@ -150,48 +231,80 @@ cat << EOF > bitcore-node.json } EOF +#TODO Prompt option + Automate SSL Setup (LetsEncrypt) +#"https": true, +#"privateKeyFile": "/etc/ssl/bws.bitpay.com.key", +#"certificateFile": "/etc/ssl/bws.bitpay.com.crt", + } -# -- Begin Fetching + Building -- -cd ~ +install_bower_browserify_js_libs() { + cd ~/btcp-explorer/node_modules/store-demo + npm install -g bower browserify + bower install + cd node_modules/bitcore-lib-btcp + browserify --require ./index.js:bitcore-lib-btcp -o bitcore-lib-btcp.js + cp bitcore-lib-btcp.js ~/btcp-explorer/node_modules/store-demo/static/js/bitcore-lib-btcp +} -echo "Begin Setup." -echo "" - -install_ubuntu +run_install() { echo "" -echo "Can we make you a 3gb swapfile? EC2 Micro needs it because it takes a lot of memory to build BTCP." +echo "Begin Setup - Installing required packages." echo "" -read -r -p "[y/N] " response + +install_ubuntu > /dev/null + +echo "" +echo "How would you like to fetch BTCP (btcpd and btcp-cli):" +echo "1) [fast] Download the latest binaries" +echo "2) [slow] Download + build from source code" +echo "" +read -r -p "[1/2] " response case "$response" in - [yY][eE][sS]|[yY]) - make_swapfile + [1]) + fetch_zcash_params + fetch_btcp_binaries + ;; + [2]) + prompt_swapfile clone_and_build_btcp ;; *) - clone_and_build_btcp + echo "Neither; Skipped." ;; esac +init_btcprivate_dotdir install_nvm_npm -#install_mongodb +install_mongodb install_bitcore +install_bower_browserify_js_libs + echo "Complete." echo "" # Verify that nvm is exported export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion -echo "To start mongodb for bitcore-wallet-service, run 'mongod &'" -echo "To start the bitcore-node, run:" +echo "To start the demo, run:" echo "cd ~/btcp-explorer; nvm use v4; ./node_modules/bitcore-node-btcp/bin/bitcore-node start" echo "" -echo "To view the explorer in your browser - http://server_ip:8001" -echo "For https, we recommend you route through Cloudflare. bitcore-node also supports it via the config; provide certs." +echo "To view the demo in your browser:" +echo "http://my_ip:8001" +echo "" + +} + + +# *** SCRIPT START *** + +cd ~ +run_install + diff --git a/btcp_explorer_upgrade.sh b/experimental/btcp_explorer_upgrade.sh similarity index 100% rename from btcp_explorer_upgrade.sh rename to experimental/btcp_explorer_upgrade.sh diff --git a/btcp_node_v5.sh b/experimental/btcp_node_v5.sh similarity index 100% rename from btcp_node_v5.sh rename to experimental/btcp_node_v5.sh diff --git a/start_v5.sh b/experimental/start_v5.sh similarity index 100% rename from start_v5.sh rename to experimental/start_v5.sh