aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 15880e7de5abc252c3dae215d83ef72fb811d630 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# coinos-server

Coinos is a bitcoin wallet app that supports payments over the <a href="https://bitcoin.org">bitcoin</a>, <a href="https://blockstream.com/liquid/">liquid</a> and <a href="http://lightning.network/">lightning</a> networks. Try it out at <a href="https://coinos.io/">coinos.io</a>.

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 <a href="https://github.com/asoltys/coinos.io">here</a> (but is automatically installed & started via the Docker way outlined below). 

## Install/Run (the Docker way)

### Requirements 

* <a href="https://docs.docker.com/get-docker/
">docker</a> and <a href="https://docs.docker.com/compose/install/">docker-compose</a>
* NodeJS (recommended version: 16)
* ~7GB of hard drive space (which will go into /var/lib/docker; primarily for Liquid)

### Getting Started

    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
    sudo base64 config/lnd/tls.cert | tr -d '\n' > cert
    sudo base64 config/lnd/data/chain/bitcoin/regtest/admin.macaroon | tr -d '\n'
    docker run -it -v $(pwd):/app --entrypoint yarn asoltys/coinos-server
    docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --remove-orphans
    docker exec -i mariadb mysql -u root -ppassword < db/schema.sql   
    docker exec -it liquid elements-cli -conf=/config/elements.conf sendtoaddress AzpsKhC6xE9FEK4aWAzMnbvueMLiSa5ym1xpuYogFkHzWgMHSt8B79aNNbFppQzCSQ2yZ9E4nL6RQJU7 1000000
    docker exec -it lnd lncli create
    docker exec -it lnd lncli --network=regtest --chain=bitcoin unlock

### Config changes
    navigate to config/index.js.
    for the lna dictionary, update the values for cert and macaroon. These values can be found in the macaroon and cert files created in the previous section in the root folder of the coinos project.

### Wallet not found issues
    If your app logs complain that the wallet was not found, do the following:
    docker-compose exec bitcoin bash
    bitcoin-cli -datadir=config/ createwallet coinos
    exit
    docker exec -it lnd lncli --network=regtest --chain=bitcoin unlock






Note the last step will take some time on first run as it will download the aforementioned docker 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` 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 <a href="https://docs.docker.com/storage/volumes/">volume feature</a> these override what is in the container's 'virtual' filesystem for those folders and instead will map to what is on your local filesystem.  As such, changes/developments that occur in these locations will be reflected without needing to restart the containers. 

Additionally <a href="https://github.com/remy/nodemon">Nodemon</a> is setup by default to watch coinos-server directory and will auto-restart the app as changes occur. 

Alternative to allowing nodemon to manage the app, you may enter bash on the docker to start/stop the node app manually ie: 

    docker exec -it app bash
    node index.js 
    # ^ starts app manually in a bash session inside the docker
    # ( reflecting your local coinos-server directory)


To prevent nodemon from starting with the container change the `package.json` `"start"` script value to: `"tail -f /dev/null"` which will then keep the container alive so you may enter an interactive bash as above to start the app manually. 

#### Debugging

To debug the node app while it is running via Docker, edit `docker-compose.yml` to add `9229` to the ports section for the `app` service: 

    ports:
      - '3119:3119'
      - '9229'

then get the IP of the app container: 

    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' app
    > 192.168.115.72 #outputs the coinos app container IP

then edit `package.json` start script to: 

    "start" : "nodemon --inspect=0.0.0.0 index.js",

(or use the interactive bash technique above with this same inspect flag)

restart with `docker-compose restart app`

then open your browser (Chrome in this example) to the URL`chrome://inspect` then click "Configure" and add the IP address + debugger port to the list of targets ex- `192.168.115.72:92229`

an inspect link will then display under 'Remote Target'!

  Note the IP address may change between restarts so you may have to rerun the docker inspect command above again to make sure you have the correct IP on following sessions. 

----

### Install/Run (standalone)

Note the Docker way outlined above is recommended as manual setup requirements/instructions shown below are out of date. 


#### Requirements

* <a href="https://github.com/bitcoin/bitcoin">bitcoind</a> with zmq support
* <a href="https://github.com/ElementsProject/elements">elementsd</a> with zmq support
* <a href="https://github.com/lightningnetwork/lnd">lnd</a> or <a href="https://github.com/elementsproject/lightning">c-lightning</a>
* a database that <a href="https://github.com/sequelize/sequelize">sequelize</a> can talk to

The bitcoind and elementsd nodes can be a pruned if you want to limit the amount of disk space used.

#### Getting Started

    git clone [email protected]:coinos/coinos-server.git
    cd coinos-server
    cp -rf sampleconfig ./config    # edit config files as necessary for your local setup
    cp .env.sample .env
    yarn
    yarn start 
    # or, alternatively
    yarn min    # to run a stripped down development version that doesn't do payments or talk to any nodes

#### Database Setup

I've only tested with <a href="https://mariadb.org/">Maria</a>. Here's a [schema](https://github.com/asoltys/coinos-server/blob/master/db/schema.sql) to get you started.

    cat db/schema.sql | mysql -u root -p