From 41a5b24fafe701426db1ebf6c57b308545fe9f2f Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 11 Jan 2021 16:22:27 -0800 Subject: [PATCH] Updating README and shell script examples --- README.md | 19 +++++++----- docker/mainnet/start-local-mainnet.sh | 42 +++++++++++++++++++------- docker/testnet/start-local-testnet.sh | 43 ++++++++++++++++++++------- start-dev-example.sh | 12 ++++++-- 4 files changed, 84 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f4027dc..4649777 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # bch-api -This is a node.js JavaScript REST API server using Express.js. 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/Permissionless-Software-Foundation/bch-js) JavaScript library. +[![License](https://img.shields.io/npm/l/@psf/bch-js)](https://github.com/Permissionless-Software-Foundation/bch-js/blob/master/LICENSE.md) +[![js-standard-style](https://img.shields.io/badge/javascript-standard%20code%20style-green.svg?style=flat-square)](https://github.com/feross/standard) + +This is a node.js JavaScript REST API server using [Express.js](https://expressjs.com/). 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://psfoundation.cash/blog/cash-stack) 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/Permissionless-Software-Foundation/bch-js) JavaScript library. This repository is intended to be paired with [bch-js](https://github.com/Permissionless-Software-Foundation/bch-js), an npm JavaScript library for building Bitcoin Cash apps. @@ -20,7 +23,7 @@ The following features set this repository apart from rest.bitcoin.com: - 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). Can be used to monetize access to the REST API. - Typescript removed and ES8 JavaScript used instead. -- npm audit run on all dependencies. +- `npm audit fix` frequently run to fix dependencies. ## Live Demo You can test a live demo of the REST API by running the @@ -31,17 +34,17 @@ You can bootstrap your own REST API server by downloading and installing the inf ### Configure bch-js The live servers can be used by [bch-js](https://github.com/Permissionless-Software-Foundation/bch-js) by settings the `restURL` config property to one of these servers: -- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v3/ -- ABC Mainnet REST API server: https://abc.fullstack.cash/v3/ -- Testnet3 REST API server: https://testnet3.fullstack.cash/v3/ +- BCHN Mainnet REST API server: https://bchn.fullstack.cash/v4/ +- ABC Mainnet REST API server: https://abc.fullstack.cash/v4/ +- Testnet3 REST API server: https://testnet3.fullstack.cash/v4/ - 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 on [this page](https://troutsblog.com/research/bitcoin-cash/how-to-bch-full-stack-developer). +described on [this page](https://psfoundation.cash/blog/cash-stack). -This code targets the Ubuntu 18.04 LTS Linux OS. +This code targets the Ubuntu 18.04 LTS Linux OS or higher. ### Development This is a standard node.js project. The installation is as follows: @@ -86,7 +89,7 @@ Have questions? Need help? Join our community support ## IPFS Copies of this repository will occasionally be uploaded and hosted on [IPFS](https://ipfs.io): -- v1.15.4: QmSAerFmDJm6KQp2HC8jsRR5MdL5X39hoUsJYvWNDvrD8m +- v1.25.1: [QmXFzFJHenymhReDc9oGAxbpmvK2fJYnisQ2pJn3gGyKKX](https://ipfs.io/ipfs/QmXFzFJHenymhReDc9oGAxbpmvK2fJYnisQ2pJn3gGyKKX) ## License [MIT](./LICENSE.md) diff --git a/docker/mainnet/start-local-mainnet.sh b/docker/mainnet/start-local-mainnet.sh index b68cfb7..a526be8 100755 --- a/docker/mainnet/start-local-mainnet.sh +++ b/docker/mainnet/start-local-mainnet.sh @@ -1,21 +1,28 @@ #!/bin/bash -# test +# Docker containers for the below infrastructure is described here: +# https://psfoundation.cash/blog/cash-stack +# Pre-synced databases can be downloaded on the CashStrap page: +# https://fullstack.cash/cashstrap + +# Which network are you using? +export NETWORK=mainnet +#export NETWORK=testnet # Full node -export RPC_BASEURL=http://172.17.0.1:8332/ +export RPC_IP=172.17.0.1:8332 +export RPC_BASEURL=http://$RPC_IP/ export RPC_USERNAME=bitcoin export RPC_PASSWORD=password -export NETWORK=mainnet # SLPDB export SLPDB_URL=http://172.17.0.1:12300/ export SLPDB_PASS=somelongpassword - -# Blockbook Indexer -export BLOCKBOOK_URL=https://172.17.0.1:9131/ -# Allow node.js to make network calls to https using self-signed certificate. -export NODE_TLS_REJECT_UNAUTHORIZED=0 +# Use the same address as SLPDB_URL if you don't have a separate whitelist server. +export SLPDB_WHITELIST_URL=http://172.17.0.1:12300/ +# slp-api alternative SLP validator using slp-validate: +# https://github.com/Permissionless-Software-Foundation/slp-api +export SLP_API_URL=http://10.0.0.5:5001/ # Mainnet Fulcrum / ElectrumX export FULCRUM_URL=172.17.0.1 @@ -26,12 +33,25 @@ export REDIS_PORT=6379 export REDIS_HOST=172.17.0.1 # JWT Token Secret +# This is used to verify JWT tokens generated with jwt-bch-api: +# https://github.com/Permissionless-Software-Foundation/jwt-bch-api export TOKENSECRET=somelongsecretvalue # So that bch-api can call bch-js locally. -export LOCAL_RESTURL=http://127.0.0.1:3000/v3/ +export LOCAL_RESTURL=http://127.0.0.1:3000/v4/ -# slp-api alternative SLP validator. -export SLP_API_URL=http://10.0.0.5:5001/ +# Basic Authentication password +export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword + +# Whitelisted domains. Automatically give pro-tier rate limit access to apps +# that originate froma domain on the whitelist. +export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash + +# Rate Limits. Numbers are divided into 1000. e.g. 1000 / 50 = 20 RPM for ANON. +# Requests use the ANON rate limit if they fail to pass in a JWT token. +# ANON = 20 requests per minute (RPM) +export ANON_RATE_LIMIT=50 +# 10 = 100 RPM +export WHITELIST_RATE_LIMIT=10 npm start diff --git a/docker/testnet/start-local-testnet.sh b/docker/testnet/start-local-testnet.sh index 14fcacc..ddbcd70 100755 --- a/docker/testnet/start-local-testnet.sh +++ b/docker/testnet/start-local-testnet.sh @@ -1,22 +1,32 @@ #!/bin/bash +# Docker containers for the below infrastructure is described here: +# https://psfoundation.cash/blog/cash-stack +# Pre-synced databases can be downloaded on the CashStrap page: +# https://fullstack.cash/cashstrap + +# Which network are you using? +#export NETWORK=mainnet +export NETWORK=testnet + # Full node -export RPC_BASEURL=http://172.17.0.1:18332/ +export RPC_IP=172.17.0.1:18332 +export RPC_BASEURL=http://$RPC_IP/ export RPC_USERNAME=bitcoin export RPC_PASSWORD=password -export NETWORK=testnet # SLPDB export SLPDB_URL=http://172.17.0.1:13300/ - -# Blockbook Indexer -export BLOCKBOOK_URL=https://172.17.0.1:19131/ -# Allow node.js to make network calls to https using self-signed certificate. -export NODE_TLS_REJECT_UNAUTHORIZED=0 +export SLPDB_PASS=somelongpassword +# Use the same address as SLPDB_URL if you don't have a separate whitelist server. +export SLPDB_WHITELIST_URL=http://172.17.0.1:13300/ +# slp-api alternative SLP validator using slp-validate: +# https://github.com/Permissionless-Software-Foundation/slp-api +export SLP_API_URL=http://10.0.0.5:5001/ # Mainnet Fulcrum / ElectrumX export FULCRUM_URL=172.17.0.1 -export FULCRUM_PORT=50002 +export FULCRUM_PORT=60002 # Redis DB export REDIS_PORT=6380 @@ -26,9 +36,20 @@ export REDIS_HOST=172.17.0.1 export TOKENSECRET=somelongsecretvalue # So that bch-api can call bch-js locally. -export LOCAL_RESTURL=http://127.0.0.1:3000/v3/ +export LOCAL_RESTURL=http://127.0.0.1:3000/v4/ -# slp-api alternative SLP validator. -export SLP_API_URL=http://10.0.0.5:5001/ +# Basic Authentication password (optional) +export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword + +# Whitelisted domains. Automatically give pro-tier rate limit access to apps +# that originate froma domain on the whitelist. +export WHITELIST_DOMAINS=fullstack.cash,psfoundation.cash,torlist.cash + +# Rate Limits. Numbers are divided into 1000. e.g. 1000 / 50 = 20 RPM for ANON. +# Requests use the ANON rate limit if they fail to pass in a JWT token. +# ANON = 20 requests per minute (RPM) +export ANON_RATE_LIMIT=50 +# 10 = 100 RPM +export WHITELIST_RATE_LIMIT=10 npm start diff --git a/start-dev-example.sh b/start-dev-example.sh index c5c912d..c9bbcea 100755 --- a/start-dev-example.sh +++ b/start-dev-example.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Docker containers for the below infrastructure is described here: +# https://psfoundation.cash/blog/cash-stack +# Pre-synced databases can be downloaded on the CashStrap page: +# https://fullstack.cash/cashstrap + # Which network are you using? export NETWORK=mainnet #export NETWORK=testnet @@ -15,7 +20,6 @@ export SLPDB_URL=http://:12300/ export SLPDB_PASS=somelongpassword # Use the same address as SLPDB_URL if you don't have a separate whitelist server. export SLPDB_WHITELIST_URL=http://:12300/ - # slp-api alternative SLP validator using slp-validate: # https://github.com/Permissionless-Software-Foundation/slp-api export SLP_API_URL=http://10.0.0.5:5001/ @@ -24,13 +28,17 @@ export SLP_API_URL=http://10.0.0.5:5001/ export FULCRUM_URL=192.168.0.6 export FULCRUM_PORT=50002 +# Redis DB - Used for rate limiting - customize to your own Redis installation. +export REDIS_PORT=6379 +export REDIS_HOST=172.17.0.1 + # JWT Token Secret # This is used to verify JWT tokens generated with jwt-bch-api: # https://github.com/Permissionless-Software-Foundation/jwt-bch-api export TOKENSECRET=somelongpassword # So that bch-api can call bch-js locally. -export LOCAL_RESTURL=http://127.0.0.1:3000/v3/ +export LOCAL_RESTURL=http://127.0.0.1:3000/v4/ # Basic Authentication password export PRO_PASS=somerandomepassword:someotherrandompassword:aThirdPassword