BuyCo.io Proof of Concept / MVP
The implementation consists of:
An explanation of the working process with forks and pull requests is in docs/README.GIT.md.
A version of the development branch is running here: https://blockstars.io:4124/. This version uses the development Uphold app, database and blockchain node.
selfsigned.blockstars.io
resolves to the IP of your development machine (e.g. by adding 127.0.0.1 selfsigned.blockstars.io
to your hosts file)(sudo) npm -g bower tsd grunt-cli
git clone git@github.com:OutlierVentures/BuyCo.git
)sh ./install.sh
grunt
grunt serve
The BuyCo app can now be loaded on https://selfsigned.blockstars.io:4124/.
If this doesn't work for you, or you want to know more, read on.
For development on your local machine, at least the Node.js backend should run locally. You'll need access to the following components:
The default configuration in config.default.json
contains valid configuration for all of these.
The following instructions have been tested on Ubuntu 14.04, Windows 8.1 and Mac OS X (version unknown). Commands might differ slightly per OS.
The installation steps assume the default configuration in config.default.json. To use a different configuration, copy that file to config.json
and change what you need.
Ensure that selfsigned.blockstars.io
resolves to the IP of your development machine (e.g. by adding 127.0.0.1 selfsigned.blockstars.io
to your hosts file)
Ensure that git
and Node JS (0.10+) are installed on your system
git clone
this repository into a folder, say ~/dev/BuyCo
. As this is a private repository, make sure an SSH key or token has been configured.
git clone git@github.com:OutlierVentures/BuyCo.git
If you're using a fork of the repository, be sure to clone that and not the main repository under OutlierVentures.
Install global dependencies from npm
:
(sudo) npm install -g typescript nodemon grunt-cli tsd bower node-gyp
TODO AvA: check whether nodemon
and node-gyp
are still necessary as a global install.
Run the install script in the project root. This runs e.g. npm install
, bower install
etc.
sh ./install.sh
As the code is written in TypeScript, it has to be compiled using tsc
. A grunt
task has been included to facilitate this. The grunt task also runs less
and several other tasks.
To build the code:
grunt
The output should look something like this:
Aron@SuryaNamaskar MINGW64 /p/BuyCo/buyco (development)
$ grunt
Running "ts:build" (ts) task
Compiling...
Using tsc v1.7.5
TypeScript compilation complete: 3.92s for 94 typescript files
Running "wiredep:task" (wiredep) task
Running "injector:local_dependencies" (injector) task
Missing option `template`, using `dest` as template instead
Injecting js files (25 files)
>> Nothing changed
Running "less:development" (less) task
>> 1 stylesheet created.
Done, without errors.
Start the node server:
grunt serve
The output should look something like this:
Aron@SuryaNamaskar MINGW64 /p/BuyCo/buyco (development)
$ grunt serve
Running "concurrent:watchers" (concurrent) task
Running "ts:build" (ts) task
Running "watch" task
Running "nodemon:dev" (nodemon) task
Waiting...
[nodemon] 1.8.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node --debug launcher.js`
Debugger listening on port 5858
Using configuration from ./config.json
My configuration:
(...)
web3 initialized with provider URL: http://blockstars.io:9001
web3 coinbase: 0x7bfc1a07c41f8cb9ecb3331f51a32b0f67ed2a33
web3 coinbase balance: 510000000000000000000
web3plus initialized with contract path 'P:\BuyCo\buyco\contracts'.
Trying custom certificate.
Falling back to default self-signed certificate.
http server started on port 4123
https server started on port 4124
Open https://selfsigned.blockstars:4124 in a browser
Requests to the server are logged to the console like this:
GET / 304 6.697 ms - -
GET /vendors/bootstrap/dist/css/bootstrap.css 304 2.410 ms - -
GET /vendors/font-awesome/css/font-awesome.min.css 304 1.102 ms - -
GET /vendors/jquery/jquery.js 304 0.550 ms - -
GET /dist/app.css 200 27.554 ms - 443
The grunt serve
task includes modules to detect changes to the TypeScript files, recompile them and restarting Node on the fly. You don't need to do anything beyond starting grunt serve
.
When any .ts file is changed, a rebuild occurs, which looks like this:
>> File "client/js/app.ts" changed.
>> File "server.ts" changed.
Running "ts:build" (ts) task
Compiling...
Using tsc v1.7.5
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
TypeScript compilation complete: 1.33s for 26 typescript files
Running "watch" task
Completed in 2.180s at Tue Sep 01 2015 20:28:49 GMT+0200 (CEST) - Waiting...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
http server started on port 3123
https server started on port 3124
When developing on Windows, Visual Studio 2015 Community + Node.js Tools for Visual Studio can be a powerful toolset for developing, testing and debugging Node.js.
Just press F5 to build and start running. Place breakpoints to make the debugger stop on your code.
When working from Visual Studio, you don't need to run grunt
. NTVS takes care of most that is done in the grunt tasks (e.g. building), and that which is not is run in an after-build task (i.e. less).
However, it doesn't always work. NTVS has some performance issues which might or might not occur on your system, and these might be so serious that they make VS unusable (see NTVS GitHub issues, for example this one).
If they do, try this:
.ntvs_analysis.dat
from the project folder and open the solution again.Also, Visual Studio might crash occasionally.
The Docker installation is used for live deployment. The Docker configuration currently contains all internal components except for MongoDB. You can also use it to run the server components on your local machine, e.g. to allow for offline working.
Installation using the Docker containers is preferred for maximal portability. It consists of two images. The images haven't been added to the public Docker registry; they have to be built locally from the Dockerfile
on the machine where they will be run.
blockstars/buyco_blockchain
: Ethereum node with geth
, including the Embark framework to manage the private blockchain.blockstars/buyco_server
: Node.js backend with all dependencies to run the backend.The commands to build and run the containers have been automated in scripts in the directory docker/
. These scripts contain further comments on which commands are run and why.
In the docker/
folder:
bash ./build-blockchain.sh
bash ./build-server.sh
Building the containers can take a long time (10-30 min), because it downloads quite a lot of data, installs a lot of libraries and builds the "DAG" needed for Ethereum mining. It only has to be done once though.
The blockchain node:
bash ./run-blockchain.sh development
The Node.js server:
bash ./run-server.sh development
The bcpoc_server
connects to the blockchain node through internal Docker routing. The bcpoc_server
container should expose the web server on the port for the chosen configuration (for development
, 4124).
docker run hello-world
)docker images
)docker ps -a
)docker exec -ti [container id] bash
) When running on Windows: Docker uses a virtual Linux machine running in VirtualBox as the machine that runs the containers. This has consequences for the way you can interact with the containers.
default
VM.C:\Users
and below is made available within the Docker machine as /c/Users
. If your working folder is outside of this path, add a shared folder in the Settings of the default
VM within VirtualBox.Note AvA 2016-01-26 using Unix line endings might actually not be necessary anymore for running the Docker containers on Windows. Check again with current config.
Configure the checked out repository to use Unix Line endings:
git config core.autocrlf false
git config core.eol lf
Update the line endings of the files on disk:
git rm --cached -rf .
git reset --hard HEAD
Most tests reside under test/
but will increasingly be placed together with the code they test according to folder-by-feature.
Mocha is used as the testing framework.
Things to be aware of:
Running all tests:
npm test
Running tests in a specific folder:
npm test test/contracts/
Running a specific test file (note to refer to the .js file and not the .ts file):
npm test test/contracts/testProposals.js
In the file properties of the test, type "Mocha" under Test framework. There is no dropdown. This makes NTVS discover it.
Test discovery is executed on save of a test file and on project build.
All test cases should be listed in the Test explorer. You can run them from there.
Test code can be debugged just like normal code. Choose "Debug test" instead of "Run test" and be sure to place a breakpoint. Also be sure to increase the timeout for the test that you will debug, otherwise the test might stop early.
tsd
to search for and install TypeScript typings. These facilitate syntax completion and design-time error checking. Two separate tsd
configurations are used: /tsd.json
for the backend, /client/tsd.json
for the front end.someFunction = (req: express.Request, res: express.Response) => { ... }
) for functions that will be called by Express routes.npm
for all dependencies.bower
for all dependencies