Skip to content

Instantly share code, notes, and snippets.

@jcvernaleo
Last active October 18, 2018 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jcvernaleo/af88614a7c3f399819af0aaf074d7725 to your computer and use it in GitHub Desktop.
Save jcvernaleo/af88614a7c3f399819af0aaf074d7725 to your computer and use it in GitHub Desktop.
Insight/Copay setup

Copay/Insight setup.

This describes how to setup the decred fork of the copay webwallet and insight block explorer along with how to hack on them.

Prerequisites

bws requires mongodb. This should work on Linux and OpenBSD. The node packages currently ONLY work on Linux.

On Ubuntu/Debian/similar you can install it with:

sudo apt-get install mongodb git build-essential

It will then start up automatically. Other systems may vary.

Keep in mind that once the blockchain reaches any reasonable size this will require a ton of disk space (at least 3X blockchain size). The dcrd node has a copy of the chain, insight has a copy, and bws has a copy using mongodb. For now with dcrd this is a not a big deal, but for bitcoin-mainnet it is a serious requirement.

node install

You also need nodejs and npm.

To ensure we are all on the same version and to help us migrate to newer versions, it is useful to use nvm. If you are already using npm with a prefix, you need to remove that first:

npm config delete prefix

It is also important that you DO NOT INSTALL nodejs or npm from your system packages. If they are installed, please uninstall them.

git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
. ~/.nvm/nvm.sh

You should add this to your .bashrc so it is always available to you. Other shells (ksh) might require something slightly different but I haven't tested:

if [ -f ~/.nvm/nvm.sh ];
then
   . ~/.nvm/nvm.sh
fi

Now we will install an old version of npm and a newer version (and update npm since we always want a new one of those). Different components require different node versions.

nvm install v0.10.40
npm install -g npm
npm install -g node-gyp bower grunt-cli
nvm install v4.2.1
npm install -g npm
npm install -g node-gyp bower grunt-cli

You can use the command:

nvm ls

to see what version you are using and what versions are installed locally. Your version of npm MUST be 2.0 or greater. Anything earlier will fail to even install our code with confusing errors.

Use the command nvm use VERSION to switch active versions and nvm alias default VERSION if you want to set the default.

Install/Run

NOTE: Some of the steps in the various READMEs are incorrect or misleading. It is important to either follow this document or be careful when following the READMEs.

I will assume you are going to put all code in ~/code/bitpay. If not, adjust as required for you organization.

mkdir -p ~/code/bitpay

dcrd

dcrd is required as the data source for insight. Install it as usual. It must be fully synced which can take a while.

dcrd -u user -P pass --notls --txindex --testnet
dcrd -u user -P pass --notls --txindex

insight

Install insight and connect it to a btcd node over rpc.

nvm use v0.10.40
cd ~/code/bitpay
git clone git@github.com:decred/insight.git
cd insight
npm install
BITCOIND_USER=user BITCOIND_PASS=pass INSIGHT_NETWORK=dcrdtestnet LOGGER_LEVEL=debug npm start
BITCOIND_USER=user BITCOIND_PASS=pass INSIGHT_NETWORK=dcrdlivenet LOGGER_LEVEL=debug npm start

It may take insight a long time to sync.

You can browse the blockchain and check the progress by going to http://localhost:3003 for mainnet or http://localhost:3004 for testnet.

bws

Next we must install and start our bws.

nvm use v4.2.1
cd ~/code/bitpay
git clone git@github.com:decred/bitcore-wallet-service.git
cd bitcore-wallet-service/
npm install && npm install
npm start

The second npm install is sometimes needed to get all the dependencies right (I have no idea why).

Note, bws goes into the background immediately and does NOT report errors on the console, even fatal ones. So you should watch the log file:

tail -f log/bws.log

bws cmd line (optional)

If you want, you can install a set of command lines tools to talk to bws. This is not required, but may be helpful.

nvm use v4.2.1
cd ~/code/bitpay
git clone git@github.com:decred/bitcore-wallet.git
cd bitcore-wallet
npm install
export BWS_HOST=http://localhost:3232/

Now you can run the cmd lines tools:

bin/wallet create NAME 1-1 COPAYERNAME -t
bin/wallet status

and so on.

copay

Now to install copay (the actually wallet website).

nvm use v0.10.40
cd ~/code/bitpay
git clone ssh://noc.decred.org/git/copay.git
cd copay
npm install
npm start

Now you can go to it at http://localhost:3000.

If you need to make changes to copay, you must rerun npm install.

Hacking (This section might need updating)

Hacking insight

Since some of the assets for insight are generated from other assets (grrr), if you hack insight code you need to regenerate things:

cd ~/code/bitpay/insight
npm install
bower install
grunt compile

You will need to commit the generated files to the repo. Normally that makes me queasy, but based on the normal workflow with this code (and node) it is currently necessary.

Hacking insight-api

Due to the way npm packages things, you need an extra step if you want to hack on insight-api.

  1. Grab additional sources:
nvm use v0.10.40
cd ~/code/bitpay
git clone git@github.com:decred/crypto-browserify.git
git clone git@github.com:decred/insight-api.git
git clone git@github.com:decred/bitcore.git
cd crypto-browserify
git checkout master-legacy
npm install
cd ..
cd bitcore
git checkout master-legacy
npm install
cd ..
cd insight-api
npm install
  1. Edit the files in ~/code/bitpay/insight-api or ~/code/bitpay/bitcore as desired.

  2. cd ~/code/bitpay

  3. rm -r insight/node_modules/insight-bitcore-api insight/node_modules/bitcore insight-api/node_modules/bitcore

  4. cd insight-api and edit packages.json to point to local bitcore (file:../bitcore) if you plan on hacking bitcore.

  5. cd insight

  6. npm install

  7. Repeat (or commit your changes in insight-api if they are what you want).

Hacking bws

There are some additional deps you may need to hack on bitcore-wallet-service.

cd ~/code/bitpay
git clone git@github.com:decred/bitcore-wallet-client.git
git clone git@github.com:decred/bitcore-wallet-utils.git

If you edit those, you will need to push to the git repo (master) for bitcore-wallet or bitcore-wallet-service to find the change. If you need to test, you can edit their line in packages.json to file:../REPO but do not commit that to master.

Hacking copay

To hack on copay you may also need the angular-bitcore-wallet libraries

nvm use v0.10.40
cd ~/code/bitpay
git clone git@github.com:decred/angular-bitcore-wallet-client.git
git co 0.4.4

If you need to update the code in it:

cd angular-bitcore-wallet-client
make clean
npm install
make

Then if it is correct, commit the modified files to the git repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment