-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2358737
Showing
82 changed files
with
36,529 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# http://editorconfig.org | ||
|
||
# A special property that should be specified at the top of the file outside of | ||
# any sections. Set to true to stop .editor config file search on current file | ||
root = true | ||
|
||
[*] | ||
# Indentation style | ||
# Possible values - tab, space | ||
indent_style = space | ||
|
||
# Indentation size in single-spaced characters | ||
# Possible values - an integer, tab | ||
indent_size = 2 | ||
|
||
# Line ending file format | ||
# Possible values - lf, crlf, cr | ||
end_of_line = lf | ||
|
||
# File character encoding | ||
# Possible values - latin1, utf-8, utf-16be, utf-16le | ||
charset = utf-8 | ||
|
||
# Denotes whether to trim whitespace at the end of lines | ||
# Possible values - true, false | ||
trim_trailing_whitespace = true | ||
|
||
# Denotes whether file should end with a newline | ||
# Possible values - true, false | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "standard", | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 10 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
node_modules/ | ||
.nyc_output/* | ||
#.env | ||
start-local-server | ||
test-local-server | ||
start-decatur-main.sh | ||
start-decatur-test.sh | ||
test-decatur-main.sh | ||
start-bitcoincom.sh | ||
test-remote-server.sh | ||
start-bitcoincom-testnet.sh | ||
start-local-server.sh | ||
start-local-testnet-server.sh | ||
start-local-mainnet.sh | ||
start-local-testnet.sh | ||
test-fullstack-main.sh | ||
start-fullstack-main.sh | ||
start-fullstack-test.sh | ||
start-free-main.sh | ||
start-local-mainnet.sh.save | ||
start-local-testnet.sh.save | ||
|
||
coverage | ||
start-my-infra | ||
dist/routes/** | ||
test-v1 | ||
nohup.out | ||
slp-tx-db/ | ||
logs/* | ||
docs/* | ||
docker/mainnet/start-local-mainnet.sh | ||
docker/testnet/start-local-testnet.sh | ||
|
||
|
||
!logs/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- "10" | ||
|
||
dist: trusty | ||
|
||
sudo: required | ||
|
||
services: | ||
- docker | ||
- redis-server | ||
|
||
#before_install: | ||
# - ./install-redis.sh | ||
|
||
script: "npm run test" | ||
|
||
after_success: | ||
- npm run coverage | ||
|
||
deploy: | ||
provider: script | ||
skip_cleanup: true | ||
script: | ||
- npx semantic-release && ./deploy-production.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Chris Troutner | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# bch-api | ||
|
||
[![Greenkeeper badge](https://badges.greenkeeper.io/christroutner/bch-api.svg)](https://greenkeeper.io/) | ||
|
||
[![Build Status](https://travis-ci.org/christroutner/bch-api.svg?branch=master)](https://travis-ci.org/christroutner/bch-api) | ||
|
||
This is a fork and alternative implementation of | ||
the [rest.bitcoin.com](https://github.com/Bitcoin-com/rest.bitcoin.com) repository. | ||
The purpose of this code is to create a REST API server that provides a common | ||
interface for working with a Bitcoin Cash full node and various indexers. See [this article](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer) to learn about the 'Cash Stack'. Visit [FullStack.cash](https://fullstack.cash), sign up for a free account, and use this REST API right away with the [bch-js](https://github.com/christroutner/bch-js) JavaScript library. | ||
|
||
This repository is intended to be paired with [bch-js](https://github.com/christroutner/bch-js), | ||
an npm JavaScript library, and an alternative implementation | ||
of [BITBOX SDK](https://github.com/Bitcoin-com/bitbox-sdk). | ||
|
||
Both bch-api and bch-js are part of the | ||
[full stack of BCH software](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer). | ||
|
||
- [API Documentation](https://api.bchjs.cash/docs/) | ||
- [BCH Example Applications](https://github.com/Permissionless-Software-Foundation/bch-js-examples) | ||
- [slp-cli-wallet](https://github.com/christroutner/slp-cli-wallet): a hacker-friendly, command-line BCH and SLP token wallet using this REST API. | ||
|
||
Have questions? Need help? Join our community support | ||
[Telegram channel](https://t.me/bch_js_toolkit) | ||
|
||
## Features | ||
The following features set this repository apart from rest.bitcoin.com: | ||
|
||
- Address balance and UTXO queries use the [Blockbook](https://github.com/trezor/blockbook) | ||
indexer instead of Insight. | ||
- Fine grain access is controlled with a JWT token using | ||
[this back end auth server](https://github.com/Permissionless-Software-Foundation/jwt-bch-api) and [this front end](https://github.com/Permissionless-Software-Foundation/jwt-bch-frontend). | ||
- Default rate limits are set to 3 RPM for anonymous connections, 10 RPM for [free accounts](https://fullstack.cash/pricing), up to 100 RPM if a full-access JWT token is used. | ||
- Typescript removed and ES8 JavaScript used instead. | ||
- npm audit run on all dependencies. | ||
- [Greenkeeper](https://greenkeeper.io/) implemented for automatic dependency management | ||
and security updates. | ||
|
||
## Live Demo | ||
You can test a live demo of the REST API by running the | ||
[bch-js examples](https://github.com/Permissionless-Software-Foundation/bch-js-examples). | ||
Rate limits are 3 requests per minute, but you can increase them to 10 with a [free account](https://fullstack.cash/pricing). | ||
This is fast enough to try out the examples | ||
but these servers are not intended as a freemium service. You can run your own | ||
REST server by purchasing the hard drive at [bchjs.cash](https://bchjs.cash). | ||
|
||
- Mainnet REST API server: https://api.fullstack.cash/v3/ | ||
- Testnet REST API server: https://tapi.fullstack.cash/v3/ | ||
- Check server status: https://metrics.fullstack.cash | ||
|
||
## Installation | ||
There are two installation paths, depending if you want a *development* or | ||
*production* environment. You'll also need to set up the underlying infrastructure | ||
described [this page](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer). | ||
|
||
This code targets the Ubuntu 18.04 LTS Linux OS. | ||
|
||
### Development | ||
This is a standard node.js project. The installation is as follows: | ||
|
||
- Clone this repository: | ||
|
||
`git clone https://github.com/christroutner/bch-api && cd bch-api` | ||
|
||
- Install dependencies: | ||
|
||
`npm install` | ||
|
||
- Customize the [start-dev-example.sh](start-dev-example.sh) shell script to | ||
point to the required infrastructure. Start the bch-api REST API by running | ||
this script: | ||
|
||
`./start-dev-example.sh` | ||
|
||
### Production | ||
For a production environment, a Docker container is provided in the | ||
[docker](docker) directory. One for mainnet and one for testnet. Again, these | ||
containers target the Ubuntu 18.04 LTS Linux OS. | ||
|
||
- Install Docker and Docker Compose by following the commands on | ||
[this Dev Ops page](https://troutsblog.com/research/dev-ops/overview). | ||
|
||
- Customize the [bash script](docker/mainnet/start-local-mainnet.sh) for your | ||
installation. | ||
|
||
- Build the Docker container with: | ||
|
||
`docker-compose build --no-cache` | ||
|
||
- Run the Docker container with: | ||
|
||
`docker-compose up` | ||
|
||
## Support | ||
Have questions? Need help? Join our community support | ||
[Telegram channel](https://t.me/bch_js_toolkit) | ||
|
||
## License | ||
[MIT](LICENSE.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
Common configuration settings. | ||
*/ | ||
|
||
const config = { | ||
apiTokenSecret: process.env.TOKENSECRET ? process.env.TOKENSECRET : 'secret-jwt-token' | ||
} | ||
|
||
module.exports = config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Triggers a webhook to update the staging server at staging.fullstack.cash. | ||
|
||
#!/bin/bash | ||
#echo $DEPLOY_SECRET | ||
|
||
echo "Deploy to production...." | ||
|
||
export DATA="{\"ref\":\"$DEPLOY_SECRET\"}" | ||
|
||
#echo $DATA | ||
|
||
curl -X POST http://fullstack.cash:9000/hooks/bch-api-mainnet -H "Content-Type: application/json" -d $DATA | ||
curl -X POST http://fullstack.cash:9000/hooks/bch-api-testnet -H "Content-Type: application/json" -d $DATA | ||
|
||
echo "...Finished deploying to production." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
COMPOSE_PROJECT_NAME=bch-api-mainnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM christroutner/ct-base-ubuntu | ||
MAINTAINER Chris Troutner <chris.troutner@gmail.com> | ||
|
||
RUN apt-get update -y | ||
|
||
#Set the working directory to be the home directory | ||
WORKDIR /home/safeuser | ||
|
||
# Switch to user account. | ||
USER safeuser | ||
# Prep 'sudo' commands. | ||
#RUN echo 'abcd8765' | sudo -S pwd | ||
|
||
# Install Redis. TODO: Make this a separate container. | ||
|
||
|
||
# Clone the repository | ||
WORKDIR /home/safeuser | ||
RUN git clone https://github.com/christroutner/bch-api | ||
WORKDIR /home/safeuser/bch-api | ||
RUN npm install | ||
|
||
# Generate documentation | ||
RUN npm run docs | ||
|
||
EXPOSE 3000 | ||
|
||
COPY start-local-mainnet.sh start-local-mainnet.sh | ||
CMD ["./start-local-mainnet.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
bch-api-main: | ||
build: . | ||
dockerfile: Dockerfile | ||
#image: bitcore | ||
container_name: bch-api-main | ||
links: | ||
- redis-main | ||
ports: | ||
- "3000:3000" | ||
volumes: | ||
- ../../logs:/home/safeuser/bch-api/logs | ||
restart: always | ||
|
||
redis-main: | ||
image: redis:latest | ||
container_name: redis-main | ||
restart: always | ||
ports: | ||
- "172.17.0.1:6379:6379" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Logs | ||
This directory holds the logs for the mainnet docker container. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
COMPOSE_PROJECT_NAME=bch-api-tesnet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM christroutner/ct-base-ubuntu | ||
MAINTAINER Chris Troutner <chris.troutner@gmail.com> | ||
|
||
RUN apt-get update -y | ||
|
||
#Set the working directory to be the home directory | ||
WORKDIR /home/safeuser | ||
|
||
# Switch to user account. | ||
USER safeuser | ||
# Prep 'sudo' commands. | ||
#RUN echo 'abcd8765' | sudo -S pwd | ||
|
||
# Clone the repository | ||
WORKDIR /home/safeuser | ||
RUN git clone https://github.com/christroutner/bch-api | ||
WORKDIR /home/safeuser/bch-api | ||
RUN npm install | ||
|
||
# Generate documentation | ||
RUN npm run docs | ||
|
||
EXPOSE 3000 | ||
|
||
COPY start-local-testnet.sh start-local-testnet.sh | ||
CMD ["./start-local-testnet.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
bch-api-test: | ||
build: . | ||
dockerfile: Dockerfile | ||
#image: bitcore | ||
container_name: bch-api-test | ||
links: | ||
- redis-test | ||
ports: | ||
- "4000:3000" | ||
volumes: | ||
- ../../logs:/home/safeuser/bch-api/logs | ||
restart: always | ||
|
||
redis-test: | ||
image: redis:latest | ||
container_name: redis-test | ||
restart: always | ||
ports: | ||
- "172.17.0.1:6380:6379" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Logs | ||
This directory holds logs. |
Oops, something went wrong.