# coinos-server Coinos is a bitcoin wallet app that supports payments over the bitcoin, liquid and lightning networks. Try it out at coinos.io. This repository contains the code for the backend API server which is implemented as a NodeJS application. The code for the frontend UI is tracked separately here (but is automatically installed & started via the Docker way outlined below). ## Install/Run (the Docker way) ### Requirements * docker and docker-compose * NodeJS (recommended version: 16) * ~7GB of hard drive space (which will go into /var/lib/docker; primarily for Liquid) ### Getting Started ```bash git clone https://github.com/coinos/coinos-server cd coinos-server cp -rf sampleconfig ./config cp .env.sample .env cp fx.sample fx docker network create net docker run -it -v $(pwd):/app --entrypoint yarn asoltys/coinos-server docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d docker exec -i mariadb mysql -u root -ppassword < db/schema.sql docker exec -it liquid elements-cli -conf=/home/elements/.elements/elements.conf sendtoaddress AzpsKhC6xE9FEK4aWAzMnbvueMLiSa5ym1xpuYogFkHzWgMHSt8B79aNNbFppQzCSQ2yZ9E4nL6RQJU7 1000000 ``` then run this and keep reference to the result for the forthcoming [Config changes] ```bash sudo base64 config/lnd/tls.cert | tr -d '\n' ``` then run this and type a password when prompted, and then 'n' to create new wallet: ```bash docker exec -it lnd lncli create ``` (optionally write down the seed as backup in case you lose the wallet and/or password) then uncomment line 12 of [config/lnd/lnd.conf] and update the [pwd file] with the new wallet password you just set. then run this and keep reference to the result again: ```bash sudo base64 config/lnd/data/chain/bitcoin/regtest/admin.macaroon | tr -d '\n' ``` then run: ```bash docker-compose down --remove-orphans ``` and start it back up again with the same command from before: ```bash docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d ``` and finally, create a Bitcoin wallet: ``` docker exec -it bitcoin bitcoin-cli -regtest -rpcuser=admin1 -rpcpassword=123 createwallet coinos ``` then [generate some BTC] to fund the server. For reviewing output, you may run `docker-compose logs` or run the docker-compose up command above but without the `-d `flag ### Setup pre-commit git hooks We have a pre-commit git hook for running prettier on all files to keep the formatting consistent. `git config core.hooksPath "./git_hooks"` - This will set the git config path to use this directory for hooks. `chmod +x ./git_hooks/pre-commit` - This will give the hook the necessary permissions to run. ### Config changes Navigate to `./config/index.js` Under `lna`, update the values for `cert` and `macaroon` with the output from the respective commands you ran in the section above. ### Wallet not found issues If your app logs complain that the wallet was not found, do the following: ```bash docker-compose exec bitcoin bash bitcoin-cli -datadir=config/ createwallet coinos exit docker exec -it lnd lncli --network=regtest --chain=bitcoin unlock ``` ### Spinning down coinos & services from the root of this repo, run: ```bash docker-compose down --remove-orphans ``` --- Note the initial `docker-compose up` step will take some time on first run as it will download all of the necessary images. After successful creation of all docker containers coinos will be available at http://localhost:8085 To shutdown coinos and all of its containers/services, run `docker-compose down --remove-orphans` again. At anypoint to purge the database and start with a new one run `rm -rf mysql` and then `mkdir mysql` and then the same steps following from that point as outlined above. Or run `purge-except-git.sh` from `./scripts` To review a log of individual containers use `docker-compose app` or `docker-compose maria` etc; container names are available in `docker-compose.yml` or via `docker-compose ps` when they are running. `docker images` will show you a list of the images installed on your system and `docker image rm [IMAGE ID]` removes them. #### Volumes and local filesystem changes The `docker-compose.yml` specifies volumes that map to the host (ie- your local machine). As per Docker's volume feature these override what is in the container's 'virtual' filesystem for those folders and instead will map to what is